Main MRPT website > C++ reference
MRPT logo
Public Member Functions | Protected Member Functions | Private Attributes

mrpt::utils::CFileStream Class Reference


Detailed Description

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.

See also:
CStream, CFileInputStream, CFileOutputStrea, CFileGZInputStream

Definition at line 60 of file CFileStream.h.

#include <mrpt/utils/CFileStream.h>

Inheritance diagram for mrpt::utils::CFileStream:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 CFileStream (const std::string &fileName, TFileOpenModes mode=fomRead|fomWrite)
 Constructor and open a file.
 CFileStream ()
 Constructor.
bool open (const std::string &fileName, TFileOpenModes mode=fomRead|fomWrite)
 Opens the file, returning true on success.
void close ()
 Closes the file.
virtual ~CFileStream ()
 Destructor.
bool fileOpenCorrectly ()
 Says if file was open successfully or not.
bool checkEOF ()
 Will be true if EOF has been already reached.
uint64_t Seek (long Offset, CStream::TSeekOrigin Origin=sFromBeginning)
 Method for moving to a specified position in the streamed resource.
uint64_t getTotalBytesCount ()
 Method for getting the total number of bytes writen to buffer.
uint64_t getPosition ()
 Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the last one.
uint64_t getPositionI ()
 The current Input cursor position, where 0 is the first byte.
uint64_t getPositionO ()
 The current Input cursor position, where 0 is the first byte.
bool readLine (std::string &str)
 Reads one string line from the file (until a new-line character)

Protected Member Functions

size_t Read (void *Buffer, size_t Count)
 Method responsible for reading from the stream.
size_t Write (const void *Buffer, size_t Count)
 Method responsible for writing to the stream.

Private Attributes

std::fstream m_f
 The actual input file stream.

Constructor & Destructor Documentation

mrpt::utils::CFileStream::CFileStream ( const std::string &  fileName,
TFileOpenModes  mode = fomRead|fomWrite 
)

Constructor and open a file.

Parameters:
fileNameThe file to be open in this stream
modeThe open mode: can be an or'd conbination of different values.
Exceptions:
std::exceptionOn error creating or accessing the file. By default the file is opened for open and write and created if not found.
mrpt::utils::CFileStream::CFileStream ( )

Constructor.

virtual mrpt::utils::CFileStream::~CFileStream ( ) [virtual]

Destructor.


Member Function Documentation

bool mrpt::utils::CFileStream::checkEOF ( )

Will be true if EOF has been already reached.

void mrpt::utils::CFileStream::close ( )

Closes the file.

bool mrpt::utils::CFileStream::fileOpenCorrectly ( )

Says if file was open successfully or not.

uint64_t mrpt::utils::CFileStream::getPosition ( ) [virtual]

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

Implements mrpt::utils::CStream.

uint64_t mrpt::utils::CFileStream::getPositionI ( )

The current Input cursor position, where 0 is the first byte.

uint64_t mrpt::utils::CFileStream::getPositionO ( )

The current Input cursor position, where 0 is the first byte.

uint64_t mrpt::utils::CFileStream::getTotalBytesCount ( ) [virtual]

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

Implements mrpt::utils::CStream.

bool mrpt::utils::CFileStream::open ( const std::string &  fileName,
TFileOpenModes  mode = fomRead|fomWrite 
)

Opens the file, returning true on success.

Parameters:
fileNameThe file to be open in this stream
modeThe 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.
size_t mrpt::utils::CFileStream::Read ( void *  Buffer,
size_t  Count 
) [protected, virtual]

Method responsible for reading from the stream.

Implements mrpt::utils::CStream.

bool mrpt::utils::CFileStream::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.
uint64_t mrpt::utils::CFileStream::Seek ( long  Offset,
CStream::TSeekOrigin  Origin = sFromBeginning 
) [virtual]

Method for moving to a specified position in the streamed resource.

See documentation of CStream::Seek

Implements mrpt::utils::CStream.

size_t mrpt::utils::CFileStream::Write ( const void *  Buffer,
size_t  Count 
) [protected, 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::utils::CStream.


Member Data Documentation

std::fstream mrpt::utils::CFileStream::m_f [private]

The actual input file stream.

Definition at line 73 of file CFileStream.h.




Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN:exported at Tue Jan 25 21:56:31 UTC 2011