This CStream derived class allow using a file as a read-only, binary stream.
Definition at line 23 of file io/CFileInputStream.h.
#include <mrpt/io/CFileInputStream.h>
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 | |
CFileInputStream & | operator= (const CFileInputStream &)=delete |
virtual | ~CFileInputStream () |
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 ('\r' characters are ignored). More... | |
Private Attributes | |
std::ifstream | m_if |
The actual input file stream. More... | |
|
inherited |
Used in CStream::Seek.
Enumerator | |
---|---|
sFromBeginning | |
sFromCurrent | |
sFromEnd |
Definition at line 34 of file io/CStream.h.
CFileInputStream::CFileInputStream | ( | const std::string & | fileName | ) |
Constructor.
fileName | The file to be open in this stream |
std::exception | On error trying to open the file. |
Definition at line 23 of file CFileInputStream.cpp.
References MRPT_END, MRPT_START, open(), and THROW_EXCEPTION_FMT.
CFileInputStream::CFileInputStream | ( | ) |
Default constructor.
Definition at line 39 of file CFileInputStream.cpp.
|
delete |
|
virtual |
Definition at line 62 of file CFileInputStream.cpp.
References close().
bool CFileInputStream::checkEOF | ( | ) |
Will be true if EOF has been already reached.
Definition at line 165 of file CFileInputStream.cpp.
References m_if.
void CFileInputStream::clearError | ( | ) |
Resets stream error status bits (e.g.
after an EOF)
Definition at line 171 of file CFileInputStream.cpp.
References m_if.
void CFileInputStream::close | ( | ) |
Close the stream.
Definition at line 54 of file CFileInputStream.cpp.
References m_if.
Referenced by mrpt::graphslam::CGraphSlamEngine< mrpt::graphs::CNetworkOfPoses2DInf >::readGTFile(), mrpt::graphslam::CGraphSlamEngine< mrpt::graphs::CNetworkOfPoses2DInf >::readGTFileRGBD_TUM(), and ~CFileInputStream().
bool CFileInputStream::fileOpenCorrectly | ( | ) | const |
Returns true if the file was open without errors.
Definition at line 149 of file CFileInputStream.cpp.
References m_if.
Referenced by getTotalBytesCount(), is_open(), mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::TRGBDInfoFileParams::parseFile(), mrpt::graphslam::CGraphSlamEngine< mrpt::graphs::CNetworkOfPoses2DInf >::readGTFile(), and mrpt::graphslam::CGraphSlamEngine< mrpt::graphs::CNetworkOfPoses2DInf >::readGTFileRGBD_TUM().
|
inherited |
Reads from the stream until a '
' character is found ('\r' characters are ignored).
Definition at line 69 of file CStream.cpp.
|
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 137 of file CFileInputStream.cpp.
References m_if.
Referenced by Seek().
|
overridevirtual |
Returns the total amount of bytes in the stream.
Implements mrpt::io::CStream.
Definition at line 121 of file CFileInputStream.cpp.
References fileOpenCorrectly(), and m_if.
Referenced by mrpt::io::zip::compress_gz_data_block(), and mrpt::io::CMemoryStream::loadBufferFromFile().
|
inline |
Returns true if the file was open without errors.
Definition at line 53 of file io/CFileInputStream.h.
References fileOpenCorrectly().
bool CFileInputStream::open | ( | const std::string & | fileName | ) |
Open a file for reading.
fileName | The file to be open in this stream |
Definition at line 43 of file CFileInputStream.cpp.
References m_if.
Referenced by CFileInputStream(), and mrpt::io::zip::compress_gz_data_block().
|
delete |
|
virtualinherited |
Writes a string to the stream in a textual form.
Definition at line 30 of file CStream.cpp.
References MRPT_END, MRPT_START, and vsnprintf.
Referenced by mrpt::hmtslam::CTopLCDetector_GridMatching::computeTopologicalObservationModel(), and mrpt::io::CStream::printf_vector().
|
inlineinherited |
Prints a vector in the format [A,B,C,...] using CStream::printf, and the fmt string for each vector element T
.
CONTAINER_TYPE | can be any vector<T>, deque<T> or alike. |
Definition at line 104 of file io/CStream.h.
References mrpt::io::CStream::printf().
Referenced by mrpt::hmtslam::CTopLCDetector_GridMatching::computeTopologicalObservationModel().
|
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(), and mrpt::io::CMemoryStream::loadBufferFromFile().
|
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.
std::exception | On any error, or if ZERO bytes are read. |
Reimplemented in mrpt::comms::CInterfaceFTDI.
Definition at line 64 of file io/CStream.h.
References mrpt::io::CStream::Read().
bool CFileInputStream::readLine | ( | std::string & | str | ) |
Reads one string line from the file (until a new-line character)
Definition at line 153 of file CFileInputStream.cpp.
References m_if.
Referenced by mrpt::graphslam::CGraphSlamEngine< GRAPH_T >::TRGBDInfoFileParams::parseFile(), mrpt::graphslam::CGraphSlamEngine< mrpt::graphs::CNetworkOfPoses2DInf >::readGTFile(), and mrpt::graphslam::CGraphSlamEngine< mrpt::graphs::CNetworkOfPoses2DInf >::readGTFileRGBD_TUM().
|
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:
Implements mrpt::io::CStream.
Definition at line 91 of file CFileInputStream.cpp.
References getPosition(), m_if, mrpt::io::CStream::sFromBeginning, mrpt::io::CStream::sFromCurrent, mrpt::io::CStream::sFromEnd, and THROW_EXCEPTION.
|
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 MRPT_UNUSED_PARAM, and THROW_EXCEPTION.
|
private |
The actual input file stream.
Definition at line 27 of file io/CFileInputStream.h.
Referenced by checkEOF(), clearError(), close(), fileOpenCorrectly(), getPosition(), getTotalBytesCount(), open(), Read(), readLine(), and Seek().
Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST |