QSFML
Public Member Functions | Friends | List of all members
qsf::QResourceStream Class Reference

sf::InputStream reading QResource files More...

#include <qresourcestream.hpp>

Inheritance diagram for qsf::QResourceStream:
Inheritance graph
[legend]

Public Member Functions

 QResourceStream ()
 Default constructor. More...
 
 ~QResourceStream ()
 Destructor. More...
 
bool open (const char *path)
 Opens file. More...
 
virtual sf::Int64 read (void *data, sf::Int64 size)
 Reads parts of resource. More...
 
virtual sf::Int64 seek (sf::Int64 position)
 Sets new cursor's position. More...
 
virtual sf::Int64 tell ()
 Returns cursor's position. More...
 
virtual sf::Int64 getSize ()
 Returns file size. More...
 
QResourceStreamoperator() (const char *path)
 Open a file using operator() More...
 

Friends

std::ostream & operator<< (std::ostream &out, QResourceStream &resource)
 Prints whole file (std::ostream) More...
 
QDebug operator<< (QDebug out, const QResourceStream &resource)
 Prints whole file (QDebug) More...
 

Detailed Description

sf::InputStream reading QResource files

This class inherits sf::InputStream, so it can by used by any SFML method that takes reference to such object. Therafore you can store your textures, sounds etc. in an execatulable/binary file using Qt resources and then read them thanks to this class.

Constructor & Destructor Documentation

qsf::QResourceStream::QResourceStream ( )

Default constructor.

Does nothing expect of setting private variables to proper values.

qsf::QResourceStream::~QResourceStream ( )

Destructor.

Frees resources (memory).

Member Function Documentation

sf::Int64 qsf::QResourceStream::getSize ( )
virtual

Returns file size.

Returns
File size.
bool qsf::QResourceStream::open ( const char *  path)

Opens file.

Parameters
[in]path– Path to file
Returns
True if file was opened and read properly, False otherwise.

Opens given file, loads its contents to memory and then closes it.

QResourceStream & qsf::QResourceStream::operator() ( const char *  path)

Open a file using operator()

Parameters
[in]path– Path to file
Returns
Reference to *this (the same object).

Opens a file and then returns reference, discards informations about file being opened properly. Such a structure allows writing code like that:

QResourceStream resource;
/* Other code */
someTexture.loadFromStream(resource("://BitTexture.png"));
someMusic.loadFromStream(resource("://BitMusic.wav"));

So you don't need to declare many instances of QResourceStream.

sf::Int64 qsf::QResourceStream::read ( void *  data,
sf::Int64  size 
)
virtual

Reads parts of resource.

Parameters
[in]size– Amount of thata to be read
[out]data– Pointer to place, where data should be copied
Returns
New position of cursor in file.
sf::Int64 qsf::QResourceStream::seek ( sf::Int64  position)
virtual

Sets new cursor's position.

Parameters
[in]position– New position
Returns
New position of cursor in file.
sf::Int64 qsf::QResourceStream::tell ( )
virtual

Returns cursor's position.

Returns
New position of cursor in file.

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
QResourceStream resource 
)
friend

Prints whole file (std::ostream)

Allows printing file to std::ostream.
Sample usage:

QResourceStream resource;
if(!resource.open("://BuiltInFile.txt")) {
std::cerr << "Could not read resource!" << std::endl;
} else {
std::cout << "Content:" << std::endl << resource << std::endl;
}
QDebug operator<< ( QDebug  out,
const QResourceStream resource 
)
friend

Prints whole file (QDebug)

Allows printing file to QDebug.
Sample usage:

QResourceStream resource;
if(!resource.open("://BuiltInFile.txt")) {
qDebug() << "Could not read resource!";
} else {
qDebug() << "Content:" << resource;
}

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