/******************************************************************************** * * * This file is part of IfcOpenShell. * * * * IfcOpenShell is free software: you can redistribute it and/or modify * * it under the terms of the Lesser GNU General Public License as published by * * the Free Software Foundation, either version 3.0 of the License, or * * (at your option) any later version. * * * * IfcOpenShell is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * Lesser GNU General Public License for more details. * * * * You should have received a copy of the Lesser GNU General Public License * * along with this program. If not, see . * * * ********************************************************************************/ #ifndef IFCHDF5FILE_H #define IFCHDF5FILE_H #include "H5Cpp.h" #include "../ifcparse/IfcUtil.h" #include "../ifcparse/IfcFile.h" namespace IfcParse { class IfcHdf5File { private: class allocator_t { private: // TODO: Change this? mutable std::vector buffers; public: void* allocate(size_t n) const { return new uint8_t[n]; } void free() { std::vector::const_iterator it; for (it = buffers.begin(); it != buffers.end(); ++it) { delete[] *it; } buffers.clear(); } ~allocator_t() { free(); } }; allocator_t allocator; std::string name_; schema_definition schema_; H5::H5File* file; H5::Group schema_group; H5::Group population_group; // TODO: const H5::CompType* instance_reference; const H5::DataType* object_reference_type; std::map declared_types; // TODO: why? get_datatype() std::map default_types; std::map default_type_names; std::map default_cpp_type_names; std::map > sorted_entities; std::vector dataset_names; H5::DataType* map_type(const IfcParse::parameter_type* pt); H5::CompType* map_entity(const IfcParse::entity* e); H5::DataType* map_select(const IfcParse::select_type* pt); H5::DataType* commit(H5::DataType* dt, const std::string& name); void init_default_types(); void visit_select(const IfcParse::select_type* pt, std::set& leafs); std::string flatten_aggregate_name(const IfcParse::parameter_type* at) const; std::pair make_instance_reference(const IfcUtil::IfcBaseClass* instance) const; void write_select(void*& ptr, IfcUtil::IfcBaseClass* instance, const H5::CompType* datatype) const; void write_schema(const schema_definition& schema); void write_population(const IfcFile& f, bool compress); template const H5::DataType* get_datatype() const { return default_types.find(IfcUtil::cpp_to_schema_type::schema_type)->second; } void advance(void*& ptr, size_t n) const; template void write(void*& ptr, const T& t) const; template <> void write(void*& ptr, const std::string& s) const; void write_vlen_t(void*& ptr, size_t n_elements, void* vlen_data) const; template void write_number_of_size(void*& ptr, size_t n, T i) const; template void write_aggregate(void*& ptr, const T& ts) const; public: typedef std::pair compound_member; IfcHdf5File(const IfcFile* f, const std::string& name, bool compress) : name_(name) , schema_(*f->schema()) { write_schema(*f->schema()); write_population(*f, compress); }; }; } #endif