From 2b5c62b34300f48028cd44112198699231cdde26 Mon Sep 17 00:00:00 2001 From: tatiana-yan Date: Wed, 27 Jun 2018 18:22:48 +0300 Subject: [PATCH] [indexer] FeatureSourceFactory is not singleton anymore --- editor/editable_data_source.hpp | 6 ++++-- editor/editable_feature_source.hpp | 9 --------- indexer/data_source.cpp | 10 +++++----- indexer/data_source.hpp | 8 ++++---- indexer/feature_source.hpp | 10 +--------- 5 files changed, 14 insertions(+), 29 deletions(-) diff --git a/editor/editable_data_source.hpp b/editor/editable_data_source.hpp index af5e4ae0b0..7de80bc45b 100644 --- a/editor/editable_data_source.hpp +++ b/editor/editable_data_source.hpp @@ -4,17 +4,19 @@ #include "indexer/data_source.hpp" +#include + class EditableDataSource : public DataSource { public: - EditableDataSource() : DataSource(EditableFeatureSourceFactory::Get()) {} + EditableDataSource() : DataSource(std::make_unique()) {} }; class EditableFeaturesLoaderGuard : public DataSource::FeaturesLoaderGuard { public: EditableFeaturesLoaderGuard(DataSource const & dataSource, DataSource::MwmId const & id) - : DataSource::FeaturesLoaderGuard(dataSource, id, EditableFeatureSourceFactory::Get()) + : DataSource::FeaturesLoaderGuard(dataSource, id, EditableFeatureSourceFactory()) { } }; diff --git a/editor/editable_feature_source.hpp b/editor/editable_feature_source.hpp index 99bb6126b7..3dadf59801 100644 --- a/editor/editable_feature_source.hpp +++ b/editor/editable_feature_source.hpp @@ -27,18 +27,9 @@ public: class EditableFeatureSourceFactory : public FeatureSourceFactory { public: - static EditableFeatureSourceFactory const & Get() - { - static EditableFeatureSourceFactory const factory; - return factory; - } - // FeatureSourceFactory overrides: std::unique_ptr operator()(MwmSet::MwmHandle const & handle) const override { return std::make_unique(handle); } - -protected: - EditableFeatureSourceFactory() = default; }; diff --git a/indexer/data_source.cpp b/indexer/data_source.cpp index 6e290b5623..aba44b226e 100644 --- a/indexer/data_source.cpp +++ b/indexer/data_source.cpp @@ -238,19 +238,19 @@ void DataSource::ForEachInIntervals(ReaderCallback const & fn, covering::Coverin void DataSource::ForEachFeatureIDInRect(FeatureIdCallback const & f, m2::RectD const & rect, int scale) const { - ReadMWMFunctor readFunctor(f, m_factory); + ReadMWMFunctor readFunctor(f, *m_factory); ForEachInIntervals(readFunctor, covering::LowLevelsOnly, rect, scale); } void DataSource::ForEachInRect(FeatureCallback const & f, m2::RectD const & rect, int scale) const { - ReadMWMFunctor readFunctor(f, m_factory); + ReadMWMFunctor readFunctor(f, *m_factory); ForEachInIntervals(readFunctor, covering::ViewportWithLowLevels, rect, scale); } void DataSource::ForEachInScale(FeatureCallback const & f, int scale) const { - ReadMWMFunctor readFunctor(f, m_factory); + ReadMWMFunctor readFunctor(f, *m_factory); ForEachInIntervals(readFunctor, covering::FullCover, m2::RectD::GetInfiniteRect(), scale); } @@ -261,7 +261,7 @@ void DataSource::ForEachInRectForMWM(FeatureCallback const & f, m2::RectD const if (handle.IsAlive()) { covering::CoveringGetter cov(rect, covering::ViewportWithLowLevels); - ReadMWMFunctor readFunctor(f, m_factory); + ReadMWMFunctor readFunctor(f, *m_factory); readFunctor(handle, cov, scale); } } @@ -280,7 +280,7 @@ void DataSource::ReadFeatures(FeatureConstCallback const & fn, if (handle.IsAlive()) { // Prepare features reading. - auto src = m_factory(handle); + auto src = (*m_factory)(handle); do { auto const fts = src->GetFeatureStatus(fidIter->m_index); diff --git a/indexer/data_source.hpp b/indexer/data_source.hpp index 723257e3b0..52c7f58222 100644 --- a/indexer/data_source.hpp +++ b/indexer/data_source.hpp @@ -85,7 +85,7 @@ protected: using ReaderCallback = std::function; - explicit DataSource(FeatureSourceFactory const & factory) : m_factory(factory) {} + explicit DataSource(std::unique_ptr factory) : m_factory(std::move(factory)) {} void ForEachInIntervals(ReaderCallback const & fn, covering::CoveringMode mode, m2::RectD const & rect, int scale) const; @@ -95,7 +95,7 @@ protected: std::unique_ptr CreateValue(MwmInfo & info) const override; private: - FeatureSourceFactory const & m_factory; + std::unique_ptr m_factory; }; // DataSource which operates with features from mwm file and does not support features creation @@ -103,14 +103,14 @@ private: class FrozenDataSource : public DataSource { public: - FrozenDataSource() : DataSource(FeatureSourceFactory::Get()) {} + FrozenDataSource() : DataSource(std::make_unique()) {} }; class FrozenFeaturesLoaderGuard : public DataSource::FeaturesLoaderGuard { public: FrozenFeaturesLoaderGuard(DataSource const & dataSource, DataSource::MwmId const & id) - : DataSource::FeaturesLoaderGuard(dataSource, id, FeatureSourceFactory::Get()) + : DataSource::FeaturesLoaderGuard(dataSource, id, FeatureSourceFactory()) { } }; diff --git a/indexer/feature_source.hpp b/indexer/feature_source.hpp index 3c1019fe07..93e8fc4ee5 100644 --- a/indexer/feature_source.hpp +++ b/indexer/feature_source.hpp @@ -51,21 +51,13 @@ protected: std::unique_ptr m_vector; }; // class FeatureSource +// Lightweight FeatureSource factory. Each DataSource owns factory object. class FeatureSourceFactory { public: virtual ~FeatureSourceFactory() = default; - static FeatureSourceFactory const & Get() - { - static FeatureSourceFactory const factory; - return factory; - } - virtual std::unique_ptr operator()(MwmSet::MwmHandle const & handle) const { return std::make_unique(handle); } - -protected: - FeatureSourceFactory() = default; };