40 #ifndef GEOGRAM_BASIC_GEOFILE
41 #define GEOGRAM_BASIC_GEOFILE
47 #include <geogram/third_party/zlib/zlib.h>
105 T* attrib =
reinterpret_cast<T*
>(base_addr);
106 for(
index_t i=0; i<nb_elements; ++i) {
109 while(
char(res = fgetc(file)) !=
'\n') {
113 buff.push_back(
char(res));
115 if(!String::from_string(buff.c_str(),attrib[i])) {
134 T* attrib =
reinterpret_cast<T*
>(base_addr);
135 for(
index_t i=0; i<nb_elements; ++i) {
138 file,
"%s\n", String::to_string(attrib[i]).c_str()
161 char* attrib =
reinterpret_cast<char*
>(base_addr);
162 for(
index_t i=0; i<nb_elements; ++i) {
164 if(fscanf(file,
"%d", &val) == 0) {
167 attrib[i] = char(val);
185 char* attrib =
reinterpret_cast<char*
>(base_addr);
186 for(
index_t i=0; i<nb_elements; ++i) {
187 if(fprintf(file,
"%d\n",
int(attrib[i])) == 0) {
207 char* attrib =
reinterpret_cast<char*
>(base_addr);
208 for(
index_t i=0; i<nb_elements; ++i) {
210 if(fscanf(file,
"%d", &val) == 0) {
213 attrib[i] = char(val);
231 char* attrib =
reinterpret_cast<char*
>(base_addr);
232 for(
index_t i=0; i<nb_elements; ++i) {
233 if(fprintf(file,
"%d\n",
int(attrib[i])) == 0) {
276 typedef bool (*AsciiAttributeSerializer)(
288 const std::string& type_name,
289 AsciiAttributeSerializer read,
290 AsciiAttributeSerializer write
320 return current_chunk_class_;
328 return current_chunk_size_;
350 const std::string& name_in,
351 const std::string& element_type_in,
352 size_t element_size_in,
356 element_type(element_type_in),
357 element_size(element_size_in),
358 dimension(dimension_in) {
402 const std::string& name_in,
406 nb_items(nb_items_in),
418 const std::string& name_in
420 for(
index_t i=0; i<attributes.size(); ++i) {
421 if(attributes[i].name == name_in) {
422 return &(attributes[i]);
436 for(
index_t i=0; i<attributes.size(); ++i) {
437 if(attributes[i].name == name_in) {
438 return &(attributes[i]);
473 auto it = attribute_sets_.find(name);
474 if(it == attribute_sets_.end()) {
477 return &(it->second);
487 const std::string& name
489 auto it = attribute_sets_.find(name);
490 if(it == attribute_sets_.end()) {
493 return &(it->second);
534 void write_string(
const std::string& s,
const char* comment =
nullptr);
595 return sizeof(
index_t) + s.length();
605 const std::vector<std::string>& strings
622 const std::string& chunk_class,
size_t size
646 std::string filename_;
650 std::string current_chunk_class_;
651 long current_chunk_size_;
652 long current_chunk_file_pos_;
653 std::map<std::string, AttributeSetInfo> attribute_sets_;
655 static std::map<std::string, AsciiAttributeSerializer>
656 ascii_attribute_read_;
658 static std::map<std::string, AsciiAttributeSerializer>
659 ascii_attribute_write_;
706 geo_assert(current_attribute_set_ !=
nullptr);
707 return *current_attribute_set_;
718 return *current_attribute_;
726 const std::string& current_comment()
const {
728 return current_comment_;
752 std::string current_comment_;
788 const std::string& name,
index_t nb_items
805 const std::string& attribute_set_name,
806 const std::string& attribute_name,
807 const std::string& element_type,
#define geo_assert(x)
Verifies that a condition is met.
GeoFileException(const std::string &s)
GeoFileException constructor.
GeoFileException(const GeoFileException &rhs)
GeoFileException copy constructor.
~GeoFileException() GEO_NOEXCEPT override
GeoFileException destructor.
Base class for reading or writing Geogram structured binary files.
std::string read_chunk_class()
Reads a chunk class from the file.
void check_chunk_size()
Checks that the actual chunk size corresponds to the specified chunk size.
const std::string & current_chunk_class() const
Gets the current chunk class.
void write_chunk_class(const std::string &chunk_class)
Writes a chunk class into the file.
long current_chunk_size() const
Gets the size of the current chunk.
bool is_ascii() const
Tests whether this GeoFile is ascii.
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.
GeoFile(const std::string &filename)
GeoFile constructor.
void clear_attribute_maps()
Clears all memorized information about attributes and attribute sets.
std::string read_string()
Reads a string 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.
const AttributeSetInfo * find_attribute_set(const std::string &name) const
Finds an attribute set by name.
void read_string_array(std::vector< std::string > &strings)
Reads a string array from the file.
AttributeSetInfo * find_attribute_set(const std::string &name)
Finds an attribute set by name.
void write_int(index_t x, const char *comment=nullptr)
Writes an integer into the file.
void write_string(const std::string &s, const char *comment=nullptr)
Writes a string into the file.
void check_zlib_version()
Compares the zlib version declared in the header file with the zlib version obtained from the runtime...
index_t read_int()
Reads an integer from the file.
void write_size(size_t x)
Writes an unsigned 64 bits integer into the file.
void write_string_array(const std::vector< std::string > &strings)
Writes a string array into the file.
~GeoFile()
GeoFile destructor.
void write_chunk_header(const std::string &chunk_class, size_t size)
Writes a chunk header into the file.
size_t read_size()
Reads an unsigned 64 bits integer from the file.
void read_chunk_header()
Reads a chunk header from the file.
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.
Used to write a structured binary file.
void write_attribute_set(const std::string &name, index_t nb_items)
Writes a new attribute set to the file.
void write_separator()
Writes a separator into the file.
OutputGeoFile(const std::string &filename, index_t compression_level=3)
OutputGeoFile constructor.
void write_comment(const std::string &comment)
Writes a new comment to the file.
void write_attribute(const std::string &attribute_set_name, const std::string &attribute_name, const std::string &element_type, size_t element_size, index_t dimension, const void *data)
Writes a new attribute to the file.
void write_command_line(const std::vector< std::string > &args)
Writes the command line to the file.
Vector with aligned memory allocation.
Common include file, providing basic definitions. Should be included before anything else by all head...
Types and functions for memory manipulation.
byte * pointer
Pointer to unsigned byte(s)
Global Vorpaline namespace.
bool read_ascii_attribute(FILE *file, Memory::pointer base_addr, index_t nb_elements)
Reads an ASCII attribute from a file.
bool write_ascii_attribute< bool >(FILE *file, Memory::pointer base_addr, index_t nb_elements)
Writes an ASCII attribute to a file.
geo_index_t index_t
The type for storing and manipulating indices.
bool write_ascii_attribute(FILE *file, Memory::pointer base_addr, index_t nb_elements)
Writes an ASCII attribute to a file.
bool read_ascii_attribute< char >(FILE *file, Memory::pointer base_addr, index_t nb_elements)
Reads an ASCII attribute from a file.
bool read_ascii_attribute< bool >(FILE *file, Memory::pointer base_addr, index_t nb_elements)
Reads an ASCII attribute from a file.
bool write_ascii_attribute< char >(FILE *file, Memory::pointer base_addr, index_t nb_elements)
Writes an ASCII attribute to a file.
Types and functions for numbers manipulation.
Functions for string manipulation.
Internal representation of attributes.
std::string name
Name of the attribute.
AttributeInfo()
AttributeInfo constructor.
index_t dimension
The number of elements per item.
size_t element_size
The size in bytes of each element.
std::string element_type
A string with the name fo the C++ type of the elements.
AttributeInfo(const std::string &name_in, const std::string &element_type_in, size_t element_size_in, index_t dimension_in)
AttributeInfo constructor.
Internal representation of an attribute set.
AttributeInfo * find_attribute(const std::string &name_in)
Finds an AttributeInfo by name.
AttributeSetInfo(const std::string &name_in, index_t nb_items_in)
AttributeSetInfo constructor.
const AttributeInfo * find_attribute(const std::string &name_in) const
Finds an AttributeInfo by name.
bool skip
if set, all attributes in the set are skipped when reading the file.
index_t nb_items
number of items in each attribute of the set.
vector< AttributeInfo > attributes
the attributes of the set.
AttributeSetInfo()
AttributeSetInfo constructor.
std::string name
name of the attribute set.