This CStream derived class allow using a memory buffer as a CStream.
This class is useful for storing any required set of variables or objects, and then read them to other objects, or storing them to a file, for example.
Definition at line 47 of file CMemoryStream.h.
#include <mrpt/utils/CMemoryStream.h>
Public Member Functions | |
CMemoryStream () | |
Default constructor. | |
CMemoryStream (const void *data, const uint64_t nBytesInData) | |
Constructor to initilize the data in the stream from a block of memory (which is copied), and sets the current stream position at the beginning of the data. | |
void | assignMemoryNotOwn (const void *data, const uint64_t nBytesInData) |
Initilize the data in the stream from a block of memory which is NEITHER OWNED NOR COPIED by the object, so it must exist during the whole live of the object. | |
virtual | ~CMemoryStream () |
Destructor. | |
void | Clear () |
Clears the memory buffer. | |
void | changeSize (uint64_t newSize) |
Change size. | |
uint64_t | Seek (long Offset, CStream::TSeekOrigin Origin=sFromBeginning) |
Method for moving to a specified position in the streamed resource. | |
uint64_t | getTotalBytesCount () |
Returns the total size of the internal buffer. | |
uint64_t | getPosition () |
Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the last one. | |
void * | getRawBufferData () |
Method for getting a pointer to the raw stored data. | |
bool | saveBufferToFile (const std::string &file_name) |
Saves the entire buffer to a file. | |
bool | loadBufferFromFile (const std::string &file_name) |
Loads the entire buffer from a file. | |
void | setAllocBlockSize (uint64_t alloc_block_size) |
Change the size of the additional memory block that is reserved whenever the current block runs too short (default=0x10000 bytes). | |
Protected Member Functions | |
size_t | Read (void *Buffer, size_t Count) |
Method responsible for reading from the stream. | |
size_t | Write (const void *Buffer, size_t Count) |
Method responsible for writing to the stream. | |
void | resize (uint64_t newSize) |
Resizes the internal buffer size. | |
Protected Attributes | |
void_ptr_noncopy | m_memory |
Internal data. | |
uint64_t | m_size |
uint64_t | m_position |
uint64_t | m_bytesWritten |
uint64_t | m_alloc_block_size |
bool | m_read_only |
If the memory block does not belong to the object. |
mrpt::utils::CMemoryStream::CMemoryStream | ( | ) |
Default constructor.
mrpt::utils::CMemoryStream::CMemoryStream | ( | const void * | data, | |
const uint64_t | nBytesInData | |||
) |
Constructor to initilize the data in the stream from a block of memory (which is copied), and sets the current stream position at the beginning of the data.
virtual mrpt::utils::CMemoryStream::~CMemoryStream | ( | ) | [virtual] |
Destructor.
void mrpt::utils::CMemoryStream::assignMemoryNotOwn | ( | const void * | data, | |
const uint64_t | nBytesInData | |||
) |
Initilize the data in the stream from a block of memory which is NEITHER OWNED NOR COPIED by the object, so it must exist during the whole live of the object.
After assigning a block of data with this method, the object becomes "read-only", so further attempts to change the size of the buffer will raise an exception. This method resets the write and read positions to the beginning.
void mrpt::utils::CMemoryStream::changeSize | ( | uint64_t | newSize | ) |
Change size.
This would be rarely used. Use ">>" operators for writing to stream.
void mrpt::utils::CMemoryStream::Clear | ( | ) |
Clears the memory buffer.
uint64_t mrpt::utils::CMemoryStream::getPosition | ( | ) | [virtual] |
Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the last one.
Implements mrpt::utils::CStream.
void* mrpt::utils::CMemoryStream::getRawBufferData | ( | ) |
Method for getting a pointer to the raw stored data.
The lenght in bytes is given by getTotalBytesCount
uint64_t mrpt::utils::CMemoryStream::getTotalBytesCount | ( | ) | [virtual] |
Returns the total size of the internal buffer.
Implements mrpt::utils::CStream.
bool mrpt::utils::CMemoryStream::loadBufferFromFile | ( | const std::string & | file_name | ) |
Loads the entire buffer from a file.
size_t mrpt::utils::CMemoryStream::Read | ( | void * | Buffer, | |
size_t | Count | |||
) | [protected, virtual] |
Method responsible for reading from the stream.
Implements mrpt::utils::CStream.
void mrpt::utils::CMemoryStream::resize | ( | uint64_t | newSize | ) | [protected] |
Resizes the internal buffer size.
bool mrpt::utils::CMemoryStream::saveBufferToFile | ( | const std::string & | file_name | ) |
Saves the entire buffer to a file.
uint64_t mrpt::utils::CMemoryStream::Seek | ( | long | Offset, | |
CStream::TSeekOrigin | Origin = sFromBeginning | |||
) | [virtual] |
Method for moving to a specified position in the streamed resource.
Implements mrpt::utils::CStream.
void mrpt::utils::CMemoryStream::setAllocBlockSize | ( | uint64_t | alloc_block_size | ) | [inline] |
Change the size of the additional memory block that is reserved whenever the current block runs too short (default=0x10000 bytes).
Definition at line 128 of file CMemoryStream.h.
References ASSERT_.
size_t mrpt::utils::CMemoryStream::Write | ( | const void * | Buffer, | |
size_t | Count | |||
) | [protected, virtual] |
Method responsible for writing to the stream.
Write attempts to write up to Count bytes to Buffer, and returns the number of bytes actually written.
Implements mrpt::utils::CStream.
uint64_t mrpt::utils::CMemoryStream::m_alloc_block_size [protected] |
Definition at line 63 of file CMemoryStream.h.
uint64_t mrpt::utils::CMemoryStream::m_bytesWritten [protected] |
Definition at line 62 of file CMemoryStream.h.
void_ptr_noncopy mrpt::utils::CMemoryStream::m_memory [protected] |
Internal data.
Definition at line 61 of file CMemoryStream.h.
uint64_t mrpt::utils::CMemoryStream::m_position [protected] |
Definition at line 62 of file CMemoryStream.h.
bool mrpt::utils::CMemoryStream::m_read_only [protected] |
If the memory block does not belong to the object.
Definition at line 64 of file CMemoryStream.h.
uint64_t mrpt::utils::CMemoryStream::m_size [protected] |
Definition at line 62 of file CMemoryStream.h.
Page generated by Doxygen 1.7.1 for MRPT 0.9.4 SVN: at Mon Jan 10 23:33:19 UTC 2011 |