Worldstone
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
WorldStone::FileStream Class Reference

Wrapper around POSIX file io, same as ifstream but without iostream formatting. More...

#include <FileStream.h>

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

Public Member Functions

 FileStream (const Path &filename)
 
bool open (const Path &filename)
 
bool is_open () const
 
bool close ()
 
long tell () override
 Return the current position of the stream pointer. More...
 
bool seek (long offset, seekdir origin) override
 Change the pointer of the stream to a given position. More...
 
long size () override
 Computes the size of the file. More...
 
size_t read (void *buffer, size_t size) override
 Read data from the stream. More...
 
int getc () override
 Read one byte from the stream. More...
 
- Public Member Functions inherited from WorldStone::IStream
bool eof () const
 True if the end of the stream was reached during the last read operation.
 
template<typename T >
bool readRaw (T &out)
 
- 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

- Public Types inherited from WorldStone::IStream
enum  seekdir { beg, cur, end }
 
- Public Types inherited from WorldStone::IOBase
using Path = std::string
 
using iostate = int
 
- 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

Wrapper around POSIX file io, same as ifstream but without iostream formatting.

Definition at line 16 of file FileStream.h.

Member Function Documentation

int WorldStone::FileStream::getc ( )
overridevirtual

Read one byte from the stream.

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

Reimplemented from WorldStone::IStream.

Definition at line 72 of file FileStream.cpp.

size_t WorldStone::FileStream::read ( void *  buffer,
size_t  size 
)
overridevirtual

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.

Implements WorldStone::IStream.

Definition at line 29 of file FileStream.cpp.

bool WorldStone::FileStream::seek ( long  offset,
seekdir  origin 
)
overridevirtual

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

Implements WorldStone::IStream.

Definition at line 52 of file FileStream.cpp.

long WorldStone::FileStream::size ( )
overridevirtual

Computes the size of the file.

Returns
The size of the file on success, -1 on error
Note
This will call tell/seek multiple times, hence can be slow
Warning
If the current position is invalid, the new position might be EOF

Implements WorldStone::IStream.

Definition at line 59 of file FileStream.cpp.

long WorldStone::FileStream::tell ( )
overridevirtual

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.

Implements WorldStone::IStream.

Definition at line 42 of file FileStream.cpp.


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