20 #include "../exception.h"
51 virtual size_t size()
const = 0;
91 template<
typename datatype>
inline datatype
read(
const std::string&
id) {
105 template<
typename datatype>
106 inline std::vector<datatype>
readVector(
const std::string&
id) {
108 DebugAssertion::check(
chunkSize(
id) %
sizeof(datatype) == 0,
112 std::vector<datatype>
result;
139 std::map<std::string, ChunkDesc>
map;
152 inline size_t size()
const {
return map.size(); }
200 template<
typename datatype>
void operator()(
const std::string&
id, datatype something) {
201 (*this)(
id, &something,
sizeof(something));
236 chunk.data =
nullptr;
245 chunk.data =
nullptr;
262 inline operator bool()
const {
return data !=
nullptr; }
264 template<
typename datatype>
inline datatype*
ptr(
size_t offset = 0) {
265 return (datatype*)(
data) + offset;
267 template<
typename datatype>
inline const datatype*
ptr(
size_t offset = 0)
const {
268 return (datatype*)(
data) + offset;
271 template<
typename datatype>
inline datatype
at(
size_t offset)
const {
272 return ((datatype*)
data)[offset];
275 template<
typename datatype>
inline datatype&
at(
size_t offset) {
276 return ((datatype*)
data)[offset];
A key-value pair set storing pieces of arbitrary data (chunks) under string keys.
virtual size_t size() const =0
Returns the number of chunks available in the collection after it is opened.
std::vector< datatype > readVector(const std::string &id)
Reads a chunk into a vector of a specific type.
virtual void save(const std::string &filename, bool append=false)=0
Saves the collection to a file.
virtual void close()=0
Closes the collection after a reading session.
virtual bool chunkExists(const std::string &id) const =0
Check if a specific chunk exists.
virtual chunksize_t chunkSize(const std::string &id) const =0
Retrieves size of a specific chunk.
virtual void open()=0
Opens the collection to read chunks from it.
virtual chunksize_t fetch(const std::string &id, void *data, const chunksize_t limit)=0
Reads a chunk.
datatype read(const std::string &id)
Reads a chunk and casts it into a given type.
void operator()(const std::string &id, const void *data, const chunksize_t size)
void operator()(const std::string &id, datatype something)
ChunkFileWriter(const std::string &filename, bool append=false)
void open()
Opens the collection to read chunks from it.
static bool readable(const std::string &filename)
Returns true if a given file is readable.
void close()
Closes the collection after a reading session.
ChunkFile(const std::string &filename, bool openNow=true)
Creates a read-only chunk collection from a file.
const std::string filename
void save(const std::string &filename, bool append=false)
Saves the collection to a file.
ChunkStream(InputStream &stream)
std::map< std::string, ChunkDesc > map
size_t size() const
Returns the number of chunks available in the collection after it is opened.
bool chunkExists(const std::string &id) const
Check if a specific chunk exists.
bool parse()
Goes through the input stream to build the list of existing chunks.
chunksize_t chunkSize(const std::string &id) const
Retrieves size of a specific chunk.
chunksize_t fetch(const std::string &id, void *data, const chunksize_t limit)
Reads a chunk.
Simply a piece of binary data of a specific size.
datatype & at(size_t offset)
datatype * ptr(size_t offset=0)
const void * operator()() const
datatype at(size_t offset) const
void writeTo(ChunkFileWriter &file, const std::string &id) const
Writes a chunk out to a file.
Chunk & operator=(Chunk &&chunk)
const datatype * ptr(size_t offset=0) const
Chunk()
Makes an empty chunk.
Beatmup object base class
std::string to_string(Beatmup::NNets::ActivationFunction function)
JNIEnv jstring jboolean openNow
JNIEnv jlong jstring filename
JNIEnv jlong jstring jboolean append