libSDL2pp
C++ bindings/wrapper for SDL2
|
I/O abstraction. More...
#include <SDL2pp/RWops.hh>
Public Member Functions | |
RWops (SDL_RWops *rwops) | |
Create RWops from existing SDL2 SDL_RWops structure. | |
RWops (RWops &&other) noexcept | |
Move constructor. | |
RWops & | operator= (RWops &&other) noexcept |
Move assignment operator. | |
RWops (const RWops &)=delete | |
Deleted copy constructor. | |
RWops & | operator= (const RWops &)=delete |
Deleted assignment operator. | |
template<class C > | |
RWops (C &&custom_rwops) | |
Create RWops from CustomRWops derived class. | |
~RWops () | |
Destructor. | |
SDL_RWops * | Get () const |
Get pointer to managed SDL_RWops structure. | |
int | Close () |
Close data source. | |
size_t | Read (void *ptr, size_t size, size_t maxnum) |
Read from a data stream. | |
Sint64 | Seek (Sint64 offset, int whence) |
Seek within the data stream. | |
size_t | Write (const void *ptr, size_t size, size_t num) |
Write to a data stream. | |
Sint64 | Tell () |
Determine the current read/write offset within the data stream. | |
Sint64 | Size () |
Get current size of the data container. | |
Uint16 | ReadBE16 () |
Read 16 bits of big-endian data from data stream and return in native format. | |
Uint32 | ReadBE32 () |
Read 32 bits of big-endian data from data stream and return in native format. | |
Uint64 | ReadBE64 () |
Read 64 bits of big-endian data from data stream and return in native format. | |
Uint16 | ReadLE16 () |
Read 16 bits of little-endian data from data stream and return in native format. | |
Uint32 | ReadLE32 () |
Read 32 bits of little-endian data from data stream and return in native format. | |
Uint64 | ReadLE64 () |
Read 64 bits of little-endian data from data stream and return in native format. | |
size_t | WriteBE16 (Uint16 value) |
Write 16 bits in native format to a data stream as big-endian data. | |
size_t | WriteBE32 (Uint32 value) |
Write 32 bits in native format to a data stream as big-endian data. | |
size_t | WriteBE64 (Uint64 value) |
Write 64 bits in native format to a data stream as big-endian data. | |
size_t | WriteLE16 (Uint16 value) |
Write 16 bits in native format to a data stream as little-endian data. | |
size_t | WriteLE32 (Uint32 value) |
Write 32 bits in native format to a data stream as little-endian data. | |
size_t | WriteLE64 (Uint64 value) |
Write 64 bits in native format to a data stream as little-endian data. | |
Static Public Member Functions | |
static RWops | FromFP (FILE *file, bool autoclose) |
Create RWops working through stdio's FILE*. | |
static RWops | FromConstMem (const void *mem, int size) |
Create RWops working with a constant memory chunk. | |
static RWops | FromMem (void *mem, int size) |
Create RWops working with a memory chunk. | |
static RWops | FromFile (const std::string &file, const std::string &mode="rb") |
Create RWops working with plain file. | |
Protected Attributes | |
SDL_RWops * | rwops_ |
Managed SDL_RWops object. | |
I/O abstraction.
RWops is an SDL2 abstraction of file-like I/O. For most functions that take file name as a parameter, SDL2 has an alternative which take RWops, and through RWops its functionality is extended from just files to arbitrary objects that support file-like operations.
For example, SDL2 provide 4 builtin types of RWops: File (takes file name and works with plain file), FP (takes stdio's FILE* and works with it), Mem and ConstMem (take memory chunk and work with it like a file) and allow one to write custom RWops.
SDL2pp::RWops support all this in extended C++ way.
Usage example:
Implementation note:
This class is more complicated than just wrapper over SDL_RWops, but it's needed to both retain compatibility with C SDL2 and to make it possible to write pure C++ RWops classes, in a safe way.
|
explicit |
Create RWops from existing SDL2 SDL_RWops structure.
[in] | rwops | Pointer to SDL_RWops to use |
|
noexcept |
Move constructor.
[in] | other | SDL2pp::RWops to move data from |
|
delete |
Deleted copy constructor.
This class is not copyable
|
inlineexplicit |
Create RWops from CustomRWops derived class.
[in] | custom_rwops | Custom RWops functions |
SDL2pp::Exception |
SDL2pp::RWops::~RWops | ( | ) |
Destructor.
int SDL2pp::RWops::Close | ( | ) |
Close data source.
|
static |
|
static |
|
static |
|
static |
SDL_RWops * SDL2pp::RWops::Get | ( | ) | const |
Get pointer to managed SDL_RWops structure.
Deleted assignment operator.
This class is not copyable
Move assignment operator.
[in] | other | SDL2pp::RWops to move data from |
size_t SDL2pp::RWops::Read | ( | void * | ptr, |
size_t | size, | ||
size_t | maxnum | ||
) |
Read from a data stream.
[in] | ptr | Pointer to a buffer to read data into |
[in] | size | Size of each object to read, in bytes |
[in] | maxnum | Maximum number of objects to be read |
Uint16 SDL2pp::RWops::ReadBE16 | ( | ) |
Read 16 bits of big-endian data from data stream and return in native format.
Uint32 SDL2pp::RWops::ReadBE32 | ( | ) |
Read 32 bits of big-endian data from data stream and return in native format.
Uint64 SDL2pp::RWops::ReadBE64 | ( | ) |
Read 64 bits of big-endian data from data stream and return in native format.
Uint16 SDL2pp::RWops::ReadLE16 | ( | ) |
Read 16 bits of little-endian data from data stream and return in native format.
Uint32 SDL2pp::RWops::ReadLE32 | ( | ) |
Read 32 bits of little-endian data from data stream and return in native format.
Uint64 SDL2pp::RWops::ReadLE64 | ( | ) |
Read 64 bits of little-endian data from data stream and return in native format.
Sint64 SDL2pp::RWops::Seek | ( | Sint64 | offset, |
int | whence | ||
) |
Seek within the data stream.
[in] | offset | Offset in bytes, relative to whence location; can be negative |
[in] | whence | Any of RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END |
Sint64 SDL2pp::RWops::Size | ( | ) |
Get current size of the data container.
Sint64 SDL2pp::RWops::Tell | ( | ) |
Determine the current read/write offset within the data stream.
size_t SDL2pp::RWops::Write | ( | const void * | ptr, |
size_t | size, | ||
size_t | num | ||
) |
Write to a data stream.
[in] | ptr | Pointer to a buffer containing data to write |
[in] | size | Size of each object to write, in bytes |
[in] | num | Number of objects to be write |
size_t SDL2pp::RWops::WriteBE16 | ( | Uint16 | value | ) |
Write 16 bits in native format to a data stream as big-endian data.
[in] | value | Data to be written, in native format |
size_t SDL2pp::RWops::WriteBE32 | ( | Uint32 | value | ) |
Write 32 bits in native format to a data stream as big-endian data.
[in] | value | Data to be written, in native format |
size_t SDL2pp::RWops::WriteBE64 | ( | Uint64 | value | ) |
Write 64 bits in native format to a data stream as big-endian data.
[in] | value | Data to be written, in native format |
size_t SDL2pp::RWops::WriteLE16 | ( | Uint16 | value | ) |
Write 16 bits in native format to a data stream as little-endian data.
[in] | value | Data to be written, in native format |
size_t SDL2pp::RWops::WriteLE32 | ( | Uint32 | value | ) |
Write 32 bits in native format to a data stream as little-endian data.
[in] | value | Data to be written, in native format |
size_t SDL2pp::RWops::WriteLE64 | ( | Uint64 | value | ) |
Write 64 bits in native format to a data stream as little-endian data.
[in] | value | Data to be written, in native format |