[indexer] FeatureSourceFactory is not singleton anymore

This commit is contained in:
tatiana-yan 2018-06-27 18:22:48 +03:00 committed by Arsentiy Milchakov
parent 767dc57bd6
commit 2b5c62b343
5 changed files with 14 additions and 29 deletions

View file

@ -4,17 +4,19 @@
#include "indexer/data_source.hpp"
#include <memory>
class EditableDataSource : public DataSource
{
public:
EditableDataSource() : DataSource(EditableFeatureSourceFactory::Get()) {}
EditableDataSource() : DataSource(std::make_unique<EditableFeatureSourceFactory>()) {}
};
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())
{
}
};

View file

@ -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<FeatureSource> operator()(MwmSet::MwmHandle const & handle) const override
{
return std::make_unique<EditableFeatureSource>(handle);
}
protected:
EditableFeatureSourceFactory() = default;
};

View file

@ -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<FeatureID const> readFunctor(f, m_factory);
ReadMWMFunctor<FeatureID const> readFunctor(f, *m_factory);
ForEachInIntervals(readFunctor, covering::LowLevelsOnly, rect, scale);
}
void DataSource::ForEachInRect(FeatureCallback const & f, m2::RectD const & rect, int scale) const
{
ReadMWMFunctor<FeatureType> readFunctor(f, m_factory);
ReadMWMFunctor<FeatureType> readFunctor(f, *m_factory);
ForEachInIntervals(readFunctor, covering::ViewportWithLowLevels, rect, scale);
}
void DataSource::ForEachInScale(FeatureCallback const & f, int scale) const
{
ReadMWMFunctor<FeatureType> readFunctor(f, m_factory);
ReadMWMFunctor<FeatureType> 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<FeatureType> readFunctor(f, m_factory);
ReadMWMFunctor<FeatureType> 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);

View file

@ -85,7 +85,7 @@ protected:
using ReaderCallback = std::function<void(MwmSet::MwmHandle const & handle,
covering::CoveringGetter & cov, int scale)>;
explicit DataSource(FeatureSourceFactory const & factory) : m_factory(factory) {}
explicit DataSource(std::unique_ptr<FeatureSourceFactory> 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<MwmValueBase> CreateValue(MwmInfo & info) const override;
private:
FeatureSourceFactory const & m_factory;
std::unique_ptr<FeatureSourceFactory> 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<FeatureSourceFactory>()) {}
};
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())
{
}
};

View file

@ -51,21 +51,13 @@ protected:
std::unique_ptr<FeaturesVector> 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<FeatureSource> operator()(MwmSet::MwmHandle const & handle) const
{
return std::make_unique<FeatureSource>(handle);
}
protected:
FeatureSourceFactory() = default;
};