22#ifndef SDL2PP_CONTAINERRWOPS_HH
23#define SDL2PP_CONTAINERRWOPS_HH
25#include <SDL2pp/RWops.hh>
58 typename std::enable_if<!std::is_const<CC>::value,
size_t>::type WriteHelper(
const void* ptr,
size_t size,
size_t num) {
62 std::copy(
reinterpret_cast<const unsigned char*
>(ptr),
reinterpret_cast<const unsigned char*
>(ptr) + size * num,
container_.begin() +
position_);
70 typename std::enable_if<std::is_const<CC>::value,
size_t>::type WriteHelper(
const void*,
size_t,
size_t) {
71 SDL_SetError(
"Can't write to read-only container");
94 virtual Sint64
Size()
override {
111 virtual Sint64
Seek(Sint64 offset,
int whence)
override {
123 throw std::logic_error(
"Unexpected whence value for ContainerRWops::Seek");
141 virtual size_t Read(
void* ptr,
size_t size,
size_t maxnum)
override {
151 return toread / size;
167 virtual size_t Write(
const void* ptr,
size_t size,
size_t num)
override {
168 return WriteHelper<C>(ptr, size, num);
RWops adaptor for random access STL containers.
Definition: ContainerRWops.hh:51
ContainerRWops(C &container)
Construct ContainerRWops for specified container.
Definition: ContainerRWops.hh:82
virtual Sint64 Size() override
Get the size of the data stream.
Definition: ContainerRWops.hh:94
size_t position_
Virtual file pointer position.
Definition: ContainerRWops.hh:54
C & container_
Reference to container.
Definition: ContainerRWops.hh:53
virtual size_t Read(void *ptr, size_t size, size_t maxnum) override
Read from a container.
Definition: ContainerRWops.hh:141
virtual int Close() override
Close data source.
Definition: ContainerRWops.hh:183
virtual Sint64 Seek(Sint64 offset, int whence) override
Seek within the container.
Definition: ContainerRWops.hh:111
virtual size_t Write(const void *ptr, size_t size, size_t num) override
Write to container.
Definition: ContainerRWops.hh:167
Base class for custom RWops.
Definition: RWops.hh:48