MRPT
2.0.1
|
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 37 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 |
~CFileStream () override | |
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 ('' 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 32 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, m_f, and out.
CFileStream::CFileStream | ( | ) |
Constructor.
Definition at line 28 of file CFileStream.cpp.
|
delete |
|
override |
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(), is_open(), and mrpt::apps::CGridMapAlignerApp::run().
|
inherited |
Reads from the stream until a '
' character is found ('' 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 mrpt::containers::end(), fileOpenCorrectly(), and m_f.
|
inline |
Returns true if the file was open without errors.
Definition at line 80 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, m_f, and out.
Referenced by mrpt::apps::CGridMapAlignerApp::run().
|
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 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().
|
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 102 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 62 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 mrpt::containers::end(), 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 41 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.14 for MRPT 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020 |