Gamedev Framework (gf)  0.11.0
A C++14 framework for 2D games
Public Member Functions | List of all members
gf::InputStream Class Referenceabstract

Abstract class for custom file input streams. More...

#include <gf/Stream.h>

Inheritance diagram for gf::InputStream:
Inheritance graph
[legend]

Public Member Functions

 InputStream ()=default
 Default constructor. More...
 
 InputStream (const InputStream &)=delete
 Deleted copy constructor. More...
 
InputStreamoperator= (const InputStream &)=delete
 Deleted copy assignment. More...
 
virtual ~InputStream ()
 Destructor. More...
 
virtual std::size_t read (BufferRef< uint8_t > buffer)=0
 Read data from the stream. More...
 
std::size_t read (uint8_t &byte)
 Read a single byte from the stream. More...
 
virtual void seek (std::ptrdiff_t position)=0
 Change the current reading position. More...
 
virtual void skip (std::ptrdiff_t position)=0
 Change the current reading position. More...
 
virtual bool isFinished ()=0
 Tell if the stream is at the end. More...
 

Detailed Description

Abstract class for custom file input streams.

This class allows users to define their own stream input sources from which Gamedev Framework can load resources.

Gamedev Framework resource classes like gf::Texture and gf::Shader provide constructors that read data from conventional sources. However, if you have data coming from a different source (over a network, embedded, encrypted, compressed, etc) you can derive your own class from gf::InputStream and use the constructor that takes a generic input stream.

See also
gf::OutputStream

Constructor & Destructor Documentation

◆ InputStream() [1/2]

gf::InputStream::InputStream ( )
default

Default constructor.

◆ InputStream() [2/2]

gf::InputStream::InputStream ( const InputStream )
delete

Deleted copy constructor.

◆ ~InputStream()

virtual gf::InputStream::~InputStream ( )
virtual

Destructor.

Member Function Documentation

◆ isFinished()

virtual bool gf::InputStream::isFinished ( )
pure virtual

Tell if the stream is at the end.

Returns
A boolean indicating the end of the stream

Implemented in gf::CompressedInputStream, gf::MemoryInputStream, and gf::FileInputStream.

◆ operator=()

InputStream& gf::InputStream::operator= ( const InputStream )
delete

Deleted copy assignment.

◆ read() [1/2]

virtual std::size_t gf::InputStream::read ( BufferRef< uint8_t >  buffer)
pure virtual

Read data from the stream.

After reading, the stream's reading position must be advanced by the amount of bytes read.

Parameters
bufferThe buffer where to copy the read data
Returns
The number of bytes actually read

Implemented in gf::CompressedInputStream, gf::MemoryInputStream, and gf::FileInputStream.

◆ read() [2/2]

std::size_t gf::InputStream::read ( uint8_t &  byte)
inline

Read a single byte from the stream.

This is a convinience function to read a single byte instead of a whole buffer.

Parameters
byteThe byte where to copy the read data
Returns
The number of bytes actually read

◆ seek()

virtual void gf::InputStream::seek ( std::ptrdiff_t  position)
pure virtual

Change the current reading position.

Parameters
positionThe position to seek to, from the beginning

Implemented in gf::CompressedInputStream, gf::MemoryInputStream, and gf::FileInputStream.

◆ skip()

virtual void gf::InputStream::skip ( std::ptrdiff_t  position)
pure virtual

Change the current reading position.

Parameters
positionThe position to seek to, from the current position

Implemented in gf::CompressedInputStream, gf::MemoryInputStream, and gf::FileInputStream.