MRPT logo

mrpt::utils::CMemoryStream Class Reference

This CStream derived class allow using a memory buffer as a CStream. More...

#include <mrpt/utils/CMemoryStream.h>

Inheritance diagram for mrpt::utils::CMemoryStream:

mrpt::utils::CStream mrpt::utils::CMemoryChunk

List of all members.

Public Member Functions

 CMemoryStream ()
 Default constructor.
 CMemoryStream (const void *data, const size_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 ~CMemoryStream ()
 Destructor.
void Clear ()
 Clears the memory buffer.
void changeSize (size_t newSize)
 Change size.
size_t Seek (long Offset, CStream::TSeekOrigin Origin=sFromBeginning)
 Method for moving to a specified position in the streamed resource.
size_t getTotalBytesCount ()
 Returns the total size of the internal buffer.
size_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 (size_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 (size_t newSize)
 Resizes the internal buffer size.

Protected Attributes

void_ptr_noncopy m_memory
 Internal data.
size_t m_size
size_t m_position
size_t m_bytesWritten
size_t m_alloc_block_size


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.


Constructor & Destructor Documentation

mrpt::utils::CMemoryStream::CMemoryStream (  ) 

Default constructor.

mrpt::utils::CMemoryStream::CMemoryStream ( const void *  data,
const size_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.


Member Function Documentation

void mrpt::utils::CMemoryStream::changeSize ( size_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.

size_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

size_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 ( size_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

size_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 ( size_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 120 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.

Definition at line 62 of file CMemoryStream.h.




Page generated by Doxygen 1.5.9 for MRPT 0.6.5 SVN:exported at Thu May 21 04:14:55 UTC 2009