MRPT  2.0.4
List of all members | Public Types | Public Member Functions
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:

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 ()=default
 
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 ( )
default

◆ ~CStream()

CStream::~CStream ( )
virtualdefault

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

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

◆ 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 mrpt::system::os::vsnprintf().

Referenced by mrpt::hmtslam::CTopLCDetector_GridMatching::computeTopologicalObservationModel(), mrpt::apps::MonteCarloLocalization_Base::do_pf_localization(), printf_vector(), mrpt::apps::CGridMapAlignerApp::run(), mrpt::apps::RBPF_SLAM_App_Base::run(), and mrpt::apps::ICP_SLAM_App_Base::run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Read()

virtual size_t mrpt::io::CStream::Read ( void *  Buffer,
size_t  Count 
)
pure virtual

Introduces a pure virtual method responsible for reading from the stream.

Implemented in mrpt::io::CPipeWriteEndPoint, mrpt::comms::CInterfaceFTDI, mrpt::comms::CSerialPort, mrpt::io::CPipeBaseEndPoint, mrpt::io::CFileGZInputStream, mrpt::io::CFileOutputStream, mrpt::io::CFileGZOutputStream, mrpt::io::CFileInputStream, mrpt::comms::CClientTCPSocket, mrpt::io::CFileStream, and mrpt::io::CMemoryStream.

Referenced by mrpt::io::zip::decompress(), mrpt::maps::CPointsMapXYZI::loadFromKittiVelodyneFile(), and ReadBufferImmediate().

Here is the caller graph for this function:

◆ 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().

Here is the call graph for this function:

◆ 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::CFileGZInputStream, mrpt::io::CFileGZOutputStream, mrpt::io::CMemoryStream, mrpt::io::CFileOutputStream, and mrpt::io::CFileInputStream.

◆ Write()

virtual size_t mrpt::io::CStream::Write ( const void *  Buffer,
size_t  Count 
)
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::comms::CInterfaceFTDI, mrpt::comms::CSerialPort, mrpt::io::CPipeReadEndPoint, mrpt::io::CPipeBaseEndPoint, mrpt::io::CFileGZInputStream, mrpt::io::CFileOutputStream, mrpt::io::CFileGZOutputStream, mrpt::comms::CClientTCPSocket, mrpt::io::CFileInputStream, mrpt::io::CFileStream, and mrpt::io::CMemoryStream.




Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020