Beatmup
Beatmup::ChunkFileWriter Class Reference

Writes chunks to a file. More...

#include <chunkfile.h>

Public Member Functions

 ChunkFileWriter (const std::string &filename, bool append=false)
 
 ~ChunkFileWriter ()
 
void operator() (const std::string &id, const void *data, const chunksize_t size)
 
template<typename datatype >
void operator() (const std::string &id, datatype something)
 

Private Attributes

std::fstream stream
 

Detailed Description

Writes chunks to a file.

Definition at line 191 of file chunkfile.h.

Constructor & Destructor Documentation

◆ ChunkFileWriter()

ChunkFileWriter::ChunkFileWriter ( const std::string &  filename,
bool  append = false 
)

Definition at line 132 of file chunkfile.cpp.

132  :
133  stream(filename, std::ios::binary | (append ? std::ios::out | std::ios::app | std::ios::ate : std::ios::out))
134 {
135  if (!stream.good())
136  throw IOError(filename, "Cannot write to file");
137 }
JNIEnv jlong jstring filename
JNIEnv jlong jstring jboolean append
JNIEnv jlong jint out

◆ ~ChunkFileWriter()

ChunkFileWriter::~ChunkFileWriter ( )

Definition at line 140 of file chunkfile.cpp.

140 {}

Member Function Documentation

◆ operator()() [1/2]

void ChunkFileWriter::operator() ( const std::string &  id,
const void *  data,
const chunksize_t  size 
)

Definition at line 143 of file chunkfile.cpp.

143  {
145  id_size_t idLen = (char)id.size();
146  stream.write((char*)&idLen, sizeof(idLen));
147  stream.write(&id[0], idLen);
148  stream.write((char*)&size, sizeof(size));
149  stream.write((char*)data, size);
150 }
uint32_t id_size_t
chunk id length type
Definition: chunkfile.cpp:23
static void check(const std::string &id)
Definition: chunkfile.cpp:31
jlong jobject size

◆ operator()() [2/2]

template<typename datatype >
void Beatmup::ChunkFileWriter::operator() ( const std::string &  id,
datatype  something 
)
inline

Definition at line 200 of file chunkfile.h.

200  {
201  (*this)(id, &something, sizeof(something));
202  }
JNIEnv jlong jstring id

Member Data Documentation

◆ stream

std::fstream Beatmup::ChunkFileWriter::stream
private

Definition at line 193 of file chunkfile.h.


The documentation for this class was generated from the following files: