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
22
23// Forward decl
24struct IOStream;
25
27using IOStreamRaw = SDL_IOStream*;
28
35
41using IOStatus = SDL_IOStatus;
42
44 SDL_IO_STATUS_READY;
45
47 SDL_IO_STATUS_ERROR;
48
49constexpr IOStatus IO_STATUS_EOF = SDL_IO_STATUS_EOF;
50
52 SDL_IO_STATUS_NOT_READY;
53
55 SDL_IO_STATUS_READONLY;
56
58 SDL_IO_STATUS_WRITEONLY;
59
68using IOWhence = SDL_IOWhence;
69
71 SDL_IO_SEEK_SET;
72
74 SDL_IO_SEEK_CUR;
75
77 SDL_IO_SEEK_END;
78
93using IOStreamInterface = SDL_IOStreamInterface;
94
107struct IOStream : ResourceBase<IOStreamRaw>
108{
110
118 constexpr explicit IOStream(IOStreamRaw resource) noexcept
119 : ResourceBase(resource)
120 {
121 }
122
124 constexpr IOStream(const IOStream& other) = delete;
125
127 constexpr IOStream(IOStream&& other) noexcept
128 : IOStream(other.release())
129 {
130 }
131
132 constexpr IOStream(const IOStreamRef& other) = delete;
133
134 constexpr IOStream(IOStreamRef&& other) = delete;
135
222 static IOStream FromFile(StringParam file, StringParam mode);
223
268 static IOStream FromMem(TargetBytes mem);
269
315
343 static IOStream FromDynamicMem();
344
373 static IOStream Open(const IOStreamInterface& iface, void* userdata);
374
376 ~IOStream() { SDL_CloseIO(get()); }
377
379 constexpr IOStream& operator=(IOStream&& other) noexcept
380 {
381 swap(*this, other);
382 return *this;
383 }
384
386 IOStream& operator=(const IOStream& other) = delete;
387
417 void Close();
418
430
448 IOStatus GetStatus() const;
449
460 Sint64 GetSize() const;
461
487 Sint64 Seek(Sint64 offset, IOWhence whence);
488
505 Sint64 Tell() const;
506
529 std::string Read(size_t size = -1)
530 {
531 Sint64 pos = Tell();
532 if (auto curSize = SDL_GetIOSize(get()); curSize < 0 || pos < 0) {
533 if (size == size_t(-1)) return {};
534 } else if (curSize - pos <= 0) {
535 return {};
536 } else if (size_t(curSize - pos) < size) {
537 size = curSize - pos;
538 }
539 std::string result(size, 0);
540 if (auto actualSize = Read(result); actualSize < size) {
541 result.resize(actualSize);
542 }
543 return result;
544 }
545
572 size_t Read(TargetBytes buf);
573
606 size_t Write(SourceBytes buf);
607
615 size_t print(std::string_view fmt, auto... args)
616 {
617 return Write(std::vformat(fmt, std::make_format_args(args...)));
618 }
619
627 size_t println(std::string_view fmt, auto... args)
628 {
629 std::string result =
630 std::vformat(fmt, std::make_format_args(args...)) + "\n";
631 return Write(result);
632 }
633
654 size_t printf(SDL_PRINTF_FORMAT_STRING const char* fmt, ...)
655 {
656 va_list ap;
657 size_t result;
658
659 va_start(ap, fmt);
660 result = SDL_IOvprintf(get(), fmt, ap);
661 va_end(ap);
662
663 return result;
664 }
665
685 size_t vprintf(SDL_PRINTF_FORMAT_STRING const char* fmt, va_list ap);
686
703 void Flush();
704
722
740 template<class T>
742 {
743 size_t datasize = 0;
744 auto data = static_cast<T*>(SDL_LoadFile_IO(get(), &datasize, false));
745 return OwnArray<T>{CheckError(data), datasize / sizeof(T)};
746 }
747
762 void SaveFile(SourceBytes data);
763
779 Uint8 ReadU8();
780
796 Sint8 ReadS8();
797
818
839
860
881
902
923
944
965
986
1006 Sint64 ReadS64LE();
1007
1027 Uint64 ReadU64BE();
1028
1048 Sint64 ReadS64BE();
1049
1064 std::optional<Uint8> TryReadU8() const
1065 {
1066 if (Uint8 value; SDL_ReadU8(get(), &value)) return value;
1067 return {};
1068 }
1069
1084 std::optional<Sint8> TryReadS8() const
1085 {
1086 if (Sint8 value; SDL_ReadS8(get(), &value)) return value;
1087 return {};
1088 }
1089
1108 std::optional<Uint16> TryReadU16LE() const
1109 {
1110 if (Uint16 value; SDL_ReadU16LE(get(), &value)) return value;
1111 return {};
1112 }
1113
1132 std::optional<Sint16> TryReadS16LE() const
1133 {
1134 if (Sint16 value; SDL_ReadS16LE(get(), &value)) return value;
1135 return {};
1136 }
1137
1156 std::optional<Uint16> TryReadU16BE() const
1157 {
1158 if (Uint16 value; SDL_ReadU16BE(get(), &value)) return value;
1159 return {};
1160 }
1161
1180 std::optional<Sint16> TryReadS16BE() const
1181 {
1182 if (Sint16 value; SDL_ReadS16BE(get(), &value)) return value;
1183 return {};
1184 }
1185
1204 std::optional<Uint32> TryReadU32LE() const
1205 {
1206 if (Uint32 value; SDL_ReadU32LE(get(), &value)) return value;
1207 return {};
1208 }
1209
1228 std::optional<Sint32> TryReadS32LE() const
1229 {
1230 if (Sint32 value; SDL_ReadS32LE(get(), &value)) return value;
1231 return {};
1232 }
1233
1252 std::optional<Uint32> TryReadU32BE() const
1253 {
1254 if (Uint32 value; SDL_ReadU32BE(get(), &value)) return value;
1255 return {};
1256 }
1257
1276 std::optional<Sint32> TryReadS32BE() const
1277 {
1278 if (Sint32 value; SDL_ReadS32BE(get(), &value)) return value;
1279 return {};
1280 }
1281
1300 std::optional<Uint64> TryReadU64LE() const
1301 {
1302 if (Uint64 value; SDL_ReadU64LE(get(), &value)) return value;
1303 return {};
1304 }
1305
1324 std::optional<Sint64> TryReadS64LE() const
1325 {
1326 if (Sint64 value; SDL_ReadS64LE(get(), &value)) return value;
1327 return {};
1328 }
1329
1348 std::optional<Uint64> TryReadU64BE() const
1349 {
1350 if (Uint64 value; SDL_ReadU64BE(get(), &value)) return value;
1351 return {};
1352 }
1353
1372 std::optional<Sint64> TryReadS64BE() const
1373 {
1374 if (Sint64 value; SDL_ReadS64BE(get(), &value)) return value;
1375 return {};
1376 }
1377
1388 void WriteU8(Uint8 value);
1389
1400 void WriteS8(Sint8 value);
1401
1417 void WriteU16LE(Uint16 value);
1418
1434 void WriteS16LE(Sint16 value);
1435
1450 void WriteU16BE(Uint16 value);
1451
1466 void WriteS16BE(Sint16 value);
1467
1483 void WriteU32LE(Uint32 value);
1484
1500 void WriteS32LE(Sint32 value);
1501
1516 void WriteU32BE(Uint32 value);
1517
1532 void WriteS32BE(Sint32 value);
1533
1549 void WriteU64LE(Uint64 value);
1550
1566 void WriteS64LE(Sint64 value);
1567
1582 void WriteU64BE(Uint64 value);
1583
1598 void WriteS64BE(Sint64 value);
1599};
1600
1684{
1685 return IOStream(SDL_IOFromFile(file, mode));
1686}
1687
1689{
1690 return SDL::IOFromFile(std::move(file), std::move(mode));
1691}
1692
1708
1710 SDL_PROP_IOSTREAM_WINDOWS_HANDLE_POINTER;
1711
1712constexpr auto STDIO_FILE_POINTER =
1713 SDL_PROP_IOSTREAM_STDIO_FILE_POINTER;
1714
1716 SDL_PROP_IOSTREAM_FILE_DESCRIPTOR_NUMBER;
1717
1719 SDL_PROP_IOSTREAM_ANDROID_AASSET_POINTER;
1720
1721constexpr auto MEMORY_POINTER =
1722 SDL_PROP_IOSTREAM_MEMORY_POINTER;
1723
1724constexpr auto MEMORY_SIZE_NUMBER =
1725 SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER;
1726
1727#if SDL_VERSION_ATLEAST(3, 4, 0)
1728
1730 SDL_PROP_IOSTREAM_MEMORY_FREE_FUNC_POINTER;
1731
1732#endif // SDL_VERSION_ATLEAST(3, 4, 0)
1733
1735 SDL_PROP_IOSTREAM_DYNAMIC_MEMORY_POINTER;
1736
1738 SDL_PROP_IOSTREAM_DYNAMIC_CHUNKSIZE_NUMBER;
1739
1740} // namespace prop::IOStream
1741
1786{
1787 return IOStream(CheckError(SDL_IOFromMem(mem.data(), mem.size_bytes())));
1788}
1789
1791{
1792 return SDL::IOFromMem(std::move(mem));
1793}
1794
1839{
1840 return IOStream(CheckError(SDL_IOFromConstMem(mem.data(), mem.size_bytes())));
1841}
1842
1844{
1845 return SDL::IOFromConstMem(std::move(mem));
1846}
1847
1875inline IOStream IOFromDynamicMem() { return IOStream(SDL_IOFromDynamicMem()); }
1876
1878
1906inline IOStream OpenIO(const IOStreamInterface& iface, void* userdata)
1907{
1908 return IOStream(CheckError(SDL_OpenIO(&iface, userdata)));
1909}
1910
1911inline IOStream IOStream::Open(const IOStreamInterface& iface, void* userdata)
1912{
1913 return SDL::OpenIO(iface, userdata);
1914}
1915
1945inline void CloseIO(IOStreamRaw context) { CheckError(SDL_CloseIO(context)); }
1946
1947inline void IOStream::Close() { CloseIO(release()); }
1948
1961{
1962 return {CheckError(SDL_GetIOProperties(context))};
1963}
1964
1966{
1967 return SDL::GetIOProperties(get());
1968}
1969
1989{
1990 return SDL_GetIOStatus(context);
1991}
1992
1994
2007{
2008 return CheckError(SDL_GetIOSize(context));
2009}
2010
2011inline Sint64 IOStream::GetSize() const { return SDL::GetIOSize(get()); }
2012
2039inline Sint64 SeekIO(IOStreamRef context, Sint64 offset, IOWhence whence)
2040{
2041 return SDL_SeekIO(context, offset, whence);
2042}
2043
2044inline Sint64 IOStream::Seek(Sint64 offset, IOWhence whence)
2045{
2046 return SDL::SeekIO(get(), offset, whence);
2047}
2048
2067inline Sint64 TellIO(IOStreamRef context) { return SDL_TellIO(context); }
2068
2069inline Sint64 IOStream::Tell() const { return SDL::TellIO(get()); }
2070
2098inline size_t ReadIO(IOStreamRef context, TargetBytes buf)
2099{
2100 return SDL_ReadIO(context, buf.data(), buf.size_bytes());
2101}
2102
2103inline size_t IOStream::Read(TargetBytes buf)
2104{
2105 return SDL::ReadIO(get(), std::move(buf));
2106}
2107
2141inline size_t WriteIO(IOStreamRef context, SourceBytes buf)
2142{
2143 return SDL_WriteIO(context, buf.data(), buf.size_bytes());
2144}
2145
2147{
2148 return SDL::WriteIO(get(), std::move(buf));
2149}
2150
2172inline size_t IOprintf(IOStreamRef context,
2173 SDL_PRINTF_FORMAT_STRING const char* fmt,
2174 ...)
2175{
2176 va_list ap;
2177 size_t result;
2178
2179 va_start(ap, fmt);
2180 result = SDL_IOvprintf(context, fmt, ap);
2181 va_end(ap);
2182
2183 return result;
2184}
2185
2204inline size_t IOvprintf(IOStreamRef context,
2205 SDL_PRINTF_FORMAT_STRING const char* fmt,
2206 va_list ap)
2207{
2208 return SDL_IOvprintf(context, fmt, ap);
2209}
2210
2211inline size_t IOStream::vprintf(SDL_PRINTF_FORMAT_STRING const char* fmt,
2212 va_list ap)
2213{
2214 return SDL::IOvprintf(get(), fmt, ap);
2215}
2216
2234inline void FlushIO(IOStreamRef context) { CheckError(SDL_FlushIO(context)); }
2235
2236inline void IOStream::Flush() { SDL::FlushIO(get()); }
2237
2260inline StringResult LoadFile_IO(IOStreamRef src, bool closeio = true)
2261{
2262 size_t datasize = 0;
2263 auto data = static_cast<char*>(SDL_LoadFile_IO(src, &datasize, closeio));
2264 return StringResult{CheckError(data), datasize};
2265}
2266
2268
2287template<class T>
2289{
2290 size_t datasize = 0;
2291 auto data = static_cast<T*>(SDL_LoadFile(file, &datasize));
2292 return OwnArray<T>{CheckError(data), datasize / sizeof(T)};
2293}
2294
2314{
2315 size_t datasize = 0;
2316 auto data = static_cast<char*>(SDL_LoadFile(file, &datasize));
2317 return StringResult{CheckError(data), datasize};
2318}
2319
2336inline void SaveFile_IO(IOStreamRef src, SourceBytes data, bool closeio = true)
2337{
2338 CheckError(SDL_SaveFile_IO(src, data.data(), data.size_bytes(), closeio));
2339}
2340
2342{
2343 SDL::SaveFile_IO(get(), std::move(data));
2344}
2345
2360inline void SaveFile(StringParam file, SourceBytes data)
2361{
2362 CheckError(SDL_SaveFile(file, data.data(), data.size_bytes()));
2363}
2364
2382{
2383 Uint8 value;
2384 CheckError(SDL_ReadU8(src, &value));
2385 return value;
2386}
2387
2388inline Uint8 IOStream::ReadU8() { return SDL::ReadU8(get()); }
2389
2407{
2408 Sint8 value;
2409 CheckError(SDL_ReadS8(src, &value));
2410 return value;
2411}
2412
2413inline Sint8 IOStream::ReadS8() { return SDL::ReadS8(get()); }
2414
2436{
2437 Uint16 value;
2438 CheckError(SDL_ReadU16LE(src, &value));
2439 return value;
2440}
2441
2443
2465{
2466 Sint16 value;
2467 CheckError(SDL_ReadS16LE(src, &value));
2468 return value;
2469}
2470
2472
2494{
2495 Uint16 value;
2496 CheckError(SDL_ReadU16BE(src, &value));
2497 return value;
2498}
2499
2501
2523{
2524 Sint16 value;
2525 CheckError(SDL_ReadS16BE(src, &value));
2526 return value;
2527}
2528
2530
2552{
2553 Uint32 value;
2554 CheckError(SDL_ReadU32LE(src, &value));
2555 return value;
2556}
2557
2559
2581{
2582 Sint32 value;
2583 CheckError(SDL_ReadS32LE(src, &value));
2584 return value;
2585}
2586
2588
2610{
2611 Uint32 value;
2612 CheckError(SDL_ReadU32BE(src, &value));
2613 return value;
2614}
2615
2617
2639{
2640 Sint32 value;
2641 CheckError(SDL_ReadS32BE(src, &value));
2642 return value;
2643}
2644
2646
2668{
2669 Uint64 value;
2670 CheckError(SDL_ReadU64LE(src, &value));
2671 return value;
2672}
2673
2675
2697{
2698 Sint64 value;
2699 CheckError(SDL_ReadS64LE(src, &value));
2700 return value;
2701}
2702
2704
2726{
2727 Uint64 value;
2728 CheckError(SDL_ReadU64BE(src, &value));
2729 return value;
2730}
2731
2733
2755{
2756 Sint64 value;
2757 CheckError(SDL_ReadS64BE(src, &value));
2758 return value;
2759}
2760
2762
2774inline void WriteU8(IOStreamRef dst, Uint8 value)
2775{
2776 CheckError(SDL_WriteU8(dst, value));
2777}
2778
2779inline void IOStream::WriteU8(Uint8 value) { SDL::WriteU8(get(), value); }
2780
2792inline void WriteS8(IOStreamRef dst, Sint8 value)
2793{
2794 CheckError(SDL_WriteS8(dst, value));
2795}
2796
2797inline void IOStream::WriteS8(Sint8 value) { SDL::WriteS8(get(), value); }
2798
2814inline void WriteU16LE(IOStreamRef dst, Uint16 value)
2815{
2816 CheckError(SDL_WriteU16LE(dst, value));
2817}
2818
2820{
2821 SDL::WriteU16LE(get(), value);
2822}
2823
2839inline void WriteS16LE(IOStreamRef dst, Sint16 value)
2840{
2841 CheckError(SDL_WriteS16LE(dst, value));
2842}
2843
2845{
2846 SDL::WriteS16LE(get(), value);
2847}
2848
2864inline void WriteU16BE(IOStreamRef dst, Uint16 value)
2865{
2866 CheckError(SDL_WriteU16BE(dst, value));
2867}
2868
2870{
2871 SDL::WriteU16BE(get(), value);
2872}
2873
2889inline void WriteS16BE(IOStreamRef dst, Sint16 value)
2890{
2891 CheckError(SDL_WriteS16BE(dst, value));
2892}
2893
2895{
2896 SDL::WriteS16BE(get(), value);
2897}
2898
2914inline void WriteU32LE(IOStreamRef dst, Uint32 value)
2915{
2916 CheckError(SDL_WriteU32LE(dst, value));
2917}
2918
2920{
2921 SDL::WriteU32LE(get(), value);
2922}
2923
2939inline void WriteS32LE(IOStreamRef dst, Sint32 value)
2940{
2941 CheckError(SDL_WriteS32LE(dst, value));
2942}
2943
2945{
2946 SDL::WriteS32LE(get(), value);
2947}
2948
2964inline void WriteU32BE(IOStreamRef dst, Uint32 value)
2965{
2966 CheckError(SDL_WriteU32BE(dst, value));
2967}
2968
2970{
2971 SDL::WriteU32BE(get(), value);
2972}
2973
2989inline void WriteS32BE(IOStreamRef dst, Sint32 value)
2990{
2991 CheckError(SDL_WriteS32BE(dst, value));
2992}
2993
2995{
2996 SDL::WriteS32BE(get(), value);
2997}
2998
3014inline void WriteU64LE(IOStreamRef dst, Uint64 value)
3015{
3016 CheckError(SDL_WriteU64LE(dst, value));
3017}
3018
3020{
3021 SDL::WriteU64LE(get(), value);
3022}
3023
3039inline void WriteS64LE(IOStreamRef dst, Sint64 value)
3040{
3041 CheckError(SDL_WriteS64LE(dst, value));
3042}
3043
3045{
3046 SDL::WriteS64LE(get(), value);
3047}
3048
3064inline void WriteU64BE(IOStreamRef dst, Uint64 value)
3065{
3066 CheckError(SDL_WriteU64BE(dst, value));
3067}
3068
3070{
3071 SDL::WriteU64BE(get(), value);
3072}
3073
3089inline void WriteS64BE(IOStreamRef dst, Sint64 value)
3090{
3091 CheckError(SDL_WriteS64BE(dst, value));
3092}
3093
3095{
3096 SDL::WriteS64BE(get(), value);
3097}
3098
3100
3101} // namespace SDL
3102
3103#endif /* SDL3PP_IOSTREAM_H_ */
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:44
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:53
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:56
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
Source byte stream.
Definition SDL3pp_strings.h:237
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition SDL3pp_strings.h:301
constexpr const char * data() const
Retrieves contained data.
Definition SDL3pp_strings.h:304
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:43
Target byte stream.
Definition SDL3pp_strings.h:323
constexpr char * data() const
Retrieves contained data.
Definition SDL3pp_strings.h:409
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition SDL3pp_strings.h:406
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:199
void WriteS16BE(IOStreamRef dst, Sint16 value)
Use this function to write 16 bits in native format to an IOStream as big-endian data.
Definition SDL3pp_iostream.h:2889
Sint8 ReadS8()
Use this function to read a signed byte from an IOStream.
Definition SDL3pp_iostream.h:2413
Sint64 GetSize() const
Use this function to get the size of the data stream in an IOStream.
Definition SDL3pp_iostream.h:2011
IOStream IOFromMem(TargetBytes mem)
Use this function to prepare a read-write memory buffer for use with IOStream.
Definition SDL3pp_iostream.h:1785
size_t ReadIO(IOStreamRef context, TargetBytes buf)
Read from a data source.
Definition SDL3pp_iostream.h:2098
void FlushIO(IOStreamRef context)
Flush any buffered data in the stream.
Definition SDL3pp_iostream.h:2234
void WriteS64BE(IOStreamRef dst, Sint64 value)
Use this function to write 64 bits in native format to an IOStream as big-endian data.
Definition SDL3pp_iostream.h:3089
SDL_IOWhence IOWhence
Possible whence values for IOStream seeking.
Definition SDL3pp_iostream.h:68
void WriteU32LE(Uint32 value)
Use this function to write 32 bits in native format to an IOStream as little-endian data.
Definition SDL3pp_iostream.h:2919
void WriteS32BE(Sint32 value)
Use this function to write 32 bits in native format to an IOStream as big-endian data.
Definition SDL3pp_iostream.h:2994
void WriteS32LE(Sint32 value)
Use this function to write 32 bits in native format to an IOStream as little-endian data.
Definition SDL3pp_iostream.h:2944
StringResult LoadFile(StringParam file)
Load all the data from a file path.
Definition SDL3pp_iostream.h:2313
void WriteU64LE(IOStreamRef dst, Uint64 value)
Use this function to write 64 bits in native format to an IOStream as little-endian data.
Definition SDL3pp_iostream.h:3014
void WriteU64BE(Uint64 value)
Use this function to write 64 bits in native format to an IOStream as big-endian data.
Definition SDL3pp_iostream.h:3069
void WriteU64BE(IOStreamRef dst, Uint64 value)
Use this function to write 64 bits in native format to an IOStream as big-endian data.
Definition SDL3pp_iostream.h:3064
IOStream OpenIO(const IOStreamInterface &iface, void *userdata)
Create a custom IOStream.
Definition SDL3pp_iostream.h:1906
PropertiesRef GetIOProperties(IOStreamRef context)
Get the properties associated with an IOStream.
Definition SDL3pp_iostream.h:1960
Uint16 ReadU16BE()
Use this function to read 16 bits of big-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2500
SDL_IOStatus IOStatus
IOStream status, set by a read or write operation.
Definition SDL3pp_iostream.h:41
void WriteU32BE(IOStreamRef dst, Uint32 value)
Use this function to write 32 bits in native format to an IOStream as big-endian data.
Definition SDL3pp_iostream.h:2964
void SaveFile(SourceBytes data)
Save all the data into an SDL data stream.
Definition SDL3pp_iostream.h:2341
size_t WriteIO(IOStreamRef context, SourceBytes buf)
Write to an IOStream data stream.
Definition SDL3pp_iostream.h:2141
void WriteU8(IOStreamRef dst, Uint8 value)
Use this function to write a byte to an IOStream.
Definition SDL3pp_iostream.h:2774
void WriteU32BE(Uint32 value)
Use this function to write 32 bits in native format to an IOStream as big-endian data.
Definition SDL3pp_iostream.h:2969
Sint64 TellIO(IOStreamRef context)
Determine the current read/write offset in an IOStream data stream.
Definition SDL3pp_iostream.h:2067
Sint32 ReadS32BE()
Use this function to read 32 bits of big-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2645
void SaveFile_IO(IOStreamRef src, SourceBytes data, bool closeio=true)
Save all the data into an SDL data stream.
Definition SDL3pp_iostream.h:2336
Sint64 ReadS64BE(IOStreamRef src)
Use this function to read 64 bits of big-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2754
void WriteS16LE(Sint16 value)
Use this function to write 16 bits in native format to an IOStream as little-endian data.
Definition SDL3pp_iostream.h:2844
void WriteS8(Sint8 value)
Use this function to write a signed byte to an IOStream.
Definition SDL3pp_iostream.h:2797
void WriteS32LE(IOStreamRef dst, Sint32 value)
Use this function to write 32 bits in native format to an IOStream as little-endian data.
Definition SDL3pp_iostream.h:2939
SDL_IOStream * IOStreamRaw
Alias to raw representation for IOStream.
Definition SDL3pp_iostream.h:27
size_t IOprintf(IOStreamRef context, SDL_PRINTF_FORMAT_STRING const char *fmt,...)
Print to an IOStream data stream.
Definition SDL3pp_iostream.h:2172
Uint32 ReadU32BE(IOStreamRef src)
Use this function to read 32 bits of big-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2609
void Flush()
Flush any buffered data in the stream.
Definition SDL3pp_iostream.h:2236
IOStream IOFromConstMem(SourceBytes mem)
Use this function to prepare a read-only memory buffer for use with IOStream.
Definition SDL3pp_iostream.h:1838
Sint32 ReadS32LE(IOStreamRef src)
Use this function to read 32 bits of little-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2580
Sint32 ReadS32BE(IOStreamRef src)
Use this function to read 32 bits of big-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2638
size_t vprintf(SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap)
Print to an IOStream data stream.
Definition SDL3pp_iostream.h:2211
Uint16 ReadU16LE()
Use this function to read 16 bits of little-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2442
void WriteS32BE(IOStreamRef dst, Sint32 value)
Use this function to write 32 bits in native format to an IOStream as big-endian data.
Definition SDL3pp_iostream.h:2989
Uint32 ReadU32LE()
Use this function to read 32 bits of little-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2558
IOStream IOFromDynamicMem()
Use this function to create an IOStream that is backed by dynamically allocated memory.
Definition SDL3pp_iostream.h:1875
void Close()
Close and free an allocated IOStream structure.
Definition SDL3pp_iostream.h:1947
OwnArray< T > LoadFileAs(StringParam file)
Load all the data from a file path.
Definition SDL3pp_iostream.h:2288
void WriteS64BE(Sint64 value)
Use this function to write 64 bits in native format to an IOStream as big-endian data.
Definition SDL3pp_iostream.h:3094
Uint8 ReadU8(IOStreamRef src)
Use this function to read a byte from an IOStream.
Definition SDL3pp_iostream.h:2381
constexpr IOStatus IO_STATUS_ERROR
Read or write I/O error.
Definition SDL3pp_iostream.h:46
Uint16 ReadU16LE(IOStreamRef src)
Use this function to read 16 bits of little-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2435
void WriteS16BE(Sint16 value)
Use this function to write 16 bits in native format to an IOStream as big-endian data.
Definition SDL3pp_iostream.h:2894
static IOStream Open(const IOStreamInterface &iface, void *userdata)
Create a custom IOStream.
Definition SDL3pp_iostream.h:1911
Uint8 ReadU8()
Use this function to read a byte from an IOStream.
Definition SDL3pp_iostream.h:2388
void WriteS64LE(IOStreamRef dst, Sint64 value)
Use this function to write 64 bits in native format to an IOStream as little-endian data.
Definition SDL3pp_iostream.h:3039
Uint32 ReadU32BE()
Use this function to read 32 bits of big-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2616
IOStream IOFromFile(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:1683
constexpr IOStatus IO_STATUS_EOF
End of file.
Definition SDL3pp_iostream.h:49
void WriteS16LE(IOStreamRef dst, Sint16 value)
Use this function to write 16 bits in native format to an IOStream as little-endian data.
Definition SDL3pp_iostream.h:2839
IOStatus GetIOStatus(IOStreamRef context)
Query the stream status of an IOStream.
Definition SDL3pp_iostream.h:1988
Sint64 GetIOSize(IOStreamRef context)
Use this function to get the size of the data stream in an IOStream.
Definition SDL3pp_iostream.h:2006
Sint64 Seek(Sint64 offset, IOWhence whence)
Seek within an IOStream data stream.
Definition SDL3pp_iostream.h:2044
Uint32 ReadU32LE(IOStreamRef src)
Use this function to read 32 bits of little-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2551
size_t Write(SourceBytes buf)
Write to an IOStream data stream.
Definition SDL3pp_iostream.h:2146
void WriteS8(IOStreamRef dst, Sint8 value)
Use this function to write a signed byte to an IOStream.
Definition SDL3pp_iostream.h:2792
Sint64 Tell() const
Determine the current read/write offset in an IOStream data stream.
Definition SDL3pp_iostream.h:2069
Sint64 ReadS64LE(IOStreamRef src)
Use this function to read 64 bits of little-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2696
size_t IOvprintf(IOStreamRef context, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap)
Print to an IOStream data stream.
Definition SDL3pp_iostream.h:2204
void WriteU16BE(Uint16 value)
Use this function to write 16 bits in native format to an IOStream as big-endian data.
Definition SDL3pp_iostream.h:2869
ResourceRef< IOStream > IOStreamRef
Reference for IOStream.
Definition SDL3pp_iostream.h:34
Sint32 ReadS32LE()
Use this function to read 32 bits of little-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2587
Sint16 ReadS16BE()
Use this function to read 16 bits of big-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2529
SDL_IOStreamInterface IOStreamInterface
The function pointers that drive an IOStream.
Definition SDL3pp_iostream.h:93
constexpr IOStatus IO_STATUS_WRITEONLY
Tried to read a write-only buffer.
Definition SDL3pp_iostream.h:57
Uint16 ReadU16BE(IOStreamRef src)
Use this function to read 16 bits of big-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2493
Sint8 ReadS8(IOStreamRef src)
Use this function to read a signed byte from an IOStream.
Definition SDL3pp_iostream.h:2406
Sint16 ReadS16BE(IOStreamRef src)
Use this function to read 16 bits of big-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2522
void WriteU16LE(IOStreamRef dst, Uint16 value)
Use this function to write 16 bits in native format to an IOStream as little-endian data.
Definition SDL3pp_iostream.h:2814
Sint64 SeekIO(IOStreamRef context, Sint64 offset, IOWhence whence)
Seek within an IOStream data stream.
Definition SDL3pp_iostream.h:2039
Sint64 ReadS64BE()
Use this function to read 64 bits of big-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2761
static IOStream FromDynamicMem()
Use this function to create an IOStream that is backed by dynamically allocated memory.
Definition SDL3pp_iostream.h:1877
void WriteU32LE(IOStreamRef dst, Uint32 value)
Use this function to write 32 bits in native format to an IOStream as little-endian data.
Definition SDL3pp_iostream.h:2914
static IOStream FromConstMem(SourceBytes mem)
Use this function to prepare a read-only memory buffer for use with IOStream.
Definition SDL3pp_iostream.h:1843
StringResult LoadFile()
Load all the data from an SDL data stream.
Definition SDL3pp_iostream.h:2267
void WriteU16LE(Uint16 value)
Use this function to write 16 bits in native format to an IOStream as little-endian data.
Definition SDL3pp_iostream.h:2819
Uint64 ReadU64BE(IOStreamRef src)
Use this function to read 64 bits of big-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2725
void SaveFile(StringParam file, SourceBytes data)
Save all the data into a file path.
Definition SDL3pp_iostream.h:2360
Uint64 ReadU64LE()
Use this function to read 64 bits of little-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2674
Sint16 ReadS16LE(IOStreamRef src)
Use this function to read 16 bits of little-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2464
constexpr IOWhence IO_SEEK_CUR
Seek relative to current read point.
Definition SDL3pp_iostream.h:73
void WriteU8(Uint8 value)
Use this function to write a byte to an IOStream.
Definition SDL3pp_iostream.h:2779
StringResult LoadFile_IO(IOStreamRef src, bool closeio=true)
Load all the data from an SDL data stream.
Definition SDL3pp_iostream.h:2260
Uint64 ReadU64BE()
Use this function to read 64 bits of big-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2732
Sint64 ReadS64LE()
Use this function to read 64 bits of little-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2703
Uint64 ReadU64LE(IOStreamRef src)
Use this function to read 64 bits of little-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2667
void WriteU16BE(IOStreamRef dst, Uint16 value)
Use this function to write 16 bits in native format to an IOStream as big-endian data.
Definition SDL3pp_iostream.h:2864
constexpr IOStatus IO_STATUS_READONLY
Tried to write a read-only buffer.
Definition SDL3pp_iostream.h:54
void WriteU64LE(Uint64 value)
Use this function to write 64 bits in native format to an IOStream as little-endian data.
Definition SDL3pp_iostream.h:3019
constexpr IOStatus IO_STATUS_READY
Everything is ready (no errors and not EOF).
Definition SDL3pp_iostream.h:43
constexpr IOStatus IO_STATUS_NOT_READY
Non blocking I/O, not ready.
Definition SDL3pp_iostream.h:51
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:1688
void CloseIO(IOStreamRaw context)
Close and free an allocated IOStream structure.
Definition SDL3pp_iostream.h:1945
void WriteS64LE(Sint64 value)
Use this function to write 64 bits in native format to an IOStream as little-endian data.
Definition SDL3pp_iostream.h:3044
Sint16 ReadS16LE()
Use this function to read 16 bits of little-endian data from an IOStream and return in native format.
Definition SDL3pp_iostream.h:2471
IOStatus GetStatus() const
Query the stream status of an IOStream.
Definition SDL3pp_iostream.h:1993
static IOStream FromMem(TargetBytes mem)
Use this function to prepare a read-write memory buffer for use with IOStream.
Definition SDL3pp_iostream.h:1790
constexpr IOWhence IO_SEEK_SET
Seek from the beginning of data.
Definition SDL3pp_iostream.h:70
constexpr IOWhence IO_SEEK_END
Seek relative to the end of data.
Definition SDL3pp_iostream.h:76
PropertiesRef GetProperties() const
Get the properties associated with an IOStream.
Definition SDL3pp_iostream.h:1965
ResourceRef< Properties > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:54
::Sint32 Sint32
A signed 32-bit integer type.
Definition SDL3pp_stdinc.h:277
::Sint64 Sint64
A signed 64-bit integer type.
Definition SDL3pp_stdinc.h:305
::Uint16 Uint16
An unsigned 16-bit integer type.
Definition SDL3pp_stdinc.h:264
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition SDL3pp_stdinc.h:290
::Sint16 Sint16
A signed 16-bit integer type.
Definition SDL3pp_stdinc.h:251
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition SDL3pp_stdinc.h:238
::Sint8 Sint8
A signed 8-bit integer type.
Definition SDL3pp_stdinc.h:225
::Uint64 Uint64
An unsigned 64-bit integer type.
Definition SDL3pp_stdinc.h:320
Properties for IOStream.
Definition SDL3pp_iostream.h:1707
constexpr auto FILE_DESCRIPTOR_NUMBER
Number for file descriptor.
Definition SDL3pp_iostream.h:1715
constexpr auto ANDROID_AASSET_POINTER
Pointer to android aasset.
Definition SDL3pp_iostream.h:1718
constexpr auto MEMORY_POINTER
Pointer to memory.
Definition SDL3pp_iostream.h:1721
constexpr auto DYNAMIC_MEMORY_POINTER
Pointer to dynamic memory.
Definition SDL3pp_iostream.h:1734
constexpr auto DYNAMIC_CHUNKSIZE_NUMBER
Number for dynamic chunksize.
Definition SDL3pp_iostream.h:1737
constexpr auto STDIO_FILE_POINTER
Pointer to stdio file.
Definition SDL3pp_iostream.h:1712
constexpr auto MEMORY_FREE_FUNC_POINTER
Pointer to memory free func.
Definition SDL3pp_iostream.h:1729
constexpr auto MEMORY_SIZE_NUMBER
Number for memory size.
Definition SDL3pp_iostream.h:1724
constexpr auto WINDOWS_HANDLE_POINTER
Pointer to windows handle.
Definition SDL3pp_iostream.h:1709
Main include header for the SDL3pp library.
The read/write operation structure.
Definition SDL3pp_iostream.h:108
constexpr IOStream(IOStreamRaw resource) noexcept
Constructs from raw IOStream.
Definition SDL3pp_iostream.h:118
std::optional< Uint32 > TryReadU32BE() const
Use this function to read 32 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:1252
~IOStream()
Destructor.
Definition SDL3pp_iostream.h:376
std::optional< Uint16 > TryReadU16BE() const
Use this function to read 16 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:1156
std::optional< Sint32 > TryReadS32LE() const
Use this function to read 32 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:1228
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
OwnArray< T > LoadFileAs()
Load all the data from an SDL data stream.
Definition SDL3pp_iostream.h:741
size_t printf(SDL_PRINTF_FORMAT_STRING const char *fmt,...)
Print to an IOStream data stream.
Definition SDL3pp_iostream.h:654
std::optional< Sint16 > TryReadS16BE() const
Use this function to read 16 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:1180
std::optional< Uint8 > TryReadU8() const
Use this function to read a byte from an IOStreamRef.
Definition SDL3pp_iostream.h:1064
constexpr IOStream(IOStream &&other) noexcept
Move constructor.
Definition SDL3pp_iostream.h:127
std::optional< Sint64 > TryReadS64LE() const
Use this function to read 64 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:1324
size_t print(std::string_view fmt, auto... args)
Prints formatted string.
Definition SDL3pp_iostream.h:615
constexpr IOStream & operator=(IOStream &&other) noexcept
Assignment operator.
Definition SDL3pp_iostream.h:379
std::optional< Sint32 > TryReadS32BE() const
Use this function to read 32 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:1276
std::optional< Sint8 > TryReadS8() const
Use this function to read a byte from an IOStreamRef.
Definition SDL3pp_iostream.h:1084
std::optional< Uint32 > TryReadU32LE() const
Use this function to read 32 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:1204
std::optional< Uint64 > TryReadU64LE() const
Use this function to read 64 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:1300
IOStream & operator=(const IOStream &other)=delete
Assignment operator.
std::optional< Sint16 > TryReadS16LE() const
Use this function to read 16 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:1132
constexpr IOStream(const IOStream &other)=delete
Copy constructor.
size_t println(std::string_view fmt, auto... args)
Prints formatted string.
Definition SDL3pp_iostream.h:627
std::optional< Uint64 > TryReadU64BE() const
Use this function to read 64 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:1348
std::optional< Uint16 > TryReadU16LE() const
Use this function to read 16 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:1108
std::string Read(size_t size=-1)
Read from a data source.
Definition SDL3pp_iostream.h:529
std::optional< Sint64 > TryReadS64BE() const
Use this function to read 64 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:1372
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:156
A simple std::string-like interface for SDL allocated strings.
Definition SDL3pp_strings.h:147