diff --git a/include/tiles/osm/tmp_file.h b/include/tiles/osm/tmp_file.h new file mode 100644 index 0000000..46ea713 --- /dev/null +++ b/include/tiles/osm/tmp_file.h @@ -0,0 +1,43 @@ +#pragma once + +#include +#include + +#include "boost/filesystem.hpp" + +#include "utl/verify.h" + +namespace tiles { + +struct tmp_file { + explicit tmp_file(std::string path) + : path_{std::move(path)}, +#ifdef _MSC_VER + file_(std::fopen(path_.c_str(), "wb+")) +#else + file_(std::fopen(path_.c_str(), "wb+e")) +#endif + { + utl::verify(file_ != nullptr, "tmp_file: unable to open file {}", path_); + } + + ~tmp_file() { + if (file_ != nullptr) { + std::fclose(file_); + boost::filesystem::remove(path_); + } + file_ = nullptr; + } + + tmp_file(tmp_file const&) = default; + tmp_file(tmp_file&&) = default; + tmp_file& operator=(tmp_file const&) = default; + tmp_file& operator=(tmp_file&&) = default; + + int fileno() const { return ::fileno(file_); } + + std::string path_; + FILE* file_; +}; + +} // namespace tiles \ No newline at end of file diff --git a/src/osm/load_osm.cc b/src/osm/load_osm.cc index 0fd41ff..3715312 100644 --- a/src/osm/load_osm.cc +++ b/src/osm/load_osm.cc @@ -17,6 +17,7 @@ #include "tiles/db/tile_database.h" #include "tiles/osm/feature_handler.h" #include "tiles/osm/hybrid_node_idx.h" +#include "tiles/osm/tmp_file.h" #include "tiles/util.h" #include "tiles/util_parallel.h" @@ -29,37 +30,6 @@ namespace orel = osmium::relations; namespace om = osmium::memory; namespace oeb = osmium::osm_entity_bits; -struct tmp_file { - explicit tmp_file(std::string path) - : path_{std::move(path)}, -#ifdef _MSC_VER - file_(std::fopen(path_.c_str(), "wb+")) -#else - file_(std::fopen(path_.c_str(), "wb+e")) -#endif - { - utl::verify(file_ != nullptr, "tmp_file: unable to open file {}", path_); - } - - ~tmp_file() { - if (file_ != nullptr) { - std::fclose(file_); - boost::filesystem::remove(path_); - } - file_ = nullptr; - } - - tmp_file(tmp_file const&) = default; - tmp_file(tmp_file&&) = default; - tmp_file& operator=(tmp_file const&) = default; - tmp_file& operator=(tmp_file&&) = default; - - int fileno() const { return ::fileno(file_); } - - std::string path_; - FILE* file_; -}; - void load_osm(tile_db_handle& db_handle, feature_inserter_mt& inserter, std::string const& osm_fname, std::string const& osm_profile, std::string const& tmp_dname) {