class mrpt::io::CFileOutputStream
This CStream derived class allow using a file as a write-only, binary stream.
See also:
CStream, CFileStream, CFileGZOutputStream
#include <mrpt/io/CFileOutputStream.h> class CFileOutputStream: public mrpt::io::CStream { public: // construction CFileOutputStream(const std::string& fileName, const OpenMode mode = OpenMode::TRUNCATE); CFileOutputStream(const std::string& fileName, bool append); CFileOutputStream(); CFileOutputStream(const CFileOutputStream&); // methods CFileOutputStream& operator = (const CFileOutputStream&); bool open(const std::string& fileName, bool append); bool open( const std::string& fileName, const OpenMode mode = OpenMode::TRUNCATE ); void close(); virtual std::string getStreamDescription() const; bool fileOpenCorrectly() const; bool is_open(); virtual uint64_t Seek(int64_t Offset, CStream::TSeekOrigin Origin = sFromBeginning); virtual uint64_t getTotalBytesCount() const; virtual uint64_t getPosition() const; virtual size_t Read(void* Buffer, size_t Count); virtual size_t Write(const void* Buffer, size_t Count); };
Inherited Members
public: // methods virtual size_t Read(void* Buffer, size_t Count) = 0; virtual size_t Write(const void* Buffer, size_t Count) = 0; virtual uint64_t getTotalBytesCount() const = 0; virtual uint64_t getPosition() const = 0;
Construction
CFileOutputStream(const std::string& fileName, const OpenMode mode = OpenMode::TRUNCATE)
Constructor.
Parameters:
fileName |
The file to be open in this stream |
mode |
Especify whether to truncate/create the file, or to append at the end if it exists. |
std::exception |
if the file cannot be opened. |
CFileOutputStream(const std::string& fileName, bool append)
Constructor.
Deprecated
Parameters:
fileName |
The file to be open in this stream |
append |
If 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. |
std::exception |
if the file cannot be opened. |
CFileOutputStream()
Default constructor.
Methods
bool open(const std::string& fileName, bool append)
Open the given file for write.
Parameters:
fileName |
The file to be open in this stream |
append |
If 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. |
Returns:
true on success.
See also:
void close()
Close the stream.
virtual std::string getStreamDescription() const
Returns a human-friendly description of the stream, e.g.
a filename.
bool fileOpenCorrectly() const
Returns true if the file was open without errors.
bool is_open()
Returns true if the file was open without errors.
virtual uint64_t Seek(int64_t Offset, CStream::TSeekOrigin Origin = sFromBeginning)
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.
virtual uint64_t getTotalBytesCount() const
Method for getting the total number of bytes written to buffer.
virtual uint64_t getPosition() const
Method for getting the current cursor position, where 0 is the first byte and TotalBytesCount-1 the last one.
virtual size_t Read(void* Buffer, size_t Count)
Introduces a pure virtual method responsible for reading from the stream.
virtual size_t Write(const void* Buffer, size_t Count)
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.