Geogram
Version 1.9.1
A programming library of geometric algorithms
|
Base class for reading or writing Geogram structured binary files. More...
#include <geogram/basic/geofile.h>
Classes | |
struct | AttributeInfo |
Internal representation of attributes. More... | |
struct | AttributeSetInfo |
Internal representation of an attribute set. More... | |
Public Types | |
typedef bool(* | AsciiAttributeSerializer) (FILE *file, Memory::pointer base_address, index_t nb_elements) |
The function pointer type for reading and writing attributes in ASCII files. | |
Public Member Functions | |
GeoFile (const std::string &filename) | |
GeoFile constructor. More... | |
~GeoFile () | |
GeoFile destructor. | |
bool | is_ascii () const |
Tests whether this GeoFile is ascii. More... | |
const std::string & | current_chunk_class () const |
Gets the current chunk class. More... | |
long | current_chunk_size () const |
Gets the size of the current chunk. More... | |
AttributeSetInfo * | find_attribute_set (const std::string &name) |
Finds an attribute set by name. More... | |
const AttributeSetInfo * | find_attribute_set (const std::string &name) const |
Finds an attribute set by name. More... | |
index_t | read_int () |
Reads an integer from the file. More... | |
void | write_int (index_t x, const char *comment=nullptr) |
Writes an integer into the file. More... | |
std::string | read_string () |
Reads a string from the file. More... | |
void | write_string (const std::string &s, const char *comment=nullptr) |
Writes a string into the file. More... | |
size_t | read_size () |
Reads an unsigned 64 bits integer from the file. More... | |
void | write_size (size_t x) |
Writes an unsigned 64 bits integer into the file. More... | |
std::string | read_chunk_class () |
Reads a chunk class from the file. More... | |
void | write_chunk_class (const std::string &chunk_class) |
Writes a chunk class into the file. More... | |
void | write_string_array (const std::vector< std::string > &strings) |
Writes a string array into the file. More... | |
void | read_string_array (std::vector< std::string > &strings) |
Reads a string array from the file. More... | |
size_t | string_size (const std::string &s) const |
Gets the size in bytes used by a given string in the file. More... | |
size_t | string_array_size (const std::vector< std::string > &strings) const |
Gets the size in bytes used by a given string array in the file. More... | |
void | read_chunk_header () |
Reads a chunk header from the file. | |
void | write_chunk_header (const std::string &chunk_class, size_t size) |
Writes a chunk header into the file. More... | |
void | check_chunk_size () |
Checks that the actual chunk size corresponds to the specified chunk size. | |
void | check_zlib_version () |
Compares the zlib version declared in the header file with the zlib version obtained from the runtime, and outputs an error message if they differ. | |
void | clear_attribute_maps () |
Clears all memorized information about attributes and attribute sets. More... | |
Static Public Member Functions | |
static void | register_ascii_attribute_serializer (const std::string &type_name, AsciiAttributeSerializer read, AsciiAttributeSerializer write) |
Declares a new attribute type that can be read from and written to ascii files. More... | |
Protected Attributes | |
std::string | filename_ |
gzFile | file_ |
bool | ascii_ |
FILE * | ascii_file_ |
std::string | current_chunk_class_ |
long | current_chunk_size_ |
long | current_chunk_file_pos_ |
std::map< std::string, AttributeSetInfo > | attribute_sets_ |
Static Protected Attributes | |
static std::map< std::string, AsciiAttributeSerializer > | ascii_attribute_read_ |
static std::map< std::string, AsciiAttributeSerializer > | ascii_attribute_write_ |
Base class for reading or writing Geogram structured binary files.
Geogram structured binary files are organized into "chunks", in a way inspired by the Interchange File Format (IFF), with several differences (GeoFile uses little endian and does not use the standard IFF chunks). Like in IFF, each chunk starts with a four characters code (FourCC) and its size in bytes, stored in a 4 bytes unsigned integer. This makes it possible to easily skip the chunks that are not needed / not understood by the software. In addition, structured binary files are (optionally) compressed, using ZLib. Structured files can also be saved/loaded in ASCII, human-readable form. Natively, GeoFile uses the following chunks:
GEO::GeoFile::GeoFile | ( | const std::string & | filename | ) |
GeoFile constructor.
[in] | filename | a const reference to the file name. |
void GEO::GeoFile::clear_attribute_maps | ( | ) |
Clears all memorized information about attributes and attribute sets.
This function is called whenever a separator is read.
|
inline |
|
inline |
|
inline |
Finds an attribute set by name.
[in] | name | a const reference to the name of the attribute set |
|
inline |
Finds an attribute set by name.
[in] | name | a const reference to the name of the attribute set |
|
inline |
std::string GEO::GeoFile::read_chunk_class | ( | ) |
Reads a chunk class from the file.
A chunk class is a 4 characters string. The function checks that I/O was completed and throws a GeoFileException if the file is truncated.
index_t GEO::GeoFile::read_int | ( | ) |
Reads an integer from the file.
Checks that I/O was completed and throws a GeoFileException if the file is truncated. In Standard mode a 32-bits integer is written. In Gargantua mode a 64-bits integer is written.
size_t GEO::GeoFile::read_size | ( | ) |
Reads an unsigned 64 bits integer from the file.
Checks that I/O was completed and throws a GeoFileException if the file is truncated.
std::string GEO::GeoFile::read_string | ( | ) |
Reads a string from the file.
Checks that I/O was completed and throws a GeoFileException if the file is truncated.
void GEO::GeoFile::read_string_array | ( | std::vector< std::string > & | strings | ) |
Reads a string array from the file.
[out] | strings | the read string array, as a reference to a vector of strings. |
|
static |
Declares a new attribute type that can be read from and written to ascii files.
[in] | type_name | the C++ type name of the attribute |
[in] | read | the function pointer for reading an attribute |
[in] | write | the function pointer for writing an attribute |
size_t GEO::GeoFile::string_array_size | ( | const std::vector< std::string > & | strings | ) | const |
Gets the size in bytes used by a given string array in the file.
|
inline |
void GEO::GeoFile::write_chunk_class | ( | const std::string & | chunk_class | ) |
Writes a chunk class into the file.
A chunk class is a 4 characters string. The function checks that I/O was completed and throws a GeoFileException if the file is truncated.
[in] | chunk_class | A 4 characters string with the chunk class. |
void GEO::GeoFile::write_chunk_header | ( | const std::string & | chunk_class, |
size_t | size | ||
) |
Writes a chunk header into the file.
[in] | chunk_class | the chunk class |
[in] | size | the size in bytes of the data attached to the chunk. |
When reading the file, to skip the chunk, one calls fseek(file_, size, SEEK_CUR)
void GEO::GeoFile::write_int | ( | index_t | x, |
const char * | comment = nullptr |
||
) |
Writes an integer into the file.
Checks that I/O was completed and throws a GeoFileException if the file is truncated. In Standard mode a 32-bits integer is read. In Gargantua mode a 64-bits integer is read.
[in] | x | the integer |
[in] | comment | an optional comment string, written to ASCII geofiles |
void GEO::GeoFile::write_size | ( | size_t | x | ) |
Writes an unsigned 64 bits integer into the file.
Checks that I/O was completed and throws a GeoFileException if the file is truncated.
[in] | x | the integer |
void GEO::GeoFile::write_string | ( | const std::string & | s, |
const char * | comment = nullptr |
||
) |
Writes a string into the file.
Checks that I/O was completed and throws a GeoFileException if the file is truncated.
[in] | s | a const reference to the string |
[in] | comment | an optional comment string, written to ASCII geofiles |
void GEO::GeoFile::write_string_array | ( | const std::vector< std::string > & | strings | ) |
Writes a string array into the file.
[in] | strings | the string array, as a const reference to a vector of strings. |