|
libtcod
|
#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 () |
| TCODImage * | getImage () |
| TCODConsole * | getConsole () |
| TCODRandom * | getRandom () |
| 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> | |
| 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 {} |
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.
| 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.
| zip | In 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);
|
inline |
Return a value of T from this zip object.
| T | A type which must match one of the get(T) overloads. |
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Extract a char to out.
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Extract a float to out.
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Extract an int to out.
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Extract an optional string to out.
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Extract a string to out.
Will throw if nullptr was put.
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Extract a color to out.
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Extract a console to out.
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Extract a console pointer to out.
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Extract an image pointer to out.
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Extract a color to out.
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Extract a console to out.
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Extract an image to out.
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Extract an RNG state to out.
embed:rst:leading-asterisk .. versionadded:: 1.24
| char TCODZip::getChar | ( | ) |
| zip | In the C version, the buffer handler, returned by the constructor |
| TCODColor TCODZip::getColor | ( | ) |
| zip | In the C version, the buffer handler, returned by the constructor. |
| TCODConsole * TCODZip::getConsole | ( | ) |
| zip | In the C version, the buffer handler, returned by the constructor. |
| uint32_t TCODZip::getCurrentBytes | ( | ) | const |
| zip | In the C version, the buffer handler, returned by the constructor. |
| 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.
| zip | In the C version, the buffer handler, returned by the constructor. |
| nbBytes | Number of bytes to read |
| data | Address 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);
| float TCODZip::getFloat | ( | ) |
| zip | In the C version, the buffer handler, returned by the constructor. |
| TCODImage * TCODZip::getImage | ( | ) |
| zip | In the C version, the buffer handler, returned by the constructor. |
| int TCODZip::getInt | ( | ) |
| zip | In the C version, the buffer handler, returned by the constructor. |
| TCODRandom * TCODZip::getRandom | ( | ) |
| zip | In the C version, the buffer handler, returned by the constructor. |
| uint32_t TCODZip::getRemainingBytes | ( | ) | const |
| zip | In the C version, the buffer handler, returned by the constructor. |
| const char * TCODZip::getString | ( | ) |
The address returned is in the buffer.
It is valid as long as you don't destroy the buffer.
| zip | In the C version, the buffer handler, returned by the constructor. |
| 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.
| zip | In the C version, the buffer handler, returned by the constructor. |
| filename | Name of the file |
|
inline |
Load objects from the file at path.
| path | The file to read. Must exist and be valid. |
| std::runtime_error | on any failure to load the file. |
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Save a char to this zip.
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Save a string to this zip.
Can be nullptr.
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Save an optional string to this zip.
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Save a string to this zip.
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Save a color to this zip.
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Save a console to this zip.
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Save a color to this zip.
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Save a console to this zip.
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Save an image to this zip.
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Save an RNG state to this zip.
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Save a float to this zip.
embed:rst:leading-asterisk .. versionadded:: 1.24
|
inline |
Save an int to this zip.
embed:rst:leading-asterisk .. versionadded:: 1.24
| void TCODZip::putChar | ( | char | val | ) |
| zip | In the C version, the buffer handler, returned by the constructor. |
| val | A 8 bits value to store in the buffer |
| void TCODZip::putColor | ( | const TCODColor * | val | ) |
| zip | In the C version, the buffer handler, returned by the constructor. |
| val | A color to store in the buffer |
| void TCODZip::putConsole | ( | const TCODConsole * | val | ) |
| zip | In the C version, the buffer handler, returned by the constructor. |
| val | A console to store in the buffer |
| void TCODZip::putData | ( | int | nbBytes, |
| const void * | data ) |
| zip | In the C version, the buffer handler, returned by the constructor. |
| nbBytes | Number of bytes to store in the buffer |
| val | Address of the data to store in the buffer |
| void TCODZip::putFloat | ( | float | val | ) |
| zip | In the C version, the buffer handler, returned by the constructor. |
| val | A float value to store in the buffer |
| void TCODZip::putImage | ( | const TCODImage * | val | ) |
| zip | In the C version, the buffer handler, returned by the constructor. |
| val | An image to store in the buffer |
| void TCODZip::putInt | ( | int | val | ) |
| zip | In the C version, the buffer handler, returned by the constructor. |
| val | An integer value to store in the buffer |
| void TCODZip::putRandom | ( | const TCODRandom * | val | ) |
| zip | In the C version, the buffer handler, returned by the constructor. |
| val | An RNG state to store in the buffer |
| void TCODZip::putString | ( | const char * | val | ) |
| zip | In the C version, the buffer handler, returned by the constructor. |
| val | A string to store in the buffer |
| 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.
| zip | In the C version, the buffer handler, returned by the constructor. |
| filename | Name 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");
|
inline |
Save this objects buffered objects to the file at path.
| path | The file to write. |
embed:rst:leading-asterisk .. versionadded:: 1.24
| void TCODZip::skipBytes | ( | uint32_t | nbBytes | ) |
| zip | In the C version, the buffer handler, returned by the constructor. |
| nbBytes | number of uncompressed bytes to skip |