Worldstone
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
WorldStone::IStream Class Referenceabstract

An interface for a stream of data. More...

#include <Stream.h>

Inheritance diagram for WorldStone::IStream:
WorldStone::IOBase WorldStone::FileStream WorldStone::MpqFileStream

Public Types

enum  seekdir { beg, cur, end }
 
- Public Types inherited from WorldStone::IOBase
using Path = std::string
 
using iostate = int
 

Public Member Functions

bool eof () const
 True if the end of the stream was reached during the last read operation.
 
virtual long size ()=0
 Compute the size of the file. More...
 
virtual size_t read (void *buffer, size_t size)=0
 Read data from the stream. More...
 
template<typename T >
bool readRaw (T &out)
 
virtual int getc ()
 Read one byte from the stream. More...
 
virtual long tell ()=0
 Return the current position of the stream pointer. More...
 
virtual bool seek (long offset, seekdir origin)=0
 Change the pointer of the stream to a given position. More...
 
- Public Member Functions inherited from WorldStone::IOBase
 operator bool () const
 
bool operator! () const
 
bool good () const
 
bool eof () const
 
bool fail () const
 
bool bad () const
 

Additional Inherited Members

- Protected Member Functions inherited from WorldStone::IOBase
void setstate (iostate state)
 
- Protected Attributes inherited from WorldStone::IOBase
iostate _state = goodbit
 
- Static Protected Attributes inherited from WorldStone::IOBase
static constexpr iostate goodbit = 0x0
 
static constexpr iostate eofbit = 0x1
 
static constexpr iostate failbit = 0x2
 
static constexpr iostate badbit = 0x4
 

Detailed Description

An interface for a stream of data.

While it can be used to abstract many types of streams, file streams are usually created through an

See Also
Archive.
Tests:
RO_filestreams

Definition at line 22 of file Stream.h.

Member Function Documentation

int WorldStone::IStream::getc ( )
virtual

Read one byte from the stream.

Returns
The next byte to read from the stream, or a negative value on failure.

Reimplemented in WorldStone::FileStream.

Definition at line 17 of file _VTablesTU.cpp.

virtual size_t WorldStone::IStream::read ( void *  buffer,
size_t  size 
)
pure virtual

Read data from the stream.

Parameters
bufferPointer to a block of memory to fill. Must be at least 'size' bytes large.
sizeNumber of bytes to copy
Returns
The number of bytes successfully read. If less than 'size', EOF was reached or an error occured.

Implemented in WorldStone::MpqFileStream, and WorldStone::FileStream.

virtual bool WorldStone::IStream::seek ( long  offset,
seekdir  origin 
)
pure virtual

Change the pointer of the stream to a given position.

Parameters
offsetThe new position relative to the given reference position 'origin'.
originArbitrary reference to a position in the stream.
Returns
true on success, false if an error occured or an invalid position was given.
See Also
seekdir values : beg cur end

Implemented in WorldStone::MpqFileStream, and WorldStone::FileStream.

virtual long WorldStone::IStream::size ( )
pure virtual

Compute the size of the file.

Returns
the size of the file, or a negative value on error

Implemented in WorldStone::MpqFileStream, and WorldStone::FileStream.

virtual long WorldStone::IStream::tell ( )
pure virtual

Return the current position of the stream pointer.

Returns
The offset in bytes to the currently pointed position. A negative value on failure.
Note
The seek method can be used to restore a position.

Implemented in WorldStone::MpqFileStream, and WorldStone::FileStream.


The documentation for this class was generated from the following files: