Beatmup
Beatmup::ChunkFile Class Reference

File containing chunks. More...

#include <chunkfile.h>

Inheritance diagram for Beatmup::ChunkFile:
Beatmup::ChunkStream Beatmup::ChunkCollection Beatmup::Object

Public Member Functions

 ChunkFile (const std::string &filename, bool openNow=true)
 Creates a read-only chunk collection from a file. More...
 
void open ()
 Opens the collection to read chunks from it. More...
 
void close ()
 Closes the collection after a reading session. More...
 
- Public Member Functions inherited from Beatmup::ChunkStream
size_t size () const
 Returns the number of chunks available in the collection after it is opened. More...
 
bool chunkExists (const std::string &id) const
 Check if a specific chunk exists. More...
 
chunksize_t chunkSize (const std::string &id) const
 Retrieves size of a specific chunk. More...
 
chunksize_t fetch (const std::string &id, void *data, const chunksize_t limit)
 Reads a chunk. More...
 
void save (const std::string &filename, bool append=false)
 Saves the collection to a file. More...
 
- Public Member Functions inherited from Beatmup::ChunkCollection
template<typename datatype >
datatype read (const std::string &id)
 Reads a chunk and casts it into a given type. More...
 
template<typename datatype >
std::vector< datatype > readVector (const std::string &id)
 Reads a chunk into a vector of a specific type. More...
 
template<>
std::string read (const std::string &id)
 
- Public Member Functions inherited from Beatmup::Object
virtual ~Object ()
 

Static Public Member Functions

static bool readable (const std::string &filename)
 Returns true if a given file is readable. More...
 

Private Attributes

const std::string filename
 
FileInputStream stream
 

Additional Inherited Members

- Protected Member Functions inherited from Beatmup::ChunkStream
 ChunkStream (InputStream &stream)
 
bool parse ()
 Goes through the input stream to build the list of existing chunks. More...
 

Detailed Description

File containing chunks.

The file is not loaded in memory, but is scanned when first opened to collect the information about available chunks.

Definition at line 167 of file chunkfile.h.

Constructor & Destructor Documentation

◆ ChunkFile()

ChunkFile::ChunkFile ( const std::string &  filename,
bool  openNow = true 
)

Creates a read-only chunk collection from a file.

Parameters
[in]filenameThe file name / path
[in]openNowIf true, the file is read right away. Otherwise it is done on open() call. No information is available about chunks in the file until it is opened.

Definition at line 111 of file chunkfile.cpp.

111  :
114 {
115  if (openNow)
116  open();
117 }
void open()
Opens the collection to read chunks from it.
Definition: chunkfile.cpp:120
FileInputStream stream
Definition: chunkfile.h:170
const std::string filename
Definition: chunkfile.h:169
ChunkStream(InputStream &stream)
Definition: chunkfile.h:143
JNIEnv jstring jboolean openNow

Member Function Documentation

◆ readable()

bool ChunkFile::readable ( const std::string &  filename)
static

Returns true if a given file is readable.

Definition at line 105 of file chunkfile.cpp.

105  {
106  std::ifstream stream(filename, std::fstream::in | std::fstream::binary);
107  return stream.good();
108 }

◆ open()

void ChunkFile::open ( )
virtual

Opens the collection to read chunks from it.

Implements Beatmup::ChunkCollection.

Definition at line 120 of file chunkfile.cpp.

120  {
121  stream.open(filename.c_str());
122  stream.clear();
123  parse();
124  stream.clear();
125 }
bool parse()
Goes through the input stream to build the list of existing chunks.
Definition: chunkfile.cpp:39
void open(const char *filename)

◆ close()

void ChunkFile::close ( )
virtual

Closes the collection after a reading session.

Implements Beatmup::ChunkCollection.

Definition at line 127 of file chunkfile.cpp.

127  {
128  stream.close();
129 }

Member Data Documentation

◆ filename

const std::string Beatmup::ChunkFile::filename
private

Definition at line 169 of file chunkfile.h.

◆ stream

FileInputStream Beatmup::ChunkFile::stream
private

Definition at line 170 of file chunkfile.h.


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