JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
fstreamer.h
Go to the documentation of this file.
1 //------------------------------------------------------------------------
2// Project : SDK Base
3// Version : 1.0
4//
5// Category : Helpers
6// Filename : base/source/fstreamer.h
7// Created by : Steinberg, 12/2005
8// Description : Extract of typed stream i/o methods from FStream
9//
10//-----------------------------------------------------------------------------
11// LICENSE
12// (c) 2023, Steinberg Media Technologies GmbH, All Rights Reserved
13//-----------------------------------------------------------------------------
14// Redistribution and use in source and binary forms, with or without modification,
15// are permitted provided that the following conditions are met:
16//
17// * Redistributions of source code must retain the above copyright notice,
18// this list of conditions and the following disclaimer.
19// * Redistributions in binary form must reproduce the above copyright notice,
20// this list of conditions and the following disclaimer in the documentation
21// and/or other materials provided with the distribution.
22// * Neither the name of the Steinberg Media Technologies nor the names of its
23// contributors may be used to endorse or promote products derived from this
24// software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
27// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
34// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
35// OF THE POSSIBILITY OF SUCH DAMAGE.
36//-----------------------------------------------------------------------------
37
38#pragma once
39
41
42namespace Steinberg {
43
44//------------------------------------------------------------------------
45enum FSeekMode
46{
47 kSeekSet,
48 kSeekCurrent,
49 kSeekEnd
50};
51
52//------------------------------------------------------------------------
53// FStreamer
54//------------------------------------------------------------------------
56//------------------------------------------------------------------------
58{
59public:
60//------------------------------------------------------------------------
61 FStreamer (int16 byteOrder = BYTEORDER);
62 virtual ~FStreamer () {}
63
66 virtual TSize readRaw (void*, TSize) = 0;
67 virtual TSize writeRaw (const void*, TSize) = 0;
68 virtual int64 seek (int64, FSeekMode) = 0;
69 virtual int64 tell () = 0;
71
74 inline void setByteOrder (int32 e) { byteOrder = (int16)e; }
75 inline int32 getByteOrder () const { return byteOrder; }
77
80 bool writeChar8 (char8);
81 bool readChar8 (char8&);
82 bool writeUChar8 (unsigned char);
83 bool readUChar8 (unsigned char&);
84 bool writeChar16 (char16 c);
85 bool readChar16 (char16& c);
86
87 bool writeInt8 (int8 c);
88 bool readInt8 (int8& c);
89 bool writeInt8u (uint8 c);
90 bool readInt8u (uint8& c);
92
95 bool writeInt16 (int16);
96 bool readInt16 (int16&);
97 bool writeInt16Array (const int16* array, int32 count);
98 bool readInt16Array (int16* array, int32 count);
99 bool writeInt16u (uint16);
100 bool readInt16u (uint16&);
101 bool writeInt16uArray (const uint16* array, int32 count);
102 bool readInt16uArray (uint16* array, int32 count);
104
107 bool writeInt32 (int32);
108 bool readInt32 (int32&);
109 bool writeInt32Array (const int32* array, int32 count);
110 bool readInt32Array (int32* array, int32 count);
111 bool writeInt32u (uint32);
112 bool readInt32u (uint32&);
113 bool writeInt32uArray (const uint32* array, int32 count);
114 bool readInt32uArray (uint32* array, int32 count);
116
119 bool writeInt64 (int64);
120 bool readInt64 (int64&);
121 bool writeInt64Array (const int64* array, int32 count);
122 bool readInt64Array (int64* array, int32 count);
123 bool writeInt64u (uint64);
124 bool readInt64u (uint64&);
125 bool writeInt64uArray (const uint64* array, int32 count);
126 bool readInt64uArray (uint64* array, int32 count);
128
131 bool writeFloat (float);
132 bool readFloat (float&);
133 bool writeFloatArray (const float* array, int32 count);
134 bool readFloatArray (float* array, int32 count);
136
139 bool writeDouble (double);
140 bool readDouble (double&);
141 bool writeDoubleArray (const double* array, int32 count);
142 bool readDoubleArray (double* array, int32 count);
144
147 bool writeBool (bool);
148 bool readBool (bool&);
150
153 TSize writeString8 (const char8* ptr, bool terminate = false);
154 TSize readString8 (char8* ptr, TSize size);
155
156 bool writeStr8 (const char8* ptr);
157 char8* readStr8 ();
158
159 static int32 getStr8Size (const char8* ptr);
160
161 bool writeStringUtf8 (const tchar* ptr);
162 int32 readStringUtf8 (tchar* ptr, int32 maxSize);
164
165 bool skip (uint32 bytes);
166 bool pad (uint32 bytes);
167
168
169//------------------------------------------------------------------------
170protected:
171 int16 byteOrder;
172};
173
174
175//------------------------------------------------------------------------
198//------------------------------------------------------------------------
200{
201public:
203
204 void beginWrite ();
205 int32 endWrite ();
206 int32 beginRead ();
207 void endRead ();
208
209protected:
210 FStreamer &stream;
211 int64 sizePos;
212};
213
214class IBStream;
215
216//------------------------------------------------------------------------
217// IBStreamer
218//------------------------------------------------------------------------
221//------------------------------------------------------------------------
223{
224public:
225//------------------------------------------------------------------------
227 IBStreamer (IBStream* stream, int16 byteOrder = BYTEORDER);
228
229 IBStream* getStream () { return stream; }
230
231 // FStreamer overrides:
232 TSize readRaw (void*, TSize) SMTG_OVERRIDE;
233 TSize writeRaw (const void*, TSize) SMTG_OVERRIDE;
234 int64 seek (int64, FSeekMode) SMTG_OVERRIDE;
235 int64 tell () SMTG_OVERRIDE;
236//------------------------------------------------------------------------
237protected:
238 IBStream* stream;
239};
240
241//------------------------------------------------------------------------
242} // namespace Steinberg
FStreamSizeHolder Declaration remembers size of stream chunk for backward compatibility.
Definition fstreamer.h:200
void beginWrite()
remembers position and writes 0
Definition fstreamer.cpp:98
void endRead()
jump to end of chunk
int32 endWrite()
writes and returns size (since the start marker)
int32 beginRead()
returns size
Byteorder-aware base class for typed stream i/o.
Definition fstreamer.h:58
char8 * readStr8()
read a string length and string text (The return string must be deleted when use is finished)
virtual TSize writeRaw(const void *, TSize)=0
Write one buffer of size.
TSize writeString8(const char8 *ptr, bool terminate=false)
a direct output function writing only one string (ascii 8bit)
int32 readStringUtf8(tchar *ptr, int32 maxSize)
read a UTF8 string
virtual int64 seek(int64, FSeekMode)=0
Set file position for stream.
TSize readString8(char8 *ptr, TSize size)
a direct input function reading only one string (ascii) (ended by a or \0 or eof)
virtual int64 tell()=0
Return current file position.
static int32 getStr8Size(const char8 *ptr)
returns the size of a saved string
bool writeStringUtf8(const tchar *ptr)
always terminated, converts to utf8 if non ascii characters are in string
bool writeBool(bool)
Write one boolean.
virtual TSize readRaw(void *, TSize)=0
Read one buffer of size.
bool writeStr8(const char8 *ptr)
write a string length (strlen) and string itself
bool readBool(bool &)
Read one bool.
Base class for streams.
Definition ibstream.h:30
Wrapper class for typed reading/writing from or to IBStream.
Definition fstreamer.h:223
IBStream * getStream()
Returns the associated IBStream.
Definition fstreamer.h:229
int64 tell() SMTG_OVERRIDE
Return current file position.
Definition fstreamer.cpp:83
TSize writeRaw(const void *, TSize) SMTG_OVERRIDE
Write one buffer of size.
Definition fstreamer.cpp:67
TSize readRaw(void *, TSize) SMTG_OVERRIDE
Read one buffer of size.
Definition fstreamer.cpp:59
int64 seek(int64, FSeekMode) SMTG_OVERRIDE
Set file position for stream.
Definition fstreamer.cpp:75