MRPT logo

mrpt::utils::CStream Class Reference

This base class is used to provide a unified interface to files,memory buffers,. More...

#include <mrpt/utils/CStream.h>

Inheritance diagram for mrpt::utils::CStream:

mrpt::hwdrivers::CInterfaceFTDI mrpt::hwdrivers::CSerialPort mrpt::utils::CClientTCPSocket mrpt::utils::CFileGZInputStream mrpt::utils::CFileInputStream mrpt::utils::CFileOutputStream mrpt::utils::CFileStream mrpt::utils::CMemoryStream mrpt::utils::CStdOutStream

List of all members.

Public Types

enum  TSeekOrigin { sFromBeginning = 0, sFromCurrent = 1, sFromEnd = 2 }
 Used in CStream::Seek. More...

Public Member Functions

 CStream ()
virtual ~CStream ()
size_t ReadBuffer (void *Buffer, size_t Count)
 Reads a block of bytes from the stream into Buffer, and returns the amound of bytes actually read.
void WriteBuffer (const void *Buffer, size_t Count)
 Writes a block of bytes to the stream from Buffer.
size_t CopyFrom (CStream *Source, size_t Count)
 Copies a specified number of bytes from one stream to another.
virtual size_t Seek (long Offset, CStream::TSeekOrigin Origin=sFromBeginning)=0
 Introduces a pure virtual method for moving to a specified position in the streamed resource.
virtual size_t getTotalBytesCount ()=0
 Returns the total amount of bytes in the stream.
virtual size_t getPosition ()=0
 Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the last one.
CStreamoperator<< (const CSerializablePtr &pObj)
 Write operator for objects.
CStreamoperator<< (const CSerializable &obj)
 Write operator for objects.
CStreamoperator>> (CSerializablePtr &pObj)
 Read operator for objects.
CStreamoperator>> (CSerializable &obj)
 Read operator for objects.
void WriteObject (const CSerializable *o)
 Writes an object to the stream.
CSerializablePtr ReadObject ()
 Reads an object from stream, its class determined at runtime, and returns a smart pointer to the object.
void ReadObject (CSerializable *existingObj)
 Reads an object from stream, where its class must be the same as the supplied object, where the loaded object will be stored in.
virtual int printf (const char *fmt,...) MRPT_printf_format_check(2
 Writes a string to the stream in a textual form.
template<typename T >
virtual int void printf_vector (const char *fmt, const std::vector< T > &V)
 Prints a vector in the format [A,B,C,.

Protected Member Functions

virtual size_t Read (void *Buffer, size_t Count)=0
 Introduces a pure virtual method responsible for reading from the stream.
virtual size_t Write (const void *Buffer, size_t Count)=0
 Introduces a pure virtual method responsible for writing to the stream.


Detailed Description

This base class is used to provide a unified interface to files,memory buffers,.

.Please see the derived classes. This class is largely inspired by Borland VCL "TStream" class.

Apart of the "VCL like" methods, operators ">>" and "<<" have been defined so that simple types (int,bool,char,float,char *,std::string,...) can be directly written and read to and from any CStream easily. Please, it is recomendable to read CSerializable documentation also.

See also:
CFileStream, CMemoryStream,CSerializable

Definition at line 56 of file CStream.h.


Member Enumeration Documentation

Used in CStream::Seek.

Enumerator:
sFromBeginning 
sFromCurrent 
sFromEnd 

Definition at line 61 of file CStream.h.


Constructor & Destructor Documentation

mrpt::utils::CStream::CStream (  )  [inline]

Definition at line 80 of file CStream.h.

virtual mrpt::utils::CStream::~CStream (  )  [virtual]


Member Function Documentation

size_t mrpt::utils::CStream::CopyFrom ( CStream Source,
size_t  Count 
)

Copies a specified number of bytes from one stream to another.

virtual size_t mrpt::utils::CStream::getPosition (  )  [pure virtual]

virtual size_t mrpt::utils::CStream::getTotalBytesCount (  )  [pure virtual]

CStream& mrpt::utils::CStream::operator<< ( const CSerializable obj  ) 

Write operator for objects.

CStream& mrpt::utils::CStream::operator<< ( const CSerializablePtr pObj  ) 

Write operator for objects.

CStream& mrpt::utils::CStream::operator>> ( CSerializable obj  ) 

Read operator for objects.

CStream& mrpt::utils::CStream::operator>> ( CSerializablePtr pObj  ) 

Read operator for objects.

virtual int mrpt::utils::CStream::printf ( const char *  fmt,
  ... 
) [virtual]

Writes a string to the stream in a textual form.

See also:
CStdOutStream

template<typename T >
virtual int void mrpt::utils::CStream::printf_vector ( const char *  fmt,
const std::vector< T > &  V 
) [inline]

Prints a vector in the format [A,B,C,.

..] using CStream::printf, and the fmt string for each vector element.

Definition at line 158 of file CStream.h.

virtual size_t mrpt::utils::CStream::Read ( void *  Buffer,
size_t  Count 
) [protected, pure virtual]

size_t mrpt::utils::CStream::ReadBuffer ( void *  Buffer,
size_t  Count 
)

Reads a block of bytes from the stream into Buffer, and returns the amound of bytes actually read.

Exceptions:
std::exception On any error, or if ZERO bytes are read.

void mrpt::utils::CStream::ReadObject ( CSerializable existingObj  ) 

Reads an object from stream, where its class must be the same as the supplied object, where the loaded object will be stored in.

Exceptions:
std::exception On I/O error or different class found.
mrpt::utils::CExceptionEOF On an End-Of-File condition found at a correct place: an EOF that abruptly finishes in the middle of one object raises a plain std::exception instead.

CSerializablePtr mrpt::utils::CStream::ReadObject (  ) 

Reads an object from stream, its class determined at runtime, and returns a smart pointer to the object.

Exceptions:
std::exception On I/O error or undefined class.
mrpt::utils::CExceptionEOF On an End-Of-File condition found at a correct place: an EOF that abruptly finishes in the middle of one object raises a plain std::exception instead.

virtual size_t mrpt::utils::CStream::Seek ( long  Offset,
CStream::TSeekOrigin  Origin = sFromBeginning 
) [pure virtual]

Introduces a pure virtual method for moving to a specified position in the streamed resource.

he Origin parameter indicates how to interpret the Offset parameter. Origin should be one of the following values:

  • sFromBeginning (Default) Offset is from the beginning of the resource. Seek moves to the position Offset. Offset must be >= 0.
  • sFromCurrent Offset is from the current position in the resource. Seek moves to Position + Offset.
  • sFromEnd Offset is from the end of the resource. Offset must be <= 0 to indicate a number of bytes before the end of the file.
    Returns:
    Seek returns the new value of the Position property.

Implemented in mrpt::hwdrivers::CInterfaceFTDI, mrpt::hwdrivers::CSerialPort, mrpt::utils::CClientTCPSocket, mrpt::utils::CFileGZInputStream, mrpt::utils::CFileInputStream, mrpt::utils::CFileOutputStream, mrpt::utils::CFileStream, mrpt::utils::CMemoryStream, and mrpt::utils::CStdOutStream.

virtual size_t mrpt::utils::CStream::Write ( const void *  Buffer,
size_t  Count 
) [protected, pure virtual]

Introduces a pure 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.

Implemented in mrpt::hwdrivers::CInterfaceFTDI, mrpt::hwdrivers::CSerialPort, mrpt::utils::CClientTCPSocket, mrpt::utils::CFileGZInputStream, mrpt::utils::CFileInputStream, mrpt::utils::CFileOutputStream, mrpt::utils::CFileStream, mrpt::utils::CMemoryStream, and mrpt::utils::CStdOutStream.

void mrpt::utils::CStream::WriteBuffer ( const void *  Buffer,
size_t  Count 
)

Writes a block of bytes to the stream from Buffer.

Exceptions:
std::exception On any error

void mrpt::utils::CStream::WriteObject ( const CSerializable o  ) 

Writes an object to the stream.




Page generated by Doxygen 1.5.8 for MRPT 0.6.5 SVN: at Thu Feb 26 02:07:47 EST 2009