class mrpt::io::CFileInputStream

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

See also:

CStream, CFileStream, CFileGZInputStream

#include <mrpt/io/CFileInputStream.h>

class CFileInputStream: public mrpt::io::CStream
{
public:
    // construction

    CFileInputStream(const std::string& fileName);
    CFileInputStream();
    CFileInputStream(const CFileInputStream&);

    //
methods

    CFileInputStream& operator = (const CFileInputStream&);
    bool open(const std::string& fileName);
    void close();
    bool fileOpenCorrectly() const;
    bool is_open();
    bool checkEOF();
    void clearError();
    virtual std::string getStreamDescription() const;
    virtual uint64_t Seek(int64_t Offset, CStream::TSeekOrigin Origin = sFromBeginning);
    virtual uint64_t getTotalBytesCount() const;
    virtual uint64_t getPosition() const;
    bool readLine(std::string& str);
    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

CFileInputStream(const std::string& fileName)

Constructor.

Parameters:

fileName

The file to be open in this stream

std::exception

On error trying to open the file.

CFileInputStream()

Default constructor.

Methods

bool open(const std::string& fileName)

Open a file for reading.

Parameters:

fileName

The file to be open in this stream

Returns:

true on success.

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.

bool checkEOF()

Will be true if EOF has been already reached.

void clearError()

Resets stream error status bits (e.g.

after an EOF)

virtual std::string getStreamDescription() const

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

a filename.

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

Returns the total amount of bytes in the stream.

virtual uint64_t getPosition() const

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

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

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.