diff options
author | vng <viktor.govako@gmail.com> | 2015-07-17 15:51:04 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:57:14 +0300 |
commit | 4df12718bfe698acf09dccdb383409f7b3468ef3 (patch) | |
tree | 4f1fd9cec808b643a7bd4855d1aa7c9ab0f93f74 | |
parent | 68403bb083aa9f66b90d9d3bdc8b14223508ab77 (diff) |
Simplified feature::DataHeader routine.
-rw-r--r-- | coding/file_container.cpp | 4 | ||||
-rw-r--r-- | coding/file_container.hpp | 2 | ||||
-rw-r--r-- | generator/dumper.cpp | 5 | ||||
-rw-r--r-- | generator/feature_sorter.cpp | 2 | ||||
-rw-r--r-- | indexer/data_factory.cpp | 26 | ||||
-rw-r--r-- | indexer/data_factory.hpp | 5 | ||||
-rw-r--r-- | indexer/data_header.cpp | 30 | ||||
-rw-r--r-- | indexer/data_header.hpp | 19 | ||||
-rw-r--r-- | indexer/features_vector.cpp | 17 | ||||
-rw-r--r-- | indexer/features_vector.hpp | 15 | ||||
-rw-r--r-- | map/benchmark_engine.cpp | 10 | ||||
-rw-r--r-- | map/benchmark_tool/features_loading.cpp | 38 | ||||
-rw-r--r-- | map/benchmark_tool/main.cpp | 8 |
13 files changed, 72 insertions, 109 deletions
diff --git a/coding/file_container.cpp b/coding/file_container.cpp index 0368c2b3d9..ece196ed24 100644 --- a/coding/file_container.cpp +++ b/coding/file_container.cpp @@ -61,10 +61,10 @@ void FilesContainerBase::ReadInfo(ReaderT & reader) // FilesContainerR ///////////////////////////////////////////////////////////////////////////// -FilesContainerR::FilesContainerR(string const & fName, +FilesContainerR::FilesContainerR(string const & filePath, uint32_t logPageSize, uint32_t logPageCount) - : m_source(new FileReader(fName, logPageSize, logPageCount)) + : m_source(new FileReader(filePath, logPageSize, logPageCount)) { ReadInfo(m_source); } diff --git a/coding/file_container.hpp b/coding/file_container.hpp index ac5640a814..406cdf95f9 100644 --- a/coding/file_container.hpp +++ b/coding/file_container.hpp @@ -107,7 +107,7 @@ class FilesContainerR : public FilesContainerBase public: typedef ModelReaderPtr ReaderT; - explicit FilesContainerR(string const & fName, + explicit FilesContainerR(string const & filePath, uint32_t logPageSize = 10, uint32_t logPageCount = 10); explicit FilesContainerR(ReaderT const & file); diff --git a/generator/dumper.cpp b/generator/dumper.cpp index aa4f0719c9..73c14cfcbc 100644 --- a/generator/dumper.cpp +++ b/generator/dumper.cpp @@ -197,10 +197,7 @@ namespace feature void DumpSearchTokens(string const & fPath) { FilesContainerR container(new FileReader(fPath)); - - feature::DataHeader header; - header.Load(container.GetReader(HEADER_FILE_TAG)); - + feature::DataHeader header(container); serial::CodingParams cp(search::GetCPForTrie(header.GetDefCodingParams())); unique_ptr<search::TrieIterator> const pTrieRoot( diff --git a/generator/feature_sorter.cpp b/generator/feature_sorter.cpp index 6871bdbe9e..076e7f4ccb 100644 --- a/generator/feature_sorter.cpp +++ b/generator/feature_sorter.cpp @@ -191,7 +191,7 @@ namespace feature points_t m_current; - DataHeader m_header; + DataHeader const & m_header; void WriteOuterPoints(points_t const & points, int i) { diff --git a/indexer/data_factory.cpp b/indexer/data_factory.cpp index e1fd15b847..68c0cc4264 100644 --- a/indexer/data_factory.cpp +++ b/indexer/data_factory.cpp @@ -1,36 +1,12 @@ #include "indexer/data_factory.hpp" #include "indexer/interval_index.hpp" #include "indexer/old/interval_index_101.hpp" -#include "indexer/mwm_version.hpp" -#include "defines.hpp" - -#include "coding/file_reader.hpp" -#include "coding/file_container.hpp" - - -using FHeaderT = feature::DataHeader; - -void LoadMapHeader(FilesContainerR const & cont, FHeaderT & header) -{ - ModelReaderPtr headerReader = cont.GetReader(HEADER_FILE_TAG); - version::MwmVersion version; - - if (version::ReadVersion(cont, version)) - header.Load(headerReader, version.format); - else - header.LoadV1(headerReader); -} - -void LoadMapHeader(ModelReaderPtr const & reader, FHeaderT & header) -{ - LoadMapHeader(FilesContainerR(reader), header); -} void IndexFactory::Load(FilesContainerR const & cont) { ReadVersion(cont, m_version); - LoadMapHeader(cont, m_header); + m_header.Load(cont); } IntervalIndexIFace * IndexFactory::CreateIndex(ModelReaderPtr reader) diff --git a/indexer/data_factory.hpp b/indexer/data_factory.hpp index 1026496563..34b5c76bae 100644 --- a/indexer/data_factory.hpp +++ b/indexer/data_factory.hpp @@ -2,8 +2,6 @@ #include "indexer/data_header.hpp" #include "indexer/mwm_version.hpp" -#include "coding/reader.hpp" - class FilesContainerR; class IntervalIndexIFace; @@ -21,6 +19,3 @@ public: IntervalIndexIFace * CreateIndex(ModelReaderPtr reader); }; - -void LoadMapHeader(FilesContainerR const & cont, feature::DataHeader & header); -void LoadMapHeader(ModelReaderPtr const & reader, feature::DataHeader & header); diff --git a/indexer/data_header.cpp b/indexer/data_header.cpp index 4e89333bcd..c426c4c046 100644 --- a/indexer/data_header.cpp +++ b/indexer/data_header.cpp @@ -2,17 +2,28 @@ #include "indexer/point_to_int64.hpp" #include "indexer/scales.hpp" -#include "defines.hpp" +#include "platform/platform.hpp" -#include "coding/file_reader.hpp" -#include "coding/file_writer.hpp" #include "coding/file_container.hpp" +#include "coding/file_writer.hpp" #include "coding/write_to_sink.hpp" #include "coding/varint.hpp" +#include "defines.hpp" + namespace feature { + DataHeader::DataHeader(string const & fileName) + : DataHeader((FilesContainerR(GetPlatform().GetReader(fileName)))) + { + } + + DataHeader::DataHeader(FilesContainerR const & cont) + { + Load(cont); + } + serial::CodingParams DataHeader::GetCodingParams(int scaleIndex) const { return serial::CodingParams(m_codingParams.GetCoordBits() - @@ -93,7 +104,18 @@ namespace feature WriteVarInt(w, static_cast<int32_t>(m_type)); } - void DataHeader::Load(ModelReaderPtr const & r, version::Format format /* = version::lastFormat */) + void DataHeader::Load(FilesContainerR const & cont) + { + ModelReaderPtr headerReader = cont.GetReader(HEADER_FILE_TAG); + version::MwmVersion version; + + if (version::ReadVersion(cont, version)) + Load(headerReader, version.format); + else + LoadV1(headerReader); + } + + void DataHeader::Load(ModelReaderPtr const & r, version::Format format) { ReaderSource<ModelReaderPtr> src(r); m_codingParams.Load(src); diff --git a/indexer/data_header.hpp b/indexer/data_header.hpp index d4ba2d43e2..b8d3b986a9 100644 --- a/indexer/data_header.hpp +++ b/indexer/data_header.hpp @@ -8,8 +8,9 @@ #include "base/buffer_vector.hpp" -class ModelReaderPtr; +class FilesContainerR; class FileWriter; +class ModelReaderPtr; namespace feature { @@ -28,6 +29,9 @@ namespace feature buffer_vector<uint8_t, 2> m_langs; public: + DataHeader() = default; + explicit DataHeader(string const & fileName); + explicit DataHeader(FilesContainerR const & cont); inline void SetCodingParams(serial::CodingParams const & cp) { @@ -66,12 +70,7 @@ namespace feature /// @name Serialization //@{ void Save(FileWriter & w) const; - - /// Use lastFormat as a default value for indexes building. - /// Pass the valid format from wmw in all other cases. - void Load(ModelReaderPtr const & r, version::Format format = version::lastFormat); - void LoadV1(ModelReaderPtr const & r); - //@} + void Load(FilesContainerR const & cont); enum MapType { @@ -86,5 +85,11 @@ namespace feature private: version::Format m_format; MapType m_type; + + /// Use lastFormat as a default value for indexes building. + /// Pass the valid format from wmw in all other cases. + void Load(ModelReaderPtr const & r, version::Format format); + void LoadV1(ModelReaderPtr const & r); + //@} }; } diff --git a/indexer/features_vector.cpp b/indexer/features_vector.cpp index a070f6286b..32bdab3adc 100644 --- a/indexer/features_vector.cpp +++ b/indexer/features_vector.cpp @@ -3,6 +3,8 @@ #include "mwm_version.hpp" #include "data_factory.hpp" +#include "platform/constants.hpp" + void FeaturesVector::GetByIndex(uint32_t ind, FeatureType & ft) const { @@ -13,23 +15,12 @@ void FeaturesVector::GetByIndex(uint32_t ind, FeatureType & ft) const FeaturesVectorTest::FeaturesVectorTest(string const & filePath) - : m_cont(filePath), m_initializer(this), m_vector(m_cont, m_header, 0) + : FeaturesVectorTest((FilesContainerR(filePath, READER_CHUNK_LOG_SIZE, READER_CHUNK_LOG_COUNT))) { - Init(); } FeaturesVectorTest::FeaturesVectorTest(FilesContainerR const & cont) - : m_cont(cont), m_initializer(this), m_vector(m_cont, m_header, 0) -{ - Init(); -} - -FeaturesVectorTest::Initializer::Initializer(FeaturesVectorTest * p) -{ - LoadMapHeader(p->m_cont, p->m_header); -} - -void FeaturesVectorTest::Init() + : m_cont(cont), m_header(m_cont), m_vector(m_cont, m_header, 0) { if (m_header.GetFormat() >= version::v5) m_vector.m_table = feature::FeaturesOffsetsTable::CreateIfNotExistsAndLoad(m_cont).release(); diff --git a/indexer/features_vector.hpp b/indexer/features_vector.hpp index 2b90b6efeb..3c63fc3833 100644 --- a/indexer/features_vector.hpp +++ b/indexer/features_vector.hpp @@ -4,8 +4,6 @@ #include "coding/var_record_reader.hpp" -#include "std/noncopyable.hpp" - namespace feature { class FeaturesOffsetsTable; } @@ -13,6 +11,8 @@ namespace feature { class FeaturesOffsetsTable; } /// You should have separate instance of Vector for every thread. class FeaturesVector { + DISALLOW_COPY(FeaturesVector); + public: FeaturesVector(FilesContainerR const & cont, feature::DataHeader const & header, feature::FeaturesOffsetsTable const * table) @@ -52,20 +52,13 @@ private: }; /// Test features vector (reader) that combines all the needed data for stand-alone work. -class FeaturesVectorTest : private noncopyable +/// Used in generator_tool and unit tests. +class FeaturesVectorTest { FilesContainerR m_cont; feature::DataHeader m_header; - - struct Initializer - { - Initializer(FeaturesVectorTest * p); - } m_initializer; - FeaturesVector m_vector; - void Init(); - public: explicit FeaturesVectorTest(string const & filePath); explicit FeaturesVectorTest(FilesContainerR const & cont); diff --git a/map/benchmark_engine.cpp b/map/benchmark_engine.cpp index 208cd1bb94..08ac130052 100644 --- a/map/benchmark_engine.cpp +++ b/map/benchmark_engine.cpp @@ -4,7 +4,6 @@ #include "indexer/data_header.hpp" #include "platform/settings.hpp" -#include "platform/platform.hpp" #include "coding/file_container.hpp" #include "coding/reader_streambuf.hpp" @@ -17,13 +16,9 @@ class DoGetBenchmarks set<string> m_processed; BenchmarkEngine & m_engine; - Platform & m_pl; public: - DoGetBenchmarks(BenchmarkEngine & engine) - : m_engine(engine), m_pl(GetPlatform()) - { - } + explicit DoGetBenchmarks(BenchmarkEngine & engine) : m_engine(engine) {} void operator() (vector<string> const & v) { @@ -38,8 +33,7 @@ public: { try { - feature::DataHeader header; - header.Load(FilesContainerR(m_pl.GetReader(v[0])).GetReader(HEADER_FILE_TAG)); + feature::DataHeader header(v[0]); r = header.GetBounds(); } catch (RootException const & e) diff --git a/map/benchmark_tool/features_loading.cpp b/map/benchmark_tool/features_loading.cpp index a316188916..8f7d711c07 100644 --- a/map/benchmark_tool/features_loading.cpp +++ b/map/benchmark_tool/features_loading.cpp @@ -2,8 +2,6 @@ #include "map/feature_vec_model.hpp" -#include "indexer/data_factory.hpp" -#include "indexer/data_header.hpp" #include "indexer/feature_visibility.hpp" #include "indexer/scales.hpp" @@ -14,6 +12,7 @@ #include "base/macros.hpp" #include "base/timer.hpp" + namespace bench { @@ -99,34 +98,29 @@ namespace void RunFeaturesLoadingBenchmark(string const & file, pair<int, int> scaleR, AllResult & res) { - string baseName = file; - my::GetNameFromFullPath(baseName); - - // Check that file is relative to maps dir. - ASSERT_EQUAL(file, baseName, ()); - - string countryFileName = baseName; - my::GetNameWithoutExt(countryFileName); + string fileName = file; + my::GetNameFromFullPath(fileName); + my::GetNameWithoutExt(fileName); platform::LocalCountryFile localFile = - platform::LocalCountryFile::MakeForTesting(countryFileName); + platform::LocalCountryFile::MakeForTesting(fileName); - feature::DataHeader header; - LoadMapHeader(GetPlatform().GetCountryReader(localFile, TMapOptions::EMap), header); + model::FeaturesFetcher src; + auto const r = src.RegisterMap(localFile); + if (r.second != MwmSet::RegResult::Success) + return; - pair<int, int> const r = header.GetScaleRange(); - if (r.first > scaleR.first) - scaleR.first = r.first; - if (r.second < scaleR.second) - scaleR.second = r.second; + uint8_t const minS = r.first.GetInfo()->m_minScale; + uint8_t const maxS = r.first.GetInfo()->m_maxScale; + if (minS > scaleR.first) + scaleR.first = minS; + if (maxS < scaleR.second) + scaleR.second = maxS; if (scaleR.first > scaleR.second) return; - model::FeaturesFetcher src; - UNUSED_VALUE(src.RegisterMap(platform::LocalCountryFile::MakeForTesting(countryFileName))); - - RunBenchmark(src, header.GetBounds(), scaleR, res); + RunBenchmark(src, r.first.GetInfo()->m_limitRect, scaleR, res); } } diff --git a/map/benchmark_tool/main.cpp b/map/benchmark_tool/main.cpp index 040ea2c348..ce11784b1a 100644 --- a/map/benchmark_tool/main.cpp +++ b/map/benchmark_tool/main.cpp @@ -1,9 +1,7 @@ #include "map/benchmark_tool/api.hpp" #include "indexer/classificator_loader.hpp" -#include "indexer/data_factory.hpp" - -#include "platform/platform.hpp" +#include "indexer/data_header.hpp" #include "std/iostream.hpp" @@ -31,9 +29,7 @@ int main(int argc, char ** argv) if (FLAGS_print_scales) { - feature::DataHeader h; - LoadMapHeader(GetPlatform().GetReader(FLAGS_input), h); - + feature::DataHeader h(FLAGS_input); cout << "Scales with geometry: "; for (size_t i = 0; i < h.GetScalesCount(); ++i) cout << h.GetScale(i) << " "; |