Main MRPT website > C++ reference
MRPT logo
Public Member Functions | Protected Member Functions | Protected Attributes

mrpt::utils::CMemoryStream Class Reference


Detailed Description

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.

See also:
CStream

Definition at line 47 of file CMemoryStream.h.

#include <mrpt/utils/CMemoryStream.h>

Inheritance diagram for mrpt::utils::CMemoryStream:
Inheritance graph
[legend]

List of all members.

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.

Constructor & Destructor Documentation

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.

See also:
assignMemoryNotOwn
virtual mrpt::utils::CMemoryStream::~CMemoryStream ( ) [virtual]

Destructor.


Member Function Documentation

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.

See also:
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.

Returns:
true on success, false on error
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.

Returns:
true on success, false on error
uint64_t mrpt::utils::CMemoryStream::Seek ( long  Offset,
CStream::TSeekOrigin  Origin = sFromBeginning 
) [virtual]

Method for moving to a specified position in the streamed resource.

See also:
CStream::Seek

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.


Member Data Documentation

Definition at line 63 of file CMemoryStream.h.

Definition at line 62 of file CMemoryStream.h.

Internal data.

Definition at line 61 of file CMemoryStream.h.

Definition at line 62 of file CMemoryStream.h.

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.3 for MRPT 0.9.4 SVN:exported at Tue Jan 25 21:56:31 UTC 2011