3ds Max C++ API Reference
BinaryStream Class Referenceabstract

Represent an abstract binary stream of data. More...

#include <maxbinarystream.h>

+ Inheritance diagram for BinaryStream:

Public Types

typedef __int64 OffsetType
 

Public Member Functions

 BinaryStream ()
 Default Constructor. More...
 
virtual ~BinaryStream ()
 Destructor. More...
 
virtual MaxString LastError () const =0
 Returns the last error encountered using the stream. More...
 
virtual bool IsEndOfFile () const =0
 Returns true when at end of file. More...
 
virtual bool CanWrite () const =0
 Returns true if a call to Write(void*, size_t) would succeed. More...
 
virtual size_t Read (void *data, size_t length)=0
 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)=0
 Write a number of bytes from the data parameter to this stream. More...
 
virtual OffsetType Seek (OffsetType offset, int direction)=0
 Move the pointer inside this stream to a specified position. More...
 
virtual void Flush ()=0
 Make sure that all the buffer are synced with the OS native objects. More...
 
virtual void Truncate ()=0
 Erase all the data after the current position. More...
 

Static Public Member Functions

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

Represent an abstract binary stream of data.

Member Typedef Documentation

◆ OffsetType

typedef __int64 OffsetType

Constructor & Destructor Documentation

◆ BinaryStream()

BinaryStream ( )
inline

Default Constructor.

95 {}

◆ ~BinaryStream()

virtual ~BinaryStream ( )
inlinevirtual

Destructor.

97 {}

Member Function Documentation

◆ LastError()

virtual MaxString LastError ( ) const
pure 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.

Implemented in BinaryStreamMemory.

◆ IsEndOfFile()

virtual bool IsEndOfFile ( ) const
pure virtual

Returns true when at end of file.

Implemented in BinaryStreamMemory.

◆ CanWrite()

virtual bool CanWrite ( ) const
pure virtual

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

Implemented in BinaryStreamMemory.

◆ Read()

virtual size_t Read ( void data,
size_t  length 
)
pure 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.

Implemented in BinaryStreamMemory.

◆ Write()

virtual size_t Write ( const void data,
size_t  length 
)
pure 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.

Implemented in BinaryStreamMemory.

◆ Seek()

virtual OffsetType Seek ( OffsetType  offset,
int  direction 
)
pure 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.

Implemented in BinaryStreamMemory.

◆ Flush()

virtual void Flush ( )
pure virtual

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

Implemented in BinaryStreamMemory.

◆ Truncate()

virtual void Truncate ( )
pure virtual

Erase all the data after the current position.

Implemented in BinaryStreamMemory.

◆ ParseStreamMode()

static unsigned int ParseStreamMode ( const MCHAR streamMode = _M("rt"))
static

Transform a C fopen-style file mode into a file mode that you can use in the BinaryStream::FromFilename parameter.

Here is the table of interpretation. It was made to match Microsoft's VC Runtime interpretation:

r: BINARYSTREAM_MODE_READ r+ or rw: BINARYSTREAM_MODE_READ | BINARYSTREAM_MODE_WRITE w: BINARYSTREAM_MODE_WRITE | BINARYSTREAM_MODE_CREATE | BINARYSTREAM_MODE_TRUNCATE w+: BINARYSTREAM_MODE_READ | BINARYSTREAM_MODE_WRITE | BINARYSTREAM_MODE_CREATE | BINARYSTREAM_MODE_TRUNCATE a: BINARYSTREAM_MODE_WRITE | BINARYSTREAM_MODE_APPEND | BINARYSTREAM_MODE_CREATE a+: BINARYSTREAM_MODE_READ | BINARYSTREAM_MODE_WRITE | BINARYSTREAM_MODE_APPEND | BINARYSTREAM_MODE_CREATE

And you can add the following suffix: b: BINARYSTREAM_MODE_BINARY t: BINARYSTREAM_MODE_TEXT e: BINARYSTREAM_MODE_EXCLUSIVE

If the stream mode contains any invalid sequence or unknown character, it will returns 0.

◆ FromFilename() [1/2]

static BinaryStream* FromFilename ( const MaxString fileName,
unsigned int  mode,
MaxString error = NULL 
)
static

Create an abstract BinaryStream that will point to the specified file.

Parameters
fileNameThe file's name you wish to open.
modeSpecify how to open the file.
errorIf this parameter is not null, it will contains an error string if this function fails.

◆ FromFilename() [2/2]

static BinaryStream* FromFilename ( const MaxString fileName,
bool  write = false,
bool  truncate = false,
bool  exclusive = false,
MaxString error = NULL 
)
static

Create an abstract BinaryStream that will point to the specified file.

Parameters
fileNameThe file's name you wish to open.
writeOpen for write ?
truncateWill erase the file prior to open it.
exclusivePrevent any other object or process to open it simultaneously.
errorIf this parameter is not null, it will contains an error string if this function fails.

◆ FromFileHandle()

static BinaryStream* FromFileHandle ( HANDLE  handle,
bool  closeOnDelete = true 
)
static

Create an abstract BinaryStream out of a Win32 file handle.

Parameters
handle- The file handle.
closeOnDelete- Will call CloseHandle(HANDLE) when the new object will be destroyed.

◆ FromFile()

static BinaryStream* FromFile ( FILE *  file,
bool  closeOnDelete = true 
)
static

Create an abstract BinaryStream out of a Win32 file handle.

Parameters
file- The file pointer.
closeOnDelete- Will call fclose(FILE*) when the new object will be destroyed.

◆ FromMemory() [1/2]

static BinaryStreamMemory* FromMemory ( void data,
size_t  length,
void(*)(void *)  freeFunction 
)
static

Create an abstract BinaryStream pointing to a memory region.

Parameters
data- Initial data.
length- Initial data's length. (Can be 0.)
freeFunction- Function to call when this object is destroyed. (Can be NULL.)

◆ FromMemory() [2/2]

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

Create an abstract BinaryStream pointing to a memory region.

Parameters
data- Initial data.
length- Initial data's length. (Can be 0.)
reallocFunction- Function to call when data needs to be resized. (Can be NULL.)
freeFunction- Function to call when this object is destroyed. (Can be NULL.)