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(std::nullptr_t = nullptr) noexcept
137 : m_resource(0)
138 {
139 }
140
148 constexpr explicit IOStream(const IOStreamRaw resource) noexcept
149 : m_resource(resource)
150 {
151 }
152
153protected:
155 constexpr IOStream(const IOStream& other) noexcept = default;
156
157public:
159 constexpr IOStream(IOStream&& other) noexcept
160 : IOStream(other.release())
161 {
162 }
163
164 constexpr IOStream(const IOStreamRef& other) = delete;
165
166 constexpr IOStream(IOStreamRef&& other) = delete;
167
254 static IOStream FromFile(StringParam file, StringParam mode);
255
300 static IOStream FromMem(TargetBytes mem);
301
347
375 static IOStream FromDynamicMem();
376
405 static IOStream Open(const IOStreamInterface& iface, void* userdata);
406
408 ~IOStream() { SDL_CloseIO(m_resource); }
409
411 constexpr IOStream& operator=(IOStream&& other) noexcept
412 {
413 std::swap(m_resource, other.m_resource);
414 return *this;
415 }
416
417protected:
419 constexpr IOStream& operator=(const IOStream& other) noexcept = default;
420
421public:
423 constexpr IOStreamRaw get() const noexcept { return m_resource; }
424
426 constexpr IOStreamRaw release() noexcept
427 {
428 auto r = m_resource;
429 m_resource = nullptr;
430 return r;
431 }
432
434 constexpr auto operator<=>(const IOStream& other) const noexcept = default;
435
437 constexpr explicit operator bool() const noexcept { return !!m_resource; }
438
440 constexpr operator IOStreamParam() const noexcept { return {m_resource}; }
441
471 void Close();
472
484
502 IOStatus GetStatus() const;
503
514 Sint64 GetSize() const;
515
541 Sint64 Seek(Sint64 offset, IOWhence whence);
542
559 Sint64 Tell() const;
560
583 std::string Read(size_t size = -1)
584 {
585 Sint64 pos = Tell();
586 auto curSize = SDL_GetIOSize(get());
587 if ((curSize < 0 || pos < 0)) {
588 if (size == size_t(-1)) return {};
589 } else if (curSize - pos <= 0) {
590 return {};
591 } else if (curSize - pos < size) {
592 size = curSize - pos;
593 }
594 std::string result(size, 0);
595 auto actualSize = Read(result);
596 if (actualSize < size) result.resize(actualSize);
597 return result;
598 }
599
626 size_t Read(TargetBytes buf);
627
660 size_t Write(SourceBytes buf);
661
669 size_t print(std::string_view fmt, auto... args)
670 {
671 return Write(std::vformat(fmt, std::make_format_args(args...)));
672 }
673
681 size_t println(std::string_view fmt, auto... args)
682 {
683 std::string result =
684 std::vformat(fmt, std::make_format_args(args...)) + "\n";
685 return Write(result);
686 }
687
708 size_t printf(SDL_PRINTF_FORMAT_STRING const char* fmt, ...)
709 {
710 va_list ap;
711 size_t result;
712
713 va_start(ap, fmt);
714 result = vprintf(fmt, ap);
715 va_end(ap);
716
717 return result;
718 }
719
739 size_t vprintf(SDL_PRINTF_FORMAT_STRING const char* fmt, va_list ap);
740
757 void Flush();
758
776
794 template<class T>
796 {
797 size_t datasize = 0;
798 auto data = static_cast<T*>(SDL_LoadFile_IO(get(), &datasize, false));
799 return OwnArray<T>{CheckError(data), datasize / sizeof(T)};
800 }
801
816 void SaveFile(SourceBytes data);
817
834
851
872
893
914
935
956
977
998
1018 Sint32 ReadS32BE();
1019
1039 Uint64 ReadU64LE();
1040
1060 Sint64 ReadS64LE();
1061
1081 Uint64 ReadU64BE();
1082
1102 Sint64 ReadS64BE();
1103
1118 std::optional<Uint8> TryReadU8()
1119 {
1120 if (Uint8 value; SDL_ReadU8(get(), &value)) return value;
1121 return {};
1122 }
1123
1138 std::optional<Sint8> TryReadS8()
1139 {
1140 if (Sint8 value; SDL_ReadS8(get(), &value)) return value;
1141 return {};
1142 }
1143
1162 std::optional<Uint16> TryReadU16LE()
1163 {
1164 if (Uint16 value; SDL_ReadU16LE(get(), &value)) return value;
1165 return {};
1166 }
1167
1186 std::optional<Sint16> TryReadS16LE()
1187 {
1188 if (Sint16 value; SDL_ReadS16LE(get(), &value)) return value;
1189 return {};
1190 }
1191
1210 std::optional<Uint16> TryReadU16BE()
1211 {
1212 if (Uint16 value; SDL_ReadU16BE(get(), &value)) return value;
1213 return {};
1214 }
1215
1234 std::optional<Sint16> TryReadS16BE()
1235 {
1236 if (Sint16 value; SDL_ReadS16BE(get(), &value)) return value;
1237 return {};
1238 }
1239
1258 std::optional<Uint32> TryReadU32LE()
1259 {
1260 if (Uint32 value; SDL_ReadU32LE(get(), &value)) return value;
1261 return {};
1262 }
1263
1282 std::optional<Sint32> TryReadS32LE()
1283 {
1284 if (Sint32 value; SDL_ReadS32LE(get(), &value)) return value;
1285 return {};
1286 }
1287
1306 std::optional<Uint32> TryReadU32BE()
1307 {
1308 if (Uint32 value; SDL_ReadU32BE(get(), &value)) return value;
1309 return {};
1310 }
1311
1330 std::optional<Sint32> TryReadS32BE()
1331 {
1332 if (Sint32 value; SDL_ReadS32BE(get(), &value)) return value;
1333 return {};
1334 }
1335
1354 std::optional<Uint64> TryReadU64LE()
1355 {
1356 if (Uint64 value; SDL_ReadU64LE(get(), &value)) return value;
1357 return {};
1358 }
1359
1378 std::optional<Sint64> TryReadS64LE()
1379 {
1380 if (Sint64 value; SDL_ReadS64LE(get(), &value)) return value;
1381 return {};
1382 }
1383
1402 std::optional<Uint64> TryReadU64BE()
1403 {
1404 if (Uint64 value; SDL_ReadU64BE(get(), &value)) return value;
1405 return {};
1406 }
1407
1426 std::optional<Sint64> TryReadS64BE()
1427 {
1428 if (Sint64 value; SDL_ReadS64BE(get(), &value)) return value;
1429 return {};
1430 }
1431
1442 void WriteU8(Uint8 value);
1443
1454 void WriteS8(Sint8 value);
1455
1471 void WriteU16LE(Uint16 value);
1472
1488 void WriteS16LE(Sint16 value);
1489
1504 void WriteU16BE(Uint16 value);
1505
1520 void WriteS16BE(Sint16 value);
1521
1537 void WriteU32LE(Uint32 value);
1538
1554 void WriteS32LE(Sint32 value);
1555
1570 void WriteU32BE(Uint32 value);
1571
1586 void WriteS32BE(Sint32 value);
1587
1603 void WriteU64LE(Uint64 value);
1604
1620 void WriteS64LE(Sint64 value);
1621
1636 void WriteU64BE(Uint64 value);
1637
1652 void WriteS64BE(Sint64 value);
1653};
1654
1657{
1658 using IOStream::IOStream;
1659
1667 IOStreamRef(IOStreamParam resource) noexcept
1668 : IOStream(resource.value)
1669 {
1670 }
1671
1679 IOStreamRef(IOStreamRaw resource) noexcept
1680 : IOStream(resource)
1681 {
1682 }
1683
1685 constexpr IOStreamRef(const IOStreamRef& other) noexcept = default;
1686
1689};
1690
1774{
1775 return IOStream(SDL_IOFromFile(file, mode));
1776}
1777
1779{
1780 return SDL::IOFromFile(std::move(file), std::move(mode));
1781}
1782
1783namespace prop::IOStream {
1784
1785constexpr auto WINDOWS_HANDLE_POINTER =
1786 SDL_PROP_IOSTREAM_WINDOWS_HANDLE_POINTER;
1787
1788constexpr auto STDIO_FILE_POINTER = SDL_PROP_IOSTREAM_STDIO_FILE_POINTER;
1789
1790constexpr auto FILE_DESCRIPTOR_NUMBER =
1791 SDL_PROP_IOSTREAM_FILE_DESCRIPTOR_NUMBER;
1792
1793constexpr auto ANDROID_AASSET_POINTER =
1794 SDL_PROP_IOSTREAM_ANDROID_AASSET_POINTER;
1795
1796constexpr auto MEMORY_POINTER = SDL_PROP_IOSTREAM_MEMORY_POINTER;
1797
1798constexpr auto MEMORY_SIZE_NUMBER = SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER;
1799
1800#if SDL_VERSION_ATLEAST(3, 4, 0)
1801
1802constexpr auto MEMORY_FREE_FUNC_POINTER =
1803 SDL_PROP_IOSTREAM_MEMORY_FREE_FUNC_POINTER;
1804
1805#endif // SDL_VERSION_ATLEAST(3, 4, 0)
1806
1807constexpr auto DYNAMIC_MEMORY_POINTER =
1808 SDL_PROP_IOSTREAM_DYNAMIC_MEMORY_POINTER;
1809
1810constexpr auto DYNAMIC_CHUNKSIZE_NUMBER =
1811 SDL_PROP_IOSTREAM_DYNAMIC_CHUNKSIZE_NUMBER;
1812
1813} // namespace prop::IOStream
1814
1859{
1860 return IOStream(CheckError(SDL_IOFromMem(mem.data(), mem.size_bytes())));
1861}
1862
1864{
1865 return SDL::IOFromMem(std::move(mem));
1866}
1867
1912{
1913 return IOStream(CheckError(SDL_IOFromConstMem(mem.data(), mem.size_bytes())));
1914}
1915
1917{
1918 return SDL::IOFromConstMem(std::move(mem));
1919}
1920
1948inline IOStream IOFromDynamicMem() { return IOStream(SDL_IOFromDynamicMem()); }
1949
1951
1979inline IOStream OpenIO(const IOStreamInterface& iface, void* userdata)
1980{
1981 return IOStream(CheckError(SDL_OpenIO(&iface, userdata)));
1982}
1983
1984inline IOStream IOStream::Open(const IOStreamInterface& iface, void* userdata)
1985{
1986 return SDL::OpenIO(iface, userdata);
1987}
1988
2018inline void CloseIO(IOStreamRaw context) { CheckError(SDL_CloseIO(context)); }
2019
2020inline void IOStream::Close() { CloseIO(release()); }
2021
2034{
2035 return {CheckError(SDL_GetIOProperties(context))};
2036}
2037
2039{
2040 return SDL::GetIOProperties(m_resource);
2041}
2042
2062{
2063 return SDL_GetIOStatus(context);
2064}
2065
2067{
2068 return SDL::GetIOStatus(m_resource);
2069}
2070
2083{
2084 return CheckError(SDL_GetIOSize(context));
2085}
2086
2087inline Sint64 IOStream::GetSize() const { return SDL::GetIOSize(m_resource); }
2088
2115inline Sint64 SeekIO(IOStreamParam context, Sint64 offset, IOWhence whence)
2116{
2117 return SDL_SeekIO(context, offset, whence);
2118}
2119
2120inline Sint64 IOStream::Seek(Sint64 offset, IOWhence whence)
2121{
2122 return SDL::SeekIO(m_resource, offset, whence);
2123}
2124
2143inline Sint64 TellIO(IOStreamParam context) { return SDL_TellIO(context); }
2144
2145inline Sint64 IOStream::Tell() const { return SDL::TellIO(m_resource); }
2146
2174inline size_t ReadIO(IOStreamParam context, TargetBytes buf)
2175{
2176 return SDL_ReadIO(context, buf.data(), buf.size_bytes());
2177}
2178
2179inline size_t IOStream::Read(TargetBytes buf)
2180{
2181 return SDL::ReadIO(m_resource, std::move(buf));
2182}
2183
2217inline size_t WriteIO(IOStreamParam context, SourceBytes buf)
2218{
2219 return SDL_WriteIO(context, buf.data(), buf.size_bytes());
2220}
2221
2223{
2224 return SDL::WriteIO(m_resource, std::move(buf));
2225}
2226
2248inline size_t IOprintf(IOStreamParam context,
2249 SDL_PRINTF_FORMAT_STRING const char* fmt,
2250 ...)
2251{
2252 va_list ap;
2253 size_t result;
2254
2255 va_start(ap, fmt);
2256 result = SDL_IOvprintf(context, fmt, ap);
2257 va_end(ap);
2258
2259 return result;
2260}
2261
2280inline size_t IOvprintf(IOStreamParam context,
2281 SDL_PRINTF_FORMAT_STRING const char* fmt,
2282 va_list ap)
2283{
2284 return SDL_IOvprintf(context, fmt, ap);
2285}
2286
2287inline size_t IOStream::vprintf(SDL_PRINTF_FORMAT_STRING const char* fmt,
2288 va_list ap)
2289{
2290 return SDL::IOvprintf(m_resource, fmt, ap);
2291}
2292
2310inline void FlushIO(IOStreamParam context) { CheckError(SDL_FlushIO(context)); }
2311
2312inline void IOStream::Flush() { SDL::FlushIO(m_resource); }
2313
2336inline StringResult LoadFile(IOStreamParam src, bool closeio = true)
2337{
2338 size_t datasize = 0;
2339 auto data = static_cast<char*>(SDL_LoadFile_IO(src, &datasize, closeio));
2340 return StringResult{CheckError(data), datasize};
2341}
2342
2362{
2363 size_t datasize = 0;
2364 auto data = static_cast<char*>(SDL_LoadFile(file, &datasize));
2365 return StringResult{CheckError(data), datasize};
2366}
2367
2369{
2370 return SDL::LoadFile(m_resource, false);
2371}
2372
2391template<class T>
2393{
2394 size_t datasize = 0;
2395 auto data = static_cast<T*>(SDL_LoadFile(file, &datasize));
2396 return OwnArray<T>{CheckError(data), datasize / sizeof(T)};
2397}
2398
2415inline void SaveFile(IOStreamParam src, SourceBytes data, bool closeio = false)
2416{
2417 CheckError(SDL_SaveFile_IO(src, data.data(), data.size_bytes(), closeio));
2418}
2419
2434inline void SaveFile(StringParam file, SourceBytes data)
2435{
2436 CheckError(SDL_SaveFile(file, data.data(), data.size_bytes()));
2437}
2438
2440{
2441 SDL::SaveFile(m_resource, std::move(data));
2442}
2443
2461{
2462 Uint8 value;
2463 CheckError(SDL_ReadU8(src, &value));
2464 return value;
2465}
2466
2484{
2485 Sint8 value;
2486 CheckError(SDL_ReadS8(src, &value));
2487 return value;
2488}
2489
2511{
2512 Uint16 value;
2513 CheckError(SDL_ReadU16LE(src, &value));
2514 return value;
2515}
2516
2517inline Uint16 IOStream::ReadU16LE() { return SDL::ReadU16LE(m_resource); }
2518
2540{
2541 Sint16 value;
2542 CheckError(SDL_ReadS16LE(src, &value));
2543 return value;
2544}
2545
2546inline Sint16 IOStream::ReadS16LE() { return SDL::ReadS16LE(m_resource); }
2547
2569{
2570 Uint16 value;
2571 CheckError(SDL_ReadU16BE(src, &value));
2572 return value;
2573}
2574
2575inline Uint16 IOStream::ReadU16BE() { return SDL::ReadU16BE(m_resource); }
2576
2598{
2599 Sint16 value;
2600 CheckError(SDL_ReadS16BE(src, &value));
2601 return value;
2602}
2603
2604inline Sint16 IOStream::ReadS16BE() { return SDL::ReadS16BE(m_resource); }
2605
2627{
2628 Uint32 value;
2629 CheckError(SDL_ReadU32LE(src, &value));
2630 return value;
2631}
2632
2633inline Uint32 IOStream::ReadU32LE() { return SDL::ReadU32LE(m_resource); }
2634
2656{
2657 Sint32 value;
2658 CheckError(SDL_ReadS32LE(src, &value));
2659 return value;
2660}
2661
2662inline Sint32 IOStream::ReadS32LE() { return SDL::ReadS32LE(m_resource); }
2663
2685{
2686 Uint32 value;
2687 CheckError(SDL_ReadU32BE(src, &value));
2688 return value;
2689}
2690
2691inline Uint32 IOStream::ReadU32BE() { return SDL::ReadU32BE(m_resource); }
2692
2714{
2715 Sint32 value;
2716 CheckError(SDL_ReadS32BE(src, &value));
2717 return value;
2718}
2719
2720inline Sint32 IOStream::ReadS32BE() { return SDL::ReadS32BE(m_resource); }
2721
2743{
2744 Uint64 value;
2745 CheckError(SDL_ReadU64LE(src, &value));
2746 return value;
2747}
2748
2749inline Uint64 IOStream::ReadU64LE() { return SDL::ReadU64LE(m_resource); }
2750
2772{
2773 Sint64 value;
2774 CheckError(SDL_ReadS64LE(src, &value));
2775 return value;
2776}
2777
2778inline Sint64 IOStream::ReadS64LE() { return SDL::ReadS64LE(m_resource); }
2779
2801{
2802 Uint64 value;
2803 CheckError(SDL_ReadU64BE(src, &value));
2804 return value;
2805}
2806
2807inline Uint64 IOStream::ReadU64BE() { return SDL::ReadU64BE(m_resource); }
2808
2830{
2831 Sint64 value;
2832 CheckError(SDL_ReadS64BE(src, &value));
2833 return value;
2834}
2835
2836inline Sint64 IOStream::ReadS64BE() { return SDL::ReadS64BE(m_resource); }
2837
2849inline void WriteU8(IOStreamParam dst, Uint8 value)
2850{
2851 CheckError(SDL_WriteU8(dst, value));
2852}
2853
2854inline void IOStream::WriteU8(Uint8 value) { SDL::WriteU8(m_resource, value); }
2855
2867inline void WriteS8(IOStreamParam dst, Sint8 value)
2868{
2869 CheckError(SDL_WriteS8(dst, value));
2870}
2871
2872inline void IOStream::WriteS8(Sint8 value) { SDL::WriteS8(m_resource, value); }
2873
2889inline void WriteU16LE(IOStreamParam dst, Uint16 value)
2890{
2891 CheckError(SDL_WriteU16LE(dst, value));
2892}
2893
2895{
2896 SDL::WriteU16LE(m_resource, value);
2897}
2898
2914inline void WriteS16LE(IOStreamParam dst, Sint16 value)
2915{
2916 CheckError(SDL_WriteS16LE(dst, value));
2917}
2918
2920{
2921 SDL::WriteS16LE(m_resource, value);
2922}
2923
2939inline void WriteU16BE(IOStreamParam dst, Uint16 value)
2940{
2941 CheckError(SDL_WriteU16BE(dst, value));
2942}
2943
2945{
2946 SDL::WriteU16BE(m_resource, value);
2947}
2948
2964inline void WriteS16BE(IOStreamParam dst, Sint16 value)
2965{
2966 CheckError(SDL_WriteS16BE(dst, value));
2967}
2968
2970{
2971 SDL::WriteS16BE(m_resource, value);
2972}
2973
2989inline void WriteU32LE(IOStreamParam dst, Uint32 value)
2990{
2991 CheckError(SDL_WriteU32LE(dst, value));
2992}
2993
2995{
2996 SDL::WriteU32LE(m_resource, value);
2997}
2998
3014inline void WriteS32LE(IOStreamParam dst, Sint32 value)
3015{
3016 CheckError(SDL_WriteS32LE(dst, value));
3017}
3018
3020{
3021 SDL::WriteS32LE(m_resource, value);
3022}
3023
3039inline void WriteU32BE(IOStreamParam dst, Uint32 value)
3040{
3041 CheckError(SDL_WriteU32BE(dst, value));
3042}
3043
3045{
3046 SDL::WriteU32BE(m_resource, value);
3047}
3048
3064inline void WriteS32BE(IOStreamParam dst, Sint32 value)
3065{
3066 CheckError(SDL_WriteS32BE(dst, value));
3067}
3068
3070{
3071 SDL::WriteS32BE(m_resource, value);
3072}
3073
3089inline void WriteU64LE(IOStreamParam dst, Uint64 value)
3090{
3091 CheckError(SDL_WriteU64LE(dst, value));
3092}
3093
3095{
3096 SDL::WriteU64LE(m_resource, value);
3097}
3098
3114inline void WriteS64LE(IOStreamParam dst, Sint64 value)
3115{
3116 CheckError(SDL_WriteS64LE(dst, value));
3117}
3118
3120{
3121 SDL::WriteS64LE(m_resource, value);
3122}
3123
3139inline void WriteU64BE(IOStreamParam dst, Uint64 value)
3140{
3141 CheckError(SDL_WriteU64BE(dst, value));
3142}
3143
3145{
3146 SDL::WriteU64BE(m_resource, value);
3147}
3148
3164inline void WriteS64BE(IOStreamParam dst, Sint64 value)
3165{
3166 CheckError(SDL_WriteS64BE(dst, value));
3167}
3168
3170{
3171 SDL::WriteS64BE(m_resource, value);
3172}
3173
3175
3176} // namespace SDL
3177
3178#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:1138
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:1186
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:1402
constexpr IOStreamRaw release() noexcept
Retrieves underlying IOStreamRaw and clear this.
Definition: SDL3pp_iostream.h:426
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:1210
constexpr IOStream(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition: SDL3pp_iostream.h:136
~IOStream()
Destructor.
Definition: SDL3pp_iostream.h:408
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:1282
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:1162
constexpr IOStreamRaw get() const noexcept
Retrieves underlying IOStreamRaw.
Definition: SDL3pp_iostream.h:423
OwnArray< T > LoadFileAs()
Load all the data from an SDL data stream.
Definition: SDL3pp_iostream.h:795
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:1234
size_t printf(SDL_PRINTF_FORMAT_STRING const char *fmt,...)
Print to an IOStream data stream.
Definition: SDL3pp_iostream.h:708
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:1354
constexpr IOStream(IOStream &&other) noexcept
Move constructor.
Definition: SDL3pp_iostream.h:159
size_t print(std::string_view fmt, auto... args)
Prints formatted string.
Definition: SDL3pp_iostream.h:669
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:1258
std::optional< Uint8 > TryReadU8()
Use this function to read a byte from an IOStreamRef.
Definition: SDL3pp_iostream.h:1118
constexpr IOStream & operator=(IOStream &&other) noexcept
Assignment operator.
Definition: SDL3pp_iostream.h:411
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:1306
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:1330
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:1426
constexpr IOStream(const IOStreamRaw resource) noexcept
Constructs from IOStreamParam.
Definition: SDL3pp_iostream.h:148
size_t println(std::string_view fmt, auto... args)
Prints formatted string.
Definition: SDL3pp_iostream.h:681
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:1378
std::string Read(size_t size=-1)
Read from a data source.
Definition: SDL3pp_iostream.h:583
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
Sint64 GetSize() const
Use this function to get the size of the data stream in an IOStream.
Definition: SDL3pp_iostream.h:2087
IOStream IOFromMem(TargetBytes mem)
Use this function to prepare a read-write memory buffer for use with IOStream.
Definition: SDL3pp_iostream.h:1858
size_t IOprintf(IOStreamParam context, SDL_PRINTF_FORMAT_STRING const char *fmt,...)
Print to an IOStream data stream.
Definition: SDL3pp_iostream.h:2248
Uint8 ReadU8(IOStreamParam src)
Use this function to read a byte from an IOStream.
Definition: SDL3pp_iostream.h:2460
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:2994
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:3069
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:3019
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:2964
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:3144
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:2829
IOStream OpenIO(const IOStreamInterface &iface, void *userdata)
Create a custom IOStream.
Definition: SDL3pp_iostream.h:1979
IOStatus GetIOStatus(IOStreamParam context)
Query the stream status of an IOStream.
Definition: SDL3pp_iostream.h:2061
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:2575
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:2439
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:2597
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:3014
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:3044
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:2720
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:2919
void WriteS8(Sint8 value)
Use this function to write a signed byte to an IOStream.
Definition: SDL3pp_iostream.h:2872
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:2626
size_t ReadIO(IOStreamParam context, TargetBytes buf)
Read from a data source.
Definition: SDL3pp_iostream.h:2174
void Flush()
Flush any buffered data in the stream.
Definition: SDL3pp_iostream.h:2312
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:2989
IOStream IOFromConstMem(SourceBytes mem)
Use this function to prepare a read-only memory buffer for use with IOStream.
Definition: SDL3pp_iostream.h:1911
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:2483
size_t vprintf(SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap)
Print to an IOStream data stream.
Definition: SDL3pp_iostream.h:2287
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:2517
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:2539
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:2633
IOStream IOFromDynamicMem()
Use this function to create an IOStream that is backed by dynamically allocated memory.
Definition: SDL3pp_iostream.h:1948
void Close()
Close and free an allocated IOStream structure.
Definition: SDL3pp_iostream.h:2020
OwnArray< T > LoadFileAs(StringParam file)
Load all the data from a file path.
Definition: SDL3pp_iostream.h:2392
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:3169
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:2280
Sint64 TellIO(IOStreamParam context)
Determine the current read/write offset in an IOStream data stream.
Definition: SDL3pp_iostream.h:2143
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:2742
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:2969
static IOStream Open(const IOStreamInterface &iface, void *userdata)
Create a custom IOStream.
Definition: SDL3pp_iostream.h:1984
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:2655
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:2684
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:2691
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:1773
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:2771
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:2568
void WriteU8(IOStreamParam dst, Uint8 value)
Use this function to write a byte to an IOStream.
Definition: SDL3pp_iostream.h:2849
Sint64 GetIOSize(IOStreamParam context)
Use this function to get the size of the data stream in an IOStream.
Definition: SDL3pp_iostream.h:2082
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:3039
Sint64 Seek(Sint64 offset, IOWhence whence)
Seek within an IOStream data stream.
Definition: SDL3pp_iostream.h:2120
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:3064
Sint64 SeekIO(IOStreamParam context, Sint64 offset, IOWhence whence)
Seek within an IOStream data stream.
Definition: SDL3pp_iostream.h:2115
size_t Write(SourceBytes buf)
Write to an IOStream data stream.
Definition: SDL3pp_iostream.h:2222
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:2889
Sint64 Tell() const
Determine the current read/write offset in an IOStream data stream.
Definition: SDL3pp_iostream.h:2145
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:2944
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:2662
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:2604
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:2033
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:2836
static IOStream FromDynamicMem()
Use this function to create an IOStream that is backed by dynamically allocated memory.
Definition: SDL3pp_iostream.h:1950
static IOStream FromConstMem(SourceBytes mem)
Use this function to prepare a read-only memory buffer for use with IOStream.
Definition: SDL3pp_iostream.h:1916
StringResult LoadFile()
Load all the data from an SDL data stream.
Definition: SDL3pp_iostream.h:2368
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:2894
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:2749
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:2854
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:2807
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:2867
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:2914
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:2778
void FlushIO(IOStreamParam context)
Flush any buffered data in the stream.
Definition: SDL3pp_iostream.h:2310
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:2800
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:2713
void SaveFile(IOStreamParam src, SourceBytes data, bool closeio=false)
Save all the data into an SDL data stream.
Definition: SDL3pp_iostream.h:2415
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:3094
StringResult LoadFile(IOStreamParam src, bool closeio=true)
Load all the data from an SDL data stream.
Definition: SDL3pp_iostream.h:2336
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:1778
void CloseIO(IOStreamRaw context)
Close and free an allocated IOStream structure.
Definition: SDL3pp_iostream.h:2018
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:3119
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:2546
IOStatus GetStatus() const
Query the stream status of an IOStream.
Definition: SDL3pp_iostream.h:2066
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:3139
size_t WriteIO(IOStreamParam context, SourceBytes buf)
Write to an IOStream data stream.
Definition: SDL3pp_iostream.h:2217
static IOStream FromMem(TargetBytes mem)
Use this function to prepare a read-write memory buffer for use with IOStream.
Definition: SDL3pp_iostream.h:1863
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:2510
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:3089
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:3114
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:3164
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:2038
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:2939
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition: SDL3pp_stdinc.h:341
::Uint64 Uint64
An unsigned 64-bit integer type.
Definition: SDL3pp_stdinc.h:371
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition: SDL3pp_stdinc.h:289
::Sint8 Sint8
A signed 8-bit integer type.
Definition: SDL3pp_stdinc.h:276
::Sint64 Sint64
A signed 64-bit integer type.
Definition: SDL3pp_stdinc.h:356
::Sint32 Sint32
A signed 32-bit integer type.
Definition: SDL3pp_stdinc.h:328
::Sint16 Sint16
A signed 16-bit integer type.
Definition: SDL3pp_stdinc.h:302
::Uint16 Uint16
An unsigned 16-bit integer type.
Definition: SDL3pp_stdinc.h:315
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:1657
IOStreamRef(IOStreamRaw resource) noexcept
Constructs from IOStreamParam.
Definition: SDL3pp_iostream.h:1679
~IOStreamRef()
Destructor.
Definition: SDL3pp_iostream.h:1688
IOStreamRef(IOStreamParam resource) noexcept
Constructs from IOStreamParam.
Definition: SDL3pp_iostream.h:1667
constexpr IOStreamRef(const IOStreamRef &other) noexcept=default
Copy constructor.
Semi-safe reference for Properties.
Definition: SDL3pp_properties.h:716
A simple std::string-like interface for SDL allocated strings.
Definition: SDL3pp_strings.h:153