22#ifndef SDL2PP_RWOPS_HH
23#define SDL2PP_RWOPS_HH
28#include <SDL2pp/Exception.hh>
29#include <SDL2pp/Export.hh>
78 virtual Sint64
Seek(Sint64 offset,
int whence) = 0;
93 virtual size_t Read(
void* ptr,
size_t size,
size_t maxnum) = 0;
106 virtual size_t Write(
const void* ptr,
size_t size,
size_t num) = 0;
161 static Sint64 StdSizeFuncWrapper(SDL_RWops* context);
162 static Sint64 StdSeekFuncWrapper(SDL_RWops* context, Sint64 offset,
int whence);
163 static size_t StdReadFuncWrapper(SDL_RWops* context,
void *ptr,
size_t size,
size_t maxnum);
164 static size_t StdWriteFuncWrapper(SDL_RWops* context,
const void *ptr,
size_t size,
size_t maxnum);
165 static int StdCloseFuncWrapper(SDL_RWops* context);
167 static Sint64 CustomSizeFuncWrapper(SDL_RWops* context);
168 static Sint64 CustomSeekFuncWrapper(SDL_RWops* context, Sint64 offset,
int whence);
169 static size_t CustomReadFuncWrapper(SDL_RWops* context,
void *ptr,
size_t size,
size_t maxnum);
170 static size_t CustomWriteFuncWrapper(SDL_RWops* context,
const void *ptr,
size_t size,
size_t maxnum);
171 static int CustomCloseFuncWrapper(SDL_RWops* context);
173 static RWops CheckedCreateStandardRWops(SDL_RWops* sdl_rwops,
const char* errmsg);
188 static RWops FromFP(FILE* file,
bool autoclose);
201 static RWops FromConstMem(
const void* mem,
int size);
214 static RWops FromMem(
void* mem,
int size);
227 static RWops FromFile(
const std::string& file,
const std::string& mode =
"rb");
235 explicit RWops(SDL_RWops* rwops);
283 rwops_ = SDL_AllocRW();
284 if (rwops_ ==
nullptr)
287 rwops_->size = CustomSizeFuncWrapper;
288 rwops_->seek = CustomSeekFuncWrapper;
289 rwops_->read = CustomReadFuncWrapper;
290 rwops_->write = CustomWriteFuncWrapper;
291 rwops_->close = CustomCloseFuncWrapper;
292 rwops_->type = 0x57524370;
294 rwops_->hidden.unknown.data1 =
static_cast<void*
>(
new C(std::move(custom_rwops)));
299 rwops_->hidden.unknown.data2 =
static_cast<void*
>(
this);
314 SDL_RWops* Get()
const;
338 size_t Read(
void* ptr,
size_t size,
size_t maxnum);
352 Sint64 Seek(Sint64 offset,
int whence);
366 size_t Write(
const void* ptr,
size_t size,
size_t num);
463 size_t WriteBE16(Uint16 value);
476 size_t WriteBE32(Uint32 value);
489 size_t WriteBE64(Uint64 value);
502 size_t WriteLE16(Uint16 value);
515 size_t WriteLE32(Uint32 value);
528 size_t WriteLE64(Uint64 value);
Base class for custom RWops.
Definition: RWops.hh:48
virtual int Close()=0
Close data source.
virtual ~CustomRWops()
Destructor.
Definition: RWops.hh:54
virtual Sint64 Seek(Sint64 offset, int whence)=0
Seek within the data stream.
virtual size_t Read(void *ptr, size_t size, size_t maxnum)=0
Read from a data stream.
virtual size_t Write(const void *ptr, size_t size, size_t num)=0
Write to a data stream.
virtual Sint64 Size()=0
Get the size of the data stream.
Exception object representing SDL2 error
Definition: Exception.hh:71
I/O abstraction.
Definition: RWops.hh:156
RWops(const RWops &)=delete
Deleted copy constructor.
RWops & operator=(const RWops &)=delete
Deleted assignment operator.
SDL_RWops * rwops_
Managed SDL_RWops object.
Definition: RWops.hh:158
RWops(C &&custom_rwops)
Create RWops from CustomRWops derived class.
Definition: RWops.hh:282