libtcod
Loading...
Searching...
No Matches
TCODZip Class Reference

#include <zip.hpp>

Public Member Functions

 TCODZip ()
 This function initializes a compression buffer.
 ~TCODZip ()
 Once you don't need the buffer anymore, you can release resources.
void putChar (char val)
void putInt (int val)
void putFloat (float val)
void putString (const char *val)
void putColor (const TCODColor *val)
void putImage (const TCODImage *val)
void putConsole (const TCODConsole *val)
void putRandom (const TCODRandom *val)
void putData (int nbBytes, const void *data)
uint32_t getCurrentBytes () const
int saveToFile (const char *filename)
 Once you have finished adding data in the buffer, you can compress it and save it in a file.
void saveToFile (const std::filesystem::path &path)
 Save this objects buffered objects to the file at path.
int loadFromFile (const char *filename)
 You can read data from a file (compressed or not) into the buffer.
void loadFromFile (const std::filesystem::path &path)
 Load objects from the file at path.
char getChar ()
int getInt ()
float getFloat ()
const char * getString ()
 The address returned is in the buffer.
TCODColor getColor ()
TCODImagegetImage ()
TCODConsolegetConsole ()
TCODRandomgetRandom ()
int getData (int nbBytes, void *data)
 Note that the getData length must match the length of the data when the file was created (with putData).
uint32_t getRemainingBytes () const
void skipBytes (uint32_t nbBytes)
void put (char value)
 Save a char to this zip.
void put (int value)
 Save an int to this zip.
void put (float value)
 Save a float to this zip.
void put (const char *value)
 Save a string to this zip.
void put (const std::string &value)
 Save a string to this zip.
void put (const std::optional< std::string > &value)
 Save an optional string to this zip.
void put (const tcod::ColorRGB &value)
 Save a color to this zip.
void put (const TCODColor &value)
 Save a color to this zip.
void put (const TCODImage &value)
 Save an image to this zip.
TCODLIB_BEGIN_IGNORE_DEPRECATIONS void put (const TCODConsole &value)
 Save a console to this zip.
void put (const tcod::Console &value)
 Save a console to this zip.
TCODLIB_END_IGNORE_DEPRECATIONS void put (const TCODRandom &value)
 Save an RNG state to this zip.
template<typename T>
get ()
 Return a value of T from this zip object.
void get (char &out)
 Extract a char to out.
void get (int &out)
 Extract an int to out.
void get (float &out)
 Extract a float to out.
void get (std::optional< std::string > &out)
 Extract an optional string to out.
void get (std::string &out)
 Extract a string to out.
void get (tcod::ColorRGB &out)
 Extract a color to out.
void get (TCODColor &out)
 Extract a color to out.
void get (tcod::ImagePtr &out)
 Extract an image pointer to out.
void get (TCODImage &out)
 Extract an image to out.
void get (tcod::ConsolePtr &out)
 Extract a console pointer to out.
void get (tcod::Console &out)
 Extract a console to out.
void get (TCODConsole &out)
 Extract a console to out.
void get (TCODRandom &out)
 Extract an RNG state to out.

Protected Attributes

TCOD_zip_t data {}

Detailed Description

This toolkit provides functions to save or read compressed data from a file. While the module is named Zip, it has nothing to do with the .zip format as it uses zlib compression (.gz format). Note that this modules has no Python wrapper. Use Python built-in zip module instead.

You can use the compression buffer in two modes: put data in the buffer, then save it to a file, load a file into the buffer, then get data from it.

Constructor & Destructor Documentation

◆ ~TCODZip()

TCODZip::~TCODZip ( )

Once you don't need the buffer anymore, you can release resources.

Note that the addresses returned by the getString function are no longer valid once the buffer has been destroyed.

Parameters
zipIn the C version, the buffer handler, returned by the constructor.

TCODZip *zip = new TCODZip(); zip->loadFromFile("myCompressedFile.gz"); char c=zip->getChar(); int i=zip->getInt(); float f= zip->getFloat(); const char *s=strdup(zip->getString()); // we duplicate the string to be able to use it after the buffer deletion zip->getData(nbBytes, dataPtr); delete zip;

TCOD_zip_t zip=TCOD_zip_new(); TCOD_zip_load_from_file(zip,"myCompressedFile.gz"); char c=TCOD_zip_get_char(zip); int i=TCOD_zip_get_int(zip); float f=TCOD_zip_get_float(zip); const char *s=strdup(TCOD_zip_get_string(zip)); TCOD_zip_get_data(zip,nbBytes, dataPtr); TCOD_zip_delete(zip);

Member Function Documentation

◆ get() [1/14]

template<typename T>
T TCODZip::get ( )
inline

Return a value of T from this zip object.

Template Parameters
TA type which must match one of the get(T) overloads.
Returns
T
embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ get() [2/14]

void TCODZip::get ( char & out)
inline

Extract a char to out.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ get() [3/14]

void TCODZip::get ( float & out)
inline

Extract a float to out.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ get() [4/14]

void TCODZip::get ( int & out)
inline

Extract an int to out.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ get() [5/14]

void TCODZip::get ( std::optional< std::string > & out)
inline

Extract an optional string to out.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ get() [6/14]

void TCODZip::get ( std::string & out)
inline

Extract a string to out.

Will throw if nullptr was put.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ get() [7/14]

void TCODZip::get ( tcod::ColorRGB & out)
inline

Extract a color to out.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ get() [8/14]

void TCODZip::get ( tcod::Console & out)
inline

Extract a console to out.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ get() [9/14]

void TCODZip::get ( tcod::ConsolePtr & out)
inline

Extract a console pointer to out.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ get() [10/14]

void TCODZip::get ( tcod::ImagePtr & out)
inline

Extract an image pointer to out.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ get() [11/14]

void TCODZip::get ( TCODColor & out)
inline

Extract a color to out.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ get() [12/14]

void TCODZip::get ( TCODConsole & out)
inline

Extract a console to out.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ get() [13/14]

void TCODZip::get ( TCODImage & out)
inline

Extract an image to out.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ get() [14/14]

void TCODZip::get ( TCODRandom & out)
inline

Extract an RNG state to out.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ getChar()

char TCODZip::getChar ( )
Parameters
zipIn the C version, the buffer handler, returned by the constructor

◆ getColor()

TCODColor TCODZip::getColor ( )
Parameters
zipIn the C version, the buffer handler, returned by the constructor.

◆ getConsole()

TCODConsole * TCODZip::getConsole ( )
Parameters
zipIn the C version, the buffer handler, returned by the constructor.

◆ getCurrentBytes()

uint32_t TCODZip::getCurrentBytes ( ) const
Parameters
zipIn the C version, the buffer handler, returned by the constructor.

◆ getData()

int TCODZip::getData ( int nbBytes,
void * data )

Note that the getData length must match the length of the data when the file was created (with putData).

The function returns the number of bytes that were stored in the file by the putData call. If more than nbBytes were stored, the function read only nbBytes and skip the rest of them.

Parameters
zipIn the C version, the buffer handler, returned by the constructor.
nbBytesNumber of bytes to read
dataAddress of a pre-allocated buffer (at least nbBytes bytes)

TCODZip zip; zip.loadFromFile("myCompressedFile.gz"); char c=zip.getChar(); int i=zip.getInt(); float f= zip.getFloat(); const char *s=zip.getString(); zip.getData(nbBytes, dataPtr);

TCOD_zip_t zip=TCOD_zip_new(); TCOD_zip_load_from_file(zip,"myCompressedFile.gz"); char c=TCOD_zip_get_char(zip); int i=TCOD_zip_get_int(zip); float f=TCOD_zip_get_float(zip); const char *s=TCOD_zip_get_string(zip); TCOD_zip_get_data(zip,nbBytes, dataPtr);

◆ getFloat()

float TCODZip::getFloat ( )
Parameters
zipIn the C version, the buffer handler, returned by the constructor.

◆ getImage()

TCODImage * TCODZip::getImage ( )
Parameters
zipIn the C version, the buffer handler, returned by the constructor.

◆ getInt()

int TCODZip::getInt ( )
Parameters
zipIn the C version, the buffer handler, returned by the constructor.

◆ getRandom()

TCODRandom * TCODZip::getRandom ( )
Parameters
zipIn the C version, the buffer handler, returned by the constructor.

◆ getRemainingBytes()

uint32_t TCODZip::getRemainingBytes ( ) const
Parameters
zipIn the C version, the buffer handler, returned by the constructor.

◆ getString()

const char * TCODZip::getString ( )

The address returned is in the buffer.

It is valid as long as you don't destroy the buffer.

Parameters
zipIn the C version, the buffer handler, returned by the constructor.

◆ loadFromFile() [1/2]

int TCODZip::loadFromFile ( const char * filename)

You can read data from a file (compressed or not) into the buffer.

The function returns the number of (uncompressed) bytes read or 0 if an error occurred.

Parameters
zipIn the C version, the buffer handler, returned by the constructor.
filenameName of the file

◆ loadFromFile() [2/2]

void TCODZip::loadFromFile ( const std::filesystem::path & path)
inline

Load objects from the file at path.

Parameters
pathThe file to read. Must exist and be valid.
Exceptions
std::runtime_erroron any failure to load the file.
embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ put() [1/12]

void TCODZip::put ( char value)
inline

Save a char to this zip.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ put() [2/12]

void TCODZip::put ( const char * value)
inline

Save a string to this zip.

Can be nullptr.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ put() [3/12]

void TCODZip::put ( const std::optional< std::string > & value)
inline

Save an optional string to this zip.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ put() [4/12]

void TCODZip::put ( const std::string & value)
inline

Save a string to this zip.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ put() [5/12]

void TCODZip::put ( const tcod::ColorRGB & value)
inline

Save a color to this zip.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ put() [6/12]

void TCODZip::put ( const tcod::Console & value)
inline

Save a console to this zip.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ put() [7/12]

void TCODZip::put ( const TCODColor & value)
inline

Save a color to this zip.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ put() [8/12]

TCODLIB_BEGIN_IGNORE_DEPRECATIONS void TCODZip::put ( const TCODConsole & value)
inline

Save a console to this zip.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ put() [9/12]

void TCODZip::put ( const TCODImage & value)
inline

Save an image to this zip.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ put() [10/12]

TCODLIB_END_IGNORE_DEPRECATIONS void TCODZip::put ( const TCODRandom & value)
inline

Save an RNG state to this zip.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ put() [11/12]

void TCODZip::put ( float value)
inline

Save a float to this zip.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ put() [12/12]

void TCODZip::put ( int value)
inline

Save an int to this zip.

embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ putChar()

void TCODZip::putChar ( char val)
Parameters
zipIn the C version, the buffer handler, returned by the constructor.
valA 8 bits value to store in the buffer

◆ putColor()

void TCODZip::putColor ( const TCODColor * val)
Parameters
zipIn the C version, the buffer handler, returned by the constructor.
valA color to store in the buffer

◆ putConsole()

void TCODZip::putConsole ( const TCODConsole * val)
Parameters
zipIn the C version, the buffer handler, returned by the constructor.
valA console to store in the buffer

◆ putData()

void TCODZip::putData ( int nbBytes,
const void * data )
Parameters
zipIn the C version, the buffer handler, returned by the constructor.
nbBytesNumber of bytes to store in the buffer
valAddress of the data to store in the buffer

◆ putFloat()

void TCODZip::putFloat ( float val)
Parameters
zipIn the C version, the buffer handler, returned by the constructor.
valA float value to store in the buffer

◆ putImage()

void TCODZip::putImage ( const TCODImage * val)
Parameters
zipIn the C version, the buffer handler, returned by the constructor.
valAn image to store in the buffer

◆ putInt()

void TCODZip::putInt ( int val)
Parameters
zipIn the C version, the buffer handler, returned by the constructor.
valAn integer value to store in the buffer

◆ putRandom()

void TCODZip::putRandom ( const TCODRandom * val)
Parameters
zipIn the C version, the buffer handler, returned by the constructor.
valAn RNG state to store in the buffer

◆ putString()

void TCODZip::putString ( const char * val)
Parameters
zipIn the C version, the buffer handler, returned by the constructor.
valA string to store in the buffer

◆ saveToFile() [1/2]

int TCODZip::saveToFile ( const char * filename)

Once you have finished adding data in the buffer, you can compress it and save it in a file.

The function returns the number of (uncompressed) bytes saved.

Parameters
zipIn the C version, the buffer handler, returned by the constructor.
filenameName of the file

TCODZip zip; zip.putChar('A'); zip.putInt(1764); zip.putFloat(3.14f); zip.putString("A string"); zip.putData(nbBytes, dataPtr); zip.saveToFile("myCompressedFile.gz");

TCOD_zip_t zip=TCOD_zip_new(); TCOD_zip_put_char(zip,'A'); TCOD_zip_put_int(zip,1764); TCOD_zip_put_float(zip,3.14f); TCOD_zip_put_string(zip,"A string"); TCOD_zip_put_data(zip,nbBytes, dataPtr); TCOD_zip_save_to_file(zip,"myCompressedFile.gz");

◆ saveToFile() [2/2]

void TCODZip::saveToFile ( const std::filesystem::path & path)
inline

Save this objects buffered objects to the file at path.

Parameters
pathThe file to write.
embed:rst:leading-asterisk 
.. versionadded:: 1.24

◆ skipBytes()

void TCODZip::skipBytes ( uint32_t nbBytes)
Parameters
zipIn the C version, the buffer handler, returned by the constructor.
nbBytesnumber of uncompressed bytes to skip

The documentation for this class was generated from the following file:
  • C:/Users/4b796/Projects/libtcod/src/libtcod/zip.hpp