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

Detailed Description

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

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

Definition at line 22 of file io/CFileOutputStream.h.

#include <mrpt/io/CFileOutputStream.h>

Inheritance diagram for mrpt::io::CFileOutputStream:

Public Types

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

Public Member Functions

 CFileOutputStream (const std::string &fileName, bool append=false)
 Constructor. More...
 
 CFileOutputStream ()
 Default constructor. More...
 
 CFileOutputStream (const CFileOutputStream &)=delete
 
CFileOutputStreamoperator= (const CFileOutputStream &)=delete
 
bool open (const std::string &fileName, bool append=false)
 Open the given file for write. More...
 
void close ()
 Close the stream. More...
 
 ~CFileOutputStream () override
 Destructor. 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...
 
uint64_t Seek (int64_t Offset, 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
 Method for getting the total number of bytes writen to buffer. 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...
 
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::ofstream m_of
 The actual output 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

◆ CFileOutputStream() [1/3]

CFileOutputStream::CFileOutputStream ( const std::string fileName,
bool  append = false 
)

Constructor.

Parameters
fileNameThe file to be open in this stream
appendIf set to true, the file will be opened for writing and the current cursor position set at the end of the file. Otherwise, previous contents will be lost.
Exceptions
std::exceptionif the file cannot be opened.

Definition at line 18 of file CFileOutputStream.cpp.

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

Here is the call graph for this function:

◆ CFileOutputStream() [2/3]

CFileOutputStream::CFileOutputStream ( )

Default constructor.

Definition at line 30 of file CFileOutputStream.cpp.

◆ CFileOutputStream() [3/3]

mrpt::io::CFileOutputStream::CFileOutputStream ( const CFileOutputStream )
delete

◆ ~CFileOutputStream()

CFileOutputStream::~CFileOutputStream ( )
override

Destructor.

Definition at line 48 of file CFileOutputStream.cpp.

References close().

Here is the call graph for this function:

Member Function Documentation

◆ close()

void CFileOutputStream::close ( )

Close the stream.

Definition at line 43 of file CFileOutputStream.cpp.

References m_of.

Referenced by open(), and ~CFileOutputStream().

Here is the caller graph for this function:

◆ fileOpenCorrectly()

bool CFileOutputStream::fileOpenCorrectly ( ) const

Returns true if the file was open without errors.

Definition at line 112 of file CFileOutputStream.cpp.

References m_of.

Referenced by mrpt::hwdrivers::CGPSInterface::doProcess(), getTotalBytesCount(), and is_open().

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 CFileOutputStream::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 103 of file CFileOutputStream.cpp.

References m_of.

Referenced by Seek().

Here is the caller graph for this function:

◆ getTotalBytesCount()

uint64_t CFileOutputStream::getTotalBytesCount ( ) const
overridevirtual

Method for getting the total number of bytes writen to buffer.

Implements mrpt::io::CStream.

Definition at line 90 of file CFileOutputStream.cpp.

References fileOpenCorrectly(), and m_of.

Here is the call graph for this function:

◆ is_open()

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

Returns true if the file was open without errors.

Definition at line 63 of file io/CFileOutputStream.h.

References fileOpenCorrectly().

Here is the call graph for this function:

◆ open()

bool CFileOutputStream::open ( const std::string fileName,
bool  append = false 
)

Open the given file for write.

Parameters
fileNameThe file to be open in this stream
appendIf set to true, the file will be opened for writing and the current cursor position set at the end of the file. Otherwise, previous contents will be lost.
See also
fileOpenCorrectly
Returns
true on success.

Definition at line 31 of file CFileOutputStream.cpp.

References close(), m_of, and out.

Referenced by CFileOutputStream(), mrpt::apps::MonteCarloLocalization_Base::do_pf_localization(), and mrpt::hwdrivers::CGPSInterface::doProcess().

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

◆ operator=()

CFileOutputStream& mrpt::io::CFileOutputStream::operator= ( const CFileOutputStream )
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 CFileOutputStream::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 49 of file CFileOutputStream.cpp.

References MRPT_UNUSED_PARAM, and THROW_EXCEPTION.

◆ 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:

◆ Seek()

uint64_t CFileOutputStream::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 64 of file CFileOutputStream.cpp.

References getPosition(), m_of, 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 CFileOutputStream::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 56 of file CFileOutputStream.cpp.

References m_of.

Referenced by mrpt::hwdrivers::CGPSInterface::doProcess(), and mrpt::io::CMemoryStream::saveBufferToFile().

Here is the caller graph for this function:

Member Data Documentation

◆ m_of

std::ofstream mrpt::io::CFileOutputStream::m_of
private

The actual output file stream.

Definition at line 26 of file io/CFileOutputStream.h.

Referenced by close(), fileOpenCorrectly(), getPosition(), getTotalBytesCount(), open(), Seek(), and Write().




Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: cb8dd5fc8 Sat Dec 7 21:55:39 2019 +0100 at sáb dic 7 22:00:13 CET 2019