SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL3pp_iostream.h
1#ifndef SDL3PP_IOSTREAM_H_
2#define SDL3PP_IOSTREAM_H_
3
4#include <SDL3/SDL_iostream.h>
5#include "SDL3pp_properties.h"
6#include "SDL3pp_stdinc.h"
7
8namespace SDL {
9
22
23// Forward decl
24struct IOStreamBase;
25
26// Forward decl
27struct IOStream;
28
30using IOStreamRaw = SDL_IOStream*;
31
38
44using IOStatus = SDL_IOStatus;
45
47 SDL_IO_STATUS_READY;
48
50 SDL_IO_STATUS_ERROR;
51
52constexpr IOStatus IO_STATUS_EOF = SDL_IO_STATUS_EOF;
53
55 SDL_IO_STATUS_NOT_READY;
56
58 SDL_IO_STATUS_READONLY;
59
61 SDL_IO_STATUS_WRITEONLY;
62
71using IOWhence = SDL_IOWhence;
72
74 SDL_IO_SEEK_SET;
75
77 SDL_IO_SEEK_CUR;
78
80 SDL_IO_SEEK_END;
81
96using IOStreamInterface = SDL_IOStreamInterface;
97
103struct IOStreamBase : ResourceBaseT<IOStreamRaw>
104{
106
135 void Close();
136
148
166 IOStatus GetStatus() const;
167
178 Sint64 GetSize() const;
179
205 Sint64 Seek(Sint64 offset, IOWhence whence);
206
223 Sint64 Tell() const;
224
247 std::string Read(size_t size = -1)
248 {
249 Sint64 pos = Tell();
250 if (auto curSize = SDL_GetIOSize(get()); curSize < 0 || pos < 0) {
251 if (size == size_t(-1)) return {};
252 } else if (curSize - pos <= 0) {
253 return {};
254 } else if (size_t(curSize - pos) < size) {
255 size = curSize - pos;
256 }
257 std::string result(size, 0);
258 if (auto actualSize = Read(result); actualSize < size) {
259 result.resize(actualSize);
260 }
261 return result;
262 }
263
290 size_t Read(TargetBytes buf);
291
324 size_t Write(SourceBytes buf);
325
333 size_t print(std::string_view fmt, auto... args)
334 {
335 return Write(std::vformat(fmt, std::make_format_args(args...)));
336 }
337
345 size_t println(std::string_view fmt, auto... args)
346 {
347 std::string result =
348 std::vformat(fmt, std::make_format_args(args...)) + "\n";
349 return Write(result);
350 }
351
372 size_t printf(SDL_PRINTF_FORMAT_STRING const char* fmt, ...)
373 {
374 va_list ap;
375 size_t result;
376
377 va_start(ap, fmt);
378 result = SDL_IOvprintf(get(), fmt, ap);
379 va_end(ap);
380
381 return result;
382 }
383
403 size_t vprintf(SDL_PRINTF_FORMAT_STRING const char* fmt, va_list ap);
404
421 void Flush();
422
440
458 template<class T>
460 {
461 size_t datasize = 0;
462 auto data = static_cast<T*>(SDL_LoadFile_IO(get(), &datasize, false));
463 return OwnArray<T>{CheckError(data), datasize / sizeof(T)};
464 }
465
480 void SaveFile(SourceBytes data);
481
497 Uint8 ReadU8();
498
514 Sint8 ReadS8();
515
536
557
578
599
620
641
662
683
704
725
746
767
782 std::optional<Uint8> TryReadU8() const
783 {
784 if (Uint8 value; SDL_ReadU8(get(), &value)) return value;
785 return {};
786 }
787
802 std::optional<Sint8> TryReadS8() const
803 {
804 if (Sint8 value; SDL_ReadS8(get(), &value)) return value;
805 return {};
806 }
807
826 std::optional<Uint16> TryReadU16LE() const
827 {
828 if (Uint16 value; SDL_ReadU16LE(get(), &value)) return value;
829 return {};
830 }
831
850 std::optional<Sint16> TryReadS16LE() const
851 {
852 if (Sint16 value; SDL_ReadS16LE(get(), &value)) return value;
853 return {};
854 }
855
874 std::optional<Uint16> TryReadU16BE() const
875 {
876 if (Uint16 value; SDL_ReadU16BE(get(), &value)) return value;
877 return {};
878 }
879
898 std::optional<Sint16> TryReadS16BE() const
899 {
900 if (Sint16 value; SDL_ReadS16BE(get(), &value)) return value;
901 return {};
902 }
903
922 std::optional<Uint32> TryReadU32LE() const
923 {
924 if (Uint32 value; SDL_ReadU32LE(get(), &value)) return value;
925 return {};
926 }
927
946 std::optional<Sint32> TryReadS32LE() const
947 {
948 if (Sint32 value; SDL_ReadS32LE(get(), &value)) return value;
949 return {};
950 }
951
970 std::optional<Uint32> TryReadU32BE() const
971 {
972 if (Uint32 value; SDL_ReadU32BE(get(), &value)) return value;
973 return {};
974 }
975
994 std::optional<Sint32> TryReadS32BE() const
995 {
996 if (Sint32 value; SDL_ReadS32BE(get(), &value)) return value;
997 return {};
998 }
999
1018 std::optional<Uint64> TryReadU64LE() const
1019 {
1020 if (Uint64 value; SDL_ReadU64LE(get(), &value)) return value;
1021 return {};
1022 }
1023
1042 std::optional<Sint64> TryReadS64LE() const
1043 {
1044 if (Sint64 value; SDL_ReadS64LE(get(), &value)) return value;
1045 return {};
1046 }
1047
1066 std::optional<Uint64> TryReadU64BE() const
1067 {
1068 if (Uint64 value; SDL_ReadU64BE(get(), &value)) return value;
1069 return {};
1070 }
1071
1090 std::optional<Sint64> TryReadS64BE() const
1091 {
1092 if (Sint64 value; SDL_ReadS64BE(get(), &value)) return value;
1093 return {};
1094 }
1095
1106 void WriteU8(Uint8 value);
1107
1118 void WriteS8(Sint8 value);
1119
1135 void WriteU16LE(Uint16 value);
1136
1152 void WriteS16LE(Sint16 value);
1153
1168 void WriteU16BE(Uint16 value);
1169
1184 void WriteS16BE(Sint16 value);
1185
1201 void WriteU32LE(Uint32 value);
1202
1218 void WriteS32LE(Sint32 value);
1219
1234 void WriteU32BE(Uint32 value);
1235
1250 void WriteS32BE(Sint32 value);
1251
1267 void WriteU64LE(Uint64 value);
1268
1284 void WriteS64LE(Sint64 value);
1285
1300 void WriteU64BE(Uint64 value);
1301
1316 void WriteS64BE(Sint64 value);
1317};
1318
1332{
1333 using IOStreamBase::IOStreamBase;
1334
1342 constexpr explicit IOStream(IOStreamRaw resource) noexcept
1343 : IOStreamBase(resource)
1344 {
1345 }
1346
1348 constexpr IOStream(IOStream&& other) noexcept
1349 : IOStream(other.release())
1350 {
1351 }
1352
1439 static IOStream FromFile(StringParam file, StringParam mode);
1440
1484 static IOStream FromMem(TargetBytes mem);
1485
1530 static IOStream FromConstMem(SourceBytes mem);
1531
1559 static IOStream FromDynamicMem();
1560
1588 static IOStream Open(const IOStreamInterface& iface, void* userdata);
1589
1591 ~IOStream() { SDL_CloseIO(get()); }
1592
1594 constexpr IOStream& operator=(IOStream&& other) noexcept
1595 {
1596 swap(*this, other);
1597 return *this;
1598 }
1599};
1600
1684{
1685 return IOStream(SDL_IOFromFile(file, mode));
1686}
1687
1689{
1690 return SDL::IOFromFile(file, mode);
1691}
1692
1708
1710 SDL_PROP_IOSTREAM_WINDOWS_HANDLE_POINTER;
1711
1712constexpr auto STDIO_FILE_POINTER =
1713 SDL_PROP_IOSTREAM_STDIO_FILE_POINTER;
1714
1716 SDL_PROP_IOSTREAM_FILE_DESCRIPTOR_NUMBER;
1717
1719 SDL_PROP_IOSTREAM_ANDROID_AASSET_POINTER;
1720
1721constexpr auto MEMORY_POINTER =
1722 SDL_PROP_IOSTREAM_MEMORY_POINTER;
1723
1724constexpr auto MEMORY_SIZE_NUMBER =
1725 SDL_PROP_IOSTREAM_MEMORY_SIZE_NUMBER;
1726
1727#if SDL_VERSION_ATLEAST(3, 4, 0)
1728
1730 SDL_PROP_IOSTREAM_MEMORY_FREE_FUNC_POINTER;
1731
1732#endif // SDL_VERSION_ATLEAST(3, 4, 0)
1733
1735 SDL_PROP_IOSTREAM_DYNAMIC_MEMORY_POINTER;
1736
1738 SDL_PROP_IOSTREAM_DYNAMIC_CHUNKSIZE_NUMBER;
1739
1740} // namespace prop::IOStream
1741
1786{
1787 return IOStream(CheckError(SDL_IOFromMem(mem.data(), mem.size_bytes())));
1788}
1789
1791{
1792 return SDL::IOFromMem(std::move(mem));
1793}
1794
1839{
1840 return IOStream(CheckError(SDL_IOFromConstMem(mem.data(), mem.size_bytes())));
1841}
1842
1844{
1845 return SDL::IOFromConstMem(std::move(mem));
1846}
1847
1875inline IOStream IOFromDynamicMem() { return IOStream(SDL_IOFromDynamicMem()); }
1876
1878
1906inline IOStream OpenIO(const IOStreamInterface& iface, void* userdata)
1907{
1908 return IOStream(CheckError(SDL_OpenIO(&iface, userdata)));
1909}
1910
1911inline IOStream IOStream::Open(const IOStreamInterface& iface, void* userdata)
1912{
1913 return SDL::OpenIO(iface, userdata);
1914}
1915
1944inline void CloseIO(IOStreamRaw context) { CheckError(SDL_CloseIO(context)); }
1945
1947
1960{
1961 return CheckError(SDL_GetIOProperties(context));
1962}
1963
1965{
1966 return SDL::GetIOProperties(get());
1967}
1968
1988{
1989 return SDL_GetIOStatus(context);
1990}
1991
1993{
1994 return SDL::GetIOStatus(get());
1995}
1996
2009{
2010 return CheckError(SDL_GetIOSize(context));
2011}
2012
2013inline Sint64 IOStreamBase::GetSize() const { return SDL::GetIOSize(get()); }
2014
2041inline Sint64 SeekIO(IOStreamRef context, Sint64 offset, IOWhence whence)
2042{
2043 return SDL_SeekIO(context, offset, whence);
2044}
2045
2047{
2048 return SDL::SeekIO(get(), offset, whence);
2049}
2050
2069inline Sint64 TellIO(IOStreamRef context) { return SDL_TellIO(context); }
2070
2071inline Sint64 IOStreamBase::Tell() const { return SDL::TellIO(get()); }
2072
2100inline size_t ReadIO(IOStreamRef context, TargetBytes buf)
2101{
2102 return SDL_ReadIO(context, buf.data(), buf.size_bytes());
2103}
2104
2106{
2107 return SDL::ReadIO(get(), std::move(buf));
2108}
2109
2143inline size_t WriteIO(IOStreamRef context, SourceBytes buf)
2144{
2145 return SDL_WriteIO(context, buf.data(), buf.size_bytes());
2146}
2147
2149{
2150 return SDL::WriteIO(get(), std::move(buf));
2151}
2152
2174inline size_t IOprintf(IOStreamRef context,
2175 SDL_PRINTF_FORMAT_STRING const char* fmt,
2176 ...)
2177{
2178 va_list ap;
2179 size_t result;
2180
2181 va_start(ap, fmt);
2182 result = SDL_IOvprintf(context, fmt, ap);
2183 va_end(ap);
2184
2185 return result;
2186}
2187
2206inline size_t IOvprintf(IOStreamRef context,
2207 SDL_PRINTF_FORMAT_STRING const char* fmt,
2208 va_list ap)
2209{
2210 return SDL_IOvprintf(context, fmt, ap);
2211}
2212
2213inline size_t IOStreamBase::vprintf(SDL_PRINTF_FORMAT_STRING const char* fmt,
2214 va_list ap)
2215{
2216 return SDL::IOvprintf(get(), fmt, ap);
2217}
2218
2236inline void FlushIO(IOStreamRef context) { CheckError(SDL_FlushIO(context)); }
2237
2239
2262inline StringResult LoadFile_IO(IOStreamRef src, bool closeio = true)
2263{
2264 size_t datasize = 0;
2265 auto data = static_cast<char*>(SDL_LoadFile_IO(src, &datasize, closeio));
2266 return StringResult{CheckError(data), datasize};
2267}
2268
2270
2289template<class T>
2291{
2292 size_t datasize = 0;
2293 auto data = static_cast<T*>(SDL_LoadFile(file, &datasize));
2294 return OwnArray<T>{CheckError(data), datasize / sizeof(T)};
2295}
2296
2316{
2317 size_t datasize = 0;
2318 auto data = static_cast<char*>(SDL_LoadFile(file, &datasize));
2319 return StringResult{CheckError(data), datasize};
2320}
2321
2339inline void SaveFile_IO(IOStreamRef src, SourceBytes data, bool closeio = true)
2340{
2341 CheckError(SDL_SaveFile_IO(src, data.data(), data.size_bytes(), closeio));
2342}
2343
2345{
2346 SDL::SaveFile_IO(get(), std::move(data));
2347}
2348
2363inline void SaveFile(StringParam file, SourceBytes data)
2364{
2365 CheckError(SDL_SaveFile(file, data.data(), data.size_bytes()));
2366}
2367
2385{
2386 Uint8 value;
2387 CheckError(SDL_ReadU8(src, &value));
2388 return value;
2389}
2390
2392
2410{
2411 Sint8 value;
2412 CheckError(SDL_ReadS8(src, &value));
2413 return value;
2414}
2415
2417
2439{
2440 Uint16 value;
2441 CheckError(SDL_ReadU16LE(src, &value));
2442 return value;
2443}
2444
2446
2468{
2469 Sint16 value;
2470 CheckError(SDL_ReadS16LE(src, &value));
2471 return value;
2472}
2473
2475
2497{
2498 Uint16 value;
2499 CheckError(SDL_ReadU16BE(src, &value));
2500 return value;
2501}
2502
2504
2526{
2527 Sint16 value;
2528 CheckError(SDL_ReadS16BE(src, &value));
2529 return value;
2530}
2531
2533
2555{
2556 Uint32 value;
2557 CheckError(SDL_ReadU32LE(src, &value));
2558 return value;
2559}
2560
2562
2584{
2585 Sint32 value;
2586 CheckError(SDL_ReadS32LE(src, &value));
2587 return value;
2588}
2589
2591
2613{
2614 Uint32 value;
2615 CheckError(SDL_ReadU32BE(src, &value));
2616 return value;
2617}
2618
2620
2642{
2643 Sint32 value;
2644 CheckError(SDL_ReadS32BE(src, &value));
2645 return value;
2646}
2647
2649
2671{
2672 Uint64 value;
2673 CheckError(SDL_ReadU64LE(src, &value));
2674 return value;
2675}
2676
2678
2700{
2701 Sint64 value;
2702 CheckError(SDL_ReadS64LE(src, &value));
2703 return value;
2704}
2705
2707
2729{
2730 Uint64 value;
2731 CheckError(SDL_ReadU64BE(src, &value));
2732 return value;
2733}
2734
2736
2758{
2759 Sint64 value;
2760 CheckError(SDL_ReadS64BE(src, &value));
2761 return value;
2762}
2763
2765
2777inline void WriteU8(IOStreamRef dst, Uint8 value)
2778{
2779 CheckError(SDL_WriteU8(dst, value));
2780}
2781
2782inline void IOStreamBase::WriteU8(Uint8 value) { SDL::WriteU8(get(), value); }
2783
2795inline void WriteS8(IOStreamRef dst, Sint8 value)
2796{
2797 CheckError(SDL_WriteS8(dst, value));
2798}
2799
2800inline void IOStreamBase::WriteS8(Sint8 value) { SDL::WriteS8(get(), value); }
2801
2817inline void WriteU16LE(IOStreamRef dst, Uint16 value)
2818{
2819 CheckError(SDL_WriteU16LE(dst, value));
2820}
2821
2823{
2824 SDL::WriteU16LE(get(), value);
2825}
2826
2842inline void WriteS16LE(IOStreamRef dst, Sint16 value)
2843{
2844 CheckError(SDL_WriteS16LE(dst, value));
2845}
2846
2848{
2849 SDL::WriteS16LE(get(), value);
2850}
2851
2867inline void WriteU16BE(IOStreamRef dst, Uint16 value)
2868{
2869 CheckError(SDL_WriteU16BE(dst, value));
2870}
2871
2873{
2874 SDL::WriteU16BE(get(), value);
2875}
2876
2892inline void WriteS16BE(IOStreamRef dst, Sint16 value)
2893{
2894 CheckError(SDL_WriteS16BE(dst, value));
2895}
2896
2898{
2899 SDL::WriteS16BE(get(), value);
2900}
2901
2917inline void WriteU32LE(IOStreamRef dst, Uint32 value)
2918{
2919 CheckError(SDL_WriteU32LE(dst, value));
2920}
2921
2923{
2924 SDL::WriteU32LE(get(), value);
2925}
2926
2942inline void WriteS32LE(IOStreamRef dst, Sint32 value)
2943{
2944 CheckError(SDL_WriteS32LE(dst, value));
2945}
2946
2948{
2949 SDL::WriteS32LE(get(), value);
2950}
2951
2967inline void WriteU32BE(IOStreamRef dst, Uint32 value)
2968{
2969 CheckError(SDL_WriteU32BE(dst, value));
2970}
2971
2973{
2974 SDL::WriteU32BE(get(), value);
2975}
2976
2992inline void WriteS32BE(IOStreamRef dst, Sint32 value)
2993{
2994 CheckError(SDL_WriteS32BE(dst, value));
2995}
2996
2998{
2999 SDL::WriteS32BE(get(), value);
3000}
3001
3017inline void WriteU64LE(IOStreamRef dst, Uint64 value)
3018{
3019 CheckError(SDL_WriteU64LE(dst, value));
3020}
3021
3023{
3024 SDL::WriteU64LE(get(), value);
3025}
3026
3042inline void WriteS64LE(IOStreamRef dst, Sint64 value)
3043{
3044 CheckError(SDL_WriteS64LE(dst, value));
3045}
3046
3048{
3049 SDL::WriteS64LE(get(), value);
3050}
3051
3067inline void WriteU64BE(IOStreamRef dst, Uint64 value)
3068{
3069 CheckError(SDL_WriteU64BE(dst, value));
3070}
3071
3073{
3074 SDL::WriteU64BE(get(), value);
3075}
3076
3092inline void WriteS64BE(IOStreamRef dst, Sint64 value)
3093{
3094 CheckError(SDL_WriteS64BE(dst, value));
3095}
3096
3098{
3099 SDL::WriteS64BE(get(), value);
3100}
3101
3103
3104} // namespace SDL
3105
3106#endif /* SDL3PP_IOSTREAM_H_ */
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:44
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:57
friend constexpr void swap(ResourceBaseT &lhs, ResourceBaseT &rhs) noexcept
Definition SDL3pp_resource.h:65
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:54
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
Source byte stream.
Definition SDL3pp_strings.h:246
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition SDL3pp_strings.h:310
constexpr const char * data() const
Retrieves contained data.
Definition SDL3pp_strings.h:313
Helpers to use C++ strings parameters.
Definition SDL3pp_strings.h:58
Target byte stream.
Definition SDL3pp_strings.h:332
constexpr char * data() const
Retrieves contained data.
Definition SDL3pp_strings.h:418
constexpr size_t size_bytes() const
Retrieves contained size in bytes.
Definition SDL3pp_strings.h:415
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:199
void WriteS16BE(IOStreamRef dst, Sint16 value)
Use this function to write 16 bits in native format to an IOStream as big-endian data.
Definition SDL3pp_iostream.h:2892
IOStream IOFromMem(TargetBytes mem)
Use this function to prepare a read-write memory buffer for use with IOStream.
Definition SDL3pp_iostream.h:1785
size_t ReadIO(IOStreamRef context, TargetBytes buf)
Read from a data source.
Definition SDL3pp_iostream.h:2100
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:2897
void FlushIO(IOStreamRef context)
Flush any buffered data in the stream.
Definition SDL3pp_iostream.h:2236
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:3092
SDL_IOWhence IOWhence
Possible whence values for IOStream seeking.
Definition SDL3pp_iostream.h:71
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:2561
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:2619
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:2445
StringResult LoadFile(StringParam file)
Load all the data from a file path.
Definition SDL3pp_iostream.h:2315
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:2847
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:3017
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:2764
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:2972
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:3067
IOStream OpenIO(const IOStreamInterface &iface, void *userdata)
Create a custom IOStream.
Definition SDL3pp_iostream.h:1906
ResourceRefT< IOStreamBase > IOStreamRef
Reference for IOStream.
Definition SDL3pp_iostream.h:37
PropertiesRef GetIOProperties(IOStreamRef context)
Get the properties associated with an IOStream.
Definition SDL3pp_iostream.h:1959
SDL_IOStatus IOStatus
IOStream status, set by a read or write operation.
Definition SDL3pp_iostream.h:44
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:2967
size_t WriteIO(IOStreamRef context, SourceBytes buf)
Write to an IOStream data stream.
Definition SDL3pp_iostream.h:2143
void WriteU8(IOStreamRef dst, Uint8 value)
Use this function to write a byte to an IOStream.
Definition SDL3pp_iostream.h:2777
Sint64 Seek(Sint64 offset, IOWhence whence)
Seek within an IOStream data stream.
Definition SDL3pp_iostream.h:2046
Sint64 TellIO(IOStreamRef context)
Determine the current read/write offset in an IOStream data stream.
Definition SDL3pp_iostream.h:2069
void SaveFile_IO(IOStreamRef src, SourceBytes data, bool closeio=true)
Save all the data into an SDL data stream.
Definition SDL3pp_iostream.h:2339
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:2757
size_t Write(SourceBytes buf)
Write to an IOStream data stream.
Definition SDL3pp_iostream.h:2148
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:2942
SDL_IOStream * IOStreamRaw
Alias to raw representation for IOStream.
Definition SDL3pp_iostream.h:30
size_t IOprintf(IOStreamRef context, SDL_PRINTF_FORMAT_STRING const char *fmt,...)
Print to an IOStream data stream.
Definition SDL3pp_iostream.h:2174
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:2872
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:2612
StringResult LoadFile()
Load all the data from an SDL data stream.
Definition SDL3pp_iostream.h:2269
IOStream IOFromConstMem(SourceBytes mem)
Use this function to prepare a read-only memory buffer for use with IOStream.
Definition SDL3pp_iostream.h:1838
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:3022
IOStatus GetStatus() const
Query the stream status of an IOStream.
Definition SDL3pp_iostream.h:1992
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:2583
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:2641
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:2992
IOStream IOFromDynamicMem()
Use this function to create an IOStream that is backed by dynamically allocated memory.
Definition SDL3pp_iostream.h:1875
OwnArray< T > LoadFileAs(StringParam file)
Load all the data from a file path.
Definition SDL3pp_iostream.h:2290
Uint8 ReadU8(IOStreamRef src)
Use this function to read a byte from an IOStream.
Definition SDL3pp_iostream.h:2384
constexpr IOStatus IO_STATUS_ERROR
Read or write I/O error.
Definition SDL3pp_iostream.h:49
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:2438
PropertiesRef GetProperties() const
Get the properties associated with an IOStream.
Definition SDL3pp_iostream.h:1964
static IOStream Open(const IOStreamInterface &iface, void *userdata)
Create a custom IOStream.
Definition SDL3pp_iostream.h:1911
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:2677
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:3042
IOStream IOFromFile(StringParam file, StringParam mode)
Use this function to create a new IOStream structure for reading from and/or writing to a named file.
Definition SDL3pp_iostream.h:1683
constexpr IOStatus IO_STATUS_EOF
End of file.
Definition SDL3pp_iostream.h:52
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:2842
IOStatus GetIOStatus(IOStreamRef context)
Query the stream status of an IOStream.
Definition SDL3pp_iostream.h:1987
Sint64 GetIOSize(IOStreamRef context)
Use this function to get the size of the data stream in an IOStream.
Definition SDL3pp_iostream.h:2008
Sint64 GetSize() const
Use this function to get the size of the data stream in an IOStream.
Definition SDL3pp_iostream.h:2013
void Flush()
Flush any buffered data in the stream.
Definition SDL3pp_iostream.h:2238
Sint8 ReadS8()
Use this function to read a signed byte from an IOStream.
Definition SDL3pp_iostream.h:2416
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:2554
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:2503
void WriteS8(IOStreamRef dst, Sint8 value)
Use this function to write a signed byte to an IOStream.
Definition SDL3pp_iostream.h:2795
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:2699
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:2206
SDL_IOStreamInterface IOStreamInterface
The function pointers that drive an IOStream.
Definition SDL3pp_iostream.h:96
constexpr IOStatus IO_STATUS_WRITEONLY
Tried to read a write-only buffer.
Definition SDL3pp_iostream.h:60
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:2496
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:3072
Sint8 ReadS8(IOStreamRef src)
Use this function to read a signed byte from an IOStream.
Definition SDL3pp_iostream.h:2409
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:2525
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:2817
Sint64 SeekIO(IOStreamRef context, Sint64 offset, IOWhence whence)
Seek within an IOStream data stream.
Definition SDL3pp_iostream.h:2041
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:2474
size_t vprintf(SDL_PRINTF_FORMAT_STRING const char *fmt, va_list ap)
Print to an IOStream data stream.
Definition SDL3pp_iostream.h:2213
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:2706
static IOStream FromDynamicMem()
Use this function to create an IOStream that is backed by dynamically allocated memory.
Definition SDL3pp_iostream.h:1877
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:2648
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:2922
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:2917
static IOStream FromConstMem(SourceBytes mem)
Use this function to prepare a read-only memory buffer for use with IOStream.
Definition SDL3pp_iostream.h:1843
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:2590
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:2728
void SaveFile(StringParam file, SourceBytes data)
Save all the data into a file path.
Definition SDL3pp_iostream.h:2363
Sint64 Tell() const
Determine the current read/write offset in an IOStream data stream.
Definition SDL3pp_iostream.h:2071
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:2467
constexpr IOWhence IO_SEEK_CUR
Seek relative to current read point.
Definition SDL3pp_iostream.h:76
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:3047
StringResult LoadFile_IO(IOStreamRef src, bool closeio=true)
Load all the data from an SDL data stream.
Definition SDL3pp_iostream.h:2262
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:2670
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:2735
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:2867
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:3097
constexpr IOStatus IO_STATUS_READONLY
Tried to write a read-only buffer.
Definition SDL3pp_iostream.h:57
Uint8 ReadU8()
Use this function to read a byte from an IOStream.
Definition SDL3pp_iostream.h:2391
constexpr IOStatus IO_STATUS_READY
Everything is ready (no errors and not EOF).
Definition SDL3pp_iostream.h:46
constexpr IOStatus IO_STATUS_NOT_READY
Non blocking I/O, not ready.
Definition SDL3pp_iostream.h:54
static IOStream FromFile(StringParam file, StringParam mode)
Use this function to create a new IOStream structure for reading from and/or writing to a named file.
Definition SDL3pp_iostream.h:1688
void CloseIO(IOStreamRaw context)
Close and free an allocated IOStream structure.
Definition SDL3pp_iostream.h:1944
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:2822
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:2997
void SaveFile(SourceBytes data)
Save all the data into an SDL data stream.
Definition SDL3pp_iostream.h:2344
static IOStream FromMem(TargetBytes mem)
Use this function to prepare a read-write memory buffer for use with IOStream.
Definition SDL3pp_iostream.h:1790
void Close()
Close and free an allocated IOStream structure.
Definition SDL3pp_iostream.h:1946
void WriteS8(Sint8 value)
Use this function to write a signed byte to an IOStream.
Definition SDL3pp_iostream.h:2800
void WriteU8(Uint8 value)
Use this function to write a byte to an IOStream.
Definition SDL3pp_iostream.h:2782
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:2947
constexpr IOWhence IO_SEEK_SET
Seek from the beginning of data.
Definition SDL3pp_iostream.h:73
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:2532
constexpr IOWhence IO_SEEK_END
Seek relative to the end of data.
Definition SDL3pp_iostream.h:79
ResourceRefT< PropertiesBase > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:55
::Sint32 Sint32
A signed 32-bit integer type.
Definition SDL3pp_stdinc.h:283
::Sint64 Sint64
A signed 64-bit integer type.
Definition SDL3pp_stdinc.h:311
::Uint16 Uint16
An unsigned 16-bit integer type.
Definition SDL3pp_stdinc.h:270
::Uint32 Uint32
An unsigned 32-bit integer type.
Definition SDL3pp_stdinc.h:296
::Sint16 Sint16
A signed 16-bit integer type.
Definition SDL3pp_stdinc.h:257
::Uint8 Uint8
An unsigned 8-bit integer type.
Definition SDL3pp_stdinc.h:244
::Sint8 Sint8
A signed 8-bit integer type.
Definition SDL3pp_stdinc.h:231
::Uint64 Uint64
An unsigned 64-bit integer type.
Definition SDL3pp_stdinc.h:326
Properties for IOStream.
Definition SDL3pp_iostream.h:1707
constexpr auto FILE_DESCRIPTOR_NUMBER
Number for file descriptor.
Definition SDL3pp_iostream.h:1715
constexpr auto ANDROID_AASSET_POINTER
Pointer to android aasset.
Definition SDL3pp_iostream.h:1718
constexpr auto MEMORY_POINTER
Pointer to memory.
Definition SDL3pp_iostream.h:1721
constexpr auto DYNAMIC_MEMORY_POINTER
Pointer to dynamic memory.
Definition SDL3pp_iostream.h:1734
constexpr auto DYNAMIC_CHUNKSIZE_NUMBER
Number for dynamic chunksize.
Definition SDL3pp_iostream.h:1737
constexpr auto STDIO_FILE_POINTER
Pointer to stdio file.
Definition SDL3pp_iostream.h:1712
constexpr auto MEMORY_FREE_FUNC_POINTER
Pointer to memory free func.
Definition SDL3pp_iostream.h:1729
constexpr auto MEMORY_SIZE_NUMBER
Number for memory size.
Definition SDL3pp_iostream.h:1724
constexpr auto WINDOWS_HANDLE_POINTER
Pointer to windows handle.
Definition SDL3pp_iostream.h:1709
Main include header for the SDL3pp library.
Base class to IOStream.
Definition SDL3pp_iostream.h:104
std::string Read(size_t size=-1)
Read from a data source.
Definition SDL3pp_iostream.h:247
std::optional< Sint64 > TryReadS64LE() const
Use this function to read 64 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:1042
std::optional< Sint16 > TryReadS16BE() const
Use this function to read 16 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:898
std::optional< Uint32 > TryReadU32LE() const
Use this function to read 32 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:922
OwnArray< T > LoadFileAs()
Load all the data from an SDL data stream.
Definition SDL3pp_iostream.h:459
std::optional< Uint16 > TryReadU16LE() const
Use this function to read 16 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:826
size_t println(std::string_view fmt, auto... args)
Prints formatted string.
Definition SDL3pp_iostream.h:345
std::optional< Uint64 > TryReadU64BE() const
Use this function to read 64 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:1066
std::optional< Uint64 > TryReadU64LE() const
Use this function to read 64 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:1018
size_t printf(SDL_PRINTF_FORMAT_STRING const char *fmt,...)
Print to an IOStream data stream.
Definition SDL3pp_iostream.h:372
std::optional< Sint16 > TryReadS16LE() const
Use this function to read 16 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:850
std::optional< Sint8 > TryReadS8() const
Use this function to read a byte from an IOStreamRef.
Definition SDL3pp_iostream.h:802
std::optional< Uint32 > TryReadU32BE() const
Use this function to read 32 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:970
std::optional< Uint8 > TryReadU8() const
Use this function to read a byte from an IOStreamRef.
Definition SDL3pp_iostream.h:782
std::optional< Sint32 > TryReadS32BE() const
Use this function to read 32 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:994
size_t print(std::string_view fmt, auto... args)
Prints formatted string.
Definition SDL3pp_iostream.h:333
std::optional< Uint16 > TryReadU16BE() const
Use this function to read 16 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:874
std::optional< Sint32 > TryReadS32LE() const
Use this function to read 32 bits of little-endian data from an IOStreamRef and return in native form...
Definition SDL3pp_iostream.h:946
std::optional< Sint64 > TryReadS64BE() const
Use this function to read 64 bits of big-endian data from an IOStreamRef and return in native format.
Definition SDL3pp_iostream.h:1090
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
The read/write operation structure.
Definition SDL3pp_iostream.h:1332
constexpr IOStream(IOStreamRaw resource) noexcept
Constructs from raw IOStream.
Definition SDL3pp_iostream.h:1342
~IOStream()
Destructor.
Definition SDL3pp_iostream.h:1591
constexpr IOStream(IOStream &&other) noexcept
Move constructor.
Definition SDL3pp_iostream.h:1348
constexpr IOStream & operator=(IOStream &&other) noexcept
Assignment operator.
Definition SDL3pp_iostream.h:1594
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:93
A simple std::string-like interface for SDL allocated strings.
Definition SDL3pp_strings.h:156