Class CFileOutputStream

Inheritance Relationships

Base Type

Class Documentation

class CFileOutputStream : public mrpt::io::CStream

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

Public Functions

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.

Throws:

std::exception – if the file cannot be opened.

CFileOutputStream()

Default constructor

CFileOutputStream(const CFileOutputStream&) = delete
CFileOutputStream &operator=(const CFileOutputStream&) = delete
bool open(const std::string &fileName, const OpenMode mode = OpenMode::TRUNCATE)
void close()

Close the stream.

virtual std::string getStreamDescription() const override

Returns a human-friendly description of the stream, e.g. a filename.

~CFileOutputStream() override

Destructor

bool fileOpenCorrectly() const

Returns true if the file was open without errors.

inline bool is_open()

Returns true if the file was open without errors.

virtual 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. 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 override

Method for getting the total number of bytes written to buffer

virtual uint64_t getPosition() const override

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) override

Introduces a pure virtual method responsible for reading from the stream.

virtual size_t Write(const void *Buffer, size_t Count) override

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.