From 12da9827b65081645ecb0fdab4dfdc9c77257e1c Mon Sep 17 00:00:00 2001 From: Sergey Yershov Date: Thu, 30 Jul 2015 17:37:05 +0300 Subject: [PATCH] Review fixes --- generator/data_cache_file.hpp | 42 +++++++++++++++++++---------------- generator/osm_source.cpp | 2 ++ 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/generator/data_cache_file.hpp b/generator/data_cache_file.hpp index 742d697416..3e75bc11ab 100644 --- a/generator/data_cache_file.hpp +++ b/generator/data_cache_file.hpp @@ -4,6 +4,7 @@ #include "coding/file_reader_stream.hpp" #include "coding/file_writer_stream.hpp" +#include "coding/file_name_utils.hpp" #include "base/logging.hpp" @@ -14,7 +15,7 @@ #include "std/exception.hpp" /// Classes for reading and writing any data in file with map of offsets for -/// fast searching in memory by some user-id. +/// fast searching in memory by some key. namespace cache { namespace detail @@ -40,9 +41,9 @@ class IndexFile bool operator()(uint64_t r1, TElement const & r2) const { return (r1 < r2.first); } }; - size_t CheckedCast(uint64_t v) + static size_t CheckedCast(uint64_t v) { - ASSERT(v < numeric_limits::max(), ("Value to long for memory address : ", v)); + ASSERT_LESS(v, numeric_limits::max(), ("Value too long for memory address : ", v)); return static_cast(v); } @@ -68,6 +69,7 @@ public: return; LOG_SHORT(LINFO, ("Offsets reading is started for file ", GetFileName())); + CHECK_EQUAL(0, fileSize % sizeof(TElement), ("Damaged file.")); try { @@ -105,12 +107,14 @@ public: } template - void ForEachByKey(uint64_t k, ToDo & toDo) const + void ForEachByKey(uint64_t k, ToDo && toDo) const { auto range = equal_range(m_elements.begin(), m_elements.end(), k, ElementComparator()); for (; range.first != range.second; ++range.first) + { if (toDo((*range.first).second)) return; + } } }; } // namespace detail @@ -119,7 +123,7 @@ template class DataFileBase { public: - typedef uint64_t TKey; + using TKey = uint64_t; protected: TStream m_stream; @@ -131,16 +135,16 @@ public: class DataFileWriter : public DataFileBase { - typedef DataFileBase base_type; + using TBase = DataFileBase; public: - DataFileWriter(string const & name) : base_type(name) {} + DataFileWriter(string const & name) : TBase(name) {} - template - void Write(TKey id, T const & t) + template + void Write(TKey id, TValue const & value) { m_offsets.Write(id, m_stream.Pos()); - m_stream << t; + m_stream << value; } void SaveOffsets() { m_offsets.Flush(); } @@ -148,19 +152,19 @@ public: class DataFileReader : public DataFileBase { - typedef DataFileBase base_type; + using TBase = DataFileBase; public: - DataFileReader(string const & name) : base_type(name) {} + DataFileReader(string const & name) : TBase(name) {} - template - bool Read(TKey id, T & t) + template + bool Read(TKey id, TValue & value) { uint64_t pos; if (m_offsets.GetValueByKey(id, pos)) { m_stream.Seek(pos); - m_stream >> t; + m_stream >> value; return true; } else @@ -191,10 +195,10 @@ protected: public: BaseFileHolder(TNodesHolder & nodes, string const & dir) : m_nodes(nodes) - , m_ways(dir + WAYS_FILE) - , m_relations(dir + RELATIONS_FILE) - , m_nodes2rel(dir + NODES_FILE + ID2REL_EXT) - , m_ways2rel(dir + WAYS_FILE + ID2REL_EXT) + , m_ways(my::JoinFoldersToPath(dir, WAYS_FILE)) + , m_relations(my::JoinFoldersToPath(dir, RELATIONS_FILE)) + , m_nodes2rel(my::JoinFoldersToPath(dir, string(NODES_FILE) + ID2REL_EXT)) + , m_ways2rel(my::JoinFoldersToPath(dir, string(WAYS_FILE) + ID2REL_EXT)) { } }; diff --git a/generator/osm_source.cpp b/generator/osm_source.cpp index 2be357d0a7..9afe0f1a43 100644 --- a/generator/osm_source.cpp +++ b/generator/osm_source.cpp @@ -54,6 +54,7 @@ namespace feature struct RelationProcessor : public ElementProcessorBase { using TBase = ElementProcessorBase; + RelationProcessor(TReader & reader, ToDo & toDo) : TBase(reader, toDo) {} }; @@ -61,6 +62,7 @@ namespace feature struct CachedRelationProcessor : public RelationProcessor { using TBase = RelationProcessor; + CachedRelationProcessor(TReader & rels, ToDo & toDo) : TBase(rels, toDo) {} bool operator()(uint64_t id) { return this->m_toDo(id, this->m_reader); } };