Documentation of SFML 2.6.1

Loading...
Searching...
No Matches
sf::InputStream Class Referenceabstract

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

#include <SFML/System/InputStream.hpp>

Inheritance diagram for sf::InputStream:
sf::FileInputStream sf::MemoryInputStream

Public Member Functions

virtual ~InputStream ()
 Virtual destructor.
 
virtual Int64 read (void *data, Int64 size)=0
 Read data from the stream.
 
virtual Int64 seek (Int64 position)=0
 Change the current reading position.
 
virtual Int64 tell ()=0
 Get the current reading position in the stream.
 
virtual Int64 getSize ()=0
 Return the size of the stream.
 

Detailed Description

Abstract class for custom file input streams.

This class allows users to define their own file input sources from which SFML can load resources.

SFML resource classes like sf::Texture and sf::SoundBuffer provide loadFromFile and loadFromMemory functions, which 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 sf::InputStream and load SFML resources with their loadFromStream function.

Usage example:

// custom stream class that reads from inside a zip file
class ZipStream : public sf::InputStream
{
public:
ZipStream(std::string archive);
bool open(std::string filename);
Int64 read(void* data, Int64 size);
Int64 seek(Int64 position);
Int64 tell();
Int64 getSize();
private:
...
};
// now you can load textures...
sf::Texture texture;
ZipStream stream("resources.zip");
stream.open("images/img.png");
texture.loadFromStream(stream);
// musics...
sf::Music music;
ZipStream stream("resources.zip");
stream.open("musics/msc.ogg");
music.openFromStream(stream);
// etc.
Abstract class for custom file input streams.
Streamed music played from an audio file.
Definition Music.hpp:49
bool openFromStream(InputStream &stream)
Open a music from an audio file in a custom stream.
Image living on the graphics card that can be used for drawing.
Definition Texture.hpp:49
bool loadFromStream(InputStream &stream, const IntRect &area=IntRect())
Load the texture from a custom stream.

Definition at line 41 of file InputStream.hpp.

Constructor & Destructor Documentation

◆ ~InputStream()

virtual sf::InputStream::~InputStream ( )
inlinevirtual

Virtual destructor.

Definition at line 49 of file InputStream.hpp.

Member Function Documentation

◆ getSize()

virtual Int64 sf::InputStream::getSize ( )
pure virtual

Return the size of the stream.

Returns
The total number of bytes available in the stream, or -1 on error

Implemented in sf::FileInputStream, and sf::MemoryInputStream.

◆ read()

virtual Int64 sf::InputStream::read ( void *  data,
Int64  size 
)
pure virtual

Read data from the stream.

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

Parameters
dataBuffer where to copy the read data
sizeDesired number of bytes to read
Returns
The number of bytes actually read, or -1 on error

Implemented in sf::FileInputStream, and sf::MemoryInputStream.

◆ seek()

virtual Int64 sf::InputStream::seek ( Int64  position)
pure virtual

Change the current reading position.

Parameters
positionThe position to seek to, from the beginning
Returns
The position actually sought to, or -1 on error

Implemented in sf::FileInputStream, and sf::MemoryInputStream.

◆ tell()

virtual Int64 sf::InputStream::tell ( )
pure virtual

Get the current reading position in the stream.

Returns
The current position, or -1 on error.

Implemented in sf::FileInputStream, and sf::MemoryInputStream.


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