Cinder  0.8.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Stream.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010, The Barbarian Group
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without modification, are permitted provided that
6  the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and
9  the following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
11  the following disclaimer in the documentation and/or other materials provided with the distribution.
12 
13  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
14  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
15  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
16  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
17  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
19  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
20  POSSIBILITY OF SUCH DAMAGE.
21 */
22 
23 #pragma once
24 
25 #include "cinder/Cinder.h"
26 #include "cinder/Buffer.h"
27 #include "cinder/Exception.h"
28 #include "cinder/Filesystem.h"
29 
30 #include <boost/noncopyable.hpp>
31 
32 #include <string>
33 #ifndef __OBJC__
34 # include <boost/iostreams/concepts.hpp>
35 # include <boost/iostreams/stream.hpp>
36 #endif
37 
38 namespace cinder {
39 
40 class StreamBase : private boost::noncopyable {
41  public:
42  virtual ~StreamBase() {}
43 
45 
47  static uint8_t getNativeEndianness()
48  {
49 #ifdef CINDER_LITTLE_ENDIAN
50  return STREAM_LITTLE_ENDIAN;
51 #else
52  return STREAM_BIG_ENDIAN;
53 #endif
54  }
55 
57  const fs::path& getFileName() const { return mFileName; }
59  void setFileName( const fs::path &aFileName ) { mFileName = aFileName; }
60 
62  bool getDeleteOnDestroy() const { return mDeleteOnDestroy; }
64  void setDeleteOnDestroy( bool enable = true ) { mDeleteOnDestroy = enable; }
65 
67  virtual off_t tell() const = 0;
68 
70  virtual void seekAbsolute( off_t absoluteOffset ) = 0;
71 
73  virtual void seekRelative( off_t relativeOffset ) = 0;
74 
75  protected:
76  StreamBase() : mDeleteOnDestroy( false ) {}
77 
78  fs::path mFileName;
80 };
81 
82 class OStream : public virtual StreamBase {
83  public:
84  virtual ~OStream() {}
85 
87  void write( const std::string &s ) { writeData( s.c_str(), s.length() + 1 ); }
88  template<typename T>
89  void write( T t ) { IOWrite( &t, sizeof(T) ); }
90  template<typename T>
91  void writeEndian( T t, uint8_t endian ) { if ( endian == STREAM_BIG_ENDIAN ) writeBig( t ); else writeLittle( t ); }
92  template<typename T>
93  void writeBig( T t );
94  template<typename T>
95  void writeLittle( T t );
96 
97  void write( const Buffer &buffer );
98  void writeData( const void *src, size_t size );
99 
100  protected:
102 
103  virtual void IOWrite( const void *t, size_t size ) = 0;
104 };
105 
106 
107 typedef std::shared_ptr<class OStream> OStreamRef;
108 
109 class IStreamCinder : public virtual StreamBase {
110  public:
111  virtual ~IStreamCinder() {};
112 
113  template<typename T>
114  void read( T *t ) { IORead( t, sizeof(T) ); }
115  template<typename T>
116  void readEndian( T *t, uint8_t endian ) { if ( endian == STREAM_BIG_ENDIAN ) readBig( t ); else readLittle( t ); }
117  template<typename T>
118  void readBig( T *t );
119  template<typename T>
120  void readLittle( T *t );
121 
123  void read( std::string *s );
124  void read( fs::path *p );
125  void readFixedString( char *t, size_t maxSize, bool nullTerminate );
126  void readFixedString( std::string *t, size_t size );
128 
129  void readData( void *dest, size_t size );
130  virtual size_t readDataAvailable( void *dest, size_t maxSize ) = 0;
131 
132  virtual off_t size() const = 0;
133  virtual bool isEof() const = 0;
134 
135  protected:
137 
138  virtual void IORead( void *t, size_t size ) = 0;
139 
140  static const int MINIMUM_BUFFER_SIZE = 8; // minimum bytes of random access a stream must offer relative to the file start
141 };
142 typedef std::shared_ptr<IStreamCinder> IStreamRef;
143 
144 
145 class IoStream : public IStreamCinder, public OStream {
146  public:
148  virtual ~IoStream() {}
149 };
150 typedef std::shared_ptr<IoStream> IoStreamRef;
151 
152 
153 typedef std::shared_ptr<class IStreamFile> IStreamFileRef;
154 
155 class IStreamFile : public IStreamCinder {
156  public:
158  static IStreamFileRef create( FILE *file, bool ownsFile = true, int32_t defaultBufferSize = 2048 );
159  ~IStreamFile();
160 
161  size_t readDataAvailable( void *dest, size_t maxSize );
162 
163  void seekAbsolute( off_t absoluteOffset );
164  void seekRelative( off_t relativeOffset );
165  off_t tell() const;
166  off_t size() const;
167 
168  bool isEof() const;
169 
170  FILE* getFILE() { return mFile; }
171 
172  protected:
173  IStreamFile( FILE *aFile, bool aOwnsFile = true, int32_t aDefaultBufferSize = 2048 );
174 
175  virtual void IORead( void *t, size_t size );
176  size_t readDataImpl( void *dest, size_t maxSize );
177 
178  FILE *mFile;
179  bool mOwnsFile;
181  std::shared_ptr<uint8_t> mBuffer;
182  off_t mBufferOffset; // actual offset to do IO from; incremented by IO
183  off_t mBufferFileOffset; // beginning of the buffer in the file
184  mutable off_t mSize;
185  mutable bool mSizeCached;
186 };
187 
188 
189 typedef std::shared_ptr<class OStreamFile> OStreamFileRef;
190 
191 class OStreamFile : public OStream {
192  public:
194  static OStreamFileRef create( FILE *file, bool ownsFile = true );
195  ~OStreamFile();
196 
197  virtual off_t tell() const;
198  virtual void seekAbsolute( off_t absoluteOffset );
199  virtual void seekRelative( off_t relativeOffset );
200 
201  FILE* getFILE() { return mFile; }
202 
203 
204  protected:
205  OStreamFile( FILE *aFile, bool aOwnsFile = true );
206 
207  virtual void IOWrite( const void *t, size_t size );
208 
209  FILE* mFile;
210  bool mOwnsFile;
211 };
212 
213 
214 typedef std::shared_ptr<class IoStreamFile> IoStreamFileRef;
215 
216 class IoStreamFile : public IoStream {
217  public:
219  static IoStreamFileRef create( FILE *file, bool ownsFile = true, int32_t defaultBufferSize = 2048 );
220  ~IoStreamFile();
221 
222  size_t readDataAvailable( void *dest, size_t maxSize );
223 
224  void seekAbsolute( off_t absoluteOffset );
225  void seekRelative( off_t relativeOffset );
226  off_t tell() const;
227  off_t size() const;
228 
229  bool isEof() const;
230 
231  FILE* getFILE() { return mFile; }
232 
233  protected:
234  IoStreamFile( FILE *aFile, bool aOwnsFile = true, int32_t aDefaultBufferSize = 2048 );
235 
236  virtual void IORead( void *t, size_t size );
237  size_t readDataImpl( void *dest, size_t maxSize );
238  virtual void IOWrite( const void *t, size_t size );
239 
240  FILE *mFile;
241  bool mOwnsFile;
243  std::shared_ptr<uint8_t> mBuffer;
244  off_t mBufferOffset; // actual offset to do IO from; incremented by IO
245  off_t mBufferFileOffset; // beginning of the buffer in the file
246  mutable off_t mSize;
247  mutable bool mSizeCached;
248 };
249 
250 
251 typedef std::shared_ptr<class IStreamMem> IStreamMemRef;
252 class IStreamMem : public IStreamCinder {
253  public:
255  static IStreamMemRef create( const void *data, size_t size );
256  ~IStreamMem();
257 
258  size_t readDataAvailable( void *dest, size_t maxSize );
259 
260  void seekAbsolute( off_t absoluteOffset );
261  void seekRelative( off_t relativeOffset );
263  off_t tell() const;
265  off_t size() const { return static_cast<off_t>( mDataSize ); }
266 
268  bool isEof() const;
269 
271  const void* getData() { return reinterpret_cast<const void*>( mData ); }
272 
273  protected:
274  IStreamMem( const void *aData, size_t aDataSize );
275 
276  virtual void IORead( void *t, size_t size );
277 
278  const uint8_t *mData;
279  size_t mDataSize;
280  size_t mOffset;
281 };
282 
283 
284 typedef std::shared_ptr<class OStreamMem> OStreamMemRef;
285 
286 class OStreamMem : public OStream {
287  public:
288  static OStreamMemRef create( size_t bufferSizeHint = 4096 ) { return std::shared_ptr<OStreamMem>( new OStreamMem( bufferSizeHint ) ); }
289 
290  ~OStreamMem();
291 
292  virtual off_t tell() const { return static_cast<off_t>( mOffset ); }
293  virtual void seekAbsolute( off_t absoluteOffset );
294  virtual void seekRelative( off_t relativeOffset );
295 
296  void* getBuffer() { return mBuffer; }
297 
298  protected:
299  OStreamMem( size_t bufferSizeHint );
300 
301  virtual void IOWrite( const void *t, size_t size );
302 
303  void* mBuffer;
304  size_t mDataSize;
305  size_t mOffset;
306 };
307 
308 
309 // This class is a utility to save and restore a stream's state
311  public:
312  IStreamStateRestore( IStreamCinder &aStream ) : mStream( aStream ), mOffset( aStream.tell() ) {}
314  {
315  mStream.seekAbsolute( mOffset );
316  }
317 
318  private:
319  IStreamCinder& mStream;
320  off_t mOffset;
321 };
322 
324 IStreamFileRef loadFileStream( const fs::path &path );
326 OStreamFileRef writeFileStream( const fs::path &path, bool createParents = true );
328 IoStreamFileRef readWriteFileStream( const fs::path &path );
329 
331 void loadStreamMemory( IStreamRef is, std::shared_ptr<uint8_t> *resultData, size_t *resultDataSize );
334 
335 
336 // Stream exception
337 class StreamExc : public Exception {
338 };
339 
341 };
342 
343 #ifndef __OBJC__
345  public:
346  typedef char char_type;
347  typedef boost::iostreams::source_tag category;
348 
350 
351  std::streamsize read( char *s, std::streamsize n )
352  {
353  if( mStream->isEof() )
354  return -1;
355 
356  return (std::streamsize)mStream->readDataAvailable( s, (size_t)n );
357  }
358 
359  protected:
360  IStreamRef mStream; // a little kludgy but this is for convenience
361 };
362 
363 typedef boost::iostreams::stream<cinder_stream_source> cinder_istream;
364 
366  public:
367  typedef char char_type;
368  typedef boost::iostreams::sink_tag category;
369 
370  cinder_stream_sink( OStreamRef aStream ) : mStream( aStream ) {}
371 
372  std::streamsize write( const char *s, std::streamsize n )
373  {
374  mStream->writeData( s, (size_t)n );
375  return n;
376  }
377 
378  protected:
380 };
381 
382 typedef boost::iostreams::stream<cinder_stream_sink> cinder_ostream;
383 
385  public:
386  typedef char char_type;
387  typedef boost::iostreams::seekable_device_tag category;
388 
390 
391  std::streamsize read( char *s, std::streamsize n )
392  {
393  return static_cast<std::streamsize>( mStream->readDataAvailable( s, (size_t)n ) );
394  }
395 
396  std::streamsize write( const char *s, std::streamsize n )
397  {
398  mStream->writeData( s, (size_t)n );
399  return n;
400  }
401 
402  boost::iostreams::stream_offset seek( boost::iostreams::stream_offset off, std::ios_base::seekdir way)
403  {
404  if( way == std::ios_base::beg ) {
405  mStream->seekAbsolute( (off_t)off );
406  }
407  else if( way == std::ios_base::cur ) {
408  mStream->seekRelative( (off_t)off );
409  }
410  else { // way == std::ios_base::end
411  mStream->seekAbsolute( -(off_t)off );
412  }
413  return mStream->tell();
414  }
415 
416  protected:
418 };
419 
420 typedef boost::iostreams::stream<cinder_stream_bidirectional_device> cinder_iostream;
421 
422 #endif // ! __OBJC__
423 
424 } // namespace cinder
void seekRelative(off_t relativeOffset)
Moves the current position of the stream by relativeOffset bytes.
Definition: Stream.cpp:227
off_t tell() const
Returns the current position of the stream measured in bytes **/.
Definition: Stream.cpp:354
Definition: Stream.h:310
virtual void seekAbsolute(off_t absoluteOffset)
Sets the current position of the stream to byte absoluteOffset. A negative offset is relative to the ...
Definition: Stream.cpp:289
virtual void IOWrite(const void *t, size_t size)
Definition: Stream.cpp:515
void seekRelative(off_t relativeOffset)
Moves the current position of the stream by relativeOffset bytes.
Definition: Stream.cpp:347
std::streamsize write(const char *s, std::streamsize n)
Definition: Stream.h:396
IStreamMem(const void *aData, size_t aDataSize)
Definition: Stream.cpp:427
FILE * mFile
Definition: Stream.h:240
~IStreamFile()
Definition: Stream.cpp:176
std::shared_ptr< class IStreamFile > IStreamFileRef
Definition: Stream.h:153
~OStreamMem()
Definition: Stream.cpp:495
size_t readDataAvailable(void *dest, size_t maxSize)
Definition: Stream.cpp:333
void enable(GLenum state)
Enables the OpenGL State state. Equivalent to calling to glEnable( state );.
Definition: dx.h:198
void seekAbsolute(off_t absoluteOffset)
Sets the current position of the stream to byte absoluteOffset. A negative offset is relative to the ...
Definition: Stream.cpp:218
void readEndian(T *t, uint8_t endian)
Definition: Stream.h:116
size_t readDataAvailable(void *dest, size_t maxSize)
Definition: Stream.cpp:184
std::streamsize write(const char *s, std::streamsize n)
Definition: Stream.h:372
static IStreamFileRef create(FILE *file, bool ownsFile=true, int32_t defaultBufferSize=2048)
Creates a new IStreamFileRef from a C-style file pointer FILE as returned by fopen(). If ownsFile the returned stream will destroy the stream upon its own destruction.
Definition: Stream.cpp:162
virtual void IOWrite(const void *t, size_t size)
Definition: Stream.cpp:302
size_t mOffset
Definition: Stream.h:305
GLsizei const GLchar ** string
Definition: GLee.h:2427
int32_t mBufferSize
Definition: Stream.h:242
std::shared_ptr< uint8_t > mBuffer
Definition: Stream.h:181
std::string readLine()
Definition: Stream.cpp:124
boost::iostreams::sink_tag category
Definition: Stream.h:368
virtual off_t tell() const
Returns the current position of the stream measured in bytes **/.
Definition: Stream.h:292
void write(const std::string &s)
Writes null-terminated string, including terminator.
Definition: Stream.h:87
virtual size_t readDataAvailable(void *dest, size_t maxSize)=0
std::shared_ptr< class OStream > OStreamRef
Definition: Stream.h:107
std::shared_ptr< uint8_t > mBuffer
Definition: Stream.h:243
size_t mDataSize
Definition: Stream.h:304
bool isEof() const
Definition: Stream.cpp:372
char char_type
Definition: Stream.h:367
off_t mBufferFileOffset
Definition: Stream.h:245
static const int MINIMUM_BUFFER_SIZE
Definition: Stream.h:140
GLuint src
Definition: GLee.h:10873
bool mOwnsFile
Definition: Stream.h:210
static uint8_t getNativeEndianness()
Returns the platform's endianness as a StreamBase::Endianness.
Definition: Stream.h:47
FILE * mFile
Definition: Stream.h:178
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: GLee.h:1011
virtual ~OStream()
Definition: Stream.h:84
OStream()
Definition: Stream.h:101
void read(T *t)
Definition: Stream.h:114
off_t mBufferFileOffset
Definition: Stream.h:183
off_t tell() const
Returns the current position of the stream measured in bytes **/.
Definition: Stream.cpp:234
IStreamFile(FILE *aFile, bool aOwnsFile=true, int32_t aDefaultBufferSize=2048)
Definition: Stream.cpp:167
IStreamStateRestore(IStreamCinder &aStream)
Definition: Stream.h:312
std::shared_ptr< IoStream > IoStreamRef
Definition: Stream.h:150
void seekAbsolute(off_t absoluteOffset)
Sets the current position of the stream to byte absoluteOffset. A negative offset is relative to the ...
Definition: Stream.cpp:338
cinder_stream_sink(OStreamRef aStream)
Definition: Stream.h:370
fs::path mFileName
Definition: Stream.h:78
void writeData(const void *src, size_t size)
Definition: Stream.cpp:155
OStreamMem(size_t bufferSizeHint)
Definition: Stream.cpp:488
cinder_stream_source(cinder::IStreamRef aStream)
Definition: Stream.h:349
Definition: Stream.h:82
IStreamCinder()
Definition: Stream.h:136
static IStreamMemRef create(const void *data, size_t size)
Creates a new IStreamMemRef from the memory pointed to by data which is of size size bytes...
Definition: Stream.cpp:422
Definition: Stream.h:252
boost::iostreams::stream< cinder_stream_sink > cinder_ostream
Definition: Stream.h:382
~IStreamStateRestore()
Definition: Stream.h:313
size_t readDataImpl(void *dest, size_t maxSize)
Definition: Stream.cpp:189
bool mDeleteOnDestroy
Definition: Stream.h:79
virtual ~IoStream()
Definition: Stream.h:148
Definition: Stream.h:365
off_t mBufferOffset
Definition: Stream.h:244
IoStreamFileRef readWriteFileStream(const fs::path &path)
Opens a path for read-write access as a stream.
Definition: Stream.cpp:563
virtual void seekAbsolute(off_t absoluteOffset)
Sets the current position of the stream to byte absoluteOffset. A negative offset is relative to the ...
Definition: Stream.cpp:500
IoStreamFile(FILE *aFile, bool aOwnsFile=true, int32_t aDefaultBufferSize=2048)
Definition: Stream.cpp:316
static OStreamFileRef create(FILE *file, bool ownsFile=true)
Creates a new OStreamFileRef from a C-style file pointer FILE as returned by fopen(). If ownsFile the returned stream will destroy the stream upon its own destruction.
Definition: Stream.cpp:266
Definition: Buffer.h:31
boost::iostreams::source_tag category
Definition: Stream.h:347
size_t mBufferSize
Definition: Stream.h:180
boost::iostreams::seekable_device_tag category
Definition: Stream.h:387
IStreamFileRef loadFileStream(const fs::path &path)
Opens the file lcoated at path for read access as a stream.
Definition: Stream.cpp:528
std::shared_ptr< IStreamCinder > IStreamRef
Definition: Stream.h:142
Endianness
Definition: Stream.h:44
off_t size() const
Definition: Stream.cpp:359
virtual ~StreamBase()
Definition: Stream.h:42
StreamBase()
Definition: Stream.h:76
virtual ~IStreamCinder()
Definition: Stream.h:111
virtual void seekRelative(off_t relativeOffset)=0
Moves the current position of the stream by relativeOffset bytes.
std::shared_ptr< class IoStreamFile > IoStreamFileRef
Definition: Stream.h:214
virtual off_t size() const =0
virtual off_t tell() const
Returns the current position of the stream measured in bytes **/.
Definition: Stream.cpp:284
static IoStreamFileRef create(FILE *file, bool ownsFile=true, int32_t defaultBufferSize=2048)
Creates a new IoStreamFileRef from a C-style file pointer FILE as returned by fopen(). If ownsFile the returned stream will destroy the stream upon its own destruction.
Definition: Stream.cpp:311
std::streamsize read(char *s, std::streamsize n)
Definition: Stream.h:351
bool isEof() const
Definition: Stream.cpp:252
void * mBuffer
Definition: Stream.h:303
const void * getData()
Returns a pointer to the data which the stream wraps.
Definition: Stream.h:271
char char_type
Definition: Stream.h:386
GLuint buffer
Definition: GLee.h:2065
Definition: Stream.h:191
off_t mSize
Definition: Stream.h:184
void readBig(T *t)
Definition: Stream.cpp:85
size_t mDataSize
Definition: Stream.h:279
GLenum GLsizei n
Definition: GLee.h:5780
virtual bool isEof() const =0
void seekAbsolute(off_t absoluteOffset)
Sets the current position of the stream to byte absoluteOffset. A negative offset is relative to the ...
Definition: Stream.cpp:452
void setDeleteOnDestroy(bool enable=true)
Sets whether the Stream has been requested to destroy its source upon its own destruction. For example, IStreamFile will delete its source file. Ignored in some types of streams. Defaults to false.
Definition: Stream.h:64
FILE * getFILE()
Definition: Stream.h:231
Definition: Stream.h:155
bool mSizeCached
Definition: Stream.h:185
off_t mSize
Definition: Stream.h:246
Buffer loadStreamBuffer(IStreamRef is)
Loads the contents of a stream into a Buffer.
Definition: Stream.cpp:596
Definition: Stream.h:340
void writeLittle(T t)
Definition: Stream.cpp:55
void seekRelative(off_t relativeOffset)
Moves the current position of the stream by relativeOffset bytes.
Definition: Stream.cpp:461
static OStreamMemRef create(size_t bufferSizeHint=4096)
Definition: Stream.h:288
FILE * mFile
Definition: Stream.h:209
Definition: Stream.h:337
~IoStreamFile()
Definition: Stream.cpp:325
boost::iostreams::stream_offset seek(boost::iostreams::stream_offset off, std::ios_base::seekdir way)
Definition: Stream.h:402
virtual void seekRelative(off_t relativeOffset)
Moves the current position of the stream by relativeOffset bytes.
Definition: Stream.cpp:297
virtual void IORead(void *t, size_t size)
Definition: Stream.cpp:478
FILE * getFILE()
Definition: Stream.h:201
off_t size() const
Definition: Stream.cpp:239
char char_type
Definition: Stream.h:346
std::streamsize read(char *s, std::streamsize n)
Definition: Stream.h:391
GLfloat GLfloat p
Definition: GLee.h:8473
std::shared_ptr< class IStreamMem > IStreamMemRef
Definition: Stream.h:251
Definition: Stream.h:344
void readFixedString(char *t, size_t maxSize, bool nullTerminate)
Definition: Stream.cpp:108
Definition: Stream.h:40
void readData(void *dest, size_t size)
Definition: Stream.cpp:145
bool isEof() const
Returns whether the stream is currently pointed at the end of the file.
Definition: Stream.cpp:473
FILE * getFILE()
Definition: Stream.h:170
virtual void IOWrite(const void *t, size_t size)
Definition: Stream.cpp:413
const uint8_t * mData
Definition: Stream.h:278
size_t readDataAvailable(void *dest, size_t maxSize)
Definition: Stream.cpp:437
~IStreamMem()
Definition: Stream.cpp:433
IStreamRef mStream
Definition: Stream.h:360
~OStreamFile()
Definition: Stream.cpp:276
void * getBuffer()
Definition: Stream.h:296
void setFileName(const fs::path &aFileName)
Sets the file name of the path from which a Stream originated when relevant. Empty string when undefi...
Definition: Stream.h:59
boost::iostreams::stream< cinder_stream_bidirectional_device > cinder_iostream
Definition: Stream.h:420
std::shared_ptr< class OStreamMem > OStreamMemRef
Definition: Stream.h:284
IoStreamRef mStream
Definition: Stream.h:417
off_t mBufferOffset
Definition: Stream.h:182
std::shared_ptr< class OStreamFile > OStreamFileRef
Definition: Stream.h:189
virtual void IORead(void *t, size_t size)
Definition: Stream.cpp:377
void write(T t)
Definition: Stream.h:89
bool mSizeCached
Definition: Stream.h:247
size_t readDataImpl(void *dest, size_t maxSize)
Definition: Stream.cpp:384
bool getDeleteOnDestroy() const
Returns whether the Stream has been requested to destroy its source upon its own destruction. For example, IStreamFile will delete its source file. Ignored in some types of streams. Defaults to false.
Definition: Stream.h:62
OStreamRef mStream
Definition: Stream.h:379
boost::iostreams::stream< cinder_stream_source > cinder_istream
Definition: Stream.h:363
size_t mOffset
Definition: Stream.h:280
Definition: Stream.h:216
Definition: Exception.h:32
const fs::path & getFileName() const
Returns the file name of the path from which a Stream originated when relevant. Empty string when und...
Definition: Stream.h:57
void writeEndian(T t, uint8_t endian)
Definition: Stream.h:91
IoStream()
Definition: Stream.h:147
void writeBig(T t)
Definition: Stream.cpp:44
virtual void seekRelative(off_t relativeOffset)
Moves the current position of the stream by relativeOffset bytes.
Definition: Stream.cpp:510
OStreamFile(FILE *aFile, bool aOwnsFile=true)
Definition: Stream.cpp:271
Definition: Stream.h:145
Definition: Stream.h:109
GLdouble GLdouble t
Definition: GLee.h:1426
GLdouble s
Definition: GLee.h:1378
BufferT< float > Buffer
Definition: Buffer.h:285
virtual void IORead(void *t, size_t size)
Definition: Stream.cpp:257
off_t size() const
Returns the total length of stream in bytes.
Definition: Stream.h:265
void loadStreamMemory(IStreamRef is, std::shared_ptr< uint8_t > *resultData, size_t *resultDataSize)
Loads the contents of a stream into a contiguous block of memory, pointed to by resultData. The size of this block is stored in resultDataSize.
Definition: Stream.cpp:579
bool mOwnsFile
Definition: Stream.h:179
virtual void IOWrite(const void *t, size_t size)=0
int32_t mDefaultBufferSize
Definition: Stream.h:242
virtual void seekAbsolute(off_t absoluteOffset)=0
Sets the current position of the stream to byte absoluteOffset. A negative offset is relative to the ...
cinder_stream_bidirectional_device(cinder::IoStreamRef aStream)
Definition: Stream.h:389
bool mOwnsFile
Definition: Stream.h:241
GLsizeiptr size
Definition: GLee.h:2089
virtual off_t tell() const =0
Returns the current position of the stream measured in bytes **/.
size_t mDefaultBufferSize
Definition: Stream.h:180
OStreamFileRef writeFileStream(const fs::path &path, bool createParents=true)
Opens the file located at path for write access as a stream, and creates it if it does not exist...
Definition: Stream.cpp:544
virtual void IORead(void *t, size_t size)=0
void readLittle(T *t)
Definition: Stream.cpp:96
off_t tell() const
Returns the current offset into the stream in bytes.
Definition: Stream.cpp:468
Definition: Stream.h:286