OpenShot Library | OpenShotAudio 0.2.2
juce_MemoryInputStream.h
1
2/** @weakgroup juce_core-streams
3 * @{
4 */
5/*
6 ==============================================================================
7
8 This file is part of the JUCE library.
9 Copyright (c) 2017 - ROLI Ltd.
10
11 JUCE is an open source library subject to commercial or open-source
12 licensing.
13
14 The code included in this file is provided under the terms of the ISC license
15 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16 To use, copy, modify, and/or distribute this software for any purpose with or
17 without fee is hereby granted provided that the above copyright notice and
18 this permission notice appear in all copies.
19
20 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22 DISCLAIMED.
23
24 ==============================================================================
25*/
26
27namespace juce
28{
29
30//==============================================================================
31/**
32 Allows a block of data to be accessed as a stream.
33
34 This can either be used to refer to a shared block of memory, or can make its
35 own internal copy of the data when the MemoryInputStream is created.
36
37 @tags{Core}
38*/
40{
41public:
42 //==============================================================================
43 /** Creates a MemoryInputStream.
44
45 @param sourceData the block of data to use as the stream's source
46 @param sourceDataSize the number of bytes in the source data block
47 @param keepInternalCopyOfData if false, the stream will just keep a pointer to
48 the source data, so this data shouldn't be changed
49 for the lifetime of the stream; if this parameter is
50 true, the stream will make its own copy of the
51 data and use that.
52 */
53 MemoryInputStream (const void* sourceData,
54 size_t sourceDataSize,
55 bool keepInternalCopyOfData);
56
57 /** Creates a MemoryInputStream.
58
59 @param data a block of data to use as the stream's source
60 @param keepInternalCopyOfData if false, the stream will just keep a reference to
61 the source data, so this data shouldn't be changed
62 for the lifetime of the stream; if this parameter is
63 true, the stream will make its own copy of the
64 data and use that.
65 */
66 MemoryInputStream (const MemoryBlock& data,
67 bool keepInternalCopyOfData);
68
69 /** Creates a stream by moving from a MemoryBlock. */
70 MemoryInputStream (MemoryBlock&& blockToTake);
71
72 /** Destructor. */
73 ~MemoryInputStream() override;
74
75 /** Returns a pointer to the source data block from which this stream is reading. */
76 const void* getData() const noexcept { return data; }
77
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; }
80
81 //==============================================================================
82 int64 getPosition() override;
83 bool setPosition (int64) override;
84 int64 getTotalLength() override;
85 bool isExhausted() override;
86 int read (void* destBuffer, int maxBytesToRead) override;
87 void skipNextBytes (int64 numBytesToSkip) override;
88
89private:
90 //==============================================================================
91 const void* data;
92 size_t dataSize, position = 0;
93 MemoryBlock internalCopy;
94
95 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MemoryInputStream)
96};
97
98} // namespace juce
99
100/** @}*/
The base class for streams that read data.
A class to hold a resizable block of raw data.
Allows a block of data to be accessed as a stream.
size_t getDataSize() const noexcept
Returns the number of bytes of source data in the block from which this stream is reading.
const void * getData() const noexcept
Returns a pointer to the source data block from which this stream is reading.
#define JUCE_API
This macro is added to all JUCE public class declarations.