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 IOStream;
25
27using IOStreamRaw = SDL_IOStream*;
28
29// Forward decl
30struct IOStreamRef;
31
34{
36
39 : value(value)
40 {
41 }
42
44 constexpr IOStreamParam(std::nullptr_t _ = nullptr)
45 : value(nullptr)
46 {
47 }
48
50 constexpr explicit operator bool() const { return !!value; }
51
53 constexpr auto operator<=>(const IOStreamParam& other) const = default;
54
56 constexpr operator IOStreamRaw() const { return value; }
57};
58
64using IOStatus = SDL_IOStatus;
65
67 SDL_IO_STATUS_READY;
68
70 SDL_IO_STATUS_ERROR;
71
72constexpr IOStatus IO_STATUS_EOF = SDL_IO_STATUS_EOF;
73
75 SDL_IO_STATUS_NOT_READY;
76
78 SDL_IO_STATUS_READONLY;
79
81 SDL_IO_STATUS_WRITEONLY;
82
91using IOWhence = SDL_IOWhence;
92
94 SDL_IO_SEEK_SET;
95
97 SDL_IO_SEEK_CUR;
98
100 SDL_IO_SEEK_END;
101
116using IOStreamInterface = SDL_IOStreamInterface;
117
131{
132 IOStreamRaw m_resource = nullptr;
133
134public:
136 constexpr IOStream() = default;
137
145 constexpr explicit IOStream(const IOStreamRaw resource)
146 : m_resource(resource)
147 {
148 }
149
151 constexpr IOStream(const IOStream& other) = delete;
152
154 constexpr IOStream(IOStream&& other)
155 : IOStream(other.release())
156 {
157 }
158
159 constexpr IOStream(const IOStreamRef& other) = delete;
160
161 constexpr IOStream(IOStreamRef&& other) = delete;
162
245 static IOStream FromFile(StringParam file, StringParam mode);
246
285 static IOStream FromMem(TargetBytes mem);
286
326
355 static IOStream FromDynamicMem();
356
385 static IOStream Open(const IOStreamInterface& iface, void* userdata);
386
388 ~IOStream() { SDL_CloseIO(m_resource); }
389
392 {
393 std::swap(m_resource, other.m_resource);
394 return *this;
395 }
396
398 constexpr IOStreamRaw get() const { return m_resource; }
399
402 {
403 auto r = m_resource;
404 m_resource = nullptr;
405 return r;
406 }
407
409 constexpr auto operator<=>(const IOStream& other) const = default;
410
412 constexpr bool operator==(std::nullptr_t _) const { return !m_resource; }
413
415 constexpr explicit operator bool() const { return !!m_resource; }
416
418 constexpr operator IOStreamParam() const { return {m_resource}; }
419
449 void Close();
450
462
480 IOStatus GetStatus() const;
481
492 Sint64 GetSize() const;
493
520 Sint64 Seek(Sint64 offset, IOWhence whence);
521
538 Sint64 Tell() const;
539
562 std::string Read(size_t size = -1)
563 {
564 Sint64 pos = Tell();
565 auto curSize = SDL_GetIOSize(get());
566 if ((curSize < 0 || pos < 0)) {
567 if (size == size_t(-1)) return {};
568 } else if (curSize - pos <= 0) {
569 return {};
570 } else if (curSize - pos < size) {
571 size = curSize - pos;
572 }
573 std::string result(size, 0);
574 auto actualSize = Read(result);
575 if (actualSize < size) result.resize(actualSize);
576 return result;
577 }
578
601 size_t Read(TargetBytes buf);
602
631 size_t Write(SourceBytes buf);
632
640 size_t print(std::string_view fmt, auto... args)
641 {
642 return Write(std::vformat(fmt, std::make_format_args(args...)));
643 }
644
652 size_t println(std::string_view fmt, auto... args)
653 {
654 std::string result =
655 std::vformat(fmt, std::make_format_args(args...)) + "\n";
656 return Write(result);
657 }
658
679 size_t printf(SDL_PRINTF_FORMAT_STRING const char* fmt, ...)
680 {
681 va_list ap;
682 size_t result;
683
684 va_start(ap, fmt);
685 result = vprintf(fmt, ap);
686 va_end(ap);
687
688 return result;
689 }
690
710 size_t vprintf(SDL_PRINTF_FORMAT_STRING const char* fmt, va_list ap);
711
728 void Flush();
729
748
766 template<class T>
768 {
769 size_t datasize = 0;
770 auto data = static_cast<T*>(SDL_LoadFile_IO(get(), &datasize, false));
771 return OwnArray<T>{CheckError(data), datasize / sizeof(T)};
772 }
773
788 void SaveFile(SourceBytes data);
789
806
823
844
865
886
907
928
949
970
991
1011 Uint64 ReadU64LE();
1012
1032 Sint64 ReadS64LE();
1033
1053 Uint64 ReadU64BE();
1054
1074 Sint64 ReadS64BE();
1075
1090 std::optional<Uint8> TryReadU8()
1091 {
1092 if (Uint8 value; SDL_ReadU8(get(), &value)) return value;
1093 return {};
1094 }
1095
1110 std::optional<Sint8> TryReadS8()
1111 {
1112 if (Sint8 value; SDL_ReadS8(get(), &value)) return value;
1113 return {};
1114 }
1115
1134 std::optional<Uint16> TryReadU16LE()
1135 {
1136 if (Uint16 value; SDL_ReadU16LE(get(), &value)) return value;
1137 return {};
1138 }
1139
1158 std::optional<Sint16> TryReadS16LE()
1159 {
1160 if (Sint16 value; SDL_ReadS16LE(get(), &value)) return value;
1161 return {};
1162 }
1163
1182 std::optional<Uint16> TryReadU16BE()
1183 {
1184 if (Uint16 value; SDL_ReadU16BE(get(), &value)) return value;
1185 return {};
1186 }
1187
1206 std::optional<Sint16> TryReadS16BE()
1207 {
1208 if (Sint16 value; SDL_ReadS16BE(get(), &value)) return value;
1209 return {};
1210 }
1211
1230 std::optional<Uint32> TryReadU32LE()
1231 {
1232 if (Uint32 value; SDL_ReadU32LE(get(), &value)) return value;
1233 return {};
1234 }
1235
1254 std::optional<Sint32> TryReadS32LE()
1255 {
1256 if (Sint32 value; SDL_ReadS32LE(get(), &value)) return value;
1257 return {};
1258 }
1259
1278 std::optional<Uint32> TryReadU32BE()
1279 {
1280 if (Uint32 value; SDL_ReadU32BE(get(), &value)) return value;
1281 return {};
1282 }
1283
1302 std::optional<Sint32> TryReadS32BE()
1303 {
1304 if (Sint32 value; SDL_ReadS32BE(get(), &value)) return value;
1305 return {};
1306 }
1307
1326 std::optional<Uint64> TryReadU64LE()
1327 {
1328 if (Uint64 value; SDL_ReadU64LE(get(), &value)) return value;
1329 return {};
1330 }
1331
1350 std::optional<Sint64> TryReadS64LE()
1351 {
1352 if (Sint64 value; SDL_ReadS64LE(get(), &value)) return value;
1353 return {};
1354 }
1355
1374 std::optional<Uint64> TryReadU64BE()
1375 {
1376 if (Uint64 value; SDL_ReadU64BE(get(), &value)) return value;
1377 return {};
1378 }
1379
1398 std::optional<Sint64> TryReadS64BE()
1399 {
1400 if (Sint64 value; SDL_ReadS64BE(get(), &value)) return value;
1401 return {};
1402 }
1403
1414 void WriteU8(Uint8 value);
1415
1426 void WriteS8(Sint8 value);
1427
1443 void WriteU16LE(Uint16 value);
1444
1460 void WriteS16LE(Sint16 value);
1461
1476 void WriteU16BE(Uint16 value);
1477
1492 void WriteS16BE(Sint16 value);
1493
1509 void WriteU32LE(Uint32 value);
1510
1526 void WriteS32LE(Sint32 value);
1527
1542 void WriteU32BE(Uint32 value);
1543
1558 void WriteS32BE(Sint32 value);
1559
1575 void WriteU64LE(Uint64 value);
1576
1592 void WriteS64LE(Sint64 value);
1593
1608 void WriteU64BE(Uint64 value);
1609
1624 void WriteS64BE(Sint64 value);
1625};
1626
1629{
1638 : IOStream(resource.value)
1639 {
1640 }
1641
1644 : IOStream(other.get())
1645 {
1646 }
1647
1650};
1651
1735{
1736 return IOStream(SDL_IOFromFile(file, mode));
1737}
1738
1740{
1741 return SDL::IOFromFile(std::move(file), std::move(mode));
1742}
1743
1744namespace prop::IOStream {
1745
1746constexpr auto WINDOWS_HANDLE_POINTER =
1747 SDL_PROP_IOSTREAM_WINDOWS_HANDLE_POINTER;
1748
1749constexpr auto STDIO_FILE_POINTER = SDL_PROP_IOSTREAM_STDIO_FILE_POINTER;
1750
1751constexpr auto FILE_DESCRIPTOR_NUMBER =
1752 SDL_PROP_IOSTREAM_FILE_DESCRIPTOR_NUMBER;
1753
1754constexpr auto ANDROID_AASSET_POINTER =
1755 SDL_PROP_IOSTREAM_ANDROID_AASSET_POINTER;
1756
1757constexpr auto MEMORY_POINTER = SDL_PROP_IOSTREAM_MEMORY_POINTER;
1758
1759constexpr auto MEMORY_SIZE_NUMBER = SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER;
1760
1761constexpr auto DYNAMIC_MEMORY_POINTER =
1762 SDL_PROP_IOSTREAM_DYNAMIC_MEMORY_POINTER;
1763
1764constexpr auto DYNAMIC_CHUNKSIZE_NUMBER =
1765 SDL_PROP_IOSTREAM_DYNAMIC_CHUNKSIZE_NUMBER;
1766
1767} // namespace prop::IOStream
1768
1808{
1809 return IOStream(CheckError(SDL_IOFromMem(mem.data(), mem.size_bytes())));
1810}
1811
1813{
1814 return SDL::IOFromMem(std::move(mem));
1815}
1816
1856{
1857 return IOStream(CheckError(SDL_IOFromConstMem(mem.data(), mem.size_bytes())));
1858}
1859
1861{
1862 return SDL::IOFromConstMem(std::move(mem));
1863}
1864
1893inline IOStream IOFromDynamicMem() { return IOStream(SDL_IOFromDynamicMem()); }
1894
1896
1924inline IOStream OpenIO(const IOStreamInterface& iface, void* userdata)
1925{
1926 return IOStream(CheckError(SDL_OpenIO(&iface, userdata)));
1927}
1928
1929inline IOStream IOStream::Open(const IOStreamInterface& iface, void* userdata)
1930{
1931 return SDL::OpenIO(iface, userdata);
1932}
1933
1964inline void CloseIO(IOStreamRaw context) { CheckError(SDL_CloseIO(context)); }
1965
1966inline void IOStream::Close() { CloseIO(release()); }
1967
1980{
1981 return {CheckError(SDL_GetIOProperties(context))};
1982}
1983
1985{
1986 return SDL::GetIOProperties(m_resource);
1987}
1988
2008{
2009 return SDL_GetIOStatus(context);
2010}
2011
2013{
2014 return SDL::GetIOStatus(m_resource);
2015}
2016
2029{
2030 return CheckError(SDL_GetIOSize(context));
2031}
2032
2033inline Sint64 IOStream::GetSize() const { return SDL::GetIOSize(m_resource); }
2034
2062inline Sint64 SeekIO(IOStreamParam context, Sint64 offset, IOWhence whence)
2063{
2064 return SDL_SeekIO(context, offset, whence);
2065}
2066
2067inline Sint64 IOStream::Seek(Sint64 offset, IOWhence whence)
2068{
2069 return SDL::SeekIO(m_resource, offset, whence);
2070}
2071
2090inline Sint64 TellIO(IOStreamParam context) { return SDL_TellIO(context); }
2091
2092inline Sint64 IOStream::Tell() const { return SDL::TellIO(m_resource); }
2093
2117inline size_t ReadIO(IOStreamParam context, TargetBytes buf)
2118{
2119 return SDL_ReadIO(context, buf.data(), buf.size_bytes());
2120}
2121
2122inline size_t IOStream::Read(TargetBytes buf)
2123{
2124 return SDL::ReadIO(m_resource, std::move(buf));
2125}
2126
2156inline size_t WriteIO(IOStreamParam context, SourceBytes buf)
2157{
2158 return SDL_WriteIO(context, buf.data(), buf.size_bytes());
2159}
2160
2162{
2163 return SDL::WriteIO(m_resource, std::move(buf));
2164}
2165
2187inline size_t IOprintf(IOStreamParam context,
2188 SDL_PRINTF_FORMAT_STRING const char* fmt,
2189 ...)
2190{
2191 va_list ap;
2192 size_t result;
2193
2194 va_start(ap, fmt);
2195 result = SDL_IOvprintf(context, fmt, ap);
2196 va_end(ap);
2197
2198 return result;
2199}
2200
2219inline size_t IOvprintf(IOStreamParam context,
2220 SDL_PRINTF_FORMAT_STRING const char* fmt,
2221 va_list ap)
2222{
2223 return SDL_IOvprintf(context, fmt, ap);
2224}
2225
2226inline size_t IOStream::vprintf(SDL_PRINTF_FORMAT_STRING const char* fmt,
2227 va_list ap)
2228{
2229 return SDL::IOvprintf(m_resource, fmt, ap);
2230}
2231
2249inline void FlushIO(IOStreamParam context) { CheckError(SDL_FlushIO(context)); }
2250
2251inline void IOStream::Flush() { SDL::FlushIO(m_resource); }
2252
2275inline StringResult LoadFile(IOStreamParam src, bool closeio = true)
2276{
2277 size_t datasize = 0;
2278 auto data = static_cast<char*>(SDL_LoadFile_IO(src, &datasize, closeio));
2279 return StringResult{CheckError(data), datasize};
2280}
2281
2301{
2302 size_t datasize = 0;
2303 auto data = static_cast<char*>(SDL_LoadFile(file, &datasize));
2304 return StringResult{CheckError(data), datasize};
2305}
2306
2308{
2309 return SDL::LoadFile(m_resource, false);
2310}
2311
2330template<class T>
2332{
2333 size_t datasize = 0;
2334 auto data = static_cast<T*>(SDL_LoadFile(file, &datasize));
2335 return OwnArray<T>{CheckError(data), datasize / sizeof(T)};
2336}
2337
2354inline void SaveFile(IOStreamParam src, SourceBytes data, bool closeio = false)
2355{
2356 CheckError(SDL_SaveFile_IO(src, data.data(), data.size_bytes(), closeio));
2357}
2358
2373inline void SaveFile(StringParam file, SourceBytes data)
2374{
2375 CheckError(SDL_SaveFile(file, data.data(), data.size_bytes()));
2376}
2377
2379{
2380 SDL::SaveFile(m_resource, std::move(data));
2381}
2382
2400{
2401 Uint8 value;
2402 CheckError(SDL_ReadU8(src, &value));
2403 return value;
2404}
2405
2423{
2424 Sint8 value;
2425 CheckError(SDL_ReadS8(src, &value));
2426 return value;
2427}
2428
2450{
2451 Uint16 value;
2452 CheckError(SDL_ReadU16LE(src, &value));
2453 return value;
2454}
2455
2456inline Uint16 IOStream::ReadU16LE() { return SDL::ReadU16LE(m_resource); }
2457
2479{
2480 Sint16 value;
2481 CheckError(SDL_ReadS16LE(src, &value));
2482 return value;
2483}
2484
2485inline Sint16 IOStream::ReadS16LE() { return SDL::ReadS16LE(m_resource); }
2486
2508{
2509 Uint16 value;
2510 CheckError(SDL_ReadU16BE(src, &value));
2511 return value;
2512}
2513
2514inline Uint16 IOStream::ReadU16BE() { return SDL::ReadU16BE(m_resource); }
2515
2537{
2538 Sint16 value;
2539 CheckError(SDL_ReadS16BE(src, &value));
2540 return value;
2541}
2542
2543inline Sint16 IOStream::ReadS16BE() { return SDL::ReadS16BE(m_resource); }
2544
2566{
2567 Uint32 value;
2568 CheckError(SDL_ReadU32LE(src, &value));
2569 return value;
2570}
2571
2572inline Uint32 IOStream::ReadU32LE() { return SDL::ReadU32LE(m_resource); }
2573
2595{
2596 Sint32 value;
2597 CheckError(SDL_ReadS32LE(src, &value));
2598 return value;
2599}
2600
2601inline Sint32 IOStream::ReadS32LE() { return SDL::ReadS32LE(m_resource); }
2602
2624{
2625 Uint32 value;
2626 CheckError(SDL_ReadU32BE(src, &value));
2627 return value;
2628}
2629
2630inline Uint32 IOStream::ReadU32BE() { return SDL::ReadU32BE(m_resource); }
2631
2653{
2654 Sint32 value;
2655 CheckError(SDL_ReadS32BE(src, &value));
2656 return value;
2657}
2658
2659inline Sint32 IOStream::ReadS32BE() { return SDL::ReadS32BE(m_resource); }
2660
2682{
2683 Uint64 value;
2684 CheckError(SDL_ReadU64LE(src, &value));
2685 return value;
2686}
2687
2688inline Uint64 IOStream::ReadU64LE() { return SDL::ReadU64LE(m_resource); }
2689
2711{
2712 Sint64 value;
2713 CheckError(SDL_ReadS64LE(src, &value));
2714 return value;
2715}
2716
2717inline Sint64 IOStream::ReadS64LE() { return SDL::ReadS64LE(m_resource); }
2718
2740{
2741 Uint64 value;
2742 CheckError(SDL_ReadU64BE(src, &value));
2743 return value;
2744}
2745
2746inline Uint64 IOStream::ReadU64BE() { return SDL::ReadU64BE(m_resource); }
2747
2769{
2770 Sint64 value;
2771 CheckError(SDL_ReadS64BE(src, &value));
2772 return value;
2773}
2774
2775inline Sint64 IOStream::ReadS64BE() { return SDL::ReadS64BE(m_resource); }
2776
2788inline void WriteU8(IOStreamParam dst, Uint8 value)
2789{
2790 CheckError(SDL_WriteU8(dst, value));
2791}
2792
2793inline void IOStream::WriteU8(Uint8 value) { SDL::WriteU8(m_resource, value); }
2794
2806inline void WriteS8(IOStreamParam dst, Sint8 value)
2807{
2808 CheckError(SDL_WriteS8(dst, value));
2809}
2810
2811inline void IOStream::WriteS8(Sint8 value) { SDL::WriteS8(m_resource, value); }
2812
2829inline void WriteU16LE(IOStreamParam dst, Uint16 value)
2830{
2831 CheckError(SDL_WriteU16LE(dst, value));
2832}
2833
2835{
2836 SDL::WriteU16LE(m_resource, value);
2837}
2838
2855inline void WriteS16LE(IOStreamParam dst, Sint16 value)
2856{
2857 CheckError(SDL_WriteS16LE(dst, value));
2858}
2859
2861{
2862 SDL::WriteS16LE(m_resource, value);
2863}
2864
2880inline void WriteU16BE(IOStreamParam dst, Uint16 value)
2881{
2882 CheckError(SDL_WriteU16BE(dst, value));
2883}
2884
2886{
2887 SDL::WriteU16BE(m_resource, value);
2888}
2889
2905inline void WriteS16BE(IOStreamParam dst, Sint16 value)
2906{
2907 CheckError(SDL_WriteS16BE(dst, value));
2908}
2909
2911{
2912 SDL::WriteS16BE(m_resource, value);
2913}
2914
2931inline void WriteU32LE(IOStreamParam dst, Uint32 value)
2932{
2933 CheckError(SDL_WriteU32LE(dst, value));
2934}
2935
2937{
2938 SDL::WriteU32LE(m_resource, value);
2939}
2940
2957inline void WriteS32LE(IOStreamParam dst, Sint32 value)
2958{
2959 CheckError(SDL_WriteS32LE(dst, value));
2960}
2961
2963{
2964 SDL::WriteS32LE(m_resource, value);
2965}
2966
2982inline void WriteU32BE(IOStreamParam dst, Uint32 value)
2983{
2984 CheckError(SDL_WriteU32BE(dst, value));
2985}
2986
2988{
2989 SDL::WriteU32BE(m_resource, value);
2990}
2991
3007inline void WriteS32BE(IOStreamParam dst, Sint32 value)
3008{
3009 CheckError(SDL_WriteS32BE(dst, value));
3010}
3011
3013{
3014 SDL::WriteS32BE(m_resource, value);
3015}
3016
3033inline void WriteU64LE(IOStreamParam dst, Uint64 value)
3034{
3035 CheckError(SDL_WriteU64LE(dst, value));
3036}
3037
3039{
3040 SDL::WriteU64LE(m_resource, value);
3041}
3042
3059inline void WriteS64LE(IOStreamParam dst, Sint64 value)
3060{
3061 CheckError(SDL_WriteS64LE(dst, value));
3062}
3063
3065{
3066 SDL::WriteS64LE(m_resource, value);
3067}
3068
3084inline void WriteU64BE(IOStreamParam dst, Uint64 value)
3085{
3086 CheckError(SDL_WriteU64BE(dst, value));
3087}
3088
3090{
3091 SDL::WriteU64BE(m_resource, value);
3092}
3093
3109inline void WriteS64BE(IOStreamParam dst, Sint64 value)
3110{
3111 CheckError(SDL_WriteS64BE(dst, value));
3112}
3113
3115{
3116 SDL::WriteS64BE(m_resource, value);
3117}
3118
3120
3121} // namespace SDL
3122
3123#endif /* SDL3PP_IOSTREAM_H_ */
The read/write operation structure.
Definition: SDL3pp_iostream.h:131
Sint8 ReadS8()
Use this function to read a signed byte from an IOStream.
std::optional< Sint8 > TryReadS8()
Use this function to read a byte from an IOStreamRef.
Definition: SDL3pp_iostream.h:1110
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:1158
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:1374
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:1182
~IOStream()
Destructor.
Definition: SDL3pp_iostream.h:388
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:1254
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:1134
constexpr IOStreamRaw get() const
Retrieves underlying IOStreamRaw.
Definition: SDL3pp_iostream.h:398
OwnArray< T > LoadFileAs()
Load all the data from an SDL data stream.
Definition: SDL3pp_iostream.h:767
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:1206
size_t printf(SDL_PRINTF_FORMAT_STRING const char *fmt,...)
Print to an IOStream data stream.
Definition: SDL3pp_iostream.h:679
constexpr bool operator==(std::nullptr_t _) const
Comparison.
Definition: SDL3pp_iostream.h:412
constexpr IOStream(const IOStreamRaw resource)
Constructs from IOStreamParam.
Definition: SDL3pp_iostream.h:145
Uint8 ReadU8()
Use this function to read a byte from an IOStream.
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:1326
constexpr IOStream()=default
Default ctor.
IOStream & operator=(IOStream other)
Assignment operator.
Definition: SDL3pp_iostream.h:391
size_t print(std::string_view fmt, auto... args)
Prints formatted string.
Definition: SDL3pp_iostream.h:640
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:1230
std::optional< Uint8 > TryReadU8()
Use this function to read a byte from an IOStreamRef.
Definition: SDL3pp_iostream.h:1090
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:1278
constexpr IOStreamRaw release()
Retrieves underlying IOStreamRaw and clear this.
Definition: SDL3pp_iostream.h:401
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:1302
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:1398
constexpr auto operator<=>(const IOStream &other) const =default
Comparison.
constexpr IOStream(const IOStream &other)=delete
Copy constructor.
size_t println(std::string_view fmt, auto... args)
Prints formatted string.
Definition: SDL3pp_iostream.h:652
constexpr IOStream(IOStream &&other)
Move constructor.
Definition: SDL3pp_iostream.h:154
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:1350
std::string Read(size_t size=-1)
Read from a data source.
Definition: SDL3pp_iostream.h:562
Base class for SDL memory allocated array wrap.
Definition: SDL3pp_ownPtr.h:44
Source byte stream.
Definition: SDL3pp_strings.h:239
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition: SDL3pp_strings.h:303
constexpr const char * data() const
Retrieves contained data.
Definition: SDL3pp_strings.h:306
Helpers to use C++ strings parameters.
Definition: SDL3pp_strings.h:43
Target byte stream.
Definition: SDL3pp_strings.h:325
constexpr char * data() const
Retrieves contained data.
Definition: SDL3pp_strings.h:411
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition: SDL3pp_strings.h:408
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:198
Sint64 GetSize() const
Use this function to get the size of the data stream in an IOStream.
Definition: SDL3pp_iostream.h:2033
IOStream IOFromMem(TargetBytes mem)
Use this function to prepare a read-write memory buffer for use with IOStream.
Definition: SDL3pp_iostream.h:1807
size_t IOprintf(IOStreamParam context, SDL_PRINTF_FORMAT_STRING const char *fmt,...)
Print to an IOStream data stream.
Definition: SDL3pp_iostream.h:2187
Uint8 ReadU8(IOStreamParam src)
Use this function to read a byte from an IOStream.
Definition: SDL3pp_iostream.h:2399
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:2936
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:3012
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:2962
void WriteS16BE(IOStreamParam dst, Sint16 value)
Use this function to write 16 bits in native format to an IOStream as big-endian data.
Definition: SDL3pp_iostream.h:2905
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:3089
Sint64 ReadS64BE(IOStreamParam src)
Use this function to read 64 bits of big-endian data from an IOStream and return in native format.
Definition: SDL3pp_iostream.h:2768
IOStream OpenIO(const IOStreamInterface &iface, void *userdata)
Create a custom IOStream.
Definition: SDL3pp_iostream.h:1924
IOStatus GetIOStatus(IOStreamParam context)
Query the stream status of an IOStream.
Definition: SDL3pp_iostream.h:2007
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:2514
SDL_IOStream * IOStreamRaw
Alias to raw representation for IOStream.
Definition: SDL3pp_iostream.h:27
void SaveFile(SourceBytes data)
Save all the data into an SDL data stream.
Definition: SDL3pp_iostream.h:2378
Sint16 ReadS16BE(IOStreamParam src)
Use this function to read 16 bits of big-endian data from an IOStream and return in native format.
Definition: SDL3pp_iostream.h:2536
void WriteS32LE(IOStreamParam dst, Sint32 value)
Use this function to write 32 bits in native format to an IOStream as little-endian data.
Definition: SDL3pp_iostream.h:2957
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:2987
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:2659
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:2860
void WriteS8(Sint8 value)
Use this function to write a signed byte to an IOStream.
Definition: SDL3pp_iostream.h:2811
Uint32 ReadU32LE(IOStreamParam src)
Use this function to read 32 bits of little-endian data from an IOStream and return in native format.
Definition: SDL3pp_iostream.h:2565
size_t ReadIO(IOStreamParam context, TargetBytes buf)
Read from a data source.
Definition: SDL3pp_iostream.h:2117
void Flush()
Flush any buffered data in the stream.
Definition: SDL3pp_iostream.h:2251
void WriteU32LE(IOStreamParam dst, Uint32 value)
Use this function to write 32 bits in native format to an IOStream as little-endian data.
Definition: SDL3pp_iostream.h:2931
IOStream IOFromConstMem(SourceBytes mem)
Use this function to prepare a read-only memory buffer for use with IOStream.
Definition: SDL3pp_iostream.h:1855
SDL_IOWhence IOWhence
Possible whence values for IOStream seeking.
Definition: SDL3pp_iostream.h:91
Sint8 ReadS8(IOStreamParam src)
Use this function to read a signed byte from an IOStream.
Definition: SDL3pp_iostream.h:2422
size_t vprintf(SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap)
Print to an IOStream data stream.
Definition: SDL3pp_iostream.h:2226
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:2456
Sint16 ReadS16LE(IOStreamParam src)
Use this function to read 16 bits of little-endian data from an IOStream and return in native format.
Definition: SDL3pp_iostream.h:2478
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:2572
IOStream IOFromDynamicMem()
Use this function to create an IOStream that is backed by dynamically allocated memory.
Definition: SDL3pp_iostream.h:1893
void Close()
Close and free an allocated IOStream structure.
Definition: SDL3pp_iostream.h:1966
OwnArray< T > LoadFileAs(StringParam file)
Load all the data from a file path.
Definition: SDL3pp_iostream.h:2331
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:3114
size_t IOvprintf(IOStreamParam context, SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap)
Print to an IOStream data stream.
Definition: SDL3pp_iostream.h:2219
Sint64 TellIO(IOStreamParam context)
Determine the current read/write offset in an IOStream data stream.
Definition: SDL3pp_iostream.h:2090
Uint64 ReadU64LE(IOStreamParam src)
Use this function to read 64 bits of little-endian data from an IOStream and return in native format.
Definition: SDL3pp_iostream.h:2681
constexpr IOStatus IO_STATUS_ERROR
Read or write I/O error.
Definition: SDL3pp_iostream.h:69
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:2910
static IOStream Open(const IOStreamInterface &iface, void *userdata)
Create a custom IOStream.
Definition: SDL3pp_iostream.h:1929
Sint32 ReadS32LE(IOStreamParam src)
Use this function to read 32 bits of little-endian data from an IOStream and return in native format.
Definition: SDL3pp_iostream.h:2594
Uint32 ReadU32BE(IOStreamParam src)
Use this function to read 32 bits of big-endian data from an IOStream and return in native format.
Definition: SDL3pp_iostream.h:2623
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:2630
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:1734
constexpr IOStatus IO_STATUS_EOF
End of file.
Definition: SDL3pp_iostream.h:72
Sint64 ReadS64LE(IOStreamParam src)
Use this function to read 64 bits of little-endian data from an IOStream and return in native format.
Definition: SDL3pp_iostream.h:2710
Uint16 ReadU16BE(IOStreamParam src)
Use this function to read 16 bits of big-endian data from an IOStream and return in native format.
Definition: SDL3pp_iostream.h:2507
void WriteU8(IOStreamParam dst, Uint8 value)
Use this function to write a byte to an IOStream.
Definition: SDL3pp_iostream.h:2788
Sint64 GetIOSize(IOStreamParam context)
Use this function to get the size of the data stream in an IOStream.
Definition: SDL3pp_iostream.h:2028
void WriteU32BE(IOStreamParam dst, Uint32 value)
Use this function to write 32 bits in native format to an IOStream as big-endian data.
Definition: SDL3pp_iostream.h:2982
Sint64 Seek(Sint64 offset, IOWhence whence)
Seek within an IOStream data stream.
Definition: SDL3pp_iostream.h:2067
void WriteS32BE(IOStreamParam dst, Sint32 value)
Use this function to write 32 bits in native format to an IOStream as big-endian data.
Definition: SDL3pp_iostream.h:3007
Sint64 SeekIO(IOStreamParam context, Sint64 offset, IOWhence whence)
Seek within an IOStream data stream.
Definition: SDL3pp_iostream.h:2062
size_t Write(SourceBytes buf)
Write to an IOStream data stream.
Definition: SDL3pp_iostream.h:2161
void WriteU16LE(IOStreamParam dst, Uint16 value)
Use this function to write 16 bits in native format to an IOStream as little-endian data.
Definition: SDL3pp_iostream.h:2829
Sint64 Tell() const
Determine the current read/write offset in an IOStream data stream.
Definition: SDL3pp_iostream.h:2092
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:2885
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:2601
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:2543
constexpr IOStatus IO_STATUS_WRITEONLY
Tried to read a write-only buffer.
Definition: SDL3pp_iostream.h:80
PropertiesRef GetIOProperties(IOStreamParam context)
Get the properties associated with an IOStream.
Definition: SDL3pp_iostream.h:1979
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:2775
static IOStream FromDynamicMem()
Use this function to create an IOStream that is backed by dynamically allocated memory.
Definition: SDL3pp_iostream.h:1895
static IOStream FromConstMem(SourceBytes mem)
Use this function to prepare a read-only memory buffer for use with IOStream.
Definition: SDL3pp_iostream.h:1860
StringResult LoadFile()
Load all the data from an SDL data stream.
Definition: SDL3pp_iostream.h:2307
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:2834
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:2688
constexpr IOWhence IO_SEEK_CUR
Seek relative to current read point.
Definition: SDL3pp_iostream.h:96
SDL_IOStreamInterface IOStreamInterface
The function pointers that drive an IOStream.
Definition: SDL3pp_iostream.h:116
void WriteU8(Uint8 value)
Use this function to write a byte to an IOStream.
Definition: SDL3pp_iostream.h:2793
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:2746
SDL_IOStatus IOStatus
IOStream status, set by a read or write operation.
Definition: SDL3pp_iostream.h:64
void WriteS8(IOStreamParam dst, Sint8 value)
Use this function to write a signed byte to an IOStream.
Definition: SDL3pp_iostream.h:2806
void WriteS16LE(IOStreamParam dst, Sint16 value)
Use this function to write 16 bits in native format to an IOStream as little-endian data.
Definition: SDL3pp_iostream.h:2855
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:2717
void FlushIO(IOStreamParam context)
Flush any buffered data in the stream.
Definition: SDL3pp_iostream.h:2249
Uint64 ReadU64BE(IOStreamParam src)
Use this function to read 64 bits of big-endian data from an IOStream and return in native format.
Definition: SDL3pp_iostream.h:2739
Sint32 ReadS32BE(IOStreamParam src)
Use this function to read 32 bits of big-endian data from an IOStream and return in native format.
Definition: SDL3pp_iostream.h:2652
void SaveFile(IOStreamParam src, SourceBytes data, bool closeio=false)
Save all the data into an SDL data stream.
Definition: SDL3pp_iostream.h:2354
constexpr IOStatus IO_STATUS_READONLY
Tried to write a read-only buffer.
Definition: SDL3pp_iostream.h:77
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:3038
StringResult LoadFile(IOStreamParam src, bool closeio=true)
Load all the data from an SDL data stream.
Definition: SDL3pp_iostream.h:2275
constexpr IOStatus IO_STATUS_READY
Everything is ready (no errors and not EOF).
Definition: SDL3pp_iostream.h:66
constexpr IOStatus IO_STATUS_NOT_READY
Non blocking I/O, not ready.
Definition: SDL3pp_iostream.h:74
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:1739
void CloseIO(IOStreamRaw context)
Close and free an allocated IOStream structure.
Definition: SDL3pp_iostream.h:1964
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:3064
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:2485
IOStatus GetStatus() const
Query the stream status of an IOStream.
Definition: SDL3pp_iostream.h:2012
void WriteU64BE(IOStreamParam dst, Uint64 value)
Use this function to write 64 bits in native format to an IOStream as big-endian data.
Definition: SDL3pp_iostream.h:3084
size_t WriteIO(IOStreamParam context, SourceBytes buf)
Write to an IOStream data stream.
Definition: SDL3pp_iostream.h:2156
static IOStream FromMem(TargetBytes mem)
Use this function to prepare a read-write memory buffer for use with IOStream.
Definition: SDL3pp_iostream.h:1812
Uint16 ReadU16LE(IOStreamParam src)
Use this function to read 16 bits of little-endian data from an IOStream and return in native format.
Definition: SDL3pp_iostream.h:2449
void WriteU64LE(IOStreamParam dst, Uint64 value)
Use this function to write 64 bits in native format to an IOStream as little-endian data.
Definition: SDL3pp_iostream.h:3033
void WriteS64LE(IOStreamParam dst, Sint64 value)
Use this function to write 64 bits in native format to an IOStream as little-endian data.
Definition: SDL3pp_iostream.h:3059
void WriteS64BE(IOStreamParam dst, Sint64 value)
Use this function to write 64 bits in native format to an IOStream as big-endian data.
Definition: SDL3pp_iostream.h:3109
constexpr IOWhence IO_SEEK_SET
Seek from the beginning of data.
Definition: SDL3pp_iostream.h:93
constexpr IOWhence IO_SEEK_END
Seek relative to the end of data.
Definition: SDL3pp_iostream.h:99
PropertiesRef GetProperties() const
Get the properties associated with an IOStream.
Definition: SDL3pp_iostream.h:1984
void WriteU16BE(IOStreamParam dst, Uint16 value)
Use this function to write 16 bits in native format to an IOStream as big-endian data.
Definition: SDL3pp_iostream.h:2880
Uint16 Uint16
An unsigned 16-bit integer type.
Definition: SDL3pp_stdinc.h:294
Sint8 Sint8
A signed 8-bit integer type.
Definition: SDL3pp_stdinc.h:243
Sint64 Sint64
A signed 64-bit integer type.
Definition: SDL3pp_stdinc.h:347
Sint32 Sint32
A signed 32-bit integer type.
Definition: SDL3pp_stdinc.h:311
Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:328
Uint64 Uint64
An unsigned 64-bit integer type.
Definition: SDL3pp_stdinc.h:366
Uint8 Uint8
An unsigned 8-bit integer type.
Definition: SDL3pp_stdinc.h:260
Sint16 Sint16
A signed 16-bit integer type.
Definition: SDL3pp_stdinc.h:277
Main include header for the SDL3pp library.
Safely wrap IOStream for non owning parameters.
Definition: SDL3pp_iostream.h:34
constexpr auto operator<=>(const IOStreamParam &other) const =default
Comparison.
constexpr IOStreamParam(IOStreamRaw value)
Constructs from IOStreamRaw.
Definition: SDL3pp_iostream.h:38
IOStreamRaw value
parameter's IOStreamRaw
Definition: SDL3pp_iostream.h:35
constexpr IOStreamParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_iostream.h:44
Semi-safe reference for IOStream.
Definition: SDL3pp_iostream.h:1629
IOStreamRef(IOStreamParam resource)
Constructs from IOStreamParam.
Definition: SDL3pp_iostream.h:1637
IOStreamRef(const IOStreamRef &other)
Copy constructor.
Definition: SDL3pp_iostream.h:1643
~IOStreamRef()
Destructor.
Definition: SDL3pp_iostream.h:1649
Semi-safe reference for Properties.
Definition: SDL3pp_properties.h:701
A simple std::string-like interface for SDL allocated strings.
Definition: SDL3pp_strings.h:153