|
SDL3pp
A slim C++ wrapper for SDL3
|
SDL provides an abstract interface for reading and writing data streams. More...
Namespaces | |
| namespace | SDL::prop |
| Constants for Properties keys. | |
| namespace | SDL::prop::IOStream |
| Properties for IOStream. | |
Classes | |
| struct | SDL::IOStream |
| The read/write operation structure. More... | |
Typedefs | |
| using | SDL::IOStreamRaw = SDL_IOStream* |
| Alias to raw representation for IOStream. | |
| using | SDL::IOStreamRef = ResourceRef<IOStream> |
| Reference for IOStream. | |
| using | SDL::IOStatus = SDL_IOStatus |
| IOStream status, set by a read or write operation. | |
| using | SDL::IOWhence = SDL_IOWhence |
| Possible whence values for IOStream seeking. | |
| using | SDL::IOStreamInterface = SDL_IOStreamInterface |
| The function pointers that drive an IOStream. | |
Functions | |
| IOStream | SDL::IOFromFile (StringParam file, StringParam mode) |
| Use this function to create a new IOStream structure for reading from and/or writing to a named file. | |
| IOStream | SDL::IOFromMem (TargetBytes mem) |
| Use this function to prepare a read-write memory buffer for use with IOStream. | |
| IOStream | SDL::IOFromConstMem (SourceBytes mem) |
| Use this function to prepare a read-only memory buffer for use with IOStream. | |
| IOStream | SDL::IOFromDynamicMem () |
| Use this function to create an IOStream that is backed by dynamically allocated memory. | |
| IOStream | SDL::OpenIO (const IOStreamInterface &iface, void *userdata) |
| Create a custom IOStream. | |
| void | SDL::CloseIO (IOStreamRaw context) |
| Close and free an allocated IOStream structure. | |
| PropertiesRef | SDL::GetIOProperties (IOStreamRef context) |
| Get the properties associated with an IOStream. | |
| IOStatus | SDL::GetIOStatus (IOStreamRef context) |
| Query the stream status of an IOStream. | |
| Sint64 | SDL::GetIOSize (IOStreamRef context) |
| Use this function to get the size of the data stream in an IOStream. | |
| Sint64 | SDL::SeekIO (IOStreamRef context, Sint64 offset, IOWhence whence) |
| Seek within an IOStream data stream. | |
| Sint64 | SDL::TellIO (IOStreamRef context) |
| Determine the current read/write offset in an IOStream data stream. | |
| size_t | SDL::ReadIO (IOStreamRef context, TargetBytes buf) |
| Read from a data source. | |
| size_t | SDL::WriteIO (IOStreamRef context, SourceBytes buf) |
| Write to an IOStream data stream. | |
| size_t | SDL::IOprintf (IOStreamRef context, SDL_PRINTF_FORMAT_STRING const char *fmt,...) |
| Print to an IOStream data stream. | |
| size_t | SDL::IOvprintf (IOStreamRef context, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) |
| Print to an IOStream data stream. | |
| void | SDL::FlushIO (IOStreamRef context) |
| Flush any buffered data in the stream. | |
| StringResult | SDL::LoadFile_IO (IOStreamRef src, bool closeio=true) |
| Load all the data from an SDL data stream. | |
| template<class T> | |
| OwnArray< T > | SDL::LoadFileAs (StringParam file) |
| Load all the data from a file path. | |
| StringResult | SDL::LoadFile (StringParam file) |
| Load all the data from a file path. | |
| void | SDL::SaveFile_IO (IOStreamRef src, SourceBytes data, bool closeio=true) |
| Save all the data into an SDL data stream. | |
| void | SDL::SaveFile (StringParam file, SourceBytes data) |
| Save all the data into a file path. | |
| Uint8 | SDL::ReadU8 (IOStreamRef src) |
| Use this function to read a byte from an IOStream. | |
| Sint8 | SDL::ReadS8 (IOStreamRef src) |
| Use this function to read a signed byte from an IOStream. | |
| Uint16 | SDL::ReadU16LE (IOStreamRef src) |
| Use this function to read 16 bits of little-endian data from an IOStream and return in native format. | |
| Sint16 | SDL::ReadS16LE (IOStreamRef src) |
| Use this function to read 16 bits of little-endian data from an IOStream and return in native format. | |
| Uint16 | SDL::ReadU16BE (IOStreamRef src) |
| Use this function to read 16 bits of big-endian data from an IOStream and return in native format. | |
| Sint16 | SDL::ReadS16BE (IOStreamRef src) |
| Use this function to read 16 bits of big-endian data from an IOStream and return in native format. | |
| Uint32 | SDL::ReadU32LE (IOStreamRef src) |
| Use this function to read 32 bits of little-endian data from an IOStream and return in native format. | |
| Sint32 | SDL::ReadS32LE (IOStreamRef src) |
| Use this function to read 32 bits of little-endian data from an IOStream and return in native format. | |
| Uint32 | SDL::ReadU32BE (IOStreamRef src) |
| Use this function to read 32 bits of big-endian data from an IOStream and return in native format. | |
| Sint32 | SDL::ReadS32BE (IOStreamRef src) |
| Use this function to read 32 bits of big-endian data from an IOStream and return in native format. | |
| Uint64 | SDL::ReadU64LE (IOStreamRef src) |
| Use this function to read 64 bits of little-endian data from an IOStream and return in native format. | |
| Sint64 | SDL::ReadS64LE (IOStreamRef src) |
| Use this function to read 64 bits of little-endian data from an IOStream and return in native format. | |
| Uint64 | SDL::ReadU64BE (IOStreamRef src) |
| Use this function to read 64 bits of big-endian data from an IOStream and return in native format. | |
| Sint64 | SDL::ReadS64BE (IOStreamRef src) |
| Use this function to read 64 bits of big-endian data from an IOStream and return in native format. | |
| void | SDL::WriteU8 (IOStreamRef dst, Uint8 value) |
| Use this function to write a byte to an IOStream. | |
| void | SDL::WriteS8 (IOStreamRef dst, Sint8 value) |
| Use this function to write a signed byte to an IOStream. | |
| void | SDL::WriteU16LE (IOStreamRef dst, Uint16 value) |
| Use this function to write 16 bits in native format to an IOStream as little-endian data. | |
| void | SDL::WriteS16LE (IOStreamRef dst, Sint16 value) |
| Use this function to write 16 bits in native format to an IOStream as little-endian data. | |
| void | SDL::WriteU16BE (IOStreamRef dst, Uint16 value) |
| Use this function to write 16 bits in native format to an IOStream as big-endian data. | |
| void | SDL::WriteS16BE (IOStreamRef dst, Sint16 value) |
| Use this function to write 16 bits in native format to an IOStream as big-endian data. | |
| void | SDL::WriteU32LE (IOStreamRef dst, Uint32 value) |
| Use this function to write 32 bits in native format to an IOStream as little-endian data. | |
| void | SDL::WriteS32LE (IOStreamRef dst, Sint32 value) |
| Use this function to write 32 bits in native format to an IOStream as little-endian data. | |
| void | SDL::WriteU32BE (IOStreamRef dst, Uint32 value) |
| Use this function to write 32 bits in native format to an IOStream as big-endian data. | |
| void | SDL::WriteS32BE (IOStreamRef dst, Sint32 value) |
| Use this function to write 32 bits in native format to an IOStream as big-endian data. | |
| void | SDL::WriteU64LE (IOStreamRef dst, Uint64 value) |
| Use this function to write 64 bits in native format to an IOStream as little-endian data. | |
| void | SDL::WriteS64LE (IOStreamRef dst, Sint64 value) |
| Use this function to write 64 bits in native format to an IOStream as little-endian data. | |
| void | SDL::WriteU64BE (IOStreamRef dst, Uint64 value) |
| Use this function to write 64 bits in native format to an IOStream as big-endian data. | |
| void | SDL::WriteS64BE (IOStreamRef dst, Sint64 value) |
| Use this function to write 64 bits in native format to an IOStream as big-endian data. | |
| static IOStream | SDL::IOStream::FromFile (StringParam file, StringParam mode) |
| Use this function to create a new IOStream structure for reading from and/or writing to a named file. | |
| static IOStream | SDL::IOStream::FromMem (TargetBytes mem) |
| Use this function to prepare a read-write memory buffer for use with IOStream. | |
| static IOStream | SDL::IOStream::FromConstMem (SourceBytes mem) |
| Use this function to prepare a read-only memory buffer for use with IOStream. | |
| static IOStream | SDL::IOStream::FromDynamicMem () |
| Use this function to create an IOStream that is backed by dynamically allocated memory. | |
| static IOStream | SDL::IOStream::Open (const IOStreamInterface &iface, void *userdata) |
| Create a custom IOStream. | |
| void | SDL::IOStream::Close () |
| Close and free an allocated IOStream structure. | |
| PropertiesRef | SDL::IOStream::GetProperties () const |
| Get the properties associated with an IOStream. | |
| IOStatus | SDL::IOStream::GetStatus () const |
| Query the stream status of an IOStream. | |
| Sint64 | SDL::IOStream::GetSize () const |
| Use this function to get the size of the data stream in an IOStream. | |
| Sint64 | SDL::IOStream::Seek (Sint64 offset, IOWhence whence) |
| Seek within an IOStream data stream. | |
| Sint64 | SDL::IOStream::Tell () const |
| Determine the current read/write offset in an IOStream data stream. | |
| size_t | SDL::IOStream::Read (TargetBytes buf) |
| Read from a data source. | |
| size_t | SDL::IOStream::Write (SourceBytes buf) |
| Write to an IOStream data stream. | |
| size_t | SDL::IOStream::vprintf (SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap) |
| Print to an IOStream data stream. | |
| void | SDL::IOStream::Flush () |
| Flush any buffered data in the stream. | |
| StringResult | SDL::IOStream::LoadFile () |
| Load all the data from an SDL data stream. | |
| void | SDL::IOStream::SaveFile (SourceBytes data) |
| Save all the data into an SDL data stream. | |
| Uint8 | SDL::IOStream::ReadU8 () |
| Use this function to read a byte from an IOStream. | |
| Sint8 | SDL::IOStream::ReadS8 () |
| Use this function to read a signed byte from an IOStream. | |
| Uint16 | SDL::IOStream::ReadU16LE () |
| Use this function to read 16 bits of little-endian data from an IOStream and return in native format. | |
| Sint16 | SDL::IOStream::ReadS16LE () |
| Use this function to read 16 bits of little-endian data from an IOStream and return in native format. | |
| Uint16 | SDL::IOStream::ReadU16BE () |
| Use this function to read 16 bits of big-endian data from an IOStream and return in native format. | |
| Sint16 | SDL::IOStream::ReadS16BE () |
| Use this function to read 16 bits of big-endian data from an IOStream and return in native format. | |
| Uint32 | SDL::IOStream::ReadU32LE () |
| Use this function to read 32 bits of little-endian data from an IOStream and return in native format. | |
| Sint32 | SDL::IOStream::ReadS32LE () |
| Use this function to read 32 bits of little-endian data from an IOStream and return in native format. | |
| Uint32 | SDL::IOStream::ReadU32BE () |
| Use this function to read 32 bits of big-endian data from an IOStream and return in native format. | |
| Sint32 | SDL::IOStream::ReadS32BE () |
| Use this function to read 32 bits of big-endian data from an IOStream and return in native format. | |
| Uint64 | SDL::IOStream::ReadU64LE () |
| Use this function to read 64 bits of little-endian data from an IOStream and return in native format. | |
| Sint64 | SDL::IOStream::ReadS64LE () |
| Use this function to read 64 bits of little-endian data from an IOStream and return in native format. | |
| Uint64 | SDL::IOStream::ReadU64BE () |
| Use this function to read 64 bits of big-endian data from an IOStream and return in native format. | |
| Sint64 | SDL::IOStream::ReadS64BE () |
| Use this function to read 64 bits of big-endian data from an IOStream and return in native format. | |
| void | SDL::IOStream::WriteU8 (Uint8 value) |
| Use this function to write a byte to an IOStream. | |
| void | SDL::IOStream::WriteS8 (Sint8 value) |
| Use this function to write a signed byte to an IOStream. | |
| void | SDL::IOStream::WriteU16LE (Uint16 value) |
| Use this function to write 16 bits in native format to an IOStream as little-endian data. | |
| void | SDL::IOStream::WriteS16LE (Sint16 value) |
| Use this function to write 16 bits in native format to an IOStream as little-endian data. | |
| void | SDL::IOStream::WriteU16BE (Uint16 value) |
| Use this function to write 16 bits in native format to an IOStream as big-endian data. | |
| void | SDL::IOStream::WriteS16BE (Sint16 value) |
| Use this function to write 16 bits in native format to an IOStream as big-endian data. | |
| void | SDL::IOStream::WriteU32LE (Uint32 value) |
| Use this function to write 32 bits in native format to an IOStream as little-endian data. | |
| void | SDL::IOStream::WriteS32LE (Sint32 value) |
| Use this function to write 32 bits in native format to an IOStream as little-endian data. | |
| void | SDL::IOStream::WriteU32BE (Uint32 value) |
| Use this function to write 32 bits in native format to an IOStream as big-endian data. | |
| void | SDL::IOStream::WriteS32BE (Sint32 value) |
| Use this function to write 32 bits in native format to an IOStream as big-endian data. | |
| void | SDL::IOStream::WriteU64LE (Uint64 value) |
| Use this function to write 64 bits in native format to an IOStream as little-endian data. | |
| void | SDL::IOStream::WriteS64LE (Sint64 value) |
| Use this function to write 64 bits in native format to an IOStream as little-endian data. | |
| void | SDL::IOStream::WriteU64BE (Uint64 value) |
| Use this function to write 64 bits in native format to an IOStream as big-endian data. | |
| void | SDL::IOStream::WriteS64BE (Sint64 value) |
| Use this function to write 64 bits in native format to an IOStream as big-endian data. | |
Variables | |
| constexpr IOStatus | SDL::IO_STATUS_READY |
| Everything is ready (no errors and not EOF). | |
| constexpr IOStatus | SDL::IO_STATUS_ERROR |
| Read or write I/O error. | |
| constexpr IOStatus | SDL::IO_STATUS_EOF = SDL_IO_STATUS_EOF |
| End of file. | |
| constexpr IOStatus | SDL::IO_STATUS_NOT_READY |
| Non blocking I/O, not ready. | |
| constexpr IOStatus | SDL::IO_STATUS_READONLY |
| Tried to write a read-only buffer. | |
| constexpr IOStatus | SDL::IO_STATUS_WRITEONLY |
| Tried to read a write-only buffer. | |
| constexpr IOWhence | SDL::IO_SEEK_SET |
| Seek from the beginning of data. | |
| constexpr IOWhence | SDL::IO_SEEK_CUR |
| Seek relative to current read point. | |
| constexpr IOWhence | SDL::IO_SEEK_END |
| Seek relative to the end of data. | |
SDL provides an abstract interface for reading and writing data streams.
It offers implementations for files, memory, etc, and the app can provide their own implementations, too.
IOStream is not related to the standard C++ iostream class, other than both are abstract interfaces to read/write data.
| using SDL::IOStatus = SDL_IOStatus |
| using SDL::IOStreamInterface = SDL_IOStreamInterface |
The function pointers that drive an IOStream.
Applications can provide this struct to IOStream.Open() to create their own implementation of IOStream. This is not necessarily required, as SDL already offers several common types of I/O streams, via functions like IOStream.FromFile() and IOStream.FromMem().
This structure should be initialized using InitInterface()
| using SDL::IOStreamRef = ResourceRef<IOStream> |
Reference for IOStream.
This does not take ownership!
| using SDL::IOWhence = SDL_IOWhence |
|
inline |
Close and free an allocated IOStream structure.
IOStream.Close() closes and cleans up the IOStream stream. It releases any resources used by the stream and frees the IOStream 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 IOStream 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 IOStream.Flush() before closing. Note that flushing takes time and makes the system and your app operate less efficiently, so do so sparingly.
| Error | on failure. |
|
inline |
Close and free an allocated IOStream structure.
IOStream.Close() closes and cleans up the IOStream stream. It releases any resources used by the stream and frees the IOStream 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 IOStream 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 IOStream.Flush() before closing. Note that flushing takes time and makes the system and your app operate less efficiently, so do so sparingly.
| context | IOStream structure to close. |
| Error | on failure. |
|
inline |
Flush any buffered data in the stream.
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 |
Flush any buffered data in the stream.
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.
| context | IOStream structure to flush. |
| Error | on failure. |
|
inlinestatic |
Use this function to prepare a read-only memory buffer for use with IOStream.
This function sets up an IOStream struct based on a memory area of a certain size. It assumes the memory area is not writable.
Attempting to write to this IOStream stream will report an error without writing to the memory buffer.
This memory buffer is not copied by the IOStream; the pointer you provide must remain valid until you close the stream.
If you need to write to a memory buffer, you should use IOStream.FromMem() with a writable buffer of memory instead.
The following properties will be set at creation time by SDL:
Additionally, the following properties are recognized:
| mem | a read-only buffer to feed an IOStreamRef stream. |
| Error | on failure. |
|
inlinestatic |
Use this function to create an IOStream that is backed by dynamically allocated memory.
This supports the following properties to provide access to the memory and control over allocations:
| Error | on failure. |
|
inlinestatic |
Use this function to create a new IOStream structure for reading from and/or writing to a named file.
The mode string is treated roughly the same as in a call to the C library's fopen(), even if SDL doesn't happen to use fopen() behind the scenes.
Available mode strings:
NOTE: In order to open a file as a binary file, a "b" character has to be included in the mode string. This additional "b" character can either be appended at the end of the string (thus making the following compound modes: "rb", "wb", "ab", "r+b", "w+b", "a+b") or be inserted between the letter and the "+" sign for the mixed modes ("rb+", "wb+", "ab+"). Additional characters may follow the sequence, although they should have no effect. For example, "t" is sometimes appended to make explicit the file is a text file.
This function supports Unicode filenames, but they must be encoded in UTF-8 format, regardless of the underlying operating system.
In Android, IOStream.FromFile() can be used to open content:// URIs. As a fallback, IOStream.FromFile() will transparently open a matching filename in the app's assets.
Closing the IOStream will close SDL's internal file handle.
The following properties may be set at creation time by SDL:
| file | a UTF-8 string representing the filename to open. |
| mode | an ASCII string representing the mode to be used for opening the file. |
|
inlinestatic |
Use this function to prepare a read-write memory buffer for use with IOStream.
This function sets up an IOStream struct based on a memory area of a certain size, for both read and write access.
This memory buffer is not copied by the IOStream; the pointer you provide must remain valid until you close the stream.
If you need to make sure the IOStream never writes to the memory buffer, you should use IOStream.FromConstMem() with a read-only buffer of memory instead.
The following properties will be set at creation time by SDL:
Additionally, the following properties are recognized:
| mem | a buffer to feed an IOStream stream. |
| Error | on failure. |
|
inline |
|
inline |
Use this function to get the size of the data stream in an IOStream.
| context | the IOStream to get the size of the data stream from. |
| Error | on failure. |
|
inline |
Query the stream status of an IOStream.
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 IOStream's status is only expected to change after a IOStream.Read or IOStream.Write call; don't expect it to change if you just call this query function in a tight loop.
| context | the IOStream to query. |
|
inline |
|
inline |
|
inline |
Query the stream status of an IOStream.
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 IOStream's status is only expected to change after a IOStream.Read or IOStream.Write call; don't expect it to change if you just call this query function in a tight loop.
|
inline |
Use this function to prepare a read-only memory buffer for use with IOStream.
This function sets up an IOStream struct based on a memory area of a certain size. It assumes the memory area is not writable.
Attempting to write to this IOStream stream will report an error without writing to the memory buffer.
This memory buffer is not copied by the IOStream; the pointer you provide must remain valid until you close the stream.
If you need to write to a memory buffer, you should use IOStream.FromMem() with a writable buffer of memory instead.
The following properties will be set at creation time by SDL:
Additionally, the following properties are recognized:
| mem | a read-only buffer to feed an IOStreamRef stream. |
| Error | on failure. |
|
inline |
Use this function to create an IOStream that is backed by dynamically allocated memory.
This supports the following properties to provide access to the memory and control over allocations:
|
inline |
Use this function to create a new IOStream structure for reading from and/or writing to a named file.
The mode string is treated roughly the same as in a call to the C library's fopen(), even if SDL doesn't happen to use fopen() behind the scenes.
Available mode strings:
NOTE: In order to open a file as a binary file, a "b" character has to be included in the mode string. This additional "b" character can either be appended at the end of the string (thus making the following compound modes: "rb", "wb", "ab", "r+b", "w+b", "a+b") or be inserted between the letter and the "+" sign for the mixed modes ("rb+", "wb+", "ab+"). Additional characters may follow the sequence, although they should have no effect. For example, "t" is sometimes appended to make explicit the file is a text file.
This function supports Unicode filenames, but they must be encoded in UTF-8 format, regardless of the underlying operating system.
In Android, IOStream.FromFile() can be used to open content:// URIs. As a fallback, IOStream.FromFile() will transparently open a matching filename in the app's assets.
Closing the IOStream will close SDL's internal file handle.
The following properties may be set at creation time by SDL:
| file | a UTF-8 string representing the filename to open. |
| mode | an ASCII string representing the mode to be used for opening the file. |
|
inline |
Use this function to prepare a read-write memory buffer for use with IOStream.
This function sets up an IOStream struct based on a memory area of a certain size, for both read and write access.
This memory buffer is not copied by the IOStream; the pointer you provide must remain valid until you close the stream.
If you need to make sure the IOStream never writes to the memory buffer, you should use IOStream.FromConstMem() with a read-only buffer of memory instead.
The following properties will be set at creation time by SDL:
Additionally, the following properties are recognized:
| mem | a buffer to feed an IOStream stream. |
| Error | on failure. |
|
inline |
Print to an IOStream data stream.
This function does formatted printing to the stream.
| context | a pointer to an IOStream structure. |
| fmt | a printf() style format string. |
| ... | additional parameters matching % tokens in the fmt string, if any. |
|
inline |
Print to an IOStream data stream.
This function does formatted printing to the stream.
| context | a pointer to an IOStream structure. |
| fmt | a printf() style format string. |
| ap | a variable argument list. |
|
inline |
Load all the data from an SDL data stream.
The data is allocated with a zero byte at the end (null terminated) for convenience.
| Error | on failure. |
|
inline |
Load all the data from a file path.
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 on the returned string.
| file | the path to read all available data from. |
| Error | on failure. |
|
inline |
Load all the data from an SDL data stream.
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 on the returned string.
The data should be freed with free().
| src | the IOStream to read all available data from. |
| closeio | if true, calls IOStream.Close() on src before returning, even in the case of an error. |
|
inline |
Load all the data from a file path.
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 on the returned string.
| file | the path to read all available data from. |
| Error | on failure. |
|
inlinestatic |
Create a custom IOStream.
Applications do not need to use this function unless they are providing their own IOStream implementation. If you just need an IOStream to read/write a common data source, you should use the built-in implementations in SDL, like IOStream.FromFile() or IOStream.FromMem(), etc.
This function makes a copy of iface and the caller does not need to keep it around after this call.
| iface | the interface that implements this IOStream, initialized using InitInterface(). |
| userdata | the pointer that will be passed to the interface functions. |
| Error | on failure. |
|
inline |
Create a custom IOStream.
Applications do not need to use this function unless they are providing their own IOStream implementation. If you just need an IOStream to read/write a common data source, you should use the built-in implementations in SDL, like IOStream.FromFile() or IOStream.FromMem(), etc.
This function makes a copy of iface and the caller does not need to keep it around after this call.
| iface | the interface that implements this IOStream, initialized using InitInterface(). |
| userdata | the pointer that will be passed to the interface functions. |
| Error | on failure. |
|
inline |
Read from a data source.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If zero is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
A request for zero bytes on a valid stream will return zero immediately without accessing the stream, so the stream status (EOF, err, etc) will not change.
| buf | a pointer to a buffer to read data into. |
|
inline |
Read from a data source.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If zero is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
A request for zero bytes on a valid stream will return zero immediately without accessing the stream, so the stream status (EOF, err, etc) will not change.
| context | a pointer to an IOStream structure. |
| buf | a pointer to a buffer to read data into. |
|
inline |
Use this function to read 16 bits of big-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| Error | on failure. |
|
inline |
Use this function to read 16 bits of big-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| src | the stream from which to read data. |
| Error | on failure. |
|
inline |
Use this function to read 16 bits of little-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| Error | on failure. |
|
inline |
Use this function to read 16 bits of little-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| src | the stream from which to read data. |
| Error | on failure. |
|
inline |
Use this function to read 32 bits of big-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| Error | on failure. |
|
inline |
Use this function to read 32 bits of big-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| src | the stream from which to read data. |
| Error | on failure. |
|
inline |
Use this function to read 32 bits of little-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| Error | on failure. |
|
inline |
Use this function to read 32 bits of little-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| src | the stream from which to read data. |
| Error | on failure. |
|
inline |
Use this function to read 64 bits of big-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| Error | on failure. |
|
inline |
Use this function to read 64 bits of big-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| src | the stream from which to read data. |
| Error | on failure. |
|
inline |
Use this function to read 64 bits of little-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| Error | on failure. |
|
inline |
Use this function to read 64 bits of little-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| src | the stream from which to read data. |
| Error | on failure. |
|
inline |
Use this function to read a signed byte from an IOStream.
This function will return false when the data stream is completely read, and IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| Error | on failure. |
|
inline |
Use this function to read a signed byte from an IOStream.
This function will return false when the data stream is completely read, and IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| src | the IOStream to read from. |
| Error | on failure. |
|
inline |
Use this function to read 16 bits of big-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| Error | on failure. |
|
inline |
Use this function to read 16 bits of big-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| src | the stream from which to read data. |
| Error | on failure. |
|
inline |
Use this function to read 16 bits of little-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| Error | on failure. |
|
inline |
Use this function to read 16 bits of little-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| src | the stream from which to read data. |
| Error | on failure. |
|
inline |
Use this function to read 32 bits of big-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| Error | on failure. |
|
inline |
Use this function to read 32 bits of big-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| src | the stream from which to read data. |
| Error | on failure. |
|
inline |
Use this function to read 32 bits of little-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| Error | on failure. |
|
inline |
Use this function to read 32 bits of little-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| src | the stream from which to read data. |
| Error | on failure. |
|
inline |
Use this function to read 64 bits of big-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| Error | on failure. |
|
inline |
Use this function to read 64 bits of big-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| src | the stream from which to read data. |
| Error | on failure. |
|
inline |
Use this function to read 64 bits of little-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| Error | on failure. |
|
inline |
Use this function to read 64 bits of little-endian data from an IOStream and return in native format.
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 IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| src | the stream from which to read data. |
| Error | on failure. |
|
inline |
Use this function to read a byte from an IOStream.
This function will return false when the data stream is completely read, and IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| Error | on failure. |
|
inline |
Use this function to read a byte from an IOStream.
This function will return false when the data stream is completely read, and IOStream.GetStatus() will return IO_STATUS_EOF. If false is returned and the stream is not at EOF, IOStream.GetStatus() will return a different error value and GetError() will offer a human-readable message.
| src | the IOStream to read from. |
| Error | on failure. |
|
inline |
Save all the data into an SDL data stream.
| data | the data to be written. If datasize is 0, may be nullptr or a invalid pointer. |
| Error | on failure. |
|
inline |
Save all the data into a file path.
| file | the path to write all available data into. |
| data | the data to be written. |
| Error | on failure. |
|
inline |
Save all the data into an SDL data stream.
| src | the IOStream to write all data to. |
| data | the data to be written. |
| closeio | if true, calls IOStream.Close() on src before returning, even in the case of an error. |
| Error | on failure. |
Seek within an IOStream data stream.
This function seeks to byte offset, relative to whence.
whence may be any of the following values:
If 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 |
Seek within an IOStream data stream.
This function seeks to byte offset, relative to whence.
whence may be any of the following values:
If this stream can not seek, it will return -1.
| context | a pointer to an IOStream structure. |
| 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 |
Determine the current read/write offset in an IOStream data stream.
IOStream.Tell is actually a wrapper function that calls the IOStream's seek method, with an offset of 0 bytes from IO_SEEK_CUR, to simplify application development.
|
inline |
Determine the current read/write offset in an IOStream data stream.
IOStream.Tell is actually a wrapper function that calls the IOStream's seek method, with an offset of 0 bytes from IO_SEEK_CUR, to simplify application development.
| context | an IOStream data stream object from which to get the current offset. |
|
inline |
Print to an IOStream data stream.
This function does formatted printing to the stream.
| fmt | a printf() style format string. |
| ap | a variable argument list. |
|
inline |
Write to an IOStream data stream.
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 IOStream.GetStatus() to determine if the problem is recoverable, such as a non-blocking write that can simply be retried later, or a fatal error.
A request for zero bytes on a valid stream will return zero immediately without accessing the stream, so the stream status (EOF, err, etc) will not change.
| buf | the bytes to write to |
|
inline |
Write to an IOStream data stream.
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 IOStream.GetStatus() to determine if the problem is recoverable, such as a non-blocking write that can simply be retried later, or a fatal error.
A request for zero bytes on a valid stream will return zero immediately without accessing the stream, so the stream status (EOF, err, etc) will not change.
| context | a pointer to an IOStream structure. |
| buf | a pointer to a buffer containing data to write. |
|
inline |
Use this function to write 16 bits in native format to an IOStream as big-endian data.
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 |
Use this function to write 16 bits in native format to an IOStream as big-endian data.
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in big-endian format.
| dst | the stream to which data will be written. |
| value | the data to be written, in native format. |
| Error | on failure. |
|
inline |
Use this function to write 16 bits in native format to an IOStream as little-endian data.
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 |
Use this function to write 16 bits in native format to an IOStream as little-endian data.
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in little-endian format.
| dst | the stream to which data will be written. |
| value | the data to be written, in native format. |
| Error | on failure. |
|
inline |
Use this function to write 32 bits in native format to an IOStream as big-endian data.
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 |
Use this function to write 32 bits in native format to an IOStream as big-endian data.
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in big-endian format.
| dst | the stream to which data will be written. |
| value | the data to be written, in native format. |
| Error | on failure. |
|
inline |
Use this function to write 32 bits in native format to an IOStream as little-endian data.
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 |
Use this function to write 32 bits in native format to an IOStream as little-endian data.
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in little-endian format.
| dst | the stream to which data will be written. |
| value | the data to be written, in native format. |
| Error | on failure. |
|
inline |
Use this function to write 64 bits in native format to an IOStream as big-endian data.
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 |
Use this function to write 64 bits in native format to an IOStream as big-endian data.
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in big-endian format.
| dst | the stream to which data will be written. |
| value | the data to be written, in native format. |
| Error | on failure. |
|
inline |
Use this function to write 64 bits in native format to an IOStream as little-endian data.
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 |
Use this function to write 64 bits in native format to an IOStream as little-endian data.
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in little-endian format.
| dst | the stream to which data will be written. |
| value | the data to be written, in native format. |
| Error | on failure. |
|
inline |
|
inline |
|
inline |
Use this function to write 16 bits in native format to an IOStream as big-endian data.
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 |
Use this function to write 16 bits in native format to an IOStream as big-endian data.
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in big-endian format.
| dst | the stream to which data will be written. |
| value | the data to be written, in native format. |
| Error | on failure. |
|
inline |
Use this function to write 16 bits in native format to an IOStream as little-endian data.
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 |
Use this function to write 16 bits in native format to an IOStream as little-endian data.
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in little-endian format.
| dst | the stream to which data will be written. |
| value | the data to be written, in native format. |
| Error | on failure. |
|
inline |
Use this function to write 32 bits in native format to an IOStream as big-endian data.
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 |
Use this function to write 32 bits in native format to an IOStream as big-endian data.
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in big-endian format.
| dst | the stream to which data will be written. |
| value | the data to be written, in native format. |
| Error | on failure. |
|
inline |
Use this function to write 32 bits in native format to an IOStream as little-endian data.
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 |
Use this function to write 32 bits in native format to an IOStream as little-endian data.
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in little-endian format.
| dst | the stream to which data will be written. |
| value | the data to be written, in native format. |
| Error | on failure. |
|
inline |
Use this function to write 64 bits in native format to an IOStream as big-endian data.
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 |
Use this function to write 64 bits in native format to an IOStream as big-endian data.
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in big-endian format.
| dst | the stream to which data will be written. |
| value | the data to be written, in native format. |
| Error | on failure. |
|
inline |
Use this function to write 64 bits in native format to an IOStream as little-endian data.
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 |
Use this function to write 64 bits in native format to an IOStream as little-endian data.
SDL byteswaps the data only if necessary, so the application always specifies native format, and the data written will be in little-endian format.
| dst | the stream to which data will be written. |
| value | the data to be written, in native format. |
| Error | on failure. |
|
inline |
|
inline |
|
constexpr |
Seek relative to current read point.
|
constexpr |
Seek relative to the end of data.
|
constexpr |
Seek from the beginning of data.
|
constexpr |
Read or write I/O error.
|
constexpr |
Non blocking I/O, not ready.
|
constexpr |
Tried to write a read-only buffer.
|
constexpr |
Everything is ready (no errors and not EOF).
|
constexpr |
Tried to read a write-only buffer.