Add initial bits for Qt6 support
[carla.git] / source / modules / water / streams / MemoryInputStream.h
blob10a807e12975936a67c436aab3cf7f825f2b9cc4
1 /*
2 ==============================================================================
4 This file is part of the Water library.
5 Copyright (c) 2016 - ROLI Ltd.
6 Copyright (C) 2021-2022 Filipe Coelho <falktx@falktx.com>
8 Permission is granted to use this software under the terms of the ISC license
9 http://www.isc.org/downloads/software-support-policy/isc-license/
11 Permission to use, copy, modify, and/or distribute this software for any
12 purpose with or without fee is hereby granted, provided that the above
13 copyright notice and this permission notice appear in all copies.
15 THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
16 TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
18 OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
19 USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
21 OF THIS SOFTWARE.
23 ==============================================================================
26 #ifndef WATER_MEMORYINPUTSTREAM_H_INCLUDED
27 #define WATER_MEMORYINPUTSTREAM_H_INCLUDED
29 #include "InputStream.h"
30 #include "../memory/MemoryBlock.h"
31 #include "../memory/HeapBlock.h"
33 namespace water {
35 //==============================================================================
36 /**
37 Allows a block of data to be accessed as a stream.
39 This can either be used to refer to a shared block of memory, or can make its
40 own internal copy of the data when the MemoryInputStream is created.
42 class MemoryInputStream : public InputStream
44 public:
45 //==============================================================================
46 /** Creates a MemoryInputStream.
48 @param sourceData the block of data to use as the stream's source
49 @param sourceDataSize the number of bytes in the source data block
50 @param keepInternalCopyOfData if false, the stream will just keep a pointer to
51 the source data, so this data shouldn't be changed
52 for the lifetime of the stream; if this parameter is
53 true, the stream will make its own copy of the
54 data and use that.
56 MemoryInputStream (const void* sourceData,
57 size_t sourceDataSize,
58 bool keepInternalCopyOfData);
60 /** Creates a MemoryInputStream.
62 @param data a block of data to use as the stream's source
63 @param keepInternalCopyOfData if false, the stream will just keep a reference to
64 the source data, so this data shouldn't be changed
65 for the lifetime of the stream; if this parameter is
66 true, the stream will make its own copy of the
67 data and use that.
69 MemoryInputStream (const MemoryBlock& data,
70 bool keepInternalCopyOfData);
72 /** Destructor. */
73 ~MemoryInputStream();
75 /** Returns a pointer to the source data block from which this stream is reading. */
76 const void* getData() const noexcept { return data; }
78 /** Returns the number of bytes of source data in the block from which this stream is reading. */
79 size_t getDataSize() const noexcept { return dataSize; }
81 //==============================================================================
82 int64 getPosition() override;
83 bool setPosition (int64 pos) override;
84 int64 getTotalLength() override;
85 bool isExhausted() override;
86 int read (void* destBuffer, int maxBytesToRead) override;
88 private:
89 //==============================================================================
90 const void* data;
91 size_t dataSize, position;
92 HeapBlock<char> internalCopy;
94 void createInternalCopy();
96 CARLA_DECLARE_NON_COPYABLE (MemoryInputStream)
101 #endif // WATER_MEMORYINPUTSTREAM_H_INCLUDED