MRPT  1.9.9
mrpt::io::CStream Class Referenceabstract

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 28 of file io/CStream.h.

#include <mrpt/io/CStream.h>

Inheritance diagram for mrpt::io::CStream:
Inheritance graph

Public Types

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

Public Member Functions

virtual size_t Read (void *Buffer, size_t Count)=0
 Introduces a pure virtual method responsible for reading from the stream. More...
 
virtual size_t Write (const void *Buffer, size_t Count)=0
 Introduces a pure virtual method responsible for writing to the stream. More...
 
 CStream ()
 
virtual ~CStream ()
 
virtual size_t ReadBufferImmediate (void *Buffer, size_t Count)
 Reads a block of bytes from the stream into Buffer, and returns the amound of bytes actually read, without waiting for more extra bytes to arrive (just those already enqued in the stream). More...
 
virtual uint64_t Seek (int64_t Offset, CStream::TSeekOrigin Origin=sFromBeginning)=0
 Introduces a pure virtual method for moving to a specified position in the streamed resource. More...
 
virtual uint64_t getTotalBytesCount () const =0
 Returns the total amount of bytes in the stream. More...
 
virtual uint64_t getPosition () const =0
 Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the last one. More...
 
virtual int printf (const char *fmt,...) MRPT_printf_format_check(2
 Writes a string to the stream in a textual form. More...
 
template<typename CONTAINER_TYPE >
virtual int void printf_vector (const char *fmt, const CONTAINER_TYPE &V, char separator=',')
 Prints a vector in the format [A,B,C,...] using CStream::printf, and the fmt string for each vector element T. More...
 
bool getline (std::string &out_str)
 Reads from the stream until a '
' character is found ('' characters are ignored). More...
 

Member Enumeration Documentation

◆ TSeekOrigin

Used in CStream::Seek.

Enumerator
sFromBeginning 
sFromCurrent 
sFromEnd 

Definition at line 32 of file io/CStream.h.

Constructor & Destructor Documentation

◆ CStream()

mrpt::io::CStream::CStream ( )
inline

Definition at line 50 of file io/CStream.h.

◆ ~CStream()

CStream::~CStream ( )
virtual

Definition at line 26 of file CStream.cpp.

Member Function Documentation

◆ getline()

bool CStream::getline ( std::string out_str)

Reads from the stream until a '
' character is found ('' characters are ignored).

Returns
false on EOF or any other read error.

Definition at line 69 of file CStream.cpp.

◆ getPosition()

virtual uint64_t mrpt::io::CStream::getPosition ( ) const
pure virtual

◆ getTotalBytesCount()

◆ printf()

int CStream::printf ( const char *  fmt,
  ... 
)
virtual

Writes a string to the stream in a textual form.

See also
CStdOutStream

Definition at line 30 of file CStream.cpp.

References MRPT_END, MRPT_START, and vsnprintf.

Referenced by mrpt::hmtslam::CTopLCDetector_GridMatching::computeTopologicalObservationModel(), and printf_vector().

◆ printf_vector()

template<typename CONTAINER_TYPE >
virtual int void mrpt::io::CStream::printf_vector ( const char *  fmt,
const CONTAINER_TYPE &  V,
char  separator = ',' 
)
inline

Prints a vector in the format [A,B,C,...] using CStream::printf, and the fmt string for each vector element T.

Template Parameters
CONTAINER_TYPEcan be any vector<T>, deque<T> or alike.

Definition at line 102 of file io/CStream.h.

References printf().

Referenced by mrpt::hmtslam::CTopLCDetector_GridMatching::computeTopologicalObservationModel().

◆ Read()

◆ ReadBufferImmediate()

virtual size_t mrpt::io::CStream::ReadBufferImmediate ( void Buffer,
size_t  Count 
)
inlinevirtual

Reads a block of bytes from the stream into Buffer, and returns the amound of bytes actually read, without waiting for more extra bytes to arrive (just those already enqued in the stream).

Note that this method will fallback to ReadBuffer() in most CStream classes but in some hardware-related classes.

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

Reimplemented in mrpt::comms::CInterfaceFTDI.

Definition at line 62 of file io/CStream.h.

References Read().

◆ Seek()

virtual uint64_t mrpt::io::CStream::Seek ( int64_t  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::io::CPipeBaseEndPoint, mrpt::io::CFileStream, mrpt::io::CMemoryStream, mrpt::io::CFileGZInputStream, mrpt::io::CFileGZOutputStream, mrpt::io::CFileOutputStream, and mrpt::io::CFileInputStream.

◆ Write()




Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020