LMMS
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) 2021, 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//------------------------------------------------------------------------
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){return writeChar8 (c);}
88 bool readInt8 (int8& c){return readChar8 (c);}
89 bool writeInt8u (uint8 c){return writeUChar8 (c);}
90 bool readInt8u (uint8& c){return readUChar8 (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);
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:
172};
173
174
175//------------------------------------------------------------------------
198//------------------------------------------------------------------------
200{
201public:
203
204 void beginWrite ();
205 int32 endWrite ();
206 int32 beginRead ();
207 void endRead ();
208
209protected:
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:
233 TSize writeRaw (const void*, TSize) SMTG_OVERRIDE;
236//------------------------------------------------------------------------
237protected:
239};
240
241//------------------------------------------------------------------------
242} // namespace Steinberg
int64 sizePos
Definition fstreamer.h:211
FStreamSizeHolder(FStreamer &s)
Definition fstreamer.cpp:93
void beginWrite()
remembers position and writes 0
Definition fstreamer.cpp:98
void endRead()
jump to end of chunk
Definition fstreamer.cpp:131
int32 endWrite()
writes and returns size (since the start marker)
Definition fstreamer.cpp:105
FStreamer & stream
Definition fstreamer.h:210
int32 beginRead()
returns size
Definition fstreamer.cpp:121
Definition fstreamer.h:58
char8 * readStr8()
read a string length and string text (The return string must be deleted when use is finished)
Definition fstreamer.cpp:686
virtual TSize writeRaw(const void *, TSize)=0
Write one buffer of size.
bool writeInt32(int32)
Definition fstreamer.cpp:279
bool writeInt64(int64)
Definition fstreamer.cpp:366
bool readDouble(double &)
Definition fstreamer.cpp:504
bool readChar8(char8 &)
Definition fstreamer.cpp:152
TSize writeString8(const char8 *ptr, bool terminate=false)
a direct output function writing only one string (ascii 8bit)
Definition fstreamer.cpp:554
int16 byteOrder
Definition fstreamer.h:171
bool readInt64u(uint64 &)
Definition fstreamer.cpp:417
FStreamer(int16 byteOrder=BYTEORDER)
Definition fstreamer.cpp:140
bool writeUChar8(unsigned char)
Definition fstreamer.cpp:158
bool readInt16u(uint16 &)
Definition fstreamer.cpp:243
bool readInt32Array(int32 *array, int32 count)
Definition fstreamer.cpp:311
bool readInt16uArray(uint16 *array, int32 count)
Definition fstreamer.cpp:267
bool writeInt8u(uint8 c)
Definition fstreamer.h:89
int32 readStringUtf8(tchar *ptr, int32 maxSize)
read a UTF8 string
Definition fstreamer.cpp:615
virtual int64 seek(int64, FSeekMode)=0
Set file position for stream.
bool readInt64uArray(uint64 *array, int32 count)
Definition fstreamer.cpp:441
TSize readString8(char8 *ptr, TSize size)
a direct input function reading only one string (ascii) (ended by a or \0 or eof)
Definition fstreamer.cpp:564
bool writeInt16(int16)
Definition fstreamer.cpp:192
bool skip(uint32 bytes)
Definition fstreamer.cpp:703
bool readInt8(int8 &c)
Definition fstreamer.h:88
virtual int64 tell()=0
Return current file position.
bool writeInt16u(uint16)
Definition fstreamer.cpp:235
bool readInt32(int32 &)
Definition fstreamer.cpp:287
int32 getByteOrder() const
Definition fstreamer.h:75
bool readInt8u(uint8 &c)
Definition fstreamer.h:90
bool writeChar8(char8)
Definition fstreamer.cpp:146
bool readInt64(int64 &)
Definition fstreamer.cpp:374
bool writeInt16Array(const int16 *array, int32 count)
Definition fstreamer.cpp:213
bool writeInt64Array(const int64 *array, int32 count)
Definition fstreamer.cpp:387
virtual ~FStreamer()
Definition fstreamer.h:62
bool writeInt64u(uint64)
Definition fstreamer.cpp:409
static int32 getStr8Size(const char8 *ptr)
returns the size of a saved string
Definition fstreamer.cpp:680
bool writeStringUtf8(const tchar *ptr)
always terminated, converts to utf8 if non ascii characters are in string
Definition fstreamer.cpp:588
bool writeInt32uArray(const uint32 *array, int32 count)
Definition fstreamer.cpp:343
bool readInt16(int16 &)
Definition fstreamer.cpp:200
bool readInt32uArray(uint32 *array, int32 count)
Definition fstreamer.cpp:354
bool readInt64Array(int64 *array, int32 count)
Definition fstreamer.cpp:398
bool writeInt32u(uint32)
Definition fstreamer.cpp:322
bool writeBool(bool)
Write one boolean.
Definition fstreamer.cpp:548
bool readChar16(char16 &c)
Definition fstreamer.cpp:178
void setByteOrder(int32 e)
Definition fstreamer.h:74
bool readUChar8(unsigned char &)
Definition fstreamer.cpp:164
bool readFloatArray(float *array, int32 count)
Definition fstreamer.cpp:485
bool writeInt64uArray(const uint64 *array, int32 count)
Definition fstreamer.cpp:430
bool pad(uint32 bytes)
Definition fstreamer.cpp:715
bool writeFloatArray(const float *array, int32 count)
Definition fstreamer.cpp:474
bool readFloat(float &)
Definition fstreamer.cpp:461
bool readInt32u(uint32 &)
Definition fstreamer.cpp:330
bool readInt16Array(int16 *array, int32 count)
Definition fstreamer.cpp:224
bool writeChar16(char16 c)
Definition fstreamer.cpp:170
bool writeInt8(int8 c)
Definition fstreamer.h:87
virtual TSize readRaw(void *, TSize)=0
Read one buffer of size.
bool writeInt16uArray(const uint16 *array, int32 count)
Definition fstreamer.cpp:256
bool writeDouble(double)
Definition fstreamer.cpp:496
bool writeFloat(float)
Definition fstreamer.cpp:453
bool writeStr8(const char8 *ptr)
write a string length (strlen) and string itself
Definition fstreamer.cpp:667
bool readBool(bool &)
Read one bool.
Definition fstreamer.cpp:539
bool readDoubleArray(double *array, int32 count)
Definition fstreamer.cpp:528
bool writeDoubleArray(const double *array, int32 count)
Definition fstreamer.cpp:517
bool writeInt32Array(const int32 *array, int32 count)
Definition fstreamer.cpp:300
Definition ibstream.h:30
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
IBStream * stream
Definition fstreamer.h:238
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
IBStreamer(IBStream *stream, int16 byteOrder=BYTEORDER)
Definition fstreamer.cpp:53
* e
Definition inflate.c:1404
unsigned s
Definition inflate.c:1555
#define SMTG_OVERRIDE
Definition fplatform.h:241
Definition baseiids.cpp:43
unsigned long long uint64
Definition ftypes.h:67
short int16
Definition ftypes.h:43
int16 char16
Definition ftypes.h:101
int int32
Definition ftypes.h:50
int64 TSize
Definition ftypes.h:75
char char8
Definition ftypes.h:93
unsigned short uint16
Definition ftypes.h:44
char int8
Definition ftypes.h:39
long long int64
Definition ftypes.h:66
char16 tchar
Definition ftypes.h:105
FSeekMode
Definition fstreamer.h:46
@ kSeekSet
Definition fstreamer.h:47
@ kSeekEnd
Definition fstreamer.h:49
@ kSeekCurrent
Definition fstreamer.h:48
unsigned char uint8
Definition ftypes.h:40
unsigned int uint32
Definition ftypes.h:51
return c
Definition crypt.c:175
ulg size
Definition extract.c:2350
_WDL_CSTRING_PREFIX void INT_PTR count
Definition wdlcstring.h:263