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
154 constexpr IOStream(const IOStream& other) = delete;
155
157 constexpr IOStream(IOStream&& other) noexcept
158 : IOStream(other.release())
159 {
160 }
161
162 constexpr IOStream(const IOStreamRef& other) = delete;
163
164 constexpr IOStream(IOStreamRef&& other) = delete;
165
248 static IOStream FromFile(StringParam file, StringParam mode);
249
288 static IOStream FromMem(TargetBytes mem);
289
329
357 static IOStream FromDynamicMem();
358
387 static IOStream Open(const IOStreamInterface& iface, void* userdata);
388
390 ~IOStream() { SDL_CloseIO(m_resource); }
391
393 constexpr IOStream& operator=(IOStream&& other) noexcept
394 {
395 std::swap(m_resource, other.m_resource);
396 return *this;
397 }
398
399protected:
401 constexpr IOStream& operator=(const IOStream& other) noexcept = default;
402
403public:
405 constexpr IOStreamRaw get() const noexcept { return m_resource; }
406
408 constexpr IOStreamRaw release() noexcept
409 {
410 auto r = m_resource;
411 m_resource = nullptr;
412 return r;
413 }
414
416 constexpr auto operator<=>(const IOStream& other) const noexcept = default;
417
419 constexpr explicit operator bool() const noexcept { return !!m_resource; }
420
422 constexpr operator IOStreamParam() const noexcept { return {m_resource}; }
423
453 void Close();
454
466
484 IOStatus GetStatus() const;
485
496 Sint64 GetSize() const;
497
523 Sint64 Seek(Sint64 offset, IOWhence whence);
524
541 Sint64 Tell() const;
542
565 std::string Read(size_t size = -1)
566 {
567 Sint64 pos = Tell();
568 auto curSize = SDL_GetIOSize(get());
569 if ((curSize < 0 || pos < 0)) {
570 if (size == size_t(-1)) return {};
571 } else if (curSize - pos <= 0) {
572 return {};
573 } else if (curSize - pos < size) {
574 size = curSize - pos;
575 }
576 std::string result(size, 0);
577 auto actualSize = Read(result);
578 if (actualSize < size) result.resize(actualSize);
579 return result;
580 }
581
604 size_t Read(TargetBytes buf);
605
634 size_t Write(SourceBytes buf);
635
643 size_t print(std::string_view fmt, auto... args)
644 {
645 return Write(std::vformat(fmt, std::make_format_args(args...)));
646 }
647
655 size_t println(std::string_view fmt, auto... args)
656 {
657 std::string result =
658 std::vformat(fmt, std::make_format_args(args...)) + "\n";
659 return Write(result);
660 }
661
682 size_t printf(SDL_PRINTF_FORMAT_STRING const char* fmt, ...)
683 {
684 va_list ap;
685 size_t result;
686
687 va_start(ap, fmt);
688 result = vprintf(fmt, ap);
689 va_end(ap);
690
691 return result;
692 }
693
713 size_t vprintf(SDL_PRINTF_FORMAT_STRING const char* fmt, va_list ap);
714
731 void Flush();
732
750
768 template<class T>
770 {
771 size_t datasize = 0;
772 auto data = static_cast<T*>(SDL_LoadFile_IO(get(), &datasize, false));
773 return OwnArray<T>{CheckError(data), datasize / sizeof(T)};
774 }
775
790 void SaveFile(SourceBytes data);
791
808
825
846
867
888
909
930
951
972
993
1013 Uint64 ReadU64LE();
1014
1034 Sint64 ReadS64LE();
1035
1055 Uint64 ReadU64BE();
1056
1076 Sint64 ReadS64BE();
1077
1092 std::optional<Uint8> TryReadU8()
1093 {
1094 if (Uint8 value; SDL_ReadU8(get(), &value)) return value;
1095 return {};
1096 }
1097
1112 std::optional<Sint8> TryReadS8()
1113 {
1114 if (Sint8 value; SDL_ReadS8(get(), &value)) return value;
1115 return {};
1116 }
1117
1136 std::optional<Uint16> TryReadU16LE()
1137 {
1138 if (Uint16 value; SDL_ReadU16LE(get(), &value)) return value;
1139 return {};
1140 }
1141
1160 std::optional<Sint16> TryReadS16LE()
1161 {
1162 if (Sint16 value; SDL_ReadS16LE(get(), &value)) return value;
1163 return {};
1164 }
1165
1184 std::optional<Uint16> TryReadU16BE()
1185 {
1186 if (Uint16 value; SDL_ReadU16BE(get(), &value)) return value;
1187 return {};
1188 }
1189
1208 std::optional<Sint16> TryReadS16BE()
1209 {
1210 if (Sint16 value; SDL_ReadS16BE(get(), &value)) return value;
1211 return {};
1212 }
1213
1232 std::optional<Uint32> TryReadU32LE()
1233 {
1234 if (Uint32 value; SDL_ReadU32LE(get(), &value)) return value;
1235 return {};
1236 }
1237
1256 std::optional<Sint32> TryReadS32LE()
1257 {
1258 if (Sint32 value; SDL_ReadS32LE(get(), &value)) return value;
1259 return {};
1260 }
1261
1280 std::optional<Uint32> TryReadU32BE()
1281 {
1282 if (Uint32 value; SDL_ReadU32BE(get(), &value)) return value;
1283 return {};
1284 }
1285
1304 std::optional<Sint32> TryReadS32BE()
1305 {
1306 if (Sint32 value; SDL_ReadS32BE(get(), &value)) return value;
1307 return {};
1308 }
1309
1328 std::optional<Uint64> TryReadU64LE()
1329 {
1330 if (Uint64 value; SDL_ReadU64LE(get(), &value)) return value;
1331 return {};
1332 }
1333
1352 std::optional<Sint64> TryReadS64LE()
1353 {
1354 if (Sint64 value; SDL_ReadS64LE(get(), &value)) return value;
1355 return {};
1356 }
1357
1376 std::optional<Uint64> TryReadU64BE()
1377 {
1378 if (Uint64 value; SDL_ReadU64BE(get(), &value)) return value;
1379 return {};
1380 }
1381
1400 std::optional<Sint64> TryReadS64BE()
1401 {
1402 if (Sint64 value; SDL_ReadS64BE(get(), &value)) return value;
1403 return {};
1404 }
1405
1416 void WriteU8(Uint8 value);
1417
1428 void WriteS8(Sint8 value);
1429
1445 void WriteU16LE(Uint16 value);
1446
1462 void WriteS16LE(Sint16 value);
1463
1478 void WriteU16BE(Uint16 value);
1479
1494 void WriteS16BE(Sint16 value);
1495
1511 void WriteU32LE(Uint32 value);
1512
1528 void WriteS32LE(Sint32 value);
1529
1544 void WriteU32BE(Uint32 value);
1545
1560 void WriteS32BE(Sint32 value);
1561
1577 void WriteU64LE(Uint64 value);
1578
1594 void WriteS64LE(Sint64 value);
1595
1610 void WriteU64BE(Uint64 value);
1611
1626 void WriteS64BE(Sint64 value);
1627};
1628
1631{
1632 using IOStream::IOStream;
1633
1641 IOStreamRef(IOStreamParam resource) noexcept
1642 : IOStream(resource.value)
1643 {
1644 }
1645
1653 IOStreamRef(IOStreamRaw resource) noexcept
1654 : IOStream(resource)
1655 {
1656 }
1657
1659 IOStreamRef(const IOStreamRef& other) noexcept
1660 : IOStream(other.get())
1661 {
1662 }
1663
1666};
1667
1747{
1748 return IOStream(SDL_IOFromFile(file, mode));
1749}
1750
1752{
1753 return SDL::IOFromFile(std::move(file), std::move(mode));
1754}
1755
1756namespace prop::IOStream {
1757
1758constexpr auto WINDOWS_HANDLE_POINTER =
1759 SDL_PROP_IOSTREAM_WINDOWS_HANDLE_POINTER;
1760
1761constexpr auto STDIO_FILE_POINTER = SDL_PROP_IOSTREAM_STDIO_FILE_POINTER;
1762
1763constexpr auto FILE_DESCRIPTOR_NUMBER =
1764 SDL_PROP_IOSTREAM_FILE_DESCRIPTOR_NUMBER;
1765
1766constexpr auto ANDROID_AASSET_POINTER =
1767 SDL_PROP_IOSTREAM_ANDROID_AASSET_POINTER;
1768
1769constexpr auto MEMORY_POINTER = SDL_PROP_IOSTREAM_MEMORY_POINTER;
1770
1771constexpr auto MEMORY_SIZE_NUMBER = SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER;
1772
1773constexpr auto DYNAMIC_MEMORY_POINTER =
1774 SDL_PROP_IOSTREAM_DYNAMIC_MEMORY_POINTER;
1775
1776constexpr auto DYNAMIC_CHUNKSIZE_NUMBER =
1777 SDL_PROP_IOSTREAM_DYNAMIC_CHUNKSIZE_NUMBER;
1778
1779} // namespace prop::IOStream
1780
1819{
1820 return IOStream(CheckError(SDL_IOFromMem(mem.data(), mem.size_bytes())));
1821}
1822
1824{
1825 return SDL::IOFromMem(std::move(mem));
1826}
1827
1866{
1867 return IOStream(CheckError(SDL_IOFromConstMem(mem.data(), mem.size_bytes())));
1868}
1869
1871{
1872 return SDL::IOFromConstMem(std::move(mem));
1873}
1874
1902inline IOStream IOFromDynamicMem() { return IOStream(SDL_IOFromDynamicMem()); }
1903
1905
1933inline IOStream OpenIO(const IOStreamInterface& iface, void* userdata)
1934{
1935 return IOStream(CheckError(SDL_OpenIO(&iface, userdata)));
1936}
1937
1938inline IOStream IOStream::Open(const IOStreamInterface& iface, void* userdata)
1939{
1940 return SDL::OpenIO(iface, userdata);
1941}
1942
1972inline void CloseIO(IOStreamRaw context) { CheckError(SDL_CloseIO(context)); }
1973
1974inline void IOStream::Close() { CloseIO(release()); }
1975
1988{
1989 return {CheckError(SDL_GetIOProperties(context))};
1990}
1991
1993{
1994 return SDL::GetIOProperties(m_resource);
1995}
1996
2016{
2017 return SDL_GetIOStatus(context);
2018}
2019
2021{
2022 return SDL::GetIOStatus(m_resource);
2023}
2024
2037{
2038 return CheckError(SDL_GetIOSize(context));
2039}
2040
2041inline Sint64 IOStream::GetSize() const { return SDL::GetIOSize(m_resource); }
2042
2069inline Sint64 SeekIO(IOStreamParam context, Sint64 offset, IOWhence whence)
2070{
2071 return SDL_SeekIO(context, offset, whence);
2072}
2073
2074inline Sint64 IOStream::Seek(Sint64 offset, IOWhence whence)
2075{
2076 return SDL::SeekIO(m_resource, offset, whence);
2077}
2078
2097inline Sint64 TellIO(IOStreamParam context) { return SDL_TellIO(context); }
2098
2099inline Sint64 IOStream::Tell() const { return SDL::TellIO(m_resource); }
2100
2124inline size_t ReadIO(IOStreamParam context, TargetBytes buf)
2125{
2126 return SDL_ReadIO(context, buf.data(), buf.size_bytes());
2127}
2128
2129inline size_t IOStream::Read(TargetBytes buf)
2130{
2131 return SDL::ReadIO(m_resource, std::move(buf));
2132}
2133
2163inline size_t WriteIO(IOStreamParam context, SourceBytes buf)
2164{
2165 return SDL_WriteIO(context, buf.data(), buf.size_bytes());
2166}
2167
2169{
2170 return SDL::WriteIO(m_resource, std::move(buf));
2171}
2172
2194inline size_t IOprintf(IOStreamParam context,
2195 SDL_PRINTF_FORMAT_STRING const char* fmt,
2196 ...)
2197{
2198 va_list ap;
2199 size_t result;
2200
2201 va_start(ap, fmt);
2202 result = SDL_IOvprintf(context, fmt, ap);
2203 va_end(ap);
2204
2205 return result;
2206}
2207
2226inline size_t IOvprintf(IOStreamParam context,
2227 SDL_PRINTF_FORMAT_STRING const char* fmt,
2228 va_list ap)
2229{
2230 return SDL_IOvprintf(context, fmt, ap);
2231}
2232
2233inline size_t IOStream::vprintf(SDL_PRINTF_FORMAT_STRING const char* fmt,
2234 va_list ap)
2235{
2236 return SDL::IOvprintf(m_resource, fmt, ap);
2237}
2238
2256inline void FlushIO(IOStreamParam context) { CheckError(SDL_FlushIO(context)); }
2257
2258inline void IOStream::Flush() { SDL::FlushIO(m_resource); }
2259
2282inline StringResult LoadFile(IOStreamParam src, bool closeio = true)
2283{
2284 size_t datasize = 0;
2285 auto data = static_cast<char*>(SDL_LoadFile_IO(src, &datasize, closeio));
2286 return StringResult{CheckError(data), datasize};
2287}
2288
2308{
2309 size_t datasize = 0;
2310 auto data = static_cast<char*>(SDL_LoadFile(file, &datasize));
2311 return StringResult{CheckError(data), datasize};
2312}
2313
2315{
2316 return SDL::LoadFile(m_resource, false);
2317}
2318
2337template<class T>
2339{
2340 size_t datasize = 0;
2341 auto data = static_cast<T*>(SDL_LoadFile(file, &datasize));
2342 return OwnArray<T>{CheckError(data), datasize / sizeof(T)};
2343}
2344
2361inline void SaveFile(IOStreamParam src, SourceBytes data, bool closeio = false)
2362{
2363 CheckError(SDL_SaveFile_IO(src, data.data(), data.size_bytes(), closeio));
2364}
2365
2380inline void SaveFile(StringParam file, SourceBytes data)
2381{
2382 CheckError(SDL_SaveFile(file, data.data(), data.size_bytes()));
2383}
2384
2386{
2387 SDL::SaveFile(m_resource, std::move(data));
2388}
2389
2407{
2408 Uint8 value;
2409 CheckError(SDL_ReadU8(src, &value));
2410 return value;
2411}
2412
2430{
2431 Sint8 value;
2432 CheckError(SDL_ReadS8(src, &value));
2433 return value;
2434}
2435
2457{
2458 Uint16 value;
2459 CheckError(SDL_ReadU16LE(src, &value));
2460 return value;
2461}
2462
2463inline Uint16 IOStream::ReadU16LE() { return SDL::ReadU16LE(m_resource); }
2464
2486{
2487 Sint16 value;
2488 CheckError(SDL_ReadS16LE(src, &value));
2489 return value;
2490}
2491
2492inline Sint16 IOStream::ReadS16LE() { return SDL::ReadS16LE(m_resource); }
2493
2515{
2516 Uint16 value;
2517 CheckError(SDL_ReadU16BE(src, &value));
2518 return value;
2519}
2520
2521inline Uint16 IOStream::ReadU16BE() { return SDL::ReadU16BE(m_resource); }
2522
2544{
2545 Sint16 value;
2546 CheckError(SDL_ReadS16BE(src, &value));
2547 return value;
2548}
2549
2550inline Sint16 IOStream::ReadS16BE() { return SDL::ReadS16BE(m_resource); }
2551
2573{
2574 Uint32 value;
2575 CheckError(SDL_ReadU32LE(src, &value));
2576 return value;
2577}
2578
2579inline Uint32 IOStream::ReadU32LE() { return SDL::ReadU32LE(m_resource); }
2580
2602{
2603 Sint32 value;
2604 CheckError(SDL_ReadS32LE(src, &value));
2605 return value;
2606}
2607
2608inline Sint32 IOStream::ReadS32LE() { return SDL::ReadS32LE(m_resource); }
2609
2631{
2632 Uint32 value;
2633 CheckError(SDL_ReadU32BE(src, &value));
2634 return value;
2635}
2636
2637inline Uint32 IOStream::ReadU32BE() { return SDL::ReadU32BE(m_resource); }
2638
2660{
2661 Sint32 value;
2662 CheckError(SDL_ReadS32BE(src, &value));
2663 return value;
2664}
2665
2666inline Sint32 IOStream::ReadS32BE() { return SDL::ReadS32BE(m_resource); }
2667
2689{
2690 Uint64 value;
2691 CheckError(SDL_ReadU64LE(src, &value));
2692 return value;
2693}
2694
2695inline Uint64 IOStream::ReadU64LE() { return SDL::ReadU64LE(m_resource); }
2696
2718{
2719 Sint64 value;
2720 CheckError(SDL_ReadS64LE(src, &value));
2721 return value;
2722}
2723
2724inline Sint64 IOStream::ReadS64LE() { return SDL::ReadS64LE(m_resource); }
2725
2747{
2748 Uint64 value;
2749 CheckError(SDL_ReadU64BE(src, &value));
2750 return value;
2751}
2752
2753inline Uint64 IOStream::ReadU64BE() { return SDL::ReadU64BE(m_resource); }
2754
2776{
2777 Sint64 value;
2778 CheckError(SDL_ReadS64BE(src, &value));
2779 return value;
2780}
2781
2782inline Sint64 IOStream::ReadS64BE() { return SDL::ReadS64BE(m_resource); }
2783
2795inline void WriteU8(IOStreamParam dst, Uint8 value)
2796{
2797 CheckError(SDL_WriteU8(dst, value));
2798}
2799
2800inline void IOStream::WriteU8(Uint8 value) { SDL::WriteU8(m_resource, value); }
2801
2813inline void WriteS8(IOStreamParam dst, Sint8 value)
2814{
2815 CheckError(SDL_WriteS8(dst, value));
2816}
2817
2818inline void IOStream::WriteS8(Sint8 value) { SDL::WriteS8(m_resource, value); }
2819
2835inline void WriteU16LE(IOStreamParam dst, Uint16 value)
2836{
2837 CheckError(SDL_WriteU16LE(dst, value));
2838}
2839
2841{
2842 SDL::WriteU16LE(m_resource, value);
2843}
2844
2860inline void WriteS16LE(IOStreamParam dst, Sint16 value)
2861{
2862 CheckError(SDL_WriteS16LE(dst, value));
2863}
2864
2866{
2867 SDL::WriteS16LE(m_resource, value);
2868}
2869
2885inline void WriteU16BE(IOStreamParam dst, Uint16 value)
2886{
2887 CheckError(SDL_WriteU16BE(dst, value));
2888}
2889
2891{
2892 SDL::WriteU16BE(m_resource, value);
2893}
2894
2910inline void WriteS16BE(IOStreamParam dst, Sint16 value)
2911{
2912 CheckError(SDL_WriteS16BE(dst, value));
2913}
2914
2916{
2917 SDL::WriteS16BE(m_resource, value);
2918}
2919
2935inline void WriteU32LE(IOStreamParam dst, Uint32 value)
2936{
2937 CheckError(SDL_WriteU32LE(dst, value));
2938}
2939
2941{
2942 SDL::WriteU32LE(m_resource, value);
2943}
2944
2960inline void WriteS32LE(IOStreamParam dst, Sint32 value)
2961{
2962 CheckError(SDL_WriteS32LE(dst, value));
2963}
2964
2966{
2967 SDL::WriteS32LE(m_resource, value);
2968}
2969
2985inline void WriteU32BE(IOStreamParam dst, Uint32 value)
2986{
2987 CheckError(SDL_WriteU32BE(dst, value));
2988}
2989
2991{
2992 SDL::WriteU32BE(m_resource, value);
2993}
2994
3010inline void WriteS32BE(IOStreamParam dst, Sint32 value)
3011{
3012 CheckError(SDL_WriteS32BE(dst, value));
3013}
3014
3016{
3017 SDL::WriteS32BE(m_resource, value);
3018}
3019
3035inline void WriteU64LE(IOStreamParam dst, Uint64 value)
3036{
3037 CheckError(SDL_WriteU64LE(dst, value));
3038}
3039
3041{
3042 SDL::WriteU64LE(m_resource, value);
3043}
3044
3060inline void WriteS64LE(IOStreamParam dst, Sint64 value)
3061{
3062 CheckError(SDL_WriteS64LE(dst, value));
3063}
3064
3066{
3067 SDL::WriteS64LE(m_resource, value);
3068}
3069
3085inline void WriteU64BE(IOStreamParam dst, Uint64 value)
3086{
3087 CheckError(SDL_WriteU64BE(dst, value));
3088}
3089
3091{
3092 SDL::WriteU64BE(m_resource, value);
3093}
3094
3110inline void WriteS64BE(IOStreamParam dst, Sint64 value)
3111{
3112 CheckError(SDL_WriteS64BE(dst, value));
3113}
3114
3116{
3117 SDL::WriteS64BE(m_resource, value);
3118}
3119
3121
3122} // namespace SDL
3123
3124#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:1112
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:1160
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:1376
constexpr IOStreamRaw release() noexcept
Retrieves underlying IOStreamRaw and clear this.
Definition: SDL3pp_iostream.h:408
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:1184
constexpr IOStream(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition: SDL3pp_iostream.h:136
~IOStream()
Destructor.
Definition: SDL3pp_iostream.h:390
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:1256
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:1136
constexpr IOStreamRaw get() const noexcept
Retrieves underlying IOStreamRaw.
Definition: SDL3pp_iostream.h:405
OwnArray< T > LoadFileAs()
Load all the data from an SDL data stream.
Definition: SDL3pp_iostream.h:769
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:1208
size_t printf(SDL_PRINTF_FORMAT_STRING const char *fmt,...)
Print to an IOStream data stream.
Definition: SDL3pp_iostream.h:682
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:1328
constexpr IOStream(IOStream &&other) noexcept
Move constructor.
Definition: SDL3pp_iostream.h:157
size_t print(std::string_view fmt, auto... args)
Prints formatted string.
Definition: SDL3pp_iostream.h:643
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:1232
std::optional< Uint8 > TryReadU8()
Use this function to read a byte from an IOStreamRef.
Definition: SDL3pp_iostream.h:1092
constexpr IOStream & operator=(IOStream &&other) noexcept
Assignment operator.
Definition: SDL3pp_iostream.h:393
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:1280
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:1304
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:1400
constexpr IOStream(const IOStreamRaw resource) noexcept
Constructs from IOStreamParam.
Definition: SDL3pp_iostream.h:148
constexpr IOStream(const IOStream &other)=delete
Copy constructor.
size_t println(std::string_view fmt, auto... args)
Prints formatted string.
Definition: SDL3pp_iostream.h:655
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:1352
std::string Read(size_t size=-1)
Read from a data source.
Definition: SDL3pp_iostream.h:565
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:197
Sint64 GetSize() const
Use this function to get the size of the data stream in an IOStream.
Definition: SDL3pp_iostream.h:2041
IOStream IOFromMem(TargetBytes mem)
Use this function to prepare a read-write memory buffer for use with IOStream.
Definition: SDL3pp_iostream.h:1818
size_t IOprintf(IOStreamParam context, SDL_PRINTF_FORMAT_STRING const char *fmt,...)
Print to an IOStream data stream.
Definition: SDL3pp_iostream.h:2194
Uint8 ReadU8(IOStreamParam src)
Use this function to read a byte from an IOStream.
Definition: SDL3pp_iostream.h:2406
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:2940
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:3015
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:2965
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:2910
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:3090
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:2775
IOStream OpenIO(const IOStreamInterface &iface, void *userdata)
Create a custom IOStream.
Definition: SDL3pp_iostream.h:1933
IOStatus GetIOStatus(IOStreamParam context)
Query the stream status of an IOStream.
Definition: SDL3pp_iostream.h:2015
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:2521
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:2385
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:2543
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:2960
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:2990
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:2666
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:2865
void WriteS8(Sint8 value)
Use this function to write a signed byte to an IOStream.
Definition: SDL3pp_iostream.h:2818
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:2572
size_t ReadIO(IOStreamParam context, TargetBytes buf)
Read from a data source.
Definition: SDL3pp_iostream.h:2124
void Flush()
Flush any buffered data in the stream.
Definition: SDL3pp_iostream.h:2258
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:2935
IOStream IOFromConstMem(SourceBytes mem)
Use this function to prepare a read-only memory buffer for use with IOStream.
Definition: SDL3pp_iostream.h:1865
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:2429
size_t vprintf(SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap)
Print to an IOStream data stream.
Definition: SDL3pp_iostream.h:2233
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:2463
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:2485
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:2579
IOStream IOFromDynamicMem()
Use this function to create an IOStream that is backed by dynamically allocated memory.
Definition: SDL3pp_iostream.h:1902
void Close()
Close and free an allocated IOStream structure.
Definition: SDL3pp_iostream.h:1974
OwnArray< T > LoadFileAs(StringParam file)
Load all the data from a file path.
Definition: SDL3pp_iostream.h:2338
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:3115
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:2226
Sint64 TellIO(IOStreamParam context)
Determine the current read/write offset in an IOStream data stream.
Definition: SDL3pp_iostream.h:2097
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:2688
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:2915
static IOStream Open(const IOStreamInterface &iface, void *userdata)
Create a custom IOStream.
Definition: SDL3pp_iostream.h:1938
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:2601
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:2630
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:2637
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:1746
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:2717
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:2514
void WriteU8(IOStreamParam dst, Uint8 value)
Use this function to write a byte to an IOStream.
Definition: SDL3pp_iostream.h:2795
Sint64 GetIOSize(IOStreamParam context)
Use this function to get the size of the data stream in an IOStream.
Definition: SDL3pp_iostream.h:2036
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:2985
Sint64 Seek(Sint64 offset, IOWhence whence)
Seek within an IOStream data stream.
Definition: SDL3pp_iostream.h:2074
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:3010
Sint64 SeekIO(IOStreamParam context, Sint64 offset, IOWhence whence)
Seek within an IOStream data stream.
Definition: SDL3pp_iostream.h:2069
size_t Write(SourceBytes buf)
Write to an IOStream data stream.
Definition: SDL3pp_iostream.h:2168
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:2835
Sint64 Tell() const
Determine the current read/write offset in an IOStream data stream.
Definition: SDL3pp_iostream.h:2099
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:2890
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:2608
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:2550
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:1987
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:2782
static IOStream FromDynamicMem()
Use this function to create an IOStream that is backed by dynamically allocated memory.
Definition: SDL3pp_iostream.h:1904
static IOStream FromConstMem(SourceBytes mem)
Use this function to prepare a read-only memory buffer for use with IOStream.
Definition: SDL3pp_iostream.h:1870
StringResult LoadFile()
Load all the data from an SDL data stream.
Definition: SDL3pp_iostream.h:2314
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:2840
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:2695
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:2800
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:2753
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:2813
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:2860
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:2724
void FlushIO(IOStreamParam context)
Flush any buffered data in the stream.
Definition: SDL3pp_iostream.h:2256
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:2746
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:2659
void SaveFile(IOStreamParam src, SourceBytes data, bool closeio=false)
Save all the data into an SDL data stream.
Definition: SDL3pp_iostream.h:2361
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:3040
StringResult LoadFile(IOStreamParam src, bool closeio=true)
Load all the data from an SDL data stream.
Definition: SDL3pp_iostream.h:2282
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:1751
void CloseIO(IOStreamRaw context)
Close and free an allocated IOStream structure.
Definition: SDL3pp_iostream.h:1972
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:3065
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:2492
IOStatus GetStatus() const
Query the stream status of an IOStream.
Definition: SDL3pp_iostream.h:2020
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:3085
size_t WriteIO(IOStreamParam context, SourceBytes buf)
Write to an IOStream data stream.
Definition: SDL3pp_iostream.h:2163
static IOStream FromMem(TargetBytes mem)
Use this function to prepare a read-write memory buffer for use with IOStream.
Definition: SDL3pp_iostream.h:1823
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:2456
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:3035
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:3060
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:3110
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:1992
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:2885
::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:1631
IOStreamRef(IOStreamRaw resource) noexcept
Constructs from IOStreamParam.
Definition: SDL3pp_iostream.h:1653
~IOStreamRef()
Destructor.
Definition: SDL3pp_iostream.h:1665
IOStreamRef(IOStreamParam resource) noexcept
Constructs from IOStreamParam.
Definition: SDL3pp_iostream.h:1641
IOStreamRef(const IOStreamRef &other) noexcept
Copy constructor.
Definition: SDL3pp_iostream.h:1659
Semi-safe reference for Properties.
Definition: SDL3pp_properties.h:708
A simple std::string-like interface for SDL allocated strings.
Definition: SDL3pp_strings.h:153