Audacity 3.2.0
lib-vst3/memorystream.h
Go to the documentation of this file.
1//-----------------------------------------------------------------------------
2// Project : SDK Core
3//
4// Category : Common Classes
5// Filename : public.sdk/source/common/memorystream.h
6// Created by : Steinberg, 03/2008
7// Description : IBStream Implementation for memory blocks
8//
9//-----------------------------------------------------------------------------
10// LICENSE
11// (c) 2021, Steinberg Media Technologies GmbH, All Rights Reserved
12//-----------------------------------------------------------------------------
13// Redistribution and use in source and binary forms, with or without modification,
14// are permitted provided that the following conditions are met:
15//
16// * Redistributions of source code must retain the above copyright notice,
17// this list of conditions and the following disclaimer.
18// * Redistributions in binary form must reproduce the above copyright notice,
19// this list of conditions and the following disclaimer in the documentation
20// and/or other materials provided with the distribution.
21// * Neither the name of the Steinberg Media Technologies nor the names of its
22// contributors may be used to endorse or promote products derived from this
23// software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
26// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
29// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
34// OF THE POSSIBILITY OF SUCH DAMAGE.
35//-----------------------------------------------------------------------------
36
37#pragma once
38
39#include "pluginterfaces/base/ibstream.h"
40
41namespace Steinberg {
42
43//------------------------------------------------------------------------
47class MemoryStream : public IBStream
48{
49public:
50 //------------------------------------------------------------------------
51 MemoryStream ();
52 MemoryStream (void* memory, TSize memorySize);
53 virtual ~MemoryStream ();
54
55 //---IBStream---------------------------------------
56 tresult PLUGIN_API read (void* buffer, int32 numBytes, int32* numBytesRead) SMTG_OVERRIDE;
57 tresult PLUGIN_API write (void* buffer, int32 numBytes, int32* numBytesWritten) SMTG_OVERRIDE;
58 tresult PLUGIN_API seek (int64 pos, int32 mode, int64* result) SMTG_OVERRIDE;
59 tresult PLUGIN_API tell (int64* pos) SMTG_OVERRIDE;
60
61 TSize getSize () const;
62 void setSize (TSize size);
63 char* getData () const;
64 char* detachData ();
65 bool truncate ();
66 bool truncateToCursor ();
67
68 //------------------------------------------------------------------------
69 DECLARE_FUNKNOWN_METHODS
70protected:
71 char* memory; // memory block
72 TSize memorySize; // size of the memory block
73 TSize size; // size of the stream
74 int64 cursor; // stream pointer
75 bool ownMemory; // stream has allocated memory itself
76 bool allocationError; // stream invalid
77};
78
79} // namespace
void setSize(TSize size)
set the memory size, a realloc will occur if memory already used
char * detachData()
returns the memory pointer and give up ownership
tresult PLUGIN_API tell(int64 *pos) SMTG_OVERRIDE
tresult PLUGIN_API read(void *buffer, int32 numBytes, int32 *numBytesRead) SMTG_OVERRIDE
TSize getSize() const
returns the current memory size
char * getData() const
returns the memory pointer
tresult PLUGIN_API seek(int64 pos, int32 mode, int64 *result) SMTG_OVERRIDE
bool truncate()
realloc to the current use memory size if needed
bool truncateToCursor()
truncate memory at current cursor position
tresult PLUGIN_API write(void *buffer, int32 numBytes, int32 *numBytesWritten) SMTG_OVERRIDE