OpenShot Library | libopenshot-audio  0.2.0
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 
27 namespace 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 {
41 public:
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  /** Destructor. */
70  ~MemoryInputStream() override;
71 
72  /** Returns a pointer to the source data block from which this stream is reading. */
73  const void* getData() const noexcept { return data; }
74 
75  /** Returns the number of bytes of source data in the block from which this stream is reading. */
76  size_t getDataSize() const noexcept { return dataSize; }
77 
78  //==============================================================================
79  int64 getPosition() override;
80  bool setPosition (int64) override;
81  int64 getTotalLength() override;
82  bool isExhausted() override;
83  int read (void* destBuffer, int maxBytesToRead) override;
84  void skipNextBytes (int64 numBytesToSkip) override;
85 
86 private:
87  //==============================================================================
88  const void* data;
89  size_t dataSize, position = 0;
90  HeapBlock<char> internalCopy;
91 
92  void createInternalCopy();
93 
94  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MemoryInputStream)
95 };
96 
97 } // namespace juce
98 
99 /** @}*/
juce::HeapBlock< char >
juce::MemoryInputStream::getData
const void * getData() const noexcept
Returns a pointer to the source data block from which this stream is reading.
Definition: juce_MemoryInputStream.h:73
juce::InputStream
The base class for streams that read data.
Definition: juce_InputStream.h:40
JUCE_API
#define JUCE_API
This macro is added to all JUCE public class declarations.
Definition: juce_StandardHeader.h:143
juce::MemoryInputStream::getDataSize
size_t getDataSize() const noexcept
Returns the number of bytes of source data in the block from which this stream is reading.
Definition: juce_MemoryInputStream.h:76
juce::MemoryInputStream
Allows a block of data to be accessed as a stream.
Definition: juce_MemoryInputStream.h:39
juce::MemoryBlock
A class to hold a resizable block of raw data.
Definition: juce_MemoryBlock.h:36