Some successes writing and reading

This commit is contained in:
Thomas Krijnen
2025-02-27 22:07:31 +01:00
parent c58c8269af
commit ce4407ff3c
19 changed files with 678 additions and 527 deletions
+14 -10
View File
@@ -206,7 +206,7 @@ size_t read_filters_from_file(const std::string&, inclusion_filter&, inclusion_t
void parse_filter(geom_filter &, const std::vector<std::string>&);
std::vector<IfcGeom::filter_t> setup_filters(const std::vector<geom_filter>&, const std::string&);
bool init_input_file(const std::string& filename, IfcParse::IfcFile*& ifc_file, bool no_progress, bool mmap);
bool init_input_file(const std::string& filename, IfcParse::IfcFile*& ifc_file, bool no_progress, bool mmap, bool rocksdb);
// from https://stackoverflow.com/questions/31696328/boost-program-options-using-zero-parameter-options-multiple-times
struct verbosity_counter {
@@ -239,6 +239,7 @@ int main(int argc, char** argv) {
path_t cache_file;
std::string log_format;
std::string geometry_kernel;
std::string input_format;
po::options_description generic_options("Command line options");
verbosity_counter vcounter;
@@ -254,6 +255,7 @@ int main(int argc, char** argv) {
("yes,y", "answer 'yes' automatically to possible confirmation queries (e.g. overwriting an existing output file)")
("no-progress", "suppress possible progress bar type of prints that use carriage return")
("log-format", po::value<std::string>(&log_format), "log format: plain or json")
("input-format", po::value<std::string>(&input_format), "input format: ifcspf, ifcxml, rocksdb")
("log-file", new po::typed_value<path_t, char_t>(&log_file), "redirect log output to file");
po::options_description fileio_options;
@@ -564,10 +566,12 @@ int main(int argc, char** argv) {
}
const path_t input_filename = vmap["input-file"].as<path_t>();
if (!file_exists(IfcUtil::path::to_utf8(input_filename))) {
/*
// todo also allow rocksdb dir
if (!file_exists(IfcUtil::path::to_utf8(input_filename))) {
cerr_ << "[Error] Input file '" << input_filename << "' does not exist" << std::endl;
return EXIT_FAILURE;
}
}*/
// If no output filename is specified a Wavefront OBJ file will be output
// to maintain backwards compatibility with the obsolete IfcObj executable.
@@ -658,7 +662,7 @@ int main(int argc, char** argv) {
if (output_extension == XML) {
int exit_code = EXIT_FAILURE;
try {
if (init_input_file(IfcUtil::path::to_utf8(input_filename), ifc_file, no_progress || quiet, mmap)) {
if (init_input_file(IfcUtil::path::to_utf8(input_filename), ifc_file, no_progress || quiet, mmap, input_format=="rocksdb")) {
time_t start, end;
time(&start);
XmlSerializer s(ifc_file, IfcUtil::path::to_utf8(output_temp_filename));
@@ -678,7 +682,7 @@ int main(int argc, char** argv) {
} else if (output_extension == IFC) {
int exit_code = EXIT_FAILURE;
try {
if (init_input_file(IfcUtil::path::to_utf8(input_filename), ifc_file, no_progress || quiet, mmap)) {
if (init_input_file(IfcUtil::path::to_utf8(input_filename), ifc_file, no_progress || quiet, mmap, input_format == "rocksdb")) {
time_t start, end;
time(&start);
std::ofstream fs(output_filename.c_str());
@@ -704,11 +708,11 @@ int main(int argc, char** argv) {
else if (output_extension == RDB) {
int exit_code = EXIT_FAILURE;
try {
if (init_input_file(IfcUtil::path::to_utf8(input_filename), ifc_file, no_progress || quiet, mmap)) {
if (init_input_file(IfcUtil::path::to_utf8(input_filename), ifc_file, no_progress || quiet, mmap, input_format == "rocksdb")) {
time_t start, end;
time(&start);
RocksDbSerializer s(ifc_file, IfcUtil::path::to_utf8(output_filename));
Logger::Status("Populating RockDB Key-Value store...");
Logger::Status("Populating RocksDB Key-Value store...");
s.finalize();
time(&end);
Logger::Status("Done! Conversion took " + format_duration(start, end));
@@ -937,7 +941,7 @@ int main(int argc, char** argv) {
time_t start,end;
time(&start);
if (!init_input_file(IfcUtil::path::to_utf8(input_filename), ifc_file, no_progress || quiet, mmap)) {
if (!init_input_file(IfcUtil::path::to_utf8(input_filename), ifc_file, no_progress || quiet, mmap, input_format == "rocksdb")) {
write_log(!quiet);
serializer.reset();
IfcUtil::path::delete_file(IfcUtil::path::to_utf8(output_temp_filename)); /**< @todo Windows Unicode support */
@@ -1270,7 +1274,7 @@ void write_log(bool header) {
#include <boost/algorithm/string/predicate.hpp>
bool init_input_file(const std::string& filename, IfcParse::IfcFile*& ifc_file, bool no_progress, bool mmap) {
bool init_input_file(const std::string& filename, IfcParse::IfcFile*& ifc_file, bool no_progress, bool mmap, bool rocksdb) {
time_t start, end;
// Prevent IfcFile::Init() prints by setting output to null temporarily
@@ -1289,7 +1293,7 @@ bool init_input_file(const std::string& filename, IfcParse::IfcFile*& ifc_file,
ifc_file = new IfcParse::IfcFile(filename, mmap);
#else
(void)mmap;
ifc_file = new IfcParse::IfcFile(filename);
ifc_file = new IfcParse::IfcFile(filename, rocksdb ? IfcParse::rocksdb : IfcParse::ifcspf);
#endif
}