3ds Max C++ API Reference
BinaryStreamMemory Class Reference

Holds binary data in memory only. More...

#include <maxbinarystream.h>

+ Inheritance diagram for BinaryStreamMemory:

Public Member Functions

 BinaryStreamMemory (void *data, size_t length, void *(*reallocFunction)(void *, size_t), void(*freeFunction)(void *))
 
virtual ~BinaryStreamMemory ()
 
size_t CurrentPosition () const
 
size_t Length () const
 
size_t Remaining () const
 
size_t Allocated () const
 
voidData () const
 
voidData (size_t pos) const
 
voidCurrentData () const
 
void Compact ()
 Reduce the memory used by this object. More...
 
void Reset ()
 Reset this object, _len = 0. More...
 
void Precate (size_t keep=0)
 Loose the information the beginning of this buffer up to the current position. More...
 
void Truncate ()
 Loose the information from the current position up to the end of this buffer. More...
 
void Truncate (size_t)
 Loose the information from the specified position up to the end of this buffer. More...
 
voidRead (size_t &length)
 Quick-read. More...
 
voidWrite (size_t &length)
 Quick-write. More...
 
void EnsureAllocated (size_t length)
 
voidInsert (size_t position, size_t length)
 
virtual MaxString LastError () const
 Returns the last error encountered using the stream. More...
 
virtual bool IsEndOfFile () const
 Returns true when at end of file. More...
 
virtual bool CanWrite () const
 Returns true if a call to Write(void*, size_t) would succeed. More...
 
virtual size_t Read (void *data, size_t length)
 Read a specified number bytes from this stream and stores it in the data parameter. More...
 
virtual size_t Write (const void *data, size_t length)
 Write a number of bytes from the data parameter to this stream. More...
 
virtual OffsetType Seek (OffsetType distance, int direction)
 Move the pointer inside this stream to a specified position. More...
 
virtual void Flush ()
 Make sure that all the buffer are synced with the OS native objects. More...
 
- Public Member Functions inherited from BinaryStream
 BinaryStream ()
 Default Constructor. More...
 
virtual ~BinaryStream ()
 Destructor. More...
 

Protected Attributes

void_data
 
size_t _allocated
 
size_t _len
 
size_t _pos
 
void *(* _reallocFunction )(void *, size_t)
 
void(* _freeFunction )(void *)
 

Additional Inherited Members

- Public Types inherited from BinaryStream
typedef __int64 OffsetType
 
- Static Public Member Functions inherited from BinaryStream
static unsigned int ParseStreamMode (const MCHAR *streamMode=_M("rt"))
 Transform a C fopen-style file mode into a file mode that you can use in the BinaryStream::FromFilename parameter. More...
 
static BinaryStreamFromFilename (const MaxString &fileName, unsigned int mode, MaxString *error=NULL)
 Create an abstract BinaryStream that will point to the specified file. More...
 
static BinaryStreamFromFilename (const MaxString &fileName, bool write=false, bool truncate=false, bool exclusive=false, MaxString *error=NULL)
 Create an abstract BinaryStream that will point to the specified file. More...
 
static BinaryStreamFromFileHandle (HANDLE handle, bool closeOnDelete=true)
 Create an abstract BinaryStream out of a Win32 file handle. More...
 
static BinaryStreamFromFile (FILE *file, bool closeOnDelete=true)
 Create an abstract BinaryStream out of a Win32 file handle. More...
 
static BinaryStreamMemoryFromMemory (void *data, size_t length, void(*freeFunction)(void *))
 Create an abstract BinaryStream pointing to a memory region. More...
 
static BinaryStreamMemoryFromMemory (void *data, size_t length, void *(*reallocFunction)(void *, size_t), void(*freeFunction)(void *))
 Create an abstract BinaryStream pointing to a memory region. More...
 
- Static Public Member Functions inherited from MaxHeapOperators
static UtilExport voidoperator new (size_t size)
 Standard new operator used to allocate objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e)
 Standard new operator used to allocate objects if there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate objects that takes the type of memory, filename and line number where the new was called If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate objects that takes the filename and line number where the new was called If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new (size_t size, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate objects that takes extra flags to specify special operations If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, int block_type, const char *filename, int line)
 New operator used to allocate arrays of objects. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, const char *filename, int line)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport voidoperator new[] (size_t size, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, an exception will be thrown. More...
 
static UtilExport voidoperator new[] (size_t size, const std::nothrow_t &e, unsigned long flags)
 New operator used to allocate arrays of objects If there is insufficient memory, NULL will be returned. More...
 
static UtilExport void operator delete (void *ptr)
 Standard delete operator used to deallocate an object If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an object If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an object that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an object that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete (void *ptr, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an object that takes extra flags to specify special operations If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e)
 Standard delete operator used to deallocate an array of objects If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, int block_type, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the type of memory, filename and line number where the delete was called If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, const char *filename, int line)
 Delete operator used to deallocate an array of objects that takes the filename and line number where the delete was called If the pointer is invalid, nothing will happen. More...
 
static UtilExport void operator delete[] (void *ptr, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport void operator delete[] (void *ptr, const std::nothrow_t &e, unsigned long flags)
 Delete operator used to deallocate an array of objects that takes extra flags to specify special operations If the pointer is invalid, an exception will be thrown. More...
 
static UtilExport voidoperator new (size_t size, void *placement_ptr)
 Placement new operator. More...
 
static UtilExport void operator delete (void *ptr, void *placement_ptr)
 Placement delete operator. More...
 
static UtilExport voidaligned_malloc (size_t size, size_t alignment)
 Allocates memory on a specified alignment boundary. More...
 
static UtilExport voidaligned_realloc (void *ptr, size_t size, size_t alignment)
 Reallocates memory on a specified alignment boundary. More...
 
static UtilExport void aligned_free (void *ptr)
 Frees a block of memory that was allocated with aligned_malloc/aligned_realloc. More...
 

Detailed Description

Holds binary data in memory only.

The Reader class uses this as a buffer for reading data.

Constructor & Destructor Documentation

◆ BinaryStreamMemory()

BinaryStreamMemory ( void data,
size_t  length,
void *(*)(void *, size_t reallocFunction,
void(*)(void *)  freeFunction 
)

◆ ~BinaryStreamMemory()

virtual ~BinaryStreamMemory ( )
virtual

Member Function Documentation

◆ CurrentPosition()

size_t CurrentPosition ( ) const
inline
253 { return _pos; }
size_t _pos
Definition: maxbinarystream.h:243

◆ Length()

size_t Length ( ) const
inline
254 { return _len; }
size_t _len
Definition: maxbinarystream.h:242

◆ Remaining()

size_t Remaining ( ) const
inline
255 { return _len - _pos; }

◆ Allocated()

size_t Allocated ( ) const
inline
256 { return _allocated; }
size_t _allocated
Definition: maxbinarystream.h:241

◆ Data() [1/2]

void* Data ( ) const
inline
257 { return _data; }
void * _data
Definition: maxbinarystream.h:240

◆ Data() [2/2]

void* Data ( size_t  pos) const
inline
258 { return ((unsigned char*)_data) + pos; }
controller mat max min numsubs x z controller keys x z pos
Definition: generics.inl:208

◆ CurrentData()

void* CurrentData ( ) const
inline
259 { return ((unsigned char*)_data) + _pos; }

◆ Compact()

void Compact ( )

Reduce the memory used by this object.

◆ Reset()

void Reset ( )

Reset this object, _len = 0.

◆ Precate()

void Precate ( size_t  keep = 0)

Loose the information the beginning of this buffer up to the current position.

Parameters
keepKeep the X last bytes of the memory buffer

◆ Truncate() [1/2]

void Truncate ( )
virtual

Loose the information from the current position up to the end of this buffer.

Implements BinaryStream.

◆ Truncate() [2/2]

void Truncate ( size_t  )

Loose the information from the specified position up to the end of this buffer.

◆ Read() [1/2]

void* Read ( size_t length)

Quick-read.

This function will returns you a direct-pointer to the memory of this buffer and move the stream position.

◆ Write() [1/2]

void* Write ( size_t length)

Quick-write.

This function will returns you a direct-pointer to the memory of this buffer where you should write and move the stream position.

◆ EnsureAllocated()

void EnsureAllocated ( size_t  length)

◆ Insert()

void* Insert ( size_t  position,
size_t  length 
)

◆ LastError()

virtual MaxString LastError ( ) const
virtual

Returns the last error encountered using the stream.

If no error occurred during the uses of this class, this function will returns null. If for any reason, any call to this interface, this member will returns a user-readable error code that explain why the operation failed.

Implements BinaryStream.

◆ IsEndOfFile()

virtual bool IsEndOfFile ( ) const
virtual

Returns true when at end of file.

Implements BinaryStream.

◆ CanWrite()

virtual bool CanWrite ( ) const
virtual

Returns true if a call to Write(void*, size_t) would succeed.

Implements BinaryStream.

◆ Read() [2/2]

virtual size_t Read ( void data,
size_t  length 
)
virtual

Read a specified number bytes from this stream and stores it in the data parameter.

Parameters
[out]data- Buffer to store the bytes taken out of this stream.
length- Number of bytes available in "data" to store the content of this stream.
Returns
Returns the number of bytes read. Or 0 if the end of file was reached.

Implements BinaryStream.

◆ Write() [2/2]

virtual size_t Write ( const void data,
size_t  length 
)
virtual

Write a number of bytes from the data parameter to this stream.

Parameters
[in]data- The byte source to copy from
length- The number of bytes to copy from the data parameter.
Returns
Returns the number of bytes written.

Implements BinaryStream.

◆ Seek()

virtual OffsetType Seek ( OffsetType  offset,
int  direction 
)
virtual

Move the pointer inside this stream to a specified position.

Parameters
offset- The amount to offset the file pointer by.
direction- Can be either SEEK_SET, SEEK_CUR, SEEK_END.

Implements BinaryStream.

◆ Flush()

virtual void Flush ( )
virtual

Make sure that all the buffer are synced with the OS native objects.

Implements BinaryStream.

Member Data Documentation

◆ _data

void* _data
protected

◆ _allocated

size_t _allocated
protected

◆ _len

size_t _len
protected

◆ _pos

size_t _pos
protected

◆ _reallocFunction

void*(* _reallocFunction) (void *, size_t)
protected

◆ _freeFunction

void(* _freeFunction) (void *)
protected