#include <maxbinarystream.h>
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 *) |
BinaryStreamMemory | ( | void * | data, |
size_t | length, | ||
void *(*)(void *, size_t) | reallocFunction, | ||
void(*)(void *) | freeFunction | ||
) |
virtual ~BinaryStreamMemory | ( | ) | [virtual] |
size_t CurrentPosition | ( | ) | const [inline] |
{ return _pos; }
size_t Length | ( | ) | const [inline] |
{ return _len; }
size_t Remaining | ( | ) | const [inline] |
size_t Allocated | ( | ) | const [inline] |
{ return _allocated; }
void* Data | ( | ) | const [inline] |
{ return _data; }
void* Data | ( | size_t | pos | ) | const [inline] |
void* CurrentData | ( | ) | const [inline] |
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.
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] |
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.
[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. |
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.
[in] | data | - The byte source to copy from |
length | - The number of bytes to copy from the data parameter. |
Implements BinaryStream.
virtual OffsetType Seek | ( | OffsetType | offset, |
int | direction | ||
) | [virtual] |
Move the pointer inside this stream to a specified position.
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.
void*
_data [protected] |
size_t
_allocated [protected] |
size_t
_len [protected] |
size_t
_pos [protected] |
void*(*
_reallocFunction)(void *, size_t) [protected] |
void(*
_freeFunction)(void *) [protected] |