This CStream derived class allow using a file as a read/write binary stream, creating it if the file didn't exist.
The default behavior can be change to open as read, write, read and write,... in the constructor.
Definition at line 39 of file CFileStream.h.
#include <mrpt/io/CFileStream.h>
Public Types | |
enum | TSeekOrigin { sFromBeginning = 0, sFromCurrent = 1, sFromEnd = 2 } |
Used in CStream::Seek. More... | |
Public Member Functions | |
CFileStream (const std::string &fileName, TFileOpenModes mode=fomRead|fomWrite) | |
Constructor and open a file. More... | |
CFileStream () | |
Constructor. More... | |
CFileStream (const CFileStream &)=delete | |
CFileStream & | operator= (const CFileStream &)=delete |
virtual | ~CFileStream () |
Destructor. 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... | |
bool | open (const std::string &fileName, TFileOpenModes mode=fomRead|fomWrite) |
Opens the file, returning true on success. More... | |
void | close () |
Closes the file. 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 org=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... | |
uint64_t | getPositionI () |
The current Input cursor position, where 0 is the first byte. More... | |
uint64_t | getPositionO () |
The current Input cursor position, where 0 is the first byte. More... | |
bool | readLine (std::string &str) |
Reads one string line from the file (until a new-line character) 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::fstream | m_f |
The actual input file stream. More... | |
|
inherited |
Used in CStream::Seek.
Enumerator | |
---|---|
sFromBeginning | |
sFromCurrent | |
sFromEnd |
Definition at line 34 of file io/CStream.h.
CFileStream::CFileStream | ( | const std::string & | fileName, |
TFileOpenModes | mode = fomRead | fomWrite |
||
) |
Constructor and open a file.
fileName | The file to be open in this stream |
mode | The open mode: can be an or'd conbination of different values. |
std::exception | On error creating or accessing the file. By default the file is opened for open and write and created if not found. |
Definition at line 32 of file CFileStream.cpp.
References mrpt::io::fomAppend, mrpt::io::fomRead, mrpt::io::fomWrite, and m_f.
CFileStream::CFileStream | ( | ) |
Constructor.
Definition at line 28 of file CFileStream.cpp.
|
delete |
|
virtual |
bool CFileStream::checkEOF | ( | ) |
Will be true if EOF has been already reached.
Definition at line 204 of file CFileStream.cpp.
References m_f.
void CFileStream::clearError | ( | ) |
Resets stream error status bits (e.g.
after an EOF)
Definition at line 210 of file CFileStream.cpp.
References m_f.
void CFileStream::close | ( | ) |
bool CFileStream::fileOpenCorrectly | ( | ) | const |
Returns true if the file was open without errors.
Definition at line 188 of file CFileStream.cpp.
References m_f.
Referenced by getTotalBytesCount(), and is_open().
|
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 154 of file CFileStream.cpp.
References m_f.
Referenced by Seek().
uint64_t CFileStream::getPositionI | ( | ) |
The current Input cursor position, where 0 is the first byte.
Definition at line 166 of file CFileStream.cpp.
References m_f.
uint64_t CFileStream::getPositionO | ( | ) |
The current Input cursor position, where 0 is the first byte.
Definition at line 177 of file CFileStream.cpp.
References m_f.
|
overridevirtual |
Returns the total amount of bytes in the stream.
Implements mrpt::io::CStream.
Definition at line 141 of file CFileStream.cpp.
References fileOpenCorrectly(), and m_f.
|
inline |
Returns true if the file was open without errors.
Definition at line 82 of file CFileStream.h.
References fileOpenCorrectly().
bool CFileStream::open | ( | const std::string & | fileName, |
TFileOpenModes | mode = fomRead | fomWrite |
||
) |
Opens the file, returning true on success.
fileName | The file to be open in this stream |
mode | The open mode: can be an or'd conbination of different values. By default the file is opened for open and write and created if not found. |
Definition at line 56 of file CFileStream.cpp.
References mrpt::io::fomAppend, mrpt::io::fomRead, mrpt::io::fomWrite, and m_f.
|
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 88 of file CFileStream.cpp.
References m_f.
|
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 CFileStream::readLine | ( | std::string & | str | ) |
Reads one string line from the file (until a new-line character)
Definition at line 192 of file CFileStream.cpp.
References m_f.
|
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 112 of file CFileStream.cpp.
References getPosition(), m_f, mrpt::io::CStream::sFromBeginning, mrpt::io::CStream::sFromCurrent, and mrpt::io::CStream::sFromEnd.
|
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 99 of file CFileStream.cpp.
References m_f.
|
private |
The actual input file stream.
Definition at line 43 of file CFileStream.h.
Referenced by CFileStream(), checkEOF(), clearError(), close(), fileOpenCorrectly(), getPosition(), getPositionI(), getPositionO(), getTotalBytesCount(), open(), Read(), readLine(), Seek(), Write(), and ~CFileStream().
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 |