MRPT  2.0.4
List of all members | Public Types | Public Member Functions | Private Attributes
mrpt::io::CFileInputStream Class Reference

Detailed Description

This CStream derived class allow using a file as a read-only, binary stream.

See also
CStream, CFileStream, CFileGZInputStream
Examples:
serialization_stl/test.cpp.

Definition at line 21 of file io/CFileInputStream.h.

#include <mrpt/io/CFileInputStream.h>

Inheritance diagram for mrpt::io::CFileInputStream:

Public Types

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

Public Member Functions

 CFileInputStream (const std::string &fileName)
 Constructor. More...
 
 CFileInputStream ()
 Default constructor. More...
 
 CFileInputStream (const CFileInputStream &)=delete
 
CFileInputStreamoperator= (const CFileInputStream &)=delete
 
 ~CFileInputStream () override
 
bool open (const std::string &fileName)
 Open a file for reading. More...
 
void close ()
 Close the stream. More...
 
bool fileOpenCorrectly () const
 Returns true if the file was open without errors. More...
 
bool is_open ()
 Returns true if the file was open without errors. More...
 
bool checkEOF ()
 Will be true if EOF has been already reached. More...
 
void clearError ()
 Resets stream error status bits (e.g. More...
 
uint64_t Seek (int64_t off, CStream::TSeekOrigin Origin=sFromBeginning) override
 Introduces a pure virtual method for moving to a specified position in the streamed resource. More...
 
uint64_t getTotalBytesCount () const override
 Returns the total amount of bytes in the stream. More...
 
uint64_t getPosition () const override
 Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the last one. More...
 
bool readLine (std::string &str)
 Reads one string line from the file (until a new-line character) More...
 
size_t Read (void *Buffer, size_t Count) override
 Introduces a pure virtual method responsible for reading from the stream. More...
 
size_t Write (const void *Buffer, size_t Count) override
 Introduces a pure virtual method responsible for writing to the stream. More...
 
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 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...
 

Private Attributes

std::ifstream m_if
 The actual input file stream. 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

◆ CFileInputStream() [1/3]

CFileInputStream::CFileInputStream ( const std::string &  fileName)

Constructor.

Parameters
fileNameThe file to be open in this stream
Exceptions
std::exceptionOn error trying to open the file.

Definition at line 23 of file CFileInputStream.cpp.

References MRPT_END, MRPT_START, open(), and THROW_EXCEPTION_FMT.

Here is the call graph for this function:

◆ CFileInputStream() [2/3]

CFileInputStream::CFileInputStream ( )

Default constructor.

Definition at line 39 of file CFileInputStream.cpp.

◆ CFileInputStream() [3/3]

mrpt::io::CFileInputStream::CFileInputStream ( const CFileInputStream )
delete

◆ ~CFileInputStream()

CFileInputStream::~CFileInputStream ( )
override

Definition at line 62 of file CFileInputStream.cpp.

References close().

Here is the call graph for this function:

Member Function Documentation

◆ checkEOF()

bool CFileInputStream::checkEOF ( )

Will be true if EOF has been already reached.

Definition at line 164 of file CFileInputStream.cpp.

References m_if.

◆ clearError()

void CFileInputStream::clearError ( )

Resets stream error status bits (e.g.

after an EOF)

Definition at line 170 of file CFileInputStream.cpp.

References m_if.

◆ close()

void CFileInputStream::close ( )

Close the stream.

Definition at line 54 of file CFileInputStream.cpp.

References m_if.

Referenced by mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::readGTFile(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::readGTFileRGBD_TUM(), and ~CFileInputStream().

Here is the caller graph for this function:

◆ fileOpenCorrectly()

bool CFileInputStream::fileOpenCorrectly ( ) const

Returns true if the file was open without errors.

Definition at line 148 of file CFileInputStream.cpp.

References m_if.

Referenced by getTotalBytesCount(), is_open(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::TRGBDInfoFileParams::parseFile(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::readGTFile(), and mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::readGTFileRGBD_TUM().

Here is the caller graph for this function:

◆ getline()

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

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

uint64_t CFileInputStream::getPosition ( ) const
overridevirtual

Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the last one.

Implements mrpt::io::CStream.

Definition at line 136 of file CFileInputStream.cpp.

References m_if.

Referenced by Seek().

Here is the caller graph for this function:

◆ getTotalBytesCount()

uint64_t CFileInputStream::getTotalBytesCount ( ) const
overridevirtual

Returns the total amount of bytes in the stream.

Implements mrpt::io::CStream.

Definition at line 120 of file CFileInputStream.cpp.

References mrpt::containers::end(), fileOpenCorrectly(), and m_if.

Referenced by mrpt::io::zip::compress_gz_data_block(), mrpt::io::loadBinaryFile(), and mrpt::io::CMemoryStream::loadBufferFromFile().

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

◆ is_open()

bool mrpt::io::CFileInputStream::is_open ( )
inline

Returns true if the file was open without errors.

Definition at line 51 of file io/CFileInputStream.h.

References fileOpenCorrectly().

Here is the call graph for this function:

◆ open()

bool CFileInputStream::open ( const std::string &  fileName)

Open a file for reading.

Parameters
fileNameThe file to be open in this stream
Returns
true on success.

Definition at line 43 of file CFileInputStream.cpp.

References m_if.

Referenced by CFileInputStream(), mrpt::io::zip::compress_gz_data_block(), and mrpt::maps::CPointsMapXYZI::loadFromKittiVelodyneFile().

Here is the caller graph for this function:

◆ operator=()

CFileInputStream& mrpt::io::CFileInputStream::operator= ( const CFileInputStream )
delete

◆ printf()

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

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(), mrpt::io::CStream::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 = ',' 
)
inlineinherited

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 mrpt::io::CStream::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()

size_t CFileInputStream::Read ( void *  Buffer,
size_t  Count 
)
overridevirtual

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

Implements mrpt::io::CStream.

Definition at line 67 of file CFileInputStream.cpp.

References m_if.

Referenced by mrpt::io::zip::compress_gz_data_block(), mrpt::io::loadBinaryFile(), and mrpt::io::CMemoryStream::loadBufferFromFile().

Here is the caller graph for this function:

◆ ReadBufferImmediate()

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

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 mrpt::io::CStream::Read().

Here is the call graph for this function:

◆ readLine()

bool CFileInputStream::readLine ( std::string &  str)

Reads one string line from the file (until a new-line character)

Returns
true if a line has been read, false on EOF or error.

Definition at line 152 of file CFileInputStream.cpp.

References m_if.

Referenced by mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::TRGBDInfoFileParams::parseFile(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::readGTFile(), and mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::readGTFileRGBD_TUM().

Here is the caller graph for this function:

◆ Seek()

uint64_t CFileInputStream::Seek ( int64_t  Offset,
CStream::TSeekOrigin  Origin = sFromBeginning 
)
overridevirtual

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.

Implements mrpt::io::CStream.

Definition at line 90 of file CFileInputStream.cpp.

References mrpt::containers::end(), getPosition(), m_if, mrpt::io::CStream::sFromBeginning, mrpt::io::CStream::sFromCurrent, mrpt::io::CStream::sFromEnd, and THROW_EXCEPTION.

Here is the call graph for this function:

◆ Write()

size_t CFileInputStream::Write ( const void *  Buffer,
size_t  Count 
)
overridevirtual

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.

Implements mrpt::io::CStream.

Definition at line 79 of file CFileInputStream.cpp.

References THROW_EXCEPTION.

Member Data Documentation

◆ m_if

std::ifstream mrpt::io::CFileInputStream::m_if
private

The actual input file stream.

Definition at line 25 of file io/CFileInputStream.h.

Referenced by checkEOF(), clearError(), close(), fileOpenCorrectly(), getPosition(), getTotalBytesCount(), open(), Read(), readLine(), and Seek().




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