8 #define ERR_FS LOG_STREAM(err, log_filesystem)
12 static Sint64
ifs_size (
struct SDL_RWops * context);
13 static Sint64 SDLCALL
ifs_seek(
struct SDL_RWops *context, Sint64
offset,
int whence);
14 static size_t SDLCALL
ifs_read(
struct SDL_RWops *context,
void *ptr,
size_t size,
size_t maxnum);
15 static size_t SDLCALL
ifs_write(
struct SDL_RWops *context,
const void *ptr,
size_t size,
size_t num);
16 static int SDLCALL
ifs_close(
struct SDL_RWops *context);
19 SDL_RWops *rw = SDL_AllocRW();
31 ERR_FS <<
"load_RWops: istream_file returned NULL on " << path <<
'\n';
35 rw->hidden.unknown.data1 = ifs;
41 static Sint64
ifs_size (
struct SDL_RWops * context) {
42 std::istream *ifs =
static_cast<std::istream*
>(context->hidden.unknown.data1);
43 std::streampos orig = ifs->tellg();
47 std::streampos
len = ifs->tellg();
55 static Sint64 SDLCALL
ifs_seek(
struct SDL_RWops *context, Sint64 offset,
int whence) {
57 std::ios_base::seekdir seekdir;
60 seekdir = std::ios_base::beg;
65 seekdir = std::ios_base::cur;
74 throw "assertion ignored";
76 std::istream *ifs =
static_cast<std::istream*
>(context->hidden.unknown.data1);
77 const std::ios_base::iostate saved_state = ifs->rdstate();
79 ifs->seekg(offset, seekdir);
81 if(saved_state != ifs->rdstate() && offset < 0) {
82 ifs->clear(saved_state);
83 ifs->seekg(0, std::ios_base::beg);
86 std::streamsize
pos = ifs->tellg();
87 return static_cast<int>(
pos);
90 static size_t SDLCALL
ifs_read(
struct SDL_RWops *context,
void *ptr,
size_t size,
size_t maxnum) {
91 std::istream *ifs =
static_cast<std::istream*
>(context->hidden.unknown.data1);
94 ifs->read(static_cast<char*>(ptr), maxnum * size);
95 std::streamsize num = ifs->good() ? maxnum : ifs->gcount() /
size;
101 return static_cast<int>(
num);
104 static size_t SDLCALL
ifs_write(
struct SDL_RWops * ,
const void * ,
size_t ,
size_t ) {
105 SDL_SetError(
"Writing not implemented");
108 static int SDLCALL
ifs_close(
struct SDL_RWops *context) {
110 std::istream *ifs =
static_cast<std::istream*
>(context->hidden.unknown.data1);
static Sint64 SDLCALL ifs_seek(struct SDL_RWops *context, Sint64 offset, int whence)
static int SDLCALL ifs_close(struct SDL_RWops *context)
GLsizei const char ** path
std::istream * istream_file(const std::string &fname, bool treat_failure_as_error=true)
Declarations for File-IO.
static Sint64 ifs_size(struct SDL_RWops *context)
static size_t SDLCALL ifs_read(struct SDL_RWops *context, void *ptr, size_t size, size_t maxnum)
Standard logging facilities (interface).
SDL_RWops * load_RWops(const std::string &path)
static size_t SDLCALL ifs_write(struct SDL_RWops *context, const void *ptr, size_t size, size_t num)
GLsizei const GLcharARB ** string
static lg::log_domain log_filesystem("filesystem")