BinaryStreamMemory Class Reference
 
 
 
BinaryStreamMemory Class Reference

#include <maxbinarystream.h>

Inheritance diagram for BinaryStreamMemory:
BinaryStream MaxHeapOperators

Class Description

Holds binary data in memory only.

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

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
void *  Data () const
void *  Data (size_t pos) const
void *  CurrentData () const
void  Compact ()
  Reduce the memory used by this object.
void  Reset ()
  Reset this object, _len = 0.
void  Precate (size_t keep=0)
  Loose the information the beginning of this buffer up to the current position.
void  Truncate ()
  Loose the information from the current position up to the end of this buffer.
void  Truncate (size_t)
  Loose the information from the specified position up to the end of this buffer.
void *  Read (size_t &length)
  Quick-read.
void *  Write (size_t &length)
  Quick-write.
void  EnsureAllocated (size_t length)
void *  Insert (size_t position, size_t length)
virtual MaxString  LastError () const
  Returns the last error encountered using the stream.
virtual bool  IsEndOfFile () const
  Returns true when at end of file.
virtual bool  CanWrite () const
  Returns true if a call to Write(void*, size_t) would succeed.
virtual size_t  Read (void *data, size_t length)
  Read a specified number bytes from this stream and stores it in the data parameter.
virtual size_t  Write (const void *data, size_t length)
  Write a number of bytes from the data parameter to this stream.
virtual OffsetType  Seek (OffsetType distance, int direction)
  Move the pointer inside this stream to a specified position.
virtual void  Flush ()
  Make sure that all the buffer are synced with the OS native objects.

Protected Attributes

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

Constructor & Destructor Documentation

BinaryStreamMemory ( void *  data,
size_t  length,
void *(*)(void *, size_t)  reallocFunction,
void(*)(void *)  freeFunction 
)
virtual ~BinaryStreamMemory ( ) [virtual]

Member Function Documentation

size_t CurrentPosition ( ) const [inline]
size_t Length ( ) const [inline]
size_t Remaining ( ) const [inline]
size_t Allocated ( ) const [inline]
void* Data ( ) const [inline]
void* Data ( size_t  pos ) const [inline]
{ return ((unsigned char*)_data) + pos; }
void* CurrentData ( ) const [inline]
{ return ((unsigned char*)_data) + _pos; }
void Compact ( )

Reduce the memory used by this object.

void Reset ( )

Reset this object, _len = 0.

void Precate ( size_t  keep = 0 )

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

Parameters:
keep Keep the X last bytes of the memory buffer
void Truncate ( ) [virtual]

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

Implements BinaryStream.

void Truncate ( size_t  )

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

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.

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.

void EnsureAllocated ( size_t  length )
void* Insert ( size_t  position,
size_t  length 
)
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.

virtual bool IsEndOfFile ( ) const [virtual]

Returns true when at end of file.

Implements BinaryStream.

virtual bool CanWrite ( ) const [virtual]

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

Implements BinaryStream.

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.

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.

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.

virtual void Flush ( ) [virtual]

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

Implements BinaryStream.


Member Data Documentation

size_t _len [protected]
size_t _pos [protected]
void*(* _reallocFunction)(void *, size_t) [protected]
void(* _freeFunction)(void *) [protected]