SDL3pp
A slim C++ wrapper for SDL3
|
The read/write operation structure. More...
Public Member Functions | |
PropertiesRef | GetProperties () const |
Get the properties associated with an IOStreamRef. | |
IOStatus | GetStatus () const |
Query the stream status of an IOStreamRef. | |
Sint64 | GetSize () const |
Use this function to get the size of the data stream in an IOStreamRef. | |
Sint64 | Seek (Sint64 offset, IOWhence whence) |
Seek within an IOStreamRef data stream. | |
Sint64 | Tell () const |
Determine the current read/write offset in an IOStreamRef data stream. | |
std::string | Read (size_t size=-1) |
Read from a data source. | |
size_t | Read (TargetBytes buf) |
Read from a data source. | |
size_t | Write (SourceBytes buf) |
Write to an IOStreamRef data stream. | |
size_t | print (std::string_view fmt, auto... args) |
size_t | println (std::string_view fmt, auto... args) |
size_t | printf (SDL_PRINTF_FORMAT_STRING const char *fmt,...) |
Print to an IOStreamRef data stream. | |
size_t | vprintf (SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) |
Print to an IOStreamRef data stream. | |
void | Flush () |
Flush any buffered data in the stream. | |
StringResult | LoadFile () |
Load all the data from an SDL data stream. | |
template<class T > | |
OwnArray< T > | LoadFileAs () |
Load all the data from an SDL data stream. | |
void | SaveFile (SourceBytes data) |
Save all the data into an SDL data stream. | |
Uint8 | ReadU8 () |
Use this function to read a byte from an IOStreamRef. | |
Sint8 | ReadS8 () |
Use this function to read a signed byte from an IOStreamRef. | |
Uint16 | ReadU16LE () |
Use this function to read 16 bits of little-endian data from an IOStreamRef and return in native format. | |
Sint16 | ReadS16LE () |
Use this function to read 16 bits of little-endian data from an IOStreamRef and return in native format. | |
Uint16 | ReadU16BE () |
Use this function to read 16 bits of big-endian data from an IOStreamRef and return in native format. | |
Sint16 | ReadS16BE () |
Use this function to read 16 bits of big-endian data from an IOStreamRef and return in native format. | |
Uint32 | ReadU32LE () |
Use this function to read 32 bits of little-endian data from an IOStreamRef and return in native format. | |
Sint32 | ReadS32LE () |
Use this function to read 32 bits of little-endian data from an IOStreamRef and return in native format. | |
Uint32 | ReadU32BE () |
Use this function to read 32 bits of big-endian data from an IOStreamRef and return in native format. | |
Sint32 | ReadS32BE () |
Use this function to read 32 bits of big-endian data from an IOStreamRef and return in native format. | |
Uint64 | ReadU64LE () |
Use this function to read 64 bits of little-endian data from an IOStreamRef and return in native format. | |
Sint64 | ReadS64LE () |
Use this function to read 64 bits of little-endian data from an IOStreamRef and return in native format. | |
Uint64 | ReadU64BE () |
Use this function to read 64 bits of big-endian data from an IOStreamRef and return in native format. | |
Sint64 | ReadS64BE () |
Use this function to read 64 bits of big-endian data from an IOStreamRef and return in native format. | |
void | WriteU8 (Uint8 value) |
Use this function to write a byte to an IOStreamRef. | |
void | WriteS8 (Sint8 value) |
Use this function to write a signed byte to an IOStreamRef. | |
void | WriteU16LE (Uint16 value) |
Use this function to write 16 bits in native format to an IOStreamRef as little-endian data. | |
void | WriteS16LE (Sint16 value) |
Use this function to write 16 bits in native format to an IOStreamRef as little-endian data. | |
void | WriteU16BE (Uint16 value) |
Use this function to write 16 bits in native format to an IOStreamRef as big-endian data. | |
void | WriteS16BE (Sint16 value) |
Use this function to write 16 bits in native format to an IOStreamRef as big-endian data. | |
void | WriteU32LE (Uint32 value) |
Use this function to write 32 bits in native format to an IOStreamRef as little-endian data. | |
void | WriteS32LE (Sint32 value) |
Use this function to write 32 bits in native format to an IOStreamRef as little-endian data. | |
void | WriteU32BE (Uint32 value) |
Use this function to write 32 bits in native format to an IOStreamRef as big-endian data. | |
void | WriteS32BE (Sint32 value) |
Use this function to write 32 bits in native format to an IOStreamRef as big-endian data. | |
void | WriteU64LE (Uint64 value) |
Use this function to write 64 bits in native format to an IOStreamRef as little-endian data. | |
void | WriteS64LE (Sint64 value) |
Use this function to write 64 bits in native format to an IOStreamRef as little-endian data. | |
void | WriteU64BE (Uint64 value) |
Use this function to write 64 bits in native format to an IOStreamRef as big-endian data. | |
void | WriteS64BE (Sint64 value) |
Use this function to write 64 bits in native format to an IOStreamRef as big-endian data. | |
std::optional< Uint8 > | TryReadU8 () |
Use this function to read a byte from an IOStreamRef. | |
std::optional< Sint8 > | TryReadS8 () |
Use this function to read a byte from an IOStreamRef. | |
std::optional< Uint16 > | TryReadU16LE () |
Use this function to read 16 bits of little-endian data from an IOStreamRef and return in native format. | |
std::optional< Sint16 > | TryReadS16LE () |
Use this function to read 16 bits of little-endian data from an IOStreamRef and return in native format. | |
std::optional< Uint16 > | TryReadU16BE () |
Use this function to read 16 bits of big-endian data from an IOStreamRef and return in native format. | |
std::optional< Sint16 > | TryReadS16BE () |
Use this function to read 16 bits of big-endian data from an IOStreamRef and return in native format. | |
std::optional< Uint32 > | TryReadU32LE () |
Use this function to read 32 bits of little-endian data from an IOStreamRef and return in native format. | |
std::optional< Sint32 > | TryReadS32LE () |
Use this function to read 32 bits of little-endian data from an IOStreamRef and return in native format. | |
std::optional< Uint32 > | TryReadU32BE () |
Use this function to read 32 bits of big-endian data from an IOStreamRef and return in native format. | |
std::optional< Sint32 > | TryReadS32BE () |
Use this function to read 32 bits of big-endian data from an IOStreamRef and return in native format. | |
std::optional< Uint64 > | TryReadU64LE () |
Use this function to read 64 bits of little-endian data from an IOStreamRef and return in native format. | |
std::optional< Sint64 > | TryReadS64LE () |
Use this function to read 64 bits of little-endian data from an IOStreamRef and return in native format. | |
std::optional< Uint64 > | TryReadU64BE () |
Use this function to read 64 bits of big-endian data from an IOStreamRef and return in native format. | |
std::optional< Sint64 > | TryReadS64BE () |
Use this function to read 64 bits of big-endian data from an IOStreamRef and return in native format. | |
constexpr | Resource (T resource={}) |
Constructs from the underlying resource. | |
constexpr | Resource (const ResourceHandle< Resource< T > > auto &resource) |
Constructs from pointer like. | |
constexpr | Resource (std::nullptr_t) |
Equivalent to default ctor. | |
constexpr | Resource (std::nullopt_t) |
Equivalent to default ctor. | |
![]() | |
constexpr | Resource (SDL_IOStream * resource={}) |
Constructs from the underlying resource. | |
constexpr | Resource (const ResourceHandle< Resource< SDL_IOStream * > > auto &resource) |
Constructs from pointer like. | |
constexpr | Resource (std::nullptr_t) |
Equivalent to default ctor. | |
constexpr | Resource (std::nullopt_t) |
Equivalent to default ctor. | |
constexpr | operator bool () const |
True if contains a valid resource. | |
constexpr | operator value_type () const |
Converts back to underlying type. | |
constexpr bool | operator== (const Resource &other) const=default |
Comparison. | |
constexpr bool | operator== (std::nullopt_t) const |
Comparison. | |
constexpr bool | operator== (std::nullptr_t) const |
Comparison. | |
constexpr SDL_IOStream * | get () const |
Return contained resource;. | |
constexpr const SDL_IOStream * | operator-> () const |
Access to fields. | |
constexpr SDL_IOStream * | operator-> () |
Access to fields. | |
Static Public Member Functions | |
static void | reset (SDL_IOStream *resource) |
Close and free an allocated IOStreamRef structure. | |
Additional Inherited Members | |
![]() | |
using | value_type = SDL_IOStream * |
The raw resource type. | |
This operates as an opaque handle. There are several APIs to create various types of I/O streams, or an app can supply an IOStreamInterface to IOStream.Open() to provide their own stream implementation behind this struct's abstract interface.
|
inline |
This function makes sure that any buffered data is written to the stream. Normally this isn't necessary but if the stream is a pipe or socket it guarantees that any pending data is sent.
Error | on failure. |
|
inline |
|
inline |
Error | on failure. |
|
inline |
This information can be useful to decide if a short read or write was due to an error, an EOF, or a non-blocking operation that isn't yet ready to complete.
An IOStreamRef's status is only expected to change after a IOStreamRef.Read or IOStreamRef.Write call; don't expect it to change if you just call this query function in a tight loop.
|
inline |
The data is allocated with a zero byte at the end (null terminated) for convenience. This extra byte is not included in the value reported via datasize
.
Error | on failure. |
|
inline |
The data is allocated with a zero byte at the end (null terminated) for convenience. This extra byte is not included in the value reported via datasize
.
Error | on failure. |
|
inline |
|
inline |
This function does formatted printing to the stream.
fmt | a printf() style format string. |
... | additional parameters matching % tokens in the fmt string, if any. |
|
inline |
|
inline |
This function reads up size
bytes from the data source to the area pointed at by ptr
. This function may read less bytes than requested.
This function will return zero when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If zero is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
size | the number of bytes to read from the data source. |
|
inline |
This function reads up size
bytes from the data source to the area pointed at by ptr
. This function may read less bytes than requested.
This function will return zero when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If zero is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
buf | the buffer to read data into. |
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
Error | on failure. |
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
Error | on failure. |
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
Error | on failure. |
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
Error | on failure. |
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
Error | on failure. |
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
Error | on failure. |
|
inline |
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
Error | on failure. |
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
Error | on failure. |
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
Error | on failure. |
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
Error | on failure. |
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
Error | on failure. |
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
Error | on failure. |
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
Error | on failure. |
|
inline |
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
Error | on failure. |
|
inlinestatic |
IOStream.Close() closes and cleans up the IOStreamRef stream. It releases any resources used by the stream and frees the IOStreamRef itself. This returns true on success, or false if the stream failed to flush to its output (e.g. to disk).
Note that if this fails to flush the stream for any reason, this function reports an error, but the IOStreamRef is still invalid once this function returns.
This call flushes any buffered writes to the operating system, but there are no guarantees that those writes have gone to physical media; they might be in the OS's file cache, waiting to go to disk later. If it's absolutely crucial that writes go to disk immediately, so they are definitely stored even if the power fails before the file cache would have caught up, one should call IOStreamRef.Flush() before closing. Note that flushing takes time and makes the system and your app operate less efficiently, so do so sparingly.
resource | IOStreamRef structure to close. |
Error | on failure. |
|
inline |
data | the buf to be written. If datasize is 0, may be nullptr or a invalid pointer. |
Error | on failure. |
|
inline |
This function seeks to byte offset
, relative to whence
.
whence
may be any of the following values:
IO_SEEK_SET
: seek from the beginning of dataIO_SEEK_CUR
: seek relative to current read pointIO_SEEK_END
: seek relative to the end of dataIf this stream can not seek, it will return -1.
offset | an offset in bytes, relative to whence location; can be negative. |
whence | any of IO_SEEK_SET , IO_SEEK_CUR , IO_SEEK_END . |
|
inline |
IOStreamRef.Tell is actually a wrapper function that calls the IOStreamRef's seek
method, with an offset of 0 bytes from IO_SEEK_CUR
, to simplify application development.
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
|
inline |
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
|
inline |
SDL byteswaps the data only if necessary, so the data returned will be in the native byte order.
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
|
inline |
This function will return false when the data stream is completely read, and IOStreamRef.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStreamRef.GetStatus() will return a different error value and GetError() will offer a human-readable message.
|
inline |
This function does formatted printing to the stream.
fmt | a printf() style format string. |
ap | a variable argument list. |
|
inline |
This function writes exactly size
bytes from the area pointed at by ptr
to the stream. If this fails for any reason, it'll return less than size
to demonstrate how far the write progressed. On success, it returns size
.
On error, this function still attempts to write as much as possible, so it might return a positive value less than the requested write size.
The caller can use IOStreamRef.GetStatus() to determine if the problem is recoverable, such as a non-blocking write that can simply be retried later, or a fatal error.
buf | the bytes to write to |
size
on failure; call GetError() for more information.
|
inline |
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in big-endian format.
value | the data to be written, in native format. |
Error | on failure. |
|
inline |
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in little-endian format.
value | the data to be written, in native format. |
Error | on failure. |
|
inline |
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in big-endian format.
value | the data to be written, in native format. |
Error | on failure. |
|
inline |
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in little-endian format.
value | the data to be written, in native format. |
Error | on failure. |
|
inline |
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in big-endian format.
value | the data to be written, in native format. |
Error | on failure. |
|
inline |
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in little-endian format.
value | the data to be written, in native format. |
Error | on failure. |
|
inline |
|
inline |
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in big-endian format.
value | the data to be written, in native format. |
Error | on failure. |
|
inline |
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in little-endian format.
value | the data to be written, in native format. |
Error | on failure. |
|
inline |
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in big-endian format.
value | the data to be written, in native format. |
Error | on failure. |
|
inline |
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in little-endian format.
value | the data to be written, in native format. |
Error | on failure. |
|
inline |
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in big-endian format.
value | the data to be written, in native format. |
Error | on failure. |
|
inline |
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in little-endian format.
value | the data to be written, in native format. |
Error | on failure. |
|
inline |