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, bool append = false);
    CFileOutputStream();
    CFileOutputStream(const CFileOutputStream&);

    //
methods

    CFileOutputStream& operator = (const CFileOutputStream&);
    bool open(const std::string& fileName, bool append = false);
    void close();
    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, bool append = false)

Constructor.

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 = false)

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:

fileOpenCorrectly

void close()

Close the stream.

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 writen 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.