/
githubmirror
/
omim
Обзор
Документация
Войти
/
githubmirror
/
omim
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
android-95
generator/utils.hpp
96 строк
3 KB
Maksim Andrianov
[generator] Added complex_generator
08 окт 2019, 18:48
08 окт 2019, 18:48
59e7eaa
Код
Авторство
О чём код?
#pragma once #include "generator/gen_mwm_info.hpp" #include "search/cbv.hpp" #include "indexer/data_source.hpp" #include "indexer/mwm_set.hpp" #include "platform/local_country_file.hpp" #include "coding/file_reader.hpp" #include "coding/reader.hpp" #include "geometry/point2d.hpp" #include "base/logging.hpp" #include <csignal> #include <cstdint> #include <string> #include <unordered_map> #include <vector> #define MAIN_WITH_ERROR_HANDLING(func) \ int main(int argc, char ** argv) \ { \ std::signal(SIGABRT, generator::ErrorHandler); \ std::signal(SIGSEGV, generator::ErrorHandler); \ return func(argc, argv); \ } namespace generator { void ErrorHandler(int signum); /// \brief This class is wrapper around |DataSource| if only one mwm is registered in DataSource. class SingleMwmDataSource { public: /// \param mwmPath is a path to mwm which should be registerd in DataSource. explicit SingleMwmDataSource(std::string const & mwmPath); DataSource & GetDataSource() { return m_dataSource; } std::string GetPath(MapFileType type) const { return m_countryFile.GetPath(type); } MwmSet::MwmId const & GetMwmId() const { return m_mwmId; } private: FrozenDataSource m_dataSource; platform::LocalCountryFile m_countryFile; MwmSet::MwmId m_mwmId; }; void LoadDataSource(DataSource & dataSource); class FeatureGetter { public: FeatureGetter(std::string const & countryFullPath); std::unique_ptr<FeatureType> GetFeatureByIndex(uint32_t index) const; private: SingleMwmDataSource m_mwm; std::unique_ptr<FeaturesLoaderGuard> m_guard; }; template <typename ToDo> bool ForEachOsmId2FeatureId(std::string const & path, ToDo && toDo) { generator::OsmID2FeatureID mapping; try { FileReader reader(path); NonOwningReaderSource source(reader); mapping.ReadAndCheckHeader(source); } catch (FileReader::Exception const & e) { LOG(LERROR, ("Exception while reading file:", path, ", message:", e.Msg())); return false; } mapping.ForEach([&](auto const & p) { toDo(p.first /* osm id */, p.second /* feature id */); }); return true; } bool ParseFeatureIdToOsmIdMapping(std::string const & path, std::unordered_map<uint32_t, base::GeoObjectId> & mapping); bool ParseFeatureIdToTestIdMapping(std::string const & path, std::unordered_map<uint32_t, uint64_t> & mapping); search::CBV GetLocalities(std::string const & dataPath); } // namespace generator