diff --git a/generator/data_cache_file.hpp b/generator/data_cache_file.hpp index c610386fc4..3dcacb3983 100644 --- a/generator/data_cache_file.hpp +++ b/generator/data_cache_file.hpp @@ -2,22 +2,25 @@ #include "generator/osm_decl.hpp" +#include "coding/file_name_utils.hpp" #include "coding/file_reader_stream.hpp" #include "coding/file_writer_stream.hpp" -#include "coding/file_name_utils.hpp" #include "base/logging.hpp" +#include "std/algorithm.hpp" +#include "std/exception.hpp" +#include "std/limits.hpp" #include "std/utility.hpp" #include "std/vector.hpp" -#include "std/algorithm.hpp" -#include "std/limits.hpp" -#include "std/exception.hpp" /// Classes for reading and writing any data in file with map of offsets for /// fast searching in memory by some key. namespace cache { + +enum class EMode { Write = true, Read = false }; + namespace detail { template @@ -122,13 +125,13 @@ public: } // namespace detail -template +template class OSMElementCache { public: using TKey = uint64_t; - using TStream = typename conditional::type; - using TOffsetFile = typename conditional::type; + using TStream = typename conditional::type; + using TOffsetFile = typename conditional::type; protected: TStream m_stream; @@ -164,4 +167,4 @@ public: inline void SaveOffsets() { m_offsets.WriteAll(); } inline void LoadOffsets() { m_offsets.ReadAll(); } }; -} +} // namespace cache diff --git a/generator/osm_decl.hpp b/generator/osm_decl.hpp index 8e377bf228..7cf78b62dd 100644 --- a/generator/osm_decl.hpp +++ b/generator/osm_decl.hpp @@ -1,14 +1,13 @@ #pragma once -#include "base/std_serialization.hpp" #include "base/assert.hpp" +#include "base/std_serialization.hpp" -#include "std/utility.hpp" -#include "std/vector.hpp" -#include "std/string.hpp" #include "std/algorithm.hpp" #include "std/bind.hpp" - +#include "std/string.hpp" +#include "std/utility.hpp" +#include "std/vector.hpp" #define NODES_FILE "nodes.dat" #define WAYS_FILE "ways.dat" @@ -17,7 +16,6 @@ #define ID2REL_EXT ".id2rel" #define MAPPED_WAYS "mapped_ways.n2w" - struct WayElement { vector nodes; @@ -32,16 +30,18 @@ struct WayElement if (id == nodes.front()) return nodes.back(); - ASSERT ( id == nodes.back(), () ); + ASSERT(id == nodes.back(), ()); return nodes.front(); } - template void ForEachPoint(ToDo & toDo) const + template + void ForEachPoint(ToDo & toDo) const { for_each(nodes.begin(), nodes.end(), ref(toDo)); } - template void ForEachPointOrdered(uint64_t start, ToDo & toDo) + template + void ForEachPointOrdered(uint64_t start, ToDo & toDo) { if (start == nodes.front()) for_each(nodes.begin(), nodes.end(), ref(toDo)); @@ -49,7 +49,6 @@ struct WayElement for_each(nodes.rbegin(), nodes.rend(), ref(toDo)); } - template void Write(TArchive & ar) const { @@ -81,17 +80,11 @@ public: return ((it != tags.end()) ? it->second : string()); } - bool FindWay(uint64_t id, string & role) const - { - return FindRoleImpl(ways, id, role); - } + bool FindWay(uint64_t id, string & role) const { return FindRoleImpl(ways, id, role); } + bool FindNode(uint64_t id, string & role) const { return FindRoleImpl(nodes, id, role); } - bool FindNode(uint64_t id, string & role) const - { - return FindRoleImpl(nodes, id, role); - } - - template void ForEachWay(ToDo & toDo) const + template + void ForEachWay(ToDo & toDo) const { for (size_t i = 0; i < ways.size(); ++i) toDo(ways[i].first, ways[i].second); @@ -117,14 +110,16 @@ public: } protected: - bool FindRoleImpl(TMembers const & cnt, uint64_t id, string & role) const + bool FindRoleImpl(TMembers const & container, uint64_t id, string & role) const { - for (auto const & e : cnt) + for (auto const & e : container) + { if (e.first == id) { role = e.second; return true; } + } return false; } }; diff --git a/generator/osm_source.cpp b/generator/osm_source.cpp index e330d1046f..245adb7640 100644 --- a/generator/osm_source.cpp +++ b/generator/osm_source.cpp @@ -48,13 +48,12 @@ uint64_t SourceReader::Read(char * buffer, uint64_t bufferSize) namespace { -template +template class IntermediateData { - using TReader = cache::OSMElementCache; - - using TFile = typename conditional::type; + using TReader = cache::OSMElementCache; + using TFile = typename conditional::type; using TKey = uint64_t; static_assert(is_integral::value, "TKey is not integral type"); @@ -480,7 +479,7 @@ bool GenerateFeaturesImpl(feature::GenerateInfo & info) { TNodesHolder nodes(info.GetIntermediateFileName(NODES_FILE, "")); - using TDataCache = IntermediateData; + using TDataCache = IntermediateData; TDataCache cache(nodes, info.m_intermediateDir); cache.LoadIndex(); @@ -526,7 +525,7 @@ bool GenerateIntermediateDataImpl(feature::GenerateInfo & info) try { TNodesHolder nodes(info.GetIntermediateFileName(NODES_FILE, "")); - using TDataCache = IntermediateData; + using TDataCache = IntermediateData; TDataCache cache(nodes, info.m_intermediateDir); SourceReader reader = info.m_osmFileName.empty() ? SourceReader() : SourceReader(info.m_osmFileName); @@ -558,11 +557,11 @@ bool GenerateFeatures(feature::GenerateInfo & info) switch (info.m_nodeStorageType) { case feature::GenerateInfo::NodeStorageType::File: - return GenerateFeaturesImpl>(info); + return GenerateFeaturesImpl>(info); case feature::GenerateInfo::NodeStorageType::Index: - return GenerateFeaturesImpl>(info); + return GenerateFeaturesImpl>(info); case feature::GenerateInfo::NodeStorageType::Memory: - return GenerateFeaturesImpl>(info); + return GenerateFeaturesImpl>(info); } return false; } @@ -572,11 +571,11 @@ bool GenerateIntermediateData(feature::GenerateInfo & info) switch (info.m_nodeStorageType) { case feature::GenerateInfo::NodeStorageType::File: - return GenerateIntermediateDataImpl>(info); + return GenerateIntermediateDataImpl>(info); case feature::GenerateInfo::NodeStorageType::Index: - return GenerateIntermediateDataImpl>(info); + return GenerateIntermediateDataImpl>(info); case feature::GenerateInfo::NodeStorageType::Memory: - return GenerateIntermediateDataImpl>(info); + return GenerateIntermediateDataImpl>(info); } return false; } diff --git a/generator/point_storage.hpp b/generator/point_storage.hpp index fc1e25e2d7..218d09caf2 100644 --- a/generator/point_storage.hpp +++ b/generator/point_storage.hpp @@ -23,19 +23,18 @@ struct LatLonPos }; static_assert(sizeof(LatLonPos) == 16, "Invalid structure size"); - class BasePointStorage { size_t m_processedPoint = 0; public: - enum EStorageMode {MODE_READ = false, MODE_WRITE = true}; + enum class EMode { Read = false, Write = true }; inline size_t GetProcessedPoint() const { return m_processedPoint; } inline void IncProcessedPoint() { ++m_processedPoint; } }; -template < BasePointStorage::EStorageMode TMode > +template class RawFilePointStorage : public BasePointStorage { #ifdef OMIM_OS_WINDOWS @@ -44,15 +43,15 @@ class RawFilePointStorage : public BasePointStorage using TFileReader = MmapReader; #endif - typename conditional::type m_file; + typename conditional::type m_file; constexpr static double const kValueOrder = 1E+7; public: RawFilePointStorage(string const & name) : m_file(name) {} - template - typename enable_if::type AddPoint(uint64_t id, double lat, double lng) + template + typename enable_if::type AddPoint(uint64_t id, double lat, double lng) { int64_t const lat64 = lat * kValueOrder; int64_t const lng64 = lng * kValueOrder; @@ -69,8 +68,9 @@ public: IncProcessedPoint(); } - template - typename enable_if::type GetPoint(uint64_t id, double & lat, double & lng) const + template + typename enable_if::type GetPoint(uint64_t id, double & lat, + double & lng) const { LatLon ll; m_file.Read(id * sizeof(ll), &ll, sizeof(ll)); @@ -82,57 +82,48 @@ public: lng = static_cast(ll.lon) / kValueOrder; return true; } - else - { - LOG(LERROR, ("Node with id = ", id, " not found!")); - return false; - } + LOG(LERROR, ("Node with id = ", id, " not found!")); + return false; } }; - -template < BasePointStorage::EStorageMode TMode > +template class RawMemPointStorage : public BasePointStorage { - typename conditional::type m_file; + typename conditional::type m_file; constexpr static double const kValueOrder = 1E+7; vector m_data; public: - RawMemPointStorage(string const & name) - : m_file(name) - , m_data((size_t)0xFFFFFFFF) + RawMemPointStorage(string const & name) : m_file(name), m_data((size_t)0xFFFFFFFF) { InitStorage(); } - ~RawMemPointStorage() - { - DoneStorage(); - } + ~RawMemPointStorage() { DoneStorage(); } - template - typename enable_if::type InitStorage() {} + template + typename enable_if::type InitStorage() {} - template - typename enable_if::type InitStorage() + template + typename enable_if::type InitStorage() { m_file.Read(0, m_data.data(), m_data.size() * sizeof(LatLon)); } - template - typename enable_if::type DoneStorage() + template + typename enable_if::type DoneStorage() { m_file.Write(m_data.data(), m_data.size() * sizeof(LatLon)); } - template - typename enable_if::type DoneStorage() {} + template + typename enable_if::type DoneStorage() {} - template - typename enable_if::type AddPoint(uint64_t id, double lat, double lng) + template + typename enable_if::type AddPoint(uint64_t id, double lat, double lng) { int64_t const lat64 = lat * kValueOrder; int64_t const lng64 = lng * kValueOrder; @@ -146,8 +137,9 @@ public: IncProcessedPoint(); } - template - typename enable_if::type GetPoint(uint64_t id, double & lat, double & lng) const + template + typename enable_if::type GetPoint(uint64_t id, double & lat, + double & lng) const { LatLon const & ll = m_data[id]; // assume that valid coordinate is not (0, 0) @@ -157,33 +149,27 @@ public: lng = static_cast(ll.lon) / kValueOrder; return true; } - else - { - LOG(LERROR, ("Node with id = ", id, " not found!")); - return false; - } + LOG(LERROR, ("Node with id = ", id, " not found!")); + return false; } }; -template < BasePointStorage::EStorageMode TMode > +template class MapFilePointStorage : public BasePointStorage { - typename conditional::type m_file; + typename conditional::type m_file; unordered_map> m_map; constexpr static double const kValueOrder = 1E+7; public: - MapFilePointStorage(string const & name) : m_file(name+".short") - { - InitStorage(); - } + MapFilePointStorage(string const & name) : m_file(name + ".short") { InitStorage(); } - template - typename enable_if::type InitStorage() {} + template + typename enable_if::type InitStorage() {} - template - typename enable_if::type InitStorage() + template + typename enable_if::type InitStorage() { LOG(LINFO, ("Nodes reading is started"));