33 : res(&resource), pos(position)
53 void seek(std::ptrdiff_t offset)
59 void read(
void* dest_buffer, std::size_t length);
67 char* begin =
reinterpret_cast<char*
>(&t);
68 std::reverse(begin, begin +
sizeof t);
91 : res(&resource), pos(position)
111 void seek(std::ptrdiff_t offset)
117 void write(
const void* source_buffer, std::size_t length);
123 if (bo == BO_OTHER) {
125 const char* begin =
reinterpret_cast<const char*
>(&t);
126 std::reverse_copy(begin, begin +
sizeof t, buf);
127 write(buf,
sizeof buf);
168 return Writer(*
this, size());
171 virtual std::size_t size()
const = 0;
173 virtual void resize(std::size_t new_size) = 0;
175 virtual void read(std::size_t offset, std::size_t length,
void* dest_buffer)
const = 0;
177 virtual void write(std::size_t offset, std::size_t length,
const void* source_buffer) = 0;
183 std::vector<char> buf;
202 std::size_t size()
const override;
204 void resize(std::size_t new_size)
override;
206 void read(std::size_t offset, std::size_t length,
void* dest_buffer)
const override;
208 void write(std::size_t offset, std::size_t length,
const void* source_buffer)
override;
238 const std::unique_ptr<Impl> pimpl;
244 std::size_t size()
const override;
246 void resize(std::size_t new_size)
override;
248 void read(std::size_t offset, std::size_t length,
void* dest_buffer)
const override;
250 void write(std::size_t offset, std::size_t length,
const void* source_buffer)
override;
Reader front_reader() const
Convenience: Creates a new Reader that reads from the start of the resource.
void write_pod(const T &t, ByteOrder bo=BO_DONT_CARE)
Convenience function; equivalent to write(&t, sizeof t).
T get_pod(ByteOrder bo=BO_DONT_CARE)
Similar to read_pod(T&), but returns the read value instead.
const void * data() const
Piece of memory with the Resource interface.
std::size_t position() const
void load_file(Buffer &buffer, const std::string &filename)
Loads a whole file into a buffer.
Resource & resource() const
Buffer(const Buffer &other)
Utility class that points to a specific position in a resource and offers an interface for sequential...
Writer(Resource &resource, std::size_t position)
Buffer & operator=(const Buffer &other)
Base class for resources.
const ByteOrder BO_NATIVE
Opens an existing file for reading; throws an exception if the file cannot be found.
std::size_t position() const
void save_file(const Buffer &buffer, const std::string &filename)
Creates or overwrites a file with the contents of a buffer.
void read_pod(T &t, ByteOrder bo=BO_DONT_CARE)
Convenience function; equivalent to read(&t, sizeof t).
Utility class that points to a specific position in a resource and offers an interface for sequential...
void set_position(std::size_t value)
File with the Resource interface.
Opens or creates a file with writing access, but does not clear existing contents.
const Resource & resource() const
Reader(const Resource &resource, std::size_t position)
void set_position(std::size_t value)
void seek(std::ptrdiff_t offset)
void read(void *dest_buffer, std::size_t length)
void seek(std::ptrdiff_t offset)
Writer back_writer()
Convenience: Creates a new Writer that appends data at the end of the resource.