From 839dd9aed6c95bcd21f4976ae416dfe78fe06112 Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Fri, 24 Nov 2017 12:15:08 +0100 Subject: [PATCH] Specify mount points from command line --- src/ifcconvert/IfcConvert.cpp | 7 ++++++- src/ifcparse/IfcHdf5File.cpp | 33 ++++++++++++++++++++++++++++++++- src/ifcparse/IfcHdf5File.h | 2 +- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/ifcconvert/IfcConvert.cpp b/src/ifcconvert/IfcConvert.cpp index eab063847e..40ba40533c 100644 --- a/src/ifcconvert/IfcConvert.cpp +++ b/src/ifcconvert/IfcConvert.cpp @@ -108,8 +108,11 @@ int main(int argc, char** argv) { std::string bounds, hdf5_profile; uint32_t hdf5_chunk_size; + std::vector entity_vector; std::vector hdf5_ref_attributes; + std::vector hdf5_mount_points; + boost::program_options::options_description geom_options; geom_options.add_options() ("plan", @@ -161,6 +164,8 @@ int main(int argc, char** argv) { ("hdf5-fix-global-id", "") ("hdf5-instantiate-inverse", "") ("hdf5-instantiate-select", "") + ("hdf5-mount", boost::program_options::value< std::vector >(&hdf5_mount_points)->multitoken(), + "") ("hdf5-chunk-size", boost::program_options::value(&hdf5_chunk_size), "") ("hdf5-ref-attributes", boost::program_options::value< std::vector >(&hdf5_ref_attributes)->multitoken(), "") @@ -322,7 +327,7 @@ int main(int argc, char** argv) { } } else if (input_extension == ".hdf") { std::ofstream fs(output_filename.c_str()); - IfcParse::IfcHdf5File::convert_to_spf(input_filename, fs); + IfcParse::IfcHdf5File::convert_to_spf(input_filename, fs, hdf5_mount_points); success = true; } else { Logger::Message(Logger::LOG_ERROR, "Unknown input extension"); diff --git a/src/ifcparse/IfcHdf5File.cpp b/src/ifcparse/IfcHdf5File.cpp index 34f627a377..d1b51035b5 100644 --- a/src/ifcparse/IfcHdf5File.cpp +++ b/src/ifcparse/IfcHdf5File.cpp @@ -2331,8 +2331,31 @@ void write_spf_header(const H5::Group& group, std::ostream& out) { spf_header.write(out); } -void IfcParse::IfcHdf5File::convert_to_spf(const std::string& name, std::ostream& output) { +void IfcParse::IfcHdf5File::convert_to_spf(const std::string& name, std::ostream& output, const boost::optional< std::vector >& mount_points) { H5::H5File f(name, H5F_ACC_RDONLY); + std::vector children; + + if (mount_points) { + std::transform(mount_points->begin(), mount_points->end(), std::back_inserter(children), [&f](const std::string& directive) { + + auto split_string = [](const std::string& s, std::string& left, std::string& right) { + const size_t pos = s.find('='); + left = s.substr(0, pos); + if (pos != std::string::npos) { + right = s.substr(pos + 1); + } + }; + + std::string point, path; + split_string(directive, point, path); + + H5::H5File* child = new H5::H5File(path, H5F_ACC_RDONLY); + f.mount(point, *child, H5::PropList::DEFAULT); + + return child; + + }); + } std::map offset_mapping; @@ -2352,4 +2375,12 @@ void IfcParse::IfcHdf5File::convert_to_spf(const std::string& name, std::ostream output << "ENDSEC;\nEND-ISO-10303-21;\n"; } } + + std::for_each(children.begin(), children.end(), [](H5::H5File* child) { + child->close(); + delete child; + }); + + f.close(); + } diff --git a/src/ifcparse/IfcHdf5File.h b/src/ifcparse/IfcHdf5File.h index 17ee2f91a5..052c756fa0 100644 --- a/src/ifcparse/IfcHdf5File.h +++ b/src/ifcparse/IfcHdf5File.h @@ -211,7 +211,7 @@ namespace IfcParse { { }; - static void convert_to_spf(const std::string& name, std::ostream& output); + static void convert_to_spf(const std::string& name, std::ostream& output, const boost::optional< std::vector >& mount_points = boost::none); }; }