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
37using IOStatus = SDL_IOStatus;
38
40 SDL_IO_STATUS_READY;
41
43 SDL_IO_STATUS_ERROR;
44
45constexpr IOStatus IO_STATUS_EOF = SDL_IO_STATUS_EOF;
46
48 SDL_IO_STATUS_NOT_READY;
49
51 SDL_IO_STATUS_READONLY;
52
54 SDL_IO_STATUS_WRITEONLY;
55
64using IOWhence = SDL_IOWhence;
65
67 SDL_IO_SEEK_SET;
68
70 SDL_IO_SEEK_CUR;
71
73 SDL_IO_SEEK_END;
74
89using IOStreamInterface = SDL_IOStreamInterface;
90
104{
105 IOStreamRaw m_resource = nullptr;
106
107public:
109 constexpr IOStream(std::nullptr_t = nullptr) noexcept
110 : m_resource(nullptr)
111 {
112 }
113
121 constexpr explicit IOStream(const IOStreamRaw resource) noexcept
122 : m_resource(resource)
123 {
124 }
125
126protected:
128 constexpr IOStream(const IOStream& other) noexcept = default;
129
130public:
132 constexpr IOStream(IOStream&& other) noexcept
133 : IOStream(other.release())
134 {
135 }
136
137 constexpr IOStream(const IOStreamRef& other) = delete;
138
139 constexpr IOStream(IOStreamRef&& other) = delete;
140
227 static IOStream FromFile(StringParam file, StringParam mode);
228
273 static IOStream FromMem(TargetBytes mem);
274
320
348 static IOStream FromDynamicMem();
349
378 static IOStream Open(const IOStreamInterface& iface, void* userdata);
379
381 ~IOStream() { SDL_CloseIO(m_resource); }
382
384 constexpr IOStream& operator=(IOStream&& other) noexcept
385 {
386 std::swap(m_resource, other.m_resource);
387 return *this;
388 }
389
390protected:
392 constexpr IOStream& operator=(const IOStream& other) noexcept = default;
393
394public:
396 constexpr IOStreamRaw get() const noexcept { return m_resource; }
397
399 constexpr IOStreamRaw release() noexcept
400 {
401 auto r = m_resource;
402 m_resource = nullptr;
403 return r;
404 }
405
407 constexpr auto operator<=>(const IOStream& other) const noexcept = default;
408
410 constexpr explicit operator bool() const noexcept { return !!m_resource; }
411
441 void Close();
442
454
472 IOStatus GetStatus() const;
473
484 Sint64 GetSize() const;
485
511 Sint64 Seek(Sint64 offset, IOWhence whence);
512
529 Sint64 Tell() const;
530
553 std::string Read(size_t size = -1)
554 {
555 Sint64 pos = Tell();
556 auto curSize = SDL_GetIOSize(get());
557 if ((curSize < 0 || pos < 0)) {
558 if (size == size_t(-1)) return {};
559 } else if (curSize - pos <= 0) {
560 return {};
561 } else if (curSize - pos < size) {
562 size = curSize - pos;
563 }
564 std::string result(size, 0);
565 auto actualSize = Read(result);
566 if (actualSize < size) result.resize(actualSize);
567 return result;
568 }
569
596 size_t Read(TargetBytes buf);
597
630 size_t Write(SourceBytes buf);
631
639 size_t print(std::string_view fmt, auto... args)
640 {
641 return Write(std::vformat(fmt, std::make_format_args(args...)));
642 }
643
651 size_t println(std::string_view fmt, auto... args)
652 {
653 std::string result =
654 std::vformat(fmt, std::make_format_args(args...)) + "\n";
655 return Write(result);
656 }
657
678 size_t printf(SDL_PRINTF_FORMAT_STRING const char* fmt, ...)
679 {
680 va_list ap;
681 size_t result;
682
683 va_start(ap, fmt);
684 result = vprintf(fmt, ap);
685 va_end(ap);
686
687 return result;
688 }
689
709 size_t vprintf(SDL_PRINTF_FORMAT_STRING const char* fmt, va_list ap);
710
727 void Flush();
728
746
764 template<class T>
766 {
767 size_t datasize = 0;
768 auto data = static_cast<T*>(SDL_LoadFile_IO(get(), &datasize, false));
769 return OwnArray<T>{CheckError(data), datasize / sizeof(T)};
770 }
771
786 void SaveFile(SourceBytes data);
787
804
821
842
863
884
905
926
947
968
989
1009 Uint64 ReadU64LE();
1010
1030 Sint64 ReadS64LE();
1031
1051 Uint64 ReadU64BE();
1052
1072 Sint64 ReadS64BE();
1073
1088 std::optional<Uint8> TryReadU8()
1089 {
1090 if (Uint8 value; SDL_ReadU8(get(), &value)) return value;
1091 return {};
1092 }
1093
1108 std::optional<Sint8> TryReadS8()
1109 {
1110 if (Sint8 value; SDL_ReadS8(get(), &value)) return value;
1111 return {};
1112 }
1113
1132 std::optional<Uint16> TryReadU16LE()
1133 {
1134 if (Uint16 value; SDL_ReadU16LE(get(), &value)) return value;
1135 return {};
1136 }
1137
1156 std::optional<Sint16> TryReadS16LE()
1157 {
1158 if (Sint16 value; SDL_ReadS16LE(get(), &value)) return value;
1159 return {};
1160 }
1161
1180 std::optional<Uint16> TryReadU16BE()
1181 {
1182 if (Uint16 value; SDL_ReadU16BE(get(), &value)) return value;
1183 return {};
1184 }
1185
1204 std::optional<Sint16> TryReadS16BE()
1205 {
1206 if (Sint16 value; SDL_ReadS16BE(get(), &value)) return value;
1207 return {};
1208 }
1209
1228 std::optional<Uint32> TryReadU32LE()
1229 {
1230 if (Uint32 value; SDL_ReadU32LE(get(), &value)) return value;
1231 return {};
1232 }
1233
1252 std::optional<Sint32> TryReadS32LE()
1253 {
1254 if (Sint32 value; SDL_ReadS32LE(get(), &value)) return value;
1255 return {};
1256 }
1257
1276 std::optional<Uint32> TryReadU32BE()
1277 {
1278 if (Uint32 value; SDL_ReadU32BE(get(), &value)) return value;
1279 return {};
1280 }
1281
1300 std::optional<Sint32> TryReadS32BE()
1301 {
1302 if (Sint32 value; SDL_ReadS32BE(get(), &value)) return value;
1303 return {};
1304 }
1305
1324 std::optional<Uint64> TryReadU64LE()
1325 {
1326 if (Uint64 value; SDL_ReadU64LE(get(), &value)) return value;
1327 return {};
1328 }
1329
1348 std::optional<Sint64> TryReadS64LE()
1349 {
1350 if (Sint64 value; SDL_ReadS64LE(get(), &value)) return value;
1351 return {};
1352 }
1353
1372 std::optional<Uint64> TryReadU64BE()
1373 {
1374 if (Uint64 value; SDL_ReadU64BE(get(), &value)) return value;
1375 return {};
1376 }
1377
1396 std::optional<Sint64> TryReadS64BE()
1397 {
1398 if (Sint64 value; SDL_ReadS64BE(get(), &value)) return value;
1399 return {};
1400 }
1401
1412 void WriteU8(Uint8 value);
1413
1424 void WriteS8(Sint8 value);
1425
1441 void WriteU16LE(Uint16 value);
1442
1458 void WriteS16LE(Sint16 value);
1459
1474 void WriteU16BE(Uint16 value);
1475
1490 void WriteS16BE(Sint16 value);
1491
1507 void WriteU32LE(Uint32 value);
1508
1524 void WriteS32LE(Sint32 value);
1525
1540 void WriteU32BE(Uint32 value);
1541
1556 void WriteS32BE(Sint32 value);
1557
1573 void WriteU64LE(Uint64 value);
1574
1590 void WriteS64LE(Sint64 value);
1591
1606 void WriteU64BE(Uint64 value);
1607
1622 void WriteS64BE(Sint64 value);
1623};
1624
1631{
1632 using IOStream::IOStream;
1633
1641 IOStreamRef(IOStreamRaw resource) noexcept
1642 : IOStream(resource)
1643 {
1644 }
1645
1653 constexpr IOStreamRef(const IOStream& resource) noexcept
1654 : IOStream(resource.get())
1655 {
1656 }
1657
1665 constexpr IOStreamRef(IOStream&& resource) noexcept
1666 : IOStream(std::move(resource).release())
1667 {
1668 }
1669
1671 constexpr IOStreamRef(const IOStreamRef& other) noexcept
1672 : IOStream(other.get())
1673 {
1674 }
1675
1677 constexpr IOStreamRef(IOStreamRef&& other) noexcept
1678 : IOStream(other.get())
1679 {
1680 }
1681
1684
1686 constexpr IOStreamRef& operator=(const IOStreamRef& other) noexcept = default;
1687
1689 constexpr operator IOStreamRaw() const noexcept { return get(); }
1690};
1691
1775{
1776 return IOStream(SDL_IOFromFile(file, mode));
1777}
1778
1780{
1781 return SDL::IOFromFile(std::move(file), std::move(mode));
1782}
1783
1784namespace prop::IOStream {
1785
1786constexpr auto WINDOWS_HANDLE_POINTER =
1787 SDL_PROP_IOSTREAM_WINDOWS_HANDLE_POINTER;
1788
1789constexpr auto STDIO_FILE_POINTER = SDL_PROP_IOSTREAM_STDIO_FILE_POINTER;
1790
1791constexpr auto FILE_DESCRIPTOR_NUMBER =
1792 SDL_PROP_IOSTREAM_FILE_DESCRIPTOR_NUMBER;
1793
1794constexpr auto ANDROID_AASSET_POINTER =
1795 SDL_PROP_IOSTREAM_ANDROID_AASSET_POINTER;
1796
1797constexpr auto MEMORY_POINTER = SDL_PROP_IOSTREAM_MEMORY_POINTER;
1798
1799constexpr auto MEMORY_SIZE_NUMBER = SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER;
1800
1801#if SDL_VERSION_ATLEAST(3, 4, 0)
1802
1803constexpr auto MEMORY_FREE_FUNC_POINTER =
1804 SDL_PROP_IOSTREAM_MEMORY_FREE_FUNC_POINTER;
1805
1806#endif // SDL_VERSION_ATLEAST(3, 4, 0)
1807
1808constexpr auto DYNAMIC_MEMORY_POINTER =
1809 SDL_PROP_IOSTREAM_DYNAMIC_MEMORY_POINTER;
1810
1811constexpr auto DYNAMIC_CHUNKSIZE_NUMBER =
1812 SDL_PROP_IOSTREAM_DYNAMIC_CHUNKSIZE_NUMBER;
1813
1814} // namespace prop::IOStream
1815
1860{
1861 return IOStream(CheckError(SDL_IOFromMem(mem.data(), mem.size_bytes())));
1862}
1863
1865{
1866 return SDL::IOFromMem(std::move(mem));
1867}
1868
1913{
1914 return IOStream(CheckError(SDL_IOFromConstMem(mem.data(), mem.size_bytes())));
1915}
1916
1918{
1919 return SDL::IOFromConstMem(std::move(mem));
1920}
1921
1949inline IOStream IOFromDynamicMem() { return IOStream(SDL_IOFromDynamicMem()); }
1950
1952
1980inline IOStream OpenIO(const IOStreamInterface& iface, void* userdata)
1981{
1982 return IOStream(CheckError(SDL_OpenIO(&iface, userdata)));
1983}
1984
1985inline IOStream IOStream::Open(const IOStreamInterface& iface, void* userdata)
1986{
1987 return SDL::OpenIO(iface, userdata);
1988}
1989
2019inline void CloseIO(IOStreamRaw context) { CheckError(SDL_CloseIO(context)); }
2020
2021inline void IOStream::Close() { CloseIO(release()); }
2022
2035{
2036 return {CheckError(SDL_GetIOProperties(context))};
2037}
2038
2040{
2041 return SDL::GetIOProperties(m_resource);
2042}
2043
2063{
2064 return SDL_GetIOStatus(context);
2065}
2066
2068{
2069 return SDL::GetIOStatus(m_resource);
2070}
2071
2084{
2085 return CheckError(SDL_GetIOSize(context));
2086}
2087
2088inline Sint64 IOStream::GetSize() const { return SDL::GetIOSize(m_resource); }
2089
2116inline Sint64 SeekIO(IOStreamRef context, Sint64 offset, IOWhence whence)
2117{
2118 return SDL_SeekIO(context, offset, whence);
2119}
2120
2121inline Sint64 IOStream::Seek(Sint64 offset, IOWhence whence)
2122{
2123 return SDL::SeekIO(m_resource, offset, whence);
2124}
2125
2144inline Sint64 TellIO(IOStreamRef context) { return SDL_TellIO(context); }
2145
2146inline Sint64 IOStream::Tell() const { return SDL::TellIO(m_resource); }
2147
2175inline size_t ReadIO(IOStreamRef context, TargetBytes buf)
2176{
2177 return SDL_ReadIO(context, buf.data(), buf.size_bytes());
2178}
2179
2180inline size_t IOStream::Read(TargetBytes buf)
2181{
2182 return SDL::ReadIO(m_resource, std::move(buf));
2183}
2184
2218inline size_t WriteIO(IOStreamRef context, SourceBytes buf)
2219{
2220 return SDL_WriteIO(context, buf.data(), buf.size_bytes());
2221}
2222
2224{
2225 return SDL::WriteIO(m_resource, std::move(buf));
2226}
2227
2249inline size_t IOprintf(IOStreamRef context,
2250 SDL_PRINTF_FORMAT_STRING const char* fmt,
2251 ...)
2252{
2253 va_list ap;
2254 size_t result;
2255
2256 va_start(ap, fmt);
2257 result = SDL_IOvprintf(context, fmt, ap);
2258 va_end(ap);
2259
2260 return result;
2261}
2262
2281inline size_t IOvprintf(IOStreamRef context,
2282 SDL_PRINTF_FORMAT_STRING const char* fmt,
2283 va_list ap)
2284{
2285 return SDL_IOvprintf(context, fmt, ap);
2286}
2287
2288inline size_t IOStream::vprintf(SDL_PRINTF_FORMAT_STRING const char* fmt,
2289 va_list ap)
2290{
2291 return SDL::IOvprintf(m_resource, fmt, ap);
2292}
2293
2311inline void FlushIO(IOStreamRef context) { CheckError(SDL_FlushIO(context)); }
2312
2313inline void IOStream::Flush() { SDL::FlushIO(m_resource); }
2314
2337inline StringResult LoadFile_IO(IOStreamRef src, bool closeio = true)
2338{
2339 size_t datasize = 0;
2340 auto data = static_cast<char*>(SDL_LoadFile_IO(src, &datasize, closeio));
2341 return StringResult{CheckError(data), datasize};
2342}
2343
2345{
2346 return SDL::LoadFile_IO(m_resource);
2347}
2348
2367template<class T>
2369{
2370 size_t datasize = 0;
2371 auto data = static_cast<T*>(SDL_LoadFile(file, &datasize));
2372 return OwnArray<T>{CheckError(data), datasize / sizeof(T)};
2373}
2374
2394{
2395 size_t datasize = 0;
2396 auto data = static_cast<char*>(SDL_LoadFile(file, &datasize));
2397 return StringResult{CheckError(data), datasize};
2398}
2399
2416inline void SaveFile_IO(IOStreamRef src, SourceBytes data, bool closeio = true)
2417{
2418 CheckError(SDL_SaveFile_IO(src, data.data(), data.size_bytes(), closeio));
2419}
2420
2422{
2423 SDL::SaveFile_IO(m_resource, std::move(data));
2424}
2425
2440inline void SaveFile(StringParam file, SourceBytes data)
2441{
2442 CheckError(SDL_SaveFile(file, data.data(), data.size_bytes()));
2443}
2444
2462{
2463 Uint8 value;
2464 CheckError(SDL_ReadU8(src, &value));
2465 return value;
2466}
2467
2485{
2486 Sint8 value;
2487 CheckError(SDL_ReadS8(src, &value));
2488 return value;
2489}
2490
2512{
2513 Uint16 value;
2514 CheckError(SDL_ReadU16LE(src, &value));
2515 return value;
2516}
2517
2518inline Uint16 IOStream::ReadU16LE() { return SDL::ReadU16LE(m_resource); }
2519
2541{
2542 Sint16 value;
2543 CheckError(SDL_ReadS16LE(src, &value));
2544 return value;
2545}
2546
2547inline Sint16 IOStream::ReadS16LE() { return SDL::ReadS16LE(m_resource); }
2548
2570{
2571 Uint16 value;
2572 CheckError(SDL_ReadU16BE(src, &value));
2573 return value;
2574}
2575
2576inline Uint16 IOStream::ReadU16BE() { return SDL::ReadU16BE(m_resource); }
2577
2599{
2600 Sint16 value;
2601 CheckError(SDL_ReadS16BE(src, &value));
2602 return value;
2603}
2604
2605inline Sint16 IOStream::ReadS16BE() { return SDL::ReadS16BE(m_resource); }
2606
2628{
2629 Uint32 value;
2630 CheckError(SDL_ReadU32LE(src, &value));
2631 return value;
2632}
2633
2634inline Uint32 IOStream::ReadU32LE() { return SDL::ReadU32LE(m_resource); }
2635
2657{
2658 Sint32 value;
2659 CheckError(SDL_ReadS32LE(src, &value));
2660 return value;
2661}
2662
2663inline Sint32 IOStream::ReadS32LE() { return SDL::ReadS32LE(m_resource); }
2664
2686{
2687 Uint32 value;
2688 CheckError(SDL_ReadU32BE(src, &value));
2689 return value;
2690}
2691
2692inline Uint32 IOStream::ReadU32BE() { return SDL::ReadU32BE(m_resource); }
2693
2715{
2716 Sint32 value;
2717 CheckError(SDL_ReadS32BE(src, &value));
2718 return value;
2719}
2720
2721inline Sint32 IOStream::ReadS32BE() { return SDL::ReadS32BE(m_resource); }
2722
2744{
2745 Uint64 value;
2746 CheckError(SDL_ReadU64LE(src, &value));
2747 return value;
2748}
2749
2750inline Uint64 IOStream::ReadU64LE() { return SDL::ReadU64LE(m_resource); }
2751
2773{
2774 Sint64 value;
2775 CheckError(SDL_ReadS64LE(src, &value));
2776 return value;
2777}
2778
2779inline Sint64 IOStream::ReadS64LE() { return SDL::ReadS64LE(m_resource); }
2780
2802{
2803 Uint64 value;
2804 CheckError(SDL_ReadU64BE(src, &value));
2805 return value;
2806}
2807
2808inline Uint64 IOStream::ReadU64BE() { return SDL::ReadU64BE(m_resource); }
2809
2831{
2832 Sint64 value;
2833 CheckError(SDL_ReadS64BE(src, &value));
2834 return value;
2835}
2836
2837inline Sint64 IOStream::ReadS64BE() { return SDL::ReadS64BE(m_resource); }
2838
2850inline void WriteU8(IOStreamRef dst, Uint8 value)
2851{
2852 CheckError(SDL_WriteU8(dst, value));
2853}
2854
2855inline void IOStream::WriteU8(Uint8 value) { SDL::WriteU8(m_resource, value); }
2856
2868inline void WriteS8(IOStreamRef dst, Sint8 value)
2869{
2870 CheckError(SDL_WriteS8(dst, value));
2871}
2872
2873inline void IOStream::WriteS8(Sint8 value) { SDL::WriteS8(m_resource, value); }
2874
2890inline void WriteU16LE(IOStreamRef dst, Uint16 value)
2891{
2892 CheckError(SDL_WriteU16LE(dst, value));
2893}
2894
2896{
2897 SDL::WriteU16LE(m_resource, value);
2898}
2899
2915inline void WriteS16LE(IOStreamRef dst, Sint16 value)
2916{
2917 CheckError(SDL_WriteS16LE(dst, value));
2918}
2919
2921{
2922 SDL::WriteS16LE(m_resource, value);
2923}
2924
2940inline void WriteU16BE(IOStreamRef dst, Uint16 value)
2941{
2942 CheckError(SDL_WriteU16BE(dst, value));
2943}
2944
2946{
2947 SDL::WriteU16BE(m_resource, value);
2948}
2949
2965inline void WriteS16BE(IOStreamRef dst, Sint16 value)
2966{
2967 CheckError(SDL_WriteS16BE(dst, value));
2968}
2969
2971{
2972 SDL::WriteS16BE(m_resource, value);
2973}
2974
2990inline void WriteU32LE(IOStreamRef dst, Uint32 value)
2991{
2992 CheckError(SDL_WriteU32LE(dst, value));
2993}
2994
2996{
2997 SDL::WriteU32LE(m_resource, value);
2998}
2999
3015inline void WriteS32LE(IOStreamRef dst, Sint32 value)
3016{
3017 CheckError(SDL_WriteS32LE(dst, value));
3018}
3019
3021{
3022 SDL::WriteS32LE(m_resource, value);
3023}
3024
3040inline void WriteU32BE(IOStreamRef dst, Uint32 value)
3041{
3042 CheckError(SDL_WriteU32BE(dst, value));
3043}
3044
3046{
3047 SDL::WriteU32BE(m_resource, value);
3048}
3049
3065inline void WriteS32BE(IOStreamRef dst, Sint32 value)
3066{
3067 CheckError(SDL_WriteS32BE(dst, value));
3068}
3069
3071{
3072 SDL::WriteS32BE(m_resource, value);
3073}
3074
3090inline void WriteU64LE(IOStreamRef dst, Uint64 value)
3091{
3092 CheckError(SDL_WriteU64LE(dst, value));
3093}
3094
3096{
3097 SDL::WriteU64LE(m_resource, value);
3098}
3099
3115inline void WriteS64LE(IOStreamRef dst, Sint64 value)
3116{
3117 CheckError(SDL_WriteS64LE(dst, value));
3118}
3119
3121{
3122 SDL::WriteS64LE(m_resource, value);
3123}
3124
3140inline void WriteU64BE(IOStreamRef dst, Uint64 value)
3141{
3142 CheckError(SDL_WriteU64BE(dst, value));
3143}
3144
3146{
3147 SDL::WriteU64BE(m_resource, value);
3148}
3149
3165inline void WriteS64BE(IOStreamRef dst, Sint64 value)
3166{
3167 CheckError(SDL_WriteS64BE(dst, value));
3168}
3169
3171{
3172 SDL::WriteS64BE(m_resource, value);
3173}
3174
3176
3177} // namespace SDL
3178
3179#endif /* SDL3PP_IOSTREAM_H_ */
The read/write operation structure.
Definition: SDL3pp_iostream.h:104
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:1108
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:1156
constexpr IOStream(const IOStream &other) noexcept=default
Copy constructor.
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:1372
constexpr IOStreamRaw release() noexcept
Retrieves underlying IOStreamRaw and clear this.
Definition: SDL3pp_iostream.h:399
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:1180
constexpr IOStream(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition: SDL3pp_iostream.h:109
~IOStream()
Destructor.
Definition: SDL3pp_iostream.h:381
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:1252
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:1132
constexpr IOStreamRaw get() const noexcept
Retrieves underlying IOStreamRaw.
Definition: SDL3pp_iostream.h:396
OwnArray< T > LoadFileAs()
Load all the data from an SDL data stream.
Definition: SDL3pp_iostream.h:765
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:1204
size_t printf(SDL_PRINTF_FORMAT_STRING const char *fmt,...)
Print to an IOStream data stream.
Definition: SDL3pp_iostream.h:678
constexpr IOStream & operator=(const IOStream &other) noexcept=default
Assignment operator.
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:1324
constexpr IOStream(IOStream &&other) noexcept
Move constructor.
Definition: SDL3pp_iostream.h:132
size_t print(std::string_view fmt, auto... args)
Prints formatted string.
Definition: SDL3pp_iostream.h:639
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:1228
std::optional< Uint8 > TryReadU8()
Use this function to read a byte from an IOStreamRef.
Definition: SDL3pp_iostream.h:1088
constexpr IOStream & operator=(IOStream &&other) noexcept
Assignment operator.
Definition: SDL3pp_iostream.h:384
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:1276
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:1300
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:1396
constexpr IOStream(const IOStreamRaw resource) noexcept
Constructs from IOStreamRef.
Definition: SDL3pp_iostream.h:121
size_t println(std::string_view fmt, auto... args)
Prints formatted string.
Definition: SDL3pp_iostream.h:651
constexpr auto operator<=>(const IOStream &other) const noexcept=default
Comparison.
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:1348
std::string Read(size_t size=-1)
Read from a data source.
Definition: SDL3pp_iostream.h:553
Base class for SDL memory allocated array wrap.
Definition: SDL3pp_ownPtr.h:44
Source byte stream.
Definition: SDL3pp_strings.h:240
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition: SDL3pp_strings.h:304
constexpr const char * data() const
Retrieves contained data.
Definition: SDL3pp_strings.h:307
Helpers to use C++ strings parameters.
Definition: SDL3pp_strings.h:43
Target byte stream.
Definition: SDL3pp_strings.h:326
constexpr char * data() const
Retrieves contained data.
Definition: SDL3pp_strings.h:412
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition: SDL3pp_strings.h:409
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:197
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:2965
Sint64 GetSize() const
Use this function to get the size of the data stream in an IOStream.
Definition: SDL3pp_iostream.h:2088
IOStream IOFromMem(TargetBytes mem)
Use this function to prepare a read-write memory buffer for use with IOStream.
Definition: SDL3pp_iostream.h:1859
size_t ReadIO(IOStreamRef context, TargetBytes buf)
Read from a data source.
Definition: SDL3pp_iostream.h:2175
void FlushIO(IOStreamRef context)
Flush any buffered data in the stream.
Definition: SDL3pp_iostream.h:2311
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:3165
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:2995
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:3070
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:3020
StringResult LoadFile(StringParam file)
Load all the data from a file path.
Definition: SDL3pp_iostream.h:2393
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:3090
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:3145
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:3140
IOStream OpenIO(const IOStreamInterface &iface, void *userdata)
Create a custom IOStream.
Definition: SDL3pp_iostream.h:1980
PropertiesRef GetIOProperties(IOStreamRef context)
Get the properties associated with an IOStream.
Definition: SDL3pp_iostream.h:2034
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:2576
SDL_IOStream * IOStreamRaw
Alias to raw representation for IOStream.
Definition: SDL3pp_iostream.h:27
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:3040
void SaveFile(SourceBytes data)
Save all the data into an SDL data stream.
Definition: SDL3pp_iostream.h:2421
size_t WriteIO(IOStreamRef context, SourceBytes buf)
Write to an IOStream data stream.
Definition: SDL3pp_iostream.h:2218
void WriteU8(IOStreamRef dst, Uint8 value)
Use this function to write a byte to an IOStream.
Definition: SDL3pp_iostream.h:2850
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:3045
Sint64 TellIO(IOStreamRef context)
Determine the current read/write offset in an IOStream data stream.
Definition: SDL3pp_iostream.h:2144
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:2721
void SaveFile_IO(IOStreamRef src, SourceBytes data, bool closeio=true)
Save all the data into an SDL data stream.
Definition: SDL3pp_iostream.h:2416
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:2830
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:2920
void WriteS8(Sint8 value)
Use this function to write a signed byte to an IOStream.
Definition: SDL3pp_iostream.h:2873
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:3015
size_t IOprintf(IOStreamRef context, SDL_PRINTF_FORMAT_STRING const char *fmt,...)
Print to an IOStream data stream.
Definition: SDL3pp_iostream.h:2249
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:2685
void Flush()
Flush any buffered data in the stream.
Definition: SDL3pp_iostream.h:2313
IOStream IOFromConstMem(SourceBytes mem)
Use this function to prepare a read-only memory buffer for use with IOStream.
Definition: SDL3pp_iostream.h:1912
SDL_IOWhence IOWhence
Possible whence values for IOStream seeking.
Definition: SDL3pp_iostream.h:64
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:2656
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:2714
size_t vprintf(SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap)
Print to an IOStream data stream.
Definition: SDL3pp_iostream.h:2288
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:2518
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:3065
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:2634
IOStream IOFromDynamicMem()
Use this function to create an IOStream that is backed by dynamically allocated memory.
Definition: SDL3pp_iostream.h:1949
void Close()
Close and free an allocated IOStream structure.
Definition: SDL3pp_iostream.h:2021
OwnArray< T > LoadFileAs(StringParam file)
Load all the data from a file path.
Definition: SDL3pp_iostream.h:2368
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:3170
Uint8 ReadU8(IOStreamRef src)
Use this function to read a byte from an IOStream.
Definition: SDL3pp_iostream.h:2461
constexpr IOStatus IO_STATUS_ERROR
Read or write I/O error.
Definition: SDL3pp_iostream.h:42
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:2511
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:2970
static IOStream Open(const IOStreamInterface &iface, void *userdata)
Create a custom IOStream.
Definition: SDL3pp_iostream.h:1985
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:3115
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:2692
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:1774
constexpr IOStatus IO_STATUS_EOF
End of file.
Definition: SDL3pp_iostream.h:45
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:2915
IOStatus GetIOStatus(IOStreamRef context)
Query the stream status of an IOStream.
Definition: SDL3pp_iostream.h:2062
Sint64 GetIOSize(IOStreamRef context)
Use this function to get the size of the data stream in an IOStream.
Definition: SDL3pp_iostream.h:2083
Sint64 Seek(Sint64 offset, IOWhence whence)
Seek within an IOStream data stream.
Definition: SDL3pp_iostream.h:2121
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:2627
size_t Write(SourceBytes buf)
Write to an IOStream data stream.
Definition: SDL3pp_iostream.h:2223
void WriteS8(IOStreamRef dst, Sint8 value)
Use this function to write a signed byte to an IOStream.
Definition: SDL3pp_iostream.h:2868
Sint64 Tell() const
Determine the current read/write offset in an IOStream data stream.
Definition: SDL3pp_iostream.h:2146
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:2772
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:2281
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:2945
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:2663
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:2605
constexpr IOStatus IO_STATUS_WRITEONLY
Tried to read a write-only buffer.
Definition: SDL3pp_iostream.h:53
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:2569
Sint8 ReadS8(IOStreamRef src)
Use this function to read a signed byte from an IOStream.
Definition: SDL3pp_iostream.h:2484
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:2598
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:2890
Sint64 SeekIO(IOStreamRef context, Sint64 offset, IOWhence whence)
Seek within an IOStream data stream.
Definition: SDL3pp_iostream.h:2116
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:2837
static IOStream FromDynamicMem()
Use this function to create an IOStream that is backed by dynamically allocated memory.
Definition: SDL3pp_iostream.h:1951
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:2990
static IOStream FromConstMem(SourceBytes mem)
Use this function to prepare a read-only memory buffer for use with IOStream.
Definition: SDL3pp_iostream.h:1917
StringResult LoadFile()
Load all the data from an SDL data stream.
Definition: SDL3pp_iostream.h:2344
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:2895
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:2801
void SaveFile(StringParam file, SourceBytes data)
Save all the data into a file path.
Definition: SDL3pp_iostream.h:2440
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:2750
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:2540
constexpr IOWhence IO_SEEK_CUR
Seek relative to current read point.
Definition: SDL3pp_iostream.h:69
SDL_IOStreamInterface IOStreamInterface
The function pointers that drive an IOStream.
Definition: SDL3pp_iostream.h:89
void WriteU8(Uint8 value)
Use this function to write a byte to an IOStream.
Definition: SDL3pp_iostream.h:2855
StringResult LoadFile_IO(IOStreamRef src, bool closeio=true)
Load all the data from an SDL data stream.
Definition: SDL3pp_iostream.h:2337
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:2808
SDL_IOStatus IOStatus
IOStream status, set by a read or write operation.
Definition: SDL3pp_iostream.h:37
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:2779
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:2743
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:2940
constexpr IOStatus IO_STATUS_READONLY
Tried to write a read-only buffer.
Definition: SDL3pp_iostream.h:50
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:3095
constexpr IOStatus IO_STATUS_READY
Everything is ready (no errors and not EOF).
Definition: SDL3pp_iostream.h:39
constexpr IOStatus IO_STATUS_NOT_READY
Non blocking I/O, not ready.
Definition: SDL3pp_iostream.h:47
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:1779
void CloseIO(IOStreamRaw context)
Close and free an allocated IOStream structure.
Definition: SDL3pp_iostream.h:2019
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:3120
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:2547
IOStatus GetStatus() const
Query the stream status of an IOStream.
Definition: SDL3pp_iostream.h:2067
static IOStream FromMem(TargetBytes mem)
Use this function to prepare a read-write memory buffer for use with IOStream.
Definition: SDL3pp_iostream.h:1864
constexpr IOWhence IO_SEEK_SET
Seek from the beginning of data.
Definition: SDL3pp_iostream.h:66
constexpr IOWhence IO_SEEK_END
Seek relative to the end of data.
Definition: SDL3pp_iostream.h:72
PropertiesRef GetProperties() const
Get the properties associated with an IOStream.
Definition: SDL3pp_iostream.h:2039
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:280
::Uint64 Uint64
An unsigned 64-bit integer type.
Definition: SDL3pp_stdinc.h:310
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition: SDL3pp_stdinc.h:228
::Sint8 Sint8
A signed 8-bit integer type.
Definition: SDL3pp_stdinc.h:215
::Sint64 Sint64
A signed 64-bit integer type.
Definition: SDL3pp_stdinc.h:295
::Sint32 Sint32
A signed 32-bit integer type.
Definition: SDL3pp_stdinc.h:267
::Sint16 Sint16
A signed 16-bit integer type.
Definition: SDL3pp_stdinc.h:241
::Uint16 Uint16
An unsigned 16-bit integer type.
Definition: SDL3pp_stdinc.h:254
Main include header for the SDL3pp library.
Reference for IOStream.
Definition: SDL3pp_iostream.h:1631
constexpr IOStreamRef(IOStream &&resource) noexcept
Constructs from IOStream.
Definition: SDL3pp_iostream.h:1665
constexpr IOStreamRef(const IOStreamRef &other) noexcept
Copy constructor.
Definition: SDL3pp_iostream.h:1671
IOStreamRef(IOStreamRaw resource) noexcept
Constructs from raw IOStream.
Definition: SDL3pp_iostream.h:1641
constexpr IOStreamRef(IOStreamRef &&other) noexcept
Move constructor.
Definition: SDL3pp_iostream.h:1677
~IOStreamRef()
Destructor.
Definition: SDL3pp_iostream.h:1683
constexpr IOStreamRef(const IOStream &resource) noexcept
Constructs from IOStream.
Definition: SDL3pp_iostream.h:1653
constexpr IOStreamRef & operator=(const IOStreamRef &other) noexcept=default
Assignment operator.
Reference for Properties.
Definition: SDL3pp_properties.h:691
A simple std::string-like interface for SDL allocated strings.
Definition: SDL3pp_strings.h:153