SDL provides an abstract interface for reading and writing data streams.
More...
It offers implementations for files, memory, etc, and the app can provide their own implementations, too.
SDL_IOStream is not related to the standard C++ iostream class, other than both are abstract interfaces to read/write data.
◆ IOStatus
- Since
- This enum is available since SDL 3.2.0.
◆ IOStreamInterface
◆ IOWhence
These map to the same "whence" concept that fseek
or lseek
use in the standard C runtime.
- Since
- This enum is available since SDL 3.2.0.
◆ IOFromConstMem()
This function sets up an IOStreamBase struct based on a memory area of a certain size. It assumes the memory area is not writable.
Attempting to write to this IOStreamBase stream will report an error without writing to the memory buffer.
This memory buffer is not copied by the IOStreamBase; the pointer you provide must remain valid until you close the stream. Closing the stream will not free the original buffer.
If you need to write to a memory buffer, you should use IOFromMem() with a writable buffer of memory instead.
The following properties will be set at creation time by SDL:
prop::IOStream.MEMORY_POINTER
: this will be the mem
parameter that was passed to this function.
prop::IOStream.MEMORY_SIZE_NUMBER
: this will be the size
parameter that was passed to this function.
- Parameters
-
- Returns
- a valid IOStream on success.
- Exceptions
-
- Thread safety:
- It is safe to call this function from any thread.
- Since
- This function is available since SDL 3.2.0.
- See also
- IOFromMem
-
IOStreamRef.Close
-
IOStreamBase.Read
-
IOStreamBase.Seek
-
IOStreamBase.Tell
◆ IOFromDynamicMem()
This supports the following properties to provide access to the memory and control over allocations:
prop::IOStream.DYNAMIC_MEMORY_POINTER
: a pointer to the internal memory of the stream. This can be set to nullptr to transfer ownership of the memory to the application, which should free the memory with free(). If this is done, the next operation on the stream must be IOStreamRef.Close().
prop::IOStream.DYNAMIC_CHUNKSIZE_NUMBER
: memory will be allocated in multiples of this size, defaulting to 1024.
- Returns
- a valid IOStream on success.
- Exceptions
-
- Thread safety:
- It is safe to call this function from any thread.
- Since
- This function is available since SDL 3.2.0.
- See also
- IOStreamRef.Close
-
IOStreamBase.Read
-
IOStreamBase.Seek
-
IOStreamBase.Tell
-
IOStreamBase.Write
◆ IOFromMem()
This function sets up an IOStreamBase struct based on a memory area of a certain size, for both read and write access.
This memory buffer is not copied by the IOStreamBase; the pointer you provide must remain valid until you close the stream. Closing the stream will not free the original buffer.
If you need to make sure the IOStreamBase never writes to the memory buffer, you should use IOFromConstMem() with a read-only buffer of memory instead.
The following properties will be set at creation time by SDL:
prop::IOStream.MEMORY_POINTER
: this will be the mem
parameter that was passed to this function.
prop::IOStream.MEMORY_SIZE_NUMBER
: this will be the size
parameter that was passed to this function.
- Parameters
-
- Returns
- a valid IOStream on success.
- Exceptions
-
- Thread safety:
- It is safe to call this function from any thread.
- Since
- This function is available since SDL 3.2.0.
- See also
- IOFromConstMem
-
IOStreamRef.Close
-
IOStreamBase.Flush
-
IOStreamBase.Read
-
IOStreamBase.Seek
-
IOStreamBase.Tell
-
IOStreamBase.Write
◆ LoadFile()
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
.
- Parameters
-
file | the path to read all available data from. |
- Returns
- the data.
- Exceptions
-
- Thread safety:
- This function is not thread safe.
- Since
- This function is available since SDL 3.2.0.
- See also
- IOStreamBase.LoadFile
-
SaveFile
◆ LoadFileAs()
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
.
- Parameters
-
file | the path to read all available data from. |
- Returns
- the data.
- Exceptions
-
- Thread safety:
- This function is not thread safe.
- Since
- This function is available since SDL 3.2.0.
- See also
- IOStreamBase.LoadFile
-
SaveFile
◆ SaveFile()
- Parameters
-
file | the path to write all available data into. |
data | the data to be written. If datasize is 0, may be nullptr or a invalid pointer. |
- Exceptions
-
- Thread safety:
- This function is not thread safe.
- Since
- This function is available since SDL 3.2.0.
- See also
- IOStreamBase.SaveFile
-
LoadFile
◆ IO_SEEK_CUR
◆ IO_SEEK_END
◆ IO_SEEK_SET
◆ IO_STATUS_ERROR
◆ IO_STATUS_NOT_READY
constexpr IOStatus SDL::IO_STATUS_NOT_READY |
|
constexpr |
Initial value:=
SDL_IO_STATUS_NOT_READY
◆ IO_STATUS_READONLY
constexpr IOStatus SDL::IO_STATUS_READONLY |
|
constexpr |
◆ IO_STATUS_READY
◆ IO_STATUS_WRITEONLY
constexpr IOStatus SDL::IO_STATUS_WRITEONLY |
|
constexpr |
Initial value:=
SDL_IO_STATUS_WRITEONLY