diff --git a/generator/statistics.cpp b/generator/statistics.cpp index c0a58d9fc..157657561 100644 --- a/generator/statistics.cpp +++ b/generator/statistics.cpp @@ -1,7 +1,6 @@ #include "statistics.hpp" #include "indexer/classificator.hpp" -#include "indexer/data_factory.hpp" #include "indexer/feature_processor.hpp" #include "geometry/mercator.hpp" diff --git a/libs/indexer/CMakeLists.txt b/libs/indexer/CMakeLists.txt index 80f49941f..48af2c680 100644 --- a/libs/indexer/CMakeLists.txt +++ b/libs/indexer/CMakeLists.txt @@ -31,8 +31,6 @@ set(SRC cuisines.hpp custom_keyvalue.cpp custom_keyvalue.hpp - data_factory.cpp - data_factory.hpp data_header.cpp data_header.hpp data_source.cpp diff --git a/libs/indexer/data_factory.cpp b/libs/indexer/data_factory.cpp deleted file mode 100644 index 651209f22..000000000 --- a/libs/indexer/data_factory.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "indexer/data_factory.hpp" - -#include "coding/files_container.hpp" - -#include "defines.hpp" - -void IndexFactory::Load(FilesContainerR const & cont) -{ - m_version = version::MwmVersion::Read(cont); - if (m_version.GetFormat() < version::Format::v11) - MYTHROW(CorruptedMwmFile, (cont.GetFileName())); - - m_header.Load(cont); - - if (cont.IsExist(REGION_INFO_FILE_TAG)) - { - ReaderSource src(cont.GetReader(REGION_INFO_FILE_TAG)); - m_regionData.Deserialize(src); - } -} diff --git a/libs/indexer/data_factory.hpp b/libs/indexer/data_factory.hpp deleted file mode 100644 index 5d1d289e7..000000000 --- a/libs/indexer/data_factory.hpp +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once -#include "indexer/data_header.hpp" -#include "indexer/feature_meta.hpp" -#include "indexer/interval_index.hpp" - -#include "platform/mwm_version.hpp" - -#include - -class FilesContainerR; - -class IndexFactory -{ - version::MwmVersion m_version; - feature::DataHeader m_header; - feature::RegionData m_regionData; - -public: - void Load(FilesContainerR const & cont); - - inline version::MwmVersion const & GetMwmVersion() const { return m_version; } - inline feature::DataHeader const & GetHeader() const { return m_header; } - inline feature::RegionData const & GetRegionData() const { return m_regionData; } - inline void MoveRegionData(feature::RegionData & data) { data = std::move(m_regionData); } - - template - std::unique_ptr> CreateIndex(Reader const & reader) const - { - return std::make_unique>(reader); - } -}; diff --git a/libs/indexer/data_source.cpp b/libs/indexer/data_source.cpp index a6205afe7..c3ac51f67 100644 --- a/libs/indexer/data_source.cpp +++ b/libs/indexer/data_source.cpp @@ -5,7 +5,6 @@ #include "platform/mwm_version.hpp" #include -#include using platform::CountryFile; using platform::LocalCountryFile; @@ -15,19 +14,19 @@ namespace class ReadMWMFunctor { public: - using Fn = std::function; - - ReadMWMFunctor(FeatureSourceFactory const & factory, Fn const & fn) : m_factory(factory), m_fn(fn) - { - m_stop = []() { return false; }; - } - - ReadMWMFunctor(FeatureSourceFactory const & factory, Fn const & fn, DataSource::StopSearchCallback const & stop) - : m_factory(factory) - , m_fn(fn) - , m_stop(stop) + template + ReadMWMFunctor(FeatureSourceFactory const & factory, FnT && fn) : m_factory(factory) + , m_fn(std::forward(fn)) {} + ReadMWMFunctor(FeatureSourceFactory const & factory, DataSource::FeatureCallback const & fn, + DataSource::StopSearchCallback stop = {}) + : m_factory(factory) + , m_stop(std::move(stop)) + { + m_fn = [&fn](uint32_t index, FeatureSource & src) { ReadFeatureType(fn, src, index); }; + } + // Reads features visible at |scale| covered by |cov| from mwm and applies |m_fn| to them. // Feature reading process consists of two steps: untouched (original) features reading and // touched (created, edited etc.) features reading. @@ -51,7 +50,7 @@ public: // Use last coding scale for covering (see index_builder.cpp). covering::Intervals const & intervals = cov.Get(lastScale); - ScaleIndex index(mwmValue->m_cont.GetReader(INDEX_FILE_TAG), mwmValue->m_factory); + ScaleIndex index(mwmValue->m_cont.GetReader(INDEX_FILE_TAG)); // iterate through intervals for (auto const & i : intervals) @@ -61,7 +60,8 @@ public: if (checkUnique(value)) m_fn(value, *src); }); - if (m_stop()) + + if (m_stop && m_stop()) break; } } @@ -75,33 +75,36 @@ public: private: FeatureSourceFactory const & m_factory; - Fn m_fn; + std::function m_fn; DataSource::StopSearchCallback m_stop; + +private: + static void ReadFeatureType(DataSource::FeatureCallback const & fn, FeatureSource & src, uint32_t index) + { + std::unique_ptr ft; + switch (src.GetFeatureStatus(index)) + { + case FeatureStatus::Deleted: + case FeatureStatus::Obsolete: return; + case FeatureStatus::Created: + case FeatureStatus::Modified: + { + ft = src.GetModifiedFeature(index); + break; + } + case FeatureStatus::Untouched: + { + ft = src.GetOriginalFeature(index); + break; + } + } + + CHECK(ft, ()); + fn(*ft); + } }; -void ReadFeatureType(std::function const & fn, FeatureSource & src, uint32_t index) -{ - std::unique_ptr ft; - switch (src.GetFeatureStatus(index)) - { - case FeatureStatus::Deleted: - case FeatureStatus::Obsolete: return; - case FeatureStatus::Created: - case FeatureStatus::Modified: - { - ft = src.GetModifiedFeature(index); - break; - } - case FeatureStatus::Untouched: - { - ft = src.GetOriginalFeature(index); - break; - } - } - CHECK(ft, ()); - fn(*ft); -} -} // namespace +} // namespace // FeaturesLoaderGuard --------------------------------------------------------------------- std::string FeaturesLoaderGuard::GetCountryFileName() const @@ -161,7 +164,12 @@ std::unique_ptr DataSource::CreateInfo(platform::LocalCountryFile const info->m_minScale = static_cast(scaleR.first); info->m_maxScale = static_cast(scaleR.second); info->m_version = value.GetMwmVersion(); - value.m_factory.MoveRegionData(info->m_data); + + if (value.m_cont.IsExist(REGION_INFO_FILE_TAG)) + { + ReaderSource src(value.m_cont.GetReader(REGION_INFO_FILE_TAG)); + info->m_data.Deserialize(src); + } return info; } @@ -234,9 +242,7 @@ void DataSource::ForEachFeatureIDInRect(FeatureIdCallback const & f, m2::RectD c void DataSource::ForEachInRect(FeatureCallback const & f, m2::RectD const & rect, int scale) const { - auto readFeatureType = [&f](uint32_t index, FeatureSource & src) { ReadFeatureType(f, src, index); }; - - ReadMWMFunctor readFunctor(*m_factory, readFeatureType); + ReadMWMFunctor readFunctor(*m_factory, f); ForEachInIntervals(readFunctor, covering::ViewportWithLowLevels, rect, scale); } @@ -244,17 +250,13 @@ void DataSource::ForClosestToPoint(FeatureCallback const & f, StopSearchCallback m2::PointD const & center, double sizeM, int scale) const { auto const rect = mercator::RectByCenterXYAndSizeInMeters(center, sizeM); - - auto readFeatureType = [&f](uint32_t index, FeatureSource & src) { ReadFeatureType(f, src, index); }; - ReadMWMFunctor readFunctor(*m_factory, readFeatureType, stop); + ReadMWMFunctor readFunctor(*m_factory, f, stop); ForEachInIntervals(readFunctor, covering::CoveringMode::Spiral, rect, scale); } void DataSource::ForEachInScale(FeatureCallback const & f, int scale) const { - auto readFeatureType = [&f](uint32_t index, FeatureSource & src) { ReadFeatureType(f, src, index); }; - - ReadMWMFunctor readFunctor(*m_factory, readFeatureType); + ReadMWMFunctor readFunctor(*m_factory, f); ForEachInIntervals(readFunctor, covering::FullCover, m2::RectD::GetInfiniteRect(), scale); } @@ -265,10 +267,7 @@ void DataSource::ForEachInRectForMWM(FeatureCallback const & f, m2::RectD const if (handle.IsAlive()) { covering::CoveringGetter cov(rect, covering::ViewportWithLowLevels); - auto readFeatureType = [&f](uint32_t index, FeatureSource & src) { ReadFeatureType(f, src, index); }; - - ReadMWMFunctor readFunctor(*m_factory, readFeatureType); - readFunctor(handle, cov, scale); + ReadMWMFunctor(*m_factory, f)(handle, cov, scale); } } diff --git a/libs/indexer/feature.cpp b/libs/indexer/feature.cpp index 06e24f3bd..96964f16e 100644 --- a/libs/indexer/feature.cpp +++ b/libs/indexer/feature.cpp @@ -358,8 +358,6 @@ void FeatureType::ParseHeader2() // For inner geometry remaining 4 bits are not used. if (elemsCount == 0) geomScalesMask = bitSource.Read(4); - else - ASSERT(headerGeomType == HeaderGeomType::Area || elemsCount > 1, ()); } ArrayByteSource src(bitSource.RoundPtr()); @@ -414,6 +412,7 @@ void FeatureType::ParseHeader2() ReadOffsets(*m_loadInfo, src, geomScalesMask, m_offsets.m_trg); } } + // Size of the whole header incl. inner geometry / triangles. m_innerStats.m_size = CalcOffset(src, m_data.data()); m_parsed.m_header2 = true; diff --git a/libs/indexer/features_vector.cpp b/libs/indexer/features_vector.cpp index 3e170424b..656fd9036 100644 --- a/libs/indexer/features_vector.cpp +++ b/libs/indexer/features_vector.cpp @@ -1,6 +1,5 @@ #include "features_vector.hpp" #include "dat_section_header.hpp" -#include "data_factory.hpp" #include "features_offsets_table.hpp" #include "platform/constants.hpp" diff --git a/libs/indexer/indexer_tests/scale_index_reading_tests.cpp b/libs/indexer/indexer_tests/scale_index_reading_tests.cpp index 2853b30cd..e3640520d 100644 --- a/libs/indexer/indexer_tests/scale_index_reading_tests.cpp +++ b/libs/indexer/indexer_tests/scale_index_reading_tests.cpp @@ -5,7 +5,6 @@ #include "generator/generator_tests_support/test_with_custom_mwms.hpp" #include "indexer/cell_id.hpp" -#include "indexer/data_factory.hpp" #include "indexer/data_header.hpp" #include "indexer/data_source.hpp" #include "indexer/feature.hpp" @@ -26,9 +25,7 @@ #include "defines.hpp" #include -#include #include -#include #include namespace scale_index_reading_tests @@ -95,15 +92,12 @@ UNIT_CLASS_TEST(ScaleIndexReadingTest, Mmap) FilesContainerR cont(path); feature::DataHeader header(cont); - IndexFactory factory; - factory.Load(cont); - auto const offsetSize = cont.GetAbsoluteOffsetAndSize(INDEX_FILE_TAG); MmapReader reader(path); ReaderPtr subReader(reader.CreateSubReader(offsetSize.first, offsetSize.second)); - ScaleIndex> index(subReader, factory); + ScaleIndex> index(subReader); auto collectNames = [&](m2::RectD const & rect) { return CollectNames(id, index, header.GetLastScale(), header.GetLastScale(), rect); }; diff --git a/libs/indexer/mwm_set.cpp b/libs/indexer/mwm_set.cpp index 8a29ec3b1..e9203c4a0 100644 --- a/libs/indexer/mwm_set.cpp +++ b/libs/indexer/mwm_set.cpp @@ -384,7 +384,11 @@ MwmValue::MwmValue(LocalCountryFile const & localFile) : m_cont(platform::GetCountryReader(localFile, MapFileType::Map)) , m_file(localFile) { - m_factory.Load(m_cont); + m_version = version::MwmVersion::Read(m_cont); + if (m_version.GetFormat() < version::Format::v11) + MYTHROW(CorruptedMwmFile, (m_cont.GetFileName())); + + m_header.Load(m_cont); } void MwmValue::SetTable(MwmInfoEx & info) diff --git a/libs/indexer/mwm_set.hpp b/libs/indexer/mwm_set.hpp index d16cd6448..9454e1f7b 100644 --- a/libs/indexer/mwm_set.hpp +++ b/libs/indexer/mwm_set.hpp @@ -1,5 +1,6 @@ #pragma once -#include "indexer/data_factory.hpp" +#include "indexer/data_header.hpp" +#include "indexer/feature_meta.hpp" #include "indexer/house_to_street_iface.hpp" #include "platform/local_country_file.hpp" @@ -373,19 +374,23 @@ class MwmValue { public: FilesContainerR const m_cont; - IndexFactory m_factory; platform::LocalCountryFile const m_file; +private: + version::MwmVersion m_version; + feature::DataHeader m_header; + +public: std::shared_ptr m_table; std::unique_ptr m_metaDeserializer; std::unique_ptr m_house2street, m_house2place; +public: explicit MwmValue(platform::LocalCountryFile const & localFile); void SetTable(MwmInfoEx & info); - feature::DataHeader const & GetHeader() const { return m_factory.GetHeader(); } - feature::RegionData const & GetRegionData() const { return m_factory.GetRegionData(); } - version::MwmVersion const & GetMwmVersion() const { return m_factory.GetMwmVersion(); } + feature::DataHeader const & GetHeader() const { return m_header; } + version::MwmVersion const & GetMwmVersion() const { return m_version; } std::string const & GetCountryFileName() const { return m_file.GetCountryName(); } bool HasSearchIndex() const { return m_cont.IsExist(SEARCH_INDEX_FILE_TAG); } diff --git a/libs/indexer/scale_index.hpp b/libs/indexer/scale_index.hpp index 60f8e226a..617453c2a 100644 --- a/libs/indexer/scale_index.hpp +++ b/libs/indexer/scale_index.hpp @@ -1,11 +1,9 @@ #pragma once -#include "indexer/data_factory.hpp" #include "indexer/interval_index.hpp" #include "coding/var_serial_vector.hpp" -#include #include #include @@ -24,26 +22,24 @@ template class ScaleIndex : public ScaleIndexBase { public: - ScaleIndex() = default; - - ScaleIndex(Reader const & reader, IndexFactory const & factory) { Attach(reader, factory); } + explicit ScaleIndex(Reader const & reader) { Attach(reader); } ~ScaleIndex() { Clear(); } void Clear() { m_IndexForScale.clear(); } - void Attach(Reader const & reader, IndexFactory const & factory) + void Attach(Reader const & reader) { Clear(); ReaderSource source(reader); VarSerialVectorReader treesReader(source); for (uint32_t i = 0; i < treesReader.Size(); ++i) - m_IndexForScale.push_back(factory.CreateIndex(treesReader.SubReader(i))); + m_IndexForScale.push_back(std::make_unique(treesReader.SubReader(i))); } - void ForEachInIntervalAndScale(uint64_t beg, uint64_t end, int scale, - std::function const & fn) const + template + void ForEachInIntervalAndScale(uint64_t beg, uint64_t end, int scale, FnT && fn) const { auto const scaleBucket = BucketByScale(scale); if (scaleBucket < m_IndexForScale.size()) @@ -52,5 +48,6 @@ public: } private: - std::vector>> m_IndexForScale; + using IndexT = IntervalIndex; + std::vector> m_IndexForScale; }; diff --git a/libs/search/mwm_context.cpp b/libs/search/mwm_context.cpp index fc2924c7b..d70b37bc6 100644 --- a/libs/search/mwm_context.cpp +++ b/libs/search/mwm_context.cpp @@ -18,7 +18,7 @@ MwmContext::MwmContext(MwmSet::MwmHandle handle) : m_handle(std::move(handle)) , m_value(*m_handle.GetValue()) , m_vector(m_value.m_cont, m_value.GetHeader(), m_value.m_table.get(), m_value.m_metaDeserializer.get()) - , m_index(m_value.m_cont.GetReader(INDEX_FILE_TAG), m_value.m_factory) + , m_index(m_value.m_cont.GetReader(INDEX_FILE_TAG)) , m_centers(m_value) , m_editableSource(m_handle) {} diff --git a/xcode/indexer/indexer.xcodeproj/project.pbxproj b/xcode/indexer/indexer.xcodeproj/project.pbxproj index 367f6cf60..56e4114f2 100644 --- a/xcode/indexer/indexer.xcodeproj/project.pbxproj +++ b/xcode/indexer/indexer.xcodeproj/project.pbxproj @@ -112,8 +112,6 @@ 675341021A3F540F00A0A8C3 /* classificator_loader.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 675340AD1A3F540F00A0A8C3 /* classificator_loader.hpp */; }; 675341031A3F540F00A0A8C3 /* classificator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 675340AE1A3F540F00A0A8C3 /* classificator.cpp */; }; 675341041A3F540F00A0A8C3 /* classificator.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 675340AF1A3F540F00A0A8C3 /* classificator.hpp */; }; - 675341071A3F540F00A0A8C3 /* data_factory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 675340B21A3F540F00A0A8C3 /* data_factory.cpp */; }; - 675341081A3F540F00A0A8C3 /* data_factory.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 675340B31A3F540F00A0A8C3 /* data_factory.hpp */; }; 675341091A3F540F00A0A8C3 /* data_header.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 675340B41A3F540F00A0A8C3 /* data_header.cpp */; }; 6753410A1A3F540F00A0A8C3 /* data_header.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 675340B51A3F540F00A0A8C3 /* data_header.hpp */; }; 6753410B1A3F540F00A0A8C3 /* drawing_rule_def.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 675340B61A3F540F00A0A8C3 /* drawing_rule_def.cpp */; }; @@ -345,8 +343,6 @@ 675340AD1A3F540F00A0A8C3 /* classificator_loader.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = classificator_loader.hpp; sourceTree = ""; }; 675340AE1A3F540F00A0A8C3 /* classificator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = classificator.cpp; sourceTree = ""; }; 675340AF1A3F540F00A0A8C3 /* classificator.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = classificator.hpp; sourceTree = ""; }; - 675340B21A3F540F00A0A8C3 /* data_factory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = data_factory.cpp; sourceTree = ""; }; - 675340B31A3F540F00A0A8C3 /* data_factory.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = data_factory.hpp; sourceTree = ""; }; 675340B41A3F540F00A0A8C3 /* data_header.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = data_header.cpp; sourceTree = ""; }; 675340B51A3F540F00A0A8C3 /* data_header.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = data_header.hpp; sourceTree = ""; }; 675340B61A3F540F00A0A8C3 /* drawing_rule_def.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = drawing_rule_def.cpp; sourceTree = ""; }; @@ -629,8 +625,6 @@ AC7C68A82A5040AC004BB71C /* custom_keyvalue.cpp */, AC7C68A72A5040AC004BB71C /* custom_keyvalue.hpp */, 40D62CEE23F2E8BE009A20F5 /* dat_section_header.hpp */, - 675340B21A3F540F00A0A8C3 /* data_factory.cpp */, - 675340B31A3F540F00A0A8C3 /* data_factory.hpp */, 675340B41A3F540F00A0A8C3 /* data_header.cpp */, 675340B51A3F540F00A0A8C3 /* data_header.hpp */, 3D928F651D50F9FE001670E0 /* data_source_helpers.cpp */, @@ -834,7 +828,6 @@ 34583BCC1C88552100F94664 /* map_object.hpp in Headers */, 456E1B1B1F90E5B7009C32E1 /* city_boundary.hpp in Headers */, 34664CF41D49FEC1003D7096 /* altitude_loader.hpp in Headers */, - 675341081A3F540F00A0A8C3 /* data_factory.hpp in Headers */, 6753410A1A3F540F00A0A8C3 /* data_header.hpp in Headers */, BBB7061023E46E0100A7F29A /* isolines_info.hpp in Headers */, 6753411B1A3F540F00A0A8C3 /* feature_impl.hpp in Headers */, @@ -1023,7 +1016,6 @@ 6753411C1A3F540F00A0A8C3 /* shared_load_info.cpp in Sources */, 67BC92F41D21476500A4A378 /* string_slice.cpp in Sources */, BBB7060F23E46E0100A7F29A /* isolines_info.cpp in Sources */, - 675341071A3F540F00A0A8C3 /* data_factory.cpp in Sources */, 408FE47724FEB95600F5D06D /* metadata_serdes.cpp in Sources */, 34583BCB1C88552100F94664 /* map_object.cpp in Sources */, 675B562320D25C9800A521D2 /* feature_source.cpp in Sources */,