libSDL2pp  0.16.0
C++11 bindings/wrapper for SDL2
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
SDL2pp::RWops Class Reference

I/O abstraction. More...

#include <SDL2pp/RWops.hh>

Public Member Functions

 RWops (SDL_RWops *rwops)
 Create RWops from existing SDL2 SDL_RWops structure. More...
 
 RWops (RWops &&other) noexcept
 Move constructor. More...
 
RWopsoperator= (RWops &&other) noexcept
 Move assignment operator. More...
 
 RWops (const RWops &)=delete
 Deleted copy constructor. More...
 
RWopsoperator= (const RWops &)=delete
 Deleted assignment operator. More...
 
template<class C >
 RWops (C &&custom_rwops)
 Create RWops from CustomRWops derived class. More...
 
 ~RWops ()
 Destructor.
 
SDL_RWops * Get () const
 Get pointer to managed SDL_RWops structure. More...
 
int Close ()
 Close data source. More...
 
size_t Read (void *ptr, size_t size, size_t maxnum)
 Read from a data stream. More...
 
Sint64 Seek (Sint64 offset, int whence)
 Seek within the data stream. More...
 
size_t Write (const void *ptr, size_t size, size_t num)
 Write to a data stream. More...
 
Sint64 Tell ()
 Determine the current read/write offset within the data stream. More...
 
Sint64 Size ()
 Get current size of the data container. More...
 
Uint16 ReadBE16 ()
 Read 16 bits of big-endian data from data stream and return in native format. More...
 
Uint32 ReadBE32 ()
 Read 32 bits of big-endian data from data stream and return in native format. More...
 
Uint64 ReadBE64 ()
 Read 64 bits of big-endian data from data stream and return in native format. More...
 
Uint16 ReadLE16 ()
 Read 16 bits of little-endian data from data stream and return in native format. More...
 
Uint32 ReadLE32 ()
 Read 32 bits of little-endian data from data stream and return in native format. More...
 
Uint64 ReadLE64 ()
 Read 64 bits of little-endian data from data stream and return in native format. More...
 
size_t WriteBE16 (Uint16 value)
 Write 16 bits in native format to a data stream as big-endian data. More...
 
size_t WriteBE32 (Uint32 value)
 Write 32 bits in native format to a data stream as big-endian data. More...
 
size_t WriteBE64 (Uint64 value)
 Write 64 bits in native format to a data stream as big-endian data. More...
 
size_t WriteLE16 (Uint16 value)
 Write 16 bits in native format to a data stream as little-endian data. More...
 
size_t WriteLE32 (Uint32 value)
 Write 32 bits in native format to a data stream as little-endian data. More...
 
size_t WriteLE64 (Uint64 value)
 Write 64 bits in native format to a data stream as little-endian data. More...
 

Static Public Member Functions

static RWops FromFP (FILE *file, bool autoclose)
 Create RWops working through stdio's FILE*. More...
 
static RWops FromConstMem (const void *mem, int size)
 Create RWops working with a constant memory chunk. More...
 
static RWops FromMem (void *mem, int size)
 Create RWops working with a memory chunk. More...
 
static RWops FromFile (const std::string &file, const std::string &mode="rb")
 Create RWops working with plain file. More...
 

Protected Attributes

SDL_RWops * rwops_
 Managed SDL_RWops object.
 

Detailed Description

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++11 way.

Usage example:

{
// RWops which work on a plain file
// Texture is loaded through RWops
}

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.

Constructor & Destructor Documentation

◆ RWops() [1/4]

SDL2pp::RWops::RWops ( SDL_RWops *  rwops)
explicit

Create RWops from existing SDL2 SDL_RWops structure.

Parameters
[in]rwopsPointer to SDL_RWops to use

◆ RWops() [2/4]

SDL2pp::RWops::RWops ( RWops &&  other)
noexcept

Move constructor.

Parameters
[in]otherSDL2pp::RWops to move data from

◆ RWops() [3/4]

SDL2pp::RWops::RWops ( const RWops )
delete

Deleted copy constructor.

This class is not copyable

◆ RWops() [4/4]

template<class C >
SDL2pp::RWops::RWops ( C &&  custom_rwops)
inlineexplicit

Create RWops from CustomRWops derived class.

Parameters
[in]custom_rwopsCustom RWops functions
Exceptions
SDL2pp::Exception
Todo:
make this take arguments for C constructor

Member Function Documentation

◆ Close()

int SDL2pp::RWops::Close ( )

Close data source.

Returns
0 on success or a negative error code on failure
See also
http://wiki.libsdl.org/SDL_RWclose

◆ FromConstMem()

RWops SDL2pp::RWops::FromConstMem ( const void *  mem,
int  size 
)
static

Create RWops working with a constant memory chunk.

Parameters
[in]memPointer to the memory to work with
[in]sizeSize of a memory chunk
Returns
Created RWops
See also
http://wiki.libsdl.org/SDL_RWFromConstMem

◆ FromFile()

RWops SDL2pp::RWops::FromFile ( const std::string &  file,
const std::string &  mode = "rb" 
)
static

Create RWops working with plain file.

Parameters
[in]filePath to file
[in]modeOpen mode in stdio way
Returns
Created RWops
See also
http://wiki.libsdl.org/SDL_RWFromFile

◆ FromFP()

RWops SDL2pp::RWops::FromFP ( FILE *  file,
bool  autoclose 
)
static

Create RWops working through stdio's FILE*.

Parameters
[in]filePointer to stdio's FILE type
[in]autocloseTrue to take ownership of given FILE and close it on RWops destruction
Returns
Created RWops
See also
http://wiki.libsdl.org/SDL_RWFromFP

◆ FromMem()

RWops SDL2pp::RWops::FromMem ( void *  mem,
int  size 
)
static

Create RWops working with a memory chunk.

Parameters
[in]memPointer to the memory to work with
[in]sizeSize of a memory chunk
Returns
Created RWops
See also
http://wiki.libsdl.org/SDL_RWFromMem

◆ Get()

SDL_RWops * SDL2pp::RWops::Get ( ) const

Get pointer to managed SDL_RWops structure.

Returns
Pointer to managed SDL_RWops structure

◆ operator=() [1/2]

RWops & SDL2pp::RWops::operator= ( RWops &&  other)
noexcept

Move assignment operator.

Parameters
[in]otherSDL2pp::RWops to move data from
Returns
Reference to self

◆ operator=() [2/2]

RWops& SDL2pp::RWops::operator= ( const RWops )
delete

Deleted assignment operator.

This class is not copyable

◆ Read()

size_t SDL2pp::RWops::Read ( void *  ptr,
size_t  size,
size_t  maxnum 
)

Read from a data stream.

Parameters
[in]ptrPointer to a buffer to read data into
[in]sizeSize of each object to read, in bytes
[in]maxnumMaximum number of objects to be read
Returns
Number of objects read, or 0 at error or end of file
See also
http://wiki.libsdl.org/SDL_RWread

◆ ReadBE16()

Uint16 SDL2pp::RWops::ReadBE16 ( )

Read 16 bits of big-endian data from data stream and return in native format.

Returns
16 bits of data in the native byte order
See also
http://wiki.libsdl.org/SDL_ReadBE16

◆ ReadBE32()

Uint32 SDL2pp::RWops::ReadBE32 ( )

Read 32 bits of big-endian data from data stream and return in native format.

Returns
32 bits of data in the native byte order
See also
http://wiki.libsdl.org/SDL_ReadBE32

◆ ReadBE64()

Uint64 SDL2pp::RWops::ReadBE64 ( )

Read 64 bits of big-endian data from data stream and return in native format.

Returns
64 bits of data in the native byte order
See also
http://wiki.libsdl.org/SDL_ReadBE64

◆ ReadLE16()

Uint16 SDL2pp::RWops::ReadLE16 ( )

Read 16 bits of little-endian data from data stream and return in native format.

Returns
16 bits of data in the native byte order
See also
http://wiki.libsdl.org/SDL_ReadLE16

◆ ReadLE32()

Uint32 SDL2pp::RWops::ReadLE32 ( )

Read 32 bits of little-endian data from data stream and return in native format.

Returns
32 bits of data in the native byte order
See also
http://wiki.libsdl.org/SDL_ReadLE32

◆ ReadLE64()

Uint64 SDL2pp::RWops::ReadLE64 ( )

Read 64 bits of little-endian data from data stream and return in native format.

Returns
64 bits of data in the native byte order
See also
http://wiki.libsdl.org/SDL_ReadLE64

◆ Seek()

Sint64 SDL2pp::RWops::Seek ( Sint64  offset,
int  whence 
)

Seek within the data stream.

Parameters
[in]offsetOffset in bytes, relative to whence location; can be negative
[in]whenceAny of RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END
Returns
Final offset in the data stream after the seek or -1 on error
See also
http://wiki.libsdl.org/SDL_RWseek

◆ Size()

Sint64 SDL2pp::RWops::Size ( )

Get current size of the data container.

Returns
Data container size in bytes, or -1 if the information can not be determined

◆ Tell()

Sint64 SDL2pp::RWops::Tell ( )

Determine the current read/write offset within the data stream.

Returns
Current offset in the stream, or -1 if the information can not be determined
See also
http://wiki.libsdl.org/SDL_RWtell

◆ Write()

size_t SDL2pp::RWops::Write ( const void *  ptr,
size_t  size,
size_t  num 
)

Write to a data stream.

Parameters
[in]ptrPointer to a buffer containing data to write
[in]sizeSize of each object to write, in bytes
[in]numNumber of objects to be write
Returns
Number of objects written, which will be less than num on error
See also
http://wiki.libsdl.org/SDL_RWwrite

◆ WriteBE16()

size_t SDL2pp::RWops::WriteBE16 ( Uint16  value)

Write 16 bits in native format to a data stream as big-endian data.

Parameters
[in]valueData to be written, in native format
Returns
1 on successful write, 0 on error
See also
http://wiki.libsdl.org/SDL_WriteBE16

◆ WriteBE32()

size_t SDL2pp::RWops::WriteBE32 ( Uint32  value)

Write 32 bits in native format to a data stream as big-endian data.

Parameters
[in]valueData to be written, in native format
Returns
1 on successful write, 0 on error
See also
http://wiki.libsdl.org/SDL_WriteBE32

◆ WriteBE64()

size_t SDL2pp::RWops::WriteBE64 ( Uint64  value)

Write 64 bits in native format to a data stream as big-endian data.

Parameters
[in]valueData to be written, in native format
Returns
1 on successful write, 0 on error
See also
http://wiki.libsdl.org/SDL_WriteBE64

◆ WriteLE16()

size_t SDL2pp::RWops::WriteLE16 ( Uint16  value)

Write 16 bits in native format to a data stream as little-endian data.

Parameters
[in]valueData to be written, in native format
Returns
1 on successful write, 0 on error
See also
http://wiki.libsdl.org/SDL_WriteLE16

◆ WriteLE32()

size_t SDL2pp::RWops::WriteLE32 ( Uint32  value)

Write 32 bits in native format to a data stream as little-endian data.

Parameters
[in]valueData to be written, in native format
Returns
1 on successful write, 0 on error
See also
http://wiki.libsdl.org/SDL_WriteLE32

◆ WriteLE64()

size_t SDL2pp::RWops::WriteLE64 ( Uint64  value)

Write 64 bits in native format to a data stream as little-endian data.

Parameters
[in]valueData to be written, in native format
Returns
1 on successful write, 0 on error
See also
http://wiki.libsdl.org/SDL_WriteLE64

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