SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL3pp_iostream.h
1#ifndef SDL3PP_IOSTREAM_H_
2#define SDL3PP_IOSTREAM_H_
3
4#include <SDL3/SDL_iostream.h>
5#include "SDL3pp_properties.h"
6#include "SDL3pp_stdinc.h"
7
8namespace SDL {
9
23// Forward decl
24struct IOStreamRef;
25
26// Forward decl
27struct IOStream;
28
38
48
54using IOStatus = SDL_IOStatus;
55
57 SDL_IO_STATUS_READY;
58
60 SDL_IO_STATUS_ERROR;
61
62constexpr IOStatus IO_STATUS_EOF = SDL_IO_STATUS_EOF;
63
65 SDL_IO_STATUS_NOT_READY;
66
68 SDL_IO_STATUS_READONLY;
69
71 SDL_IO_STATUS_WRITEONLY;
72
81using IOWhence = SDL_IOWhence;
82
84 SDL_IO_SEEK_SET;
85
87 SDL_IO_SEEK_CUR;
88
90 SDL_IO_SEEK_END;
91
106using IOStreamInterface = SDL_IOStreamInterface;
107
122struct IOStreamRef : Resource<SDL_IOStream*>
123{
124 using Resource::Resource;
125
137 {
138 return CheckError(SDL_GetIOProperties(get()));
139 }
140
158 IOStatus GetStatus() const { return SDL_GetIOStatus(get()); }
159
170 Sint64 GetSize() const
171 {
172 auto size = SDL_GetIOSize(get());
173 if (size < 0) throw Error{};
174 return size;
175 }
176
203 Sint64 Seek(Sint64 offset, IOWhence whence)
204 {
205 return SDL_SeekIO(get(), offset, whence);
206 }
207
224 Sint64 Tell() const { return SDL_TellIO(get()); }
225
248 std::string Read(size_t size = -1)
249 {
250 Sint64 pos = Tell();
251 auto curSize = SDL_GetIOSize(get());
252 if ((curSize < 0 || pos < 0)) {
253 if (size == size_t(-1)) return {};
254 } else if (curSize - pos <= 0) {
255 return {};
256 } else if (curSize - pos < size) {
257 size = curSize - pos;
258 }
259 std::string result(size, 0);
260 auto actualSize = Read(result);
261 if (actualSize < size) result.resize(actualSize);
262 return result;
263 }
264
287 size_t Read(TargetBytes buf)
288 {
289 return SDL_ReadIO(get(), buf.data, buf.size_bytes);
290 }
291
320 size_t Write(SourceBytes buf)
321 {
322 return SDL_WriteIO(get(), buf.data, buf.size_bytes);
323 }
324
328 size_t print(std::string_view fmt, auto... args)
329 {
330 return Write(std::vformat(fmt, std::make_format_args(args...)));
331 }
332
336 size_t println(std::string_view fmt, auto... args)
337 {
338 std::string result =
339 std::vformat(fmt, std::make_format_args(args...)) + "\n";
340 return Write(result);
341 }
342
363 size_t printf(SDL_PRINTF_FORMAT_STRING const char* fmt, ...)
364 {
365 va_list ap;
366 size_t result;
367
368 va_start(ap, fmt);
369 result = vprintf(fmt, ap);
370 va_end(ap);
371
372 return result;
373 }
374
394 size_t vprintf(SDL_PRINTF_FORMAT_STRING const char* fmt, va_list ap)
395 {
396 return SDL_IOvprintf(get(), fmt, ap);
397 }
398
415 void Flush() { CheckError(SDL_FlushIO(get())); }
416
435 {
436 size_t datasize = 0;
437 auto data = static_cast<char*>(SDL_LoadFile_IO(get(), &datasize, false));
438 return StringResult{CheckError(data), datasize};
439 }
440
458 template<class T>
460 {
461 size_t datasize = 0;
462 auto data = static_cast<T*>(SDL_LoadFile_IO(get(), &datasize, false));
463 return OwnArray<T>{CheckError(data), datasize / sizeof(T)};
464 }
465
481 {
482 CheckError(SDL_SaveFile_IO(get(), data.data, data.size_bytes, false));
483 }
484
500 Uint8 ReadU8()
501 {
502 Uint8 value;
503 CheckError(SDL_ReadU8(get(), &value));
504 return value;
505 }
506
522 Sint8 ReadS8()
523 {
524 Sint8 value;
525 CheckError(SDL_ReadS8(get(), &value));
526 return value;
527 }
528
548 Uint16 ReadU16LE()
549 {
550 Uint16 value;
551 CheckError(SDL_ReadU16LE(get(), &value));
552 return value;
553 }
554
574 Sint16 ReadS16LE()
575 {
576 Sint16 value;
577 CheckError(SDL_ReadS16LE(get(), &value));
578 return value;
579 }
580
600 Uint16 ReadU16BE()
601 {
602 Uint16 value;
603 CheckError(SDL_ReadU16BE(get(), &value));
604 return value;
605 }
606
626 Sint16 ReadS16BE()
627 {
628 Sint16 value;
629 CheckError(SDL_ReadS16BE(get(), &value));
630 return value;
631 }
632
652 Uint32 ReadU32LE()
653 {
654 Uint32 value;
655 CheckError(SDL_ReadU32LE(get(), &value));
656 return value;
657 }
658
678 Sint32 ReadS32LE()
679 {
680 Sint32 value;
681 CheckError(SDL_ReadS32LE(get(), &value));
682 return value;
683 }
684
704 Uint32 ReadU32BE()
705 {
706 Uint32 value;
707 CheckError(SDL_ReadU32BE(get(), &value));
708 return value;
709 }
710
730 Sint32 ReadS32BE()
731 {
732 Sint32 value;
733 CheckError(SDL_ReadS32BE(get(), &value));
734 return value;
735 }
736
756 Uint64 ReadU64LE()
757 {
758 Uint64 value;
759 CheckError(SDL_ReadU64LE(get(), &value));
760 return value;
761 }
762
782 Sint64 ReadS64LE()
783 {
784 Sint64 value;
785 CheckError(SDL_ReadS64LE(get(), &value));
786 return value;
787 }
788
808 Uint64 ReadU64BE()
809 {
810 Uint64 value;
811 CheckError(SDL_ReadU64BE(get(), &value));
812 return value;
813 }
814
834 Sint64 ReadS64BE()
835 {
836 Sint64 value;
837 CheckError(SDL_ReadS64BE(get(), &value));
838 return value;
839 }
840
851 void WriteU8(Uint8 value) { CheckError(SDL_WriteU8(get(), value)); }
852
863 void WriteS8(Sint8 value) { CheckError(SDL_WriteS8(get(), value)); }
864
880 void WriteU16LE(Uint16 value) { CheckError(SDL_WriteU16LE(get(), value)); }
881
897 void WriteS16LE(Sint16 value) { CheckError(SDL_WriteS16LE(get(), value)); }
898
913 void WriteU16BE(Uint16 value) { CheckError(SDL_WriteU16BE(get(), value)); }
914
929 void WriteS16BE(Sint16 value) { CheckError(SDL_WriteS16BE(get(), value)); }
930
946 void WriteU32LE(Uint32 value) { CheckError(SDL_WriteU32LE(get(), value)); }
947
963 void WriteS32LE(Sint32 value) { CheckError(SDL_WriteS32LE(get(), value)); }
964
979 void WriteU32BE(Uint32 value) { CheckError(SDL_WriteU32BE(get(), value)); }
980
995 void WriteS32BE(Sint32 value) { CheckError(SDL_WriteS32BE(get(), value)); }
996
1012 void WriteU64LE(Uint64 value) { CheckError(SDL_WriteU64LE(get(), value)); }
1013
1029 void WriteS64LE(Sint64 value) { CheckError(SDL_WriteS64LE(get(), value)); }
1030
1045 void WriteU64BE(Uint64 value) { CheckError(SDL_WriteU64BE(get(), value)); }
1046
1061 void WriteS64BE(Sint64 value) { CheckError(SDL_WriteS64BE(get(), value)); }
1062
1077 std::optional<Uint8> TryReadU8()
1078 {
1079 if (Uint8 value; SDL_ReadU8(get(), &value)) return value;
1080 return {};
1081 }
1082
1097 std::optional<Sint8> TryReadS8()
1098 {
1099 if (Sint8 value; SDL_ReadS8(get(), &value)) return value;
1100 return {};
1101 }
1102
1121 std::optional<Uint16> TryReadU16LE()
1122 {
1123 if (Uint16 value; SDL_ReadU16LE(get(), &value)) return value;
1124 return {};
1125 }
1126
1145 std::optional<Sint16> TryReadS16LE()
1146 {
1147 if (Sint16 value; SDL_ReadS16LE(get(), &value)) return value;
1148 return {};
1149 }
1150
1169 std::optional<Uint16> TryReadU16BE()
1170 {
1171 if (Uint16 value; SDL_ReadU16BE(get(), &value)) return value;
1172 return {};
1173 }
1174
1193 std::optional<Sint16> TryReadS16BE()
1194 {
1195 if (Sint16 value; SDL_ReadS16BE(get(), &value)) return value;
1196 return {};
1197 }
1198
1217 std::optional<Uint32> TryReadU32LE()
1218 {
1219 if (Uint32 value; SDL_ReadU32LE(get(), &value)) return value;
1220 return {};
1221 }
1222
1241 std::optional<Sint32> TryReadS32LE()
1242 {
1243 if (Sint32 value; SDL_ReadS32LE(get(), &value)) return value;
1244 return {};
1245 }
1246
1265 std::optional<Uint32> TryReadU32BE()
1266 {
1267 if (Uint32 value; SDL_ReadU32BE(get(), &value)) return value;
1268 return {};
1269 }
1270
1289 std::optional<Sint32> TryReadS32BE()
1290 {
1291 if (Sint32 value; SDL_ReadS32BE(get(), &value)) return value;
1292 return {};
1293 }
1294
1313 std::optional<Uint64> TryReadU64LE()
1314 {
1315 if (Uint64 value; SDL_ReadU64LE(get(), &value)) return value;
1316 return {};
1317 }
1318
1337 std::optional<Sint64> TryReadS64LE()
1338 {
1339 if (Sint64 value; SDL_ReadS64LE(get(), &value)) return value;
1340 return {};
1341 }
1342
1361 std::optional<Uint64> TryReadU64BE()
1362 {
1363 if (Uint64 value; SDL_ReadU64BE(get(), &value)) return value;
1364 return {};
1365 }
1366
1385 std::optional<Sint64> TryReadS64BE()
1386 {
1387 if (Sint64 value; SDL_ReadS64BE(get(), &value)) return value;
1388 return {};
1389 }
1390
1421 static void reset(SDL_IOStream* resource)
1422 {
1423 CheckError(SDL_CloseIO(resource));
1424 }
1425};
1426
1434struct IOStream : ResourceUnique<IOStreamRef>
1435{
1437
1521 {
1522 return IOStream(SDL_IOFromFile(file, mode));
1523 }
1524
1564 {
1565 return IOStream{SDL_IOFromMem(mem.data, mem.size_bytes)};
1566 }
1567
1607 {
1608 return IOStream{SDL_IOFromConstMem(mem.data, mem.size_bytes)};
1609 }
1610
1639 static IOStream FromDynamicMem() { return IOStream{SDL_IOFromDynamicMem()}; }
1640
1669 static IOStream Open(const IOStreamInterface& iface, void* userdata)
1670 {
1671 return IOStream(CheckError(SDL_OpenIO(&iface, userdata)));
1672 }
1673
1703 void Close() { reset(); }
1708
1709};
1710
1711
1713{
1714 return IOStreamShared(std::move(*this));
1715}
1716
1726struct IOStreamUnsafe : ResourceUnsafe<IOStreamRef>
1727{
1729
1733 constexpr explicit IOStreamUnsafe(IOStream&& other)
1734 : IOStreamUnsafe(other.release())
1735 {
1736 }
1737};
1738
1739namespace prop::IOStream {
1740
1741constexpr auto WINDOWS_HANDLE_POINTER =
1742 SDL_PROP_IOSTREAM_WINDOWS_HANDLE_POINTER;
1743
1744constexpr auto STDIO_FILE_POINTER = SDL_PROP_IOSTREAM_STDIO_FILE_POINTER;
1745
1746constexpr auto FILE_DESCRIPTOR_NUMBER =
1747 SDL_PROP_IOSTREAM_FILE_DESCRIPTOR_NUMBER;
1748
1749constexpr auto ANDROID_AASSET_POINTER =
1750 SDL_PROP_IOSTREAM_ANDROID_AASSET_POINTER;
1751
1752constexpr auto MEMORY_POINTER = SDL_PROP_IOSTREAM_MEMORY_POINTER;
1753
1754constexpr auto MEMORY_SIZE_NUMBER = SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER;
1755
1756constexpr auto DYNAMIC_MEMORY_POINTER =
1757 SDL_PROP_IOSTREAM_DYNAMIC_MEMORY_POINTER;
1758
1759constexpr auto DYNAMIC_CHUNKSIZE_NUMBER =
1760 SDL_PROP_IOSTREAM_DYNAMIC_CHUNKSIZE_NUMBER;
1761
1762} // namespace prop::IOStream
1763
1783{
1784 size_t datasize = 0;
1785 auto data = static_cast<char*>(SDL_LoadFile(file, &datasize));
1786 return StringResult{CheckError(data), datasize};
1787}
1788
1807template<class T>
1809{
1810 size_t datasize = 0;
1811 auto data = static_cast<T*>(SDL_LoadFile(file, &datasize));
1812 return OwnArray<T>{CheckError(data), datasize / sizeof(T)};
1813}
1814
1830inline void SaveFile(StringParam file, SourceBytes data)
1831{
1832 CheckError(SDL_SaveFile(file, data.data, data.size_bytes));
1833}
1834
1835#pragma region impl
1837
1838#pragma endregion impl
1839
1840} // namespace SDL
1841
1842#endif /* SDL3PP_IOSTREAM_H_ */
An exception that returns GetError()
Definition SDL3pp_error.h:167
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:43
RESOURCE release()
Returns reference and reset this.
Definition SDL3pp_resource.h:178
Implement shared ownership for a resource.
Definition SDL3pp_resource.h:283
Implement unique ownership for a resource.
Definition SDL3pp_resource.h:226
constexpr ResourceUnique(std::nullptr_t=nullptr)
Default constructor.
Definition SDL3pp_resource.h:231
void reset()
Resets the value, destroying the resource if not nullptr.
Definition SDL3pp_resource.h:265
A dumb pointer to resource.
Definition SDL3pp_resource.h:197
constexpr ResourceUnsafe()=default
Default constructor.
Implement weak ownership for a resource.
Definition SDL3pp_resource.h:328
A SDL managed resource.
Definition SDL3pp_resource.h:29
constexpr Resource(T resource={})
Constructs from the underlying resource.
Definition SDL3pp_resource.h:37
constexpr SDL_IOStream * get() const
Return contained resource;.
Definition SDL3pp_resource.h:76
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:206
ResourceShared< IOStream > IOStreamShared
Handle to a shared iOStream.
Definition SDL3pp_iostream.h:37
StringResult LoadFile(StringParam file)
Load all the data from a file path.
Definition SDL3pp_iostream.h:1782
SDL_IOWhence IOWhence
Possible whence values for IOStream seeking.
Definition SDL3pp_iostream.h:81
OwnArray< T > LoadFileAs(StringParam file)
Load all the data from a file path.
Definition SDL3pp_iostream.h:1808
constexpr IOStatus IO_STATUS_ERROR
Read or write I/O error.
Definition SDL3pp_iostream.h:59
constexpr IOStatus IO_STATUS_EOF
End of file.
Definition SDL3pp_iostream.h:62
constexpr IOStatus IO_STATUS_WRITEONLY
Tried to read a write-only buffer.
Definition SDL3pp_iostream.h:70
IOStreamShared share()
Move this iOStream into a IOStreamShared.
Definition SDL3pp_iostream.h:1712
void SaveFile(StringParam file, SourceBytes data)
Save all the data into a file path.
Definition SDL3pp_iostream.h:1830
constexpr IOWhence IO_SEEK_CUR
Seek relative to current read point.
Definition SDL3pp_iostream.h:86
SDL_IOStreamInterface IOStreamInterface
The function pointers that drive an IOStream.
Definition SDL3pp_iostream.h:106
SDL_IOStatus IOStatus
IOStream status, set by a read or write operation.
Definition SDL3pp_iostream.h:54
constexpr IOStatus IO_STATUS_READONLY
Tried to write a read-only buffer.
Definition SDL3pp_iostream.h:67
constexpr IOStatus IO_STATUS_READY
Everything is ready (no errors and not EOF).
Definition SDL3pp_iostream.h:56
constexpr IOStatus IO_STATUS_NOT_READY
Non blocking I/O, not ready.
Definition SDL3pp_iostream.h:64
constexpr IOWhence IO_SEEK_SET
Seek from the beginning of data.
Definition SDL3pp_iostream.h:83
constexpr IOWhence IO_SEEK_END
Seek relative to the end of data.
Definition SDL3pp_iostream.h:89
the main namespace where all SDL3pp public functions and types live
Definition SDL3pp_assert.h:7
The read/write operation structure.
Definition SDL3pp_iostream.h:123
std::optional< Sint16 > TryReadS16BE()
Use this function to read 16 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:1193
void WriteS8(Sint8 value)
Use this function to write a signed byte to an IOStreamRef.
Definition SDL3pp_iostream.h:863
Uint64 ReadU64LE()
Use this function to read 64 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:756
Sint8 ReadS8()
Use this function to read a signed byte from an IOStreamRef.
Definition SDL3pp_iostream.h:522
void WriteU64BE(Uint64 value)
Use this function to write 64 bits in native format to an IOStreamRef as big-endian data.
Definition SDL3pp_iostream.h:1045
PropertiesRef GetProperties() const
Get the properties associated with an IOStreamRef.
Definition SDL3pp_iostream.h:136
IOStatus GetStatus() const
Query the stream status of an IOStreamRef.
Definition SDL3pp_iostream.h:158
void WriteU16LE(Uint16 value)
Use this function to write 16 bits in native format to an IOStreamRef as little-endian data.
Definition SDL3pp_iostream.h:880
void WriteS64LE(Sint64 value)
Use this function to write 64 bits in native format to an IOStreamRef as little-endian data.
Definition SDL3pp_iostream.h:1029
Sint16 ReadS16BE()
Use this function to read 16 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:626
Sint64 GetSize() const
Use this function to get the size of the data stream in an IOStreamRef.
Definition SDL3pp_iostream.h:170
std::optional< Sint32 > TryReadS32BE()
Use this function to read 32 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:1289
void WriteS64BE(Sint64 value)
Use this function to write 64 bits in native format to an IOStreamRef as big-endian data.
Definition SDL3pp_iostream.h:1061
size_t print(std::string_view fmt, auto... args)
Definition SDL3pp_iostream.h:328
void WriteU32BE(Uint32 value)
Use this function to write 32 bits in native format to an IOStreamRef as big-endian data.
Definition SDL3pp_iostream.h:979
std::optional< Uint16 > TryReadU16LE()
Use this function to read 16 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:1121
static void reset(SDL_IOStream *resource)
Close and free an allocated IOStreamRef structure.
Definition SDL3pp_iostream.h:1421
Uint32 ReadU32LE()
Use this function to read 32 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:652
void WriteU64LE(Uint64 value)
Use this function to write 64 bits in native format to an IOStreamRef as little-endian data.
Definition SDL3pp_iostream.h:1012
OwnArray< T > LoadFileAs()
Load all the data from an SDL data stream.
Definition SDL3pp_iostream.h:459
Sint16 ReadS16LE()
Use this function to read 16 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:574
std::optional< Sint16 > TryReadS16LE()
Use this function to read 16 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:1145
void WriteU16BE(Uint16 value)
Use this function to write 16 bits in native format to an IOStreamRef as big-endian data.
Definition SDL3pp_iostream.h:913
void SaveFile(SourceBytes data)
Save all the data into an SDL data stream.
Definition SDL3pp_iostream.h:480
std::optional< Sint8 > TryReadS8()
Use this function to read a byte from an IOStreamRef.
Definition SDL3pp_iostream.h:1097
std::optional< Sint64 > TryReadS64BE()
Use this function to read 64 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:1385
Sint64 ReadS64BE()
Use this function to read 64 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:834
Uint16 ReadU16BE()
Use this function to read 16 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:600
size_t println(std::string_view fmt, auto... args)
Definition SDL3pp_iostream.h:336
std::optional< Sint32 > TryReadS32LE()
Use this function to read 32 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:1241
void WriteU32LE(Uint32 value)
Use this function to write 32 bits in native format to an IOStreamRef as little-endian data.
Definition SDL3pp_iostream.h:946
Sint32 ReadS32LE()
Use this function to read 32 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:678
std::optional< Uint32 > TryReadU32BE()
Use this function to read 32 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:1265
size_t Read(TargetBytes buf)
Read from a data source.
Definition SDL3pp_iostream.h:287
Uint32 ReadU32BE()
Use this function to read 32 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:704
Uint8 ReadU8()
Use this function to read a byte from an IOStreamRef.
Definition SDL3pp_iostream.h:500
size_t printf(SDL_PRINTF_FORMAT_STRING const char *fmt,...)
Print to an IOStreamRef data stream.
Definition SDL3pp_iostream.h:363
Sint32 ReadS32BE()
Use this function to read 32 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:730
Uint16 ReadU16LE()
Use this function to read 16 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:548
void WriteS32BE(Sint32 value)
Use this function to write 32 bits in native format to an IOStreamRef as big-endian data.
Definition SDL3pp_iostream.h:995
std::optional< Uint64 > TryReadU64BE()
Use this function to read 64 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:1361
void WriteU8(Uint8 value)
Use this function to write a byte to an IOStreamRef.
Definition SDL3pp_iostream.h:851
void Flush()
Flush any buffered data in the stream.
Definition SDL3pp_iostream.h:415
std::optional< Uint64 > TryReadU64LE()
Use this function to read 64 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:1313
std::optional< Sint64 > TryReadS64LE()
Use this function to read 64 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:1337
StringResult LoadFile()
Load all the data from an SDL data stream.
Definition SDL3pp_iostream.h:434
size_t vprintf(SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap)
Print to an IOStreamRef data stream.
Definition SDL3pp_iostream.h:394
Sint64 Tell() const
Determine the current read/write offset in an IOStreamRef data stream.
Definition SDL3pp_iostream.h:224
size_t Write(SourceBytes buf)
Write to an IOStreamRef data stream.
Definition SDL3pp_iostream.h:320
void WriteS16LE(Sint16 value)
Use this function to write 16 bits in native format to an IOStreamRef as little-endian data.
Definition SDL3pp_iostream.h:897
std::optional< Uint32 > TryReadU32LE()
Use this function to read 32 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:1217
std::optional< Uint8 > TryReadU8()
Use this function to read a byte from an IOStreamRef.
Definition SDL3pp_iostream.h:1077
void WriteS32LE(Sint32 value)
Use this function to write 32 bits in native format to an IOStreamRef as little-endian data.
Definition SDL3pp_iostream.h:963
std::string Read(size_t size=-1)
Read from a data source.
Definition SDL3pp_iostream.h:248
Sint64 Seek(Sint64 offset, IOWhence whence)
Seek within an IOStreamRef data stream.
Definition SDL3pp_iostream.h:203
Uint64 ReadU64BE()
Use this function to read 64 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:808
std::optional< Uint16 > TryReadU16BE()
Use this function to read 16 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:1169
void WriteS16BE(Sint16 value)
Use this function to write 16 bits in native format to an IOStreamRef as big-endian data.
Definition SDL3pp_iostream.h:929
Sint64 ReadS64LE()
Use this function to read 64 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:782
Unsafe Handle to iOStream.
Definition SDL3pp_iostream.h:1727
constexpr IOStreamUnsafe(IOStream &&other)
Constructs IOStreamUnsafe from IOStream.
Definition SDL3pp_iostream.h:1733
Handle to an owned iOStream.
Definition SDL3pp_iostream.h:1435
static IOStream Open(const IOStreamInterface &iface, void *userdata)
Create a custom IOStreamRef.
Definition SDL3pp_iostream.h:1669
void Close()
Close and free an allocated IOStreamRef structure.
Definition SDL3pp_iostream.h:1703
static IOStream FromMem(TargetBytes mem)
Use this function to prepare a read-write memory buffer for use with IOStream.
Definition SDL3pp_iostream.h:1563
static IOStream FromDynamicMem()
Use this function to create an IOStreamRef that is backed by dynamically allocated memory.
Definition SDL3pp_iostream.h:1639
static IOStream FromConstMem(SourceBytes mem)
Use this function to prepare a read-only memory buffer for use with IOStreamRef.
Definition SDL3pp_iostream.h:1606
static 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.
Definition SDL3pp_iostream.h:1520
SDL properties ID.
Definition SDL3pp_properties.h:209
Source byte stream.
Definition SDL3pp_strings.h:239
size_t size_bytes
The size in bytes.
Definition SDL3pp_strings.h:241
const void * data
The data copied from.
Definition SDL3pp_strings.h:240
A simple std::string-like interface for SDL allocated strings.
Definition SDL3pp_strings.h:153
Target byte stream.
Definition SDL3pp_strings.h:305
size_t size_bytes
The size in bytes.
Definition SDL3pp_strings.h:307
void * data
The address to have data copied to it.
Definition SDL3pp_strings.h:306