Geogram Version 1.9.6-rc
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. | |
~GeoFile () | |
GeoFile destructor. | |
bool | is_ascii () const |
Tests whether this GeoFile is ascii. | |
bool | gargantua_mode () const |
Tests whether this GeoFile is in GARGANTUA mode. | |
const std::string & | current_chunk_class () const |
Gets the current chunk class. | |
size_t | current_chunk_size () const |
Gets the size of the current chunk. | |
AttributeSetInfo * | find_attribute_set (const std::string &name) |
Finds an attribute set by name. | |
const AttributeSetInfo * | find_attribute_set (const std::string &name) const |
Finds an attribute set by name. | |
index_t | read_index_t () |
Reads an integer from the file. | |
void | write_index_t (index_t x, const char *comment=nullptr) |
Writes an integer into the file. | |
index_t | read_index_t_32 () |
Reads a 32-bit integer from the file. | |
void | write_index_t_32 (index_t x, const char *comment=nullptr) |
Writes a 32-bit integer into the file. | |
std::string | read_string () |
Reads a string from the file. | |
void | write_string (const std::string &s, const char *comment=nullptr) |
Writes a string into the file. | |
size_t | read_size_t () |
Reads an unsigned 64 bits integer from the file. | |
void | write_size_t (size_t x) |
Writes an unsigned 64 bits integer into the file. | |
std::string | read_chunk_class () |
Reads a chunk class from the file. | |
void | write_chunk_class (const std::string &chunk_class) |
Writes a chunk class into the file. | |
void | write_string_array (const std::vector< std::string > &strings) |
Writes a string array into the file. | |
void | read_string_array (std::vector< std::string > &strings) |
Reads a string array from the file. | |
size_t | string_size (const std::string &s) const |
Gets the size in bytes used by a given string in the file. | |
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. | |
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. | |
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. | |
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. | |
Protected Attributes | |
std::string | filename_ |
gzFile | file_ |
bool | ascii_ |
FILE * | ascii_file_ |
std::string | current_chunk_class_ |
size_t | current_chunk_size_ |
size_t | current_chunk_file_pos_ |
std::map< std::string, AttributeSetInfo > | attribute_sets_ |
bool | gargantua_mode_ |
True if current file is in GARGANTUA mode. | |
bool | convert_32_to_64_ |
True if reading a standard file in GARGANTUA mode. | |
bool | convert_64_to_32_ |
True if reading a GARGANTUA file in standard mode. | |
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:
typedef bool(* GEO::GeoFile::AsciiAttributeSerializer) (FILE *file, Memory::pointer base_address, index_t nb_elements) |
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 |
Tests whether this GeoFile is in GARGANTUA mode.
In GARGANTUA mode, index_t is 64 bits wide, else it is 32 bits. geogram can be compiled in standard or GARGANTUA mode. When loading a GARGANTUA file in standard mode, each time an index_t is read, it is checked whether it fits in 32 bits. An exception is thrown if it is not the case.
true | if this file is in GARGANTUA mode |
false | otherwise |
|
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_index_t | ( | ) |
Reads an integer from the file.
Checks that I/O was completed and throws a GeoFileException if the file is truncated. Reads 32 or 64 bits depending on whether geogram file is in GARGANTUA mode, and truncates or expands depending on current GARGANTUA mode. If file is in GARGANTUA mode and not current mode, check whether read integer fits in 32 bits and throws an exception if it is not the case.
index_t GEO::GeoFile::read_index_t_32 | ( | ) |
Reads a 32-bit integer from the file.
Checks that I/O was completed and throws a GeoFileException if the file is truncated.
size_t GEO::GeoFile::read_size_t | ( | ) |
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_index_t | ( | 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 written. In Gargantua mode a 64-bits integer is written.
[in] | x | the integer |
[in] | comment | an optional comment string, written to ASCII geofiles |
void GEO::GeoFile::write_index_t_32 | ( | index_t | x, |
const char * | comment = nullptr |
||
) |
Writes a 32-bit integer into the file.
Checks that I/O was completed and throws a GeoFileException if the file is truncated.
[in] | x | the integer |
[in] | comment | an optional comment string, written to ASCII geofiles |
void GEO::GeoFile::write_size_t | ( | 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. |
|
staticprotected |
|
staticprotected |
|
protected |
|
protected |
|
protected |
|
protected |