forked from organicmaps/organicmaps
Pass functor in ForEachFeature by reference.
This commit is contained in:
parent
eb15ccc1e3
commit
aca3014c79
5 changed files with 29 additions and 27 deletions
|
@ -4,7 +4,6 @@
|
|||
#include "data_factory.hpp"
|
||||
#include "features_vector.hpp"
|
||||
#include "scale_index.hpp"
|
||||
#include "scales.hpp"
|
||||
#include "search_trie.hpp"
|
||||
|
||||
#include "../../defines.hpp"
|
||||
|
@ -33,7 +32,7 @@ template <class BaseT> class IndexForEachAdapter : public BaseT
|
|||
{
|
||||
private:
|
||||
template <typename F>
|
||||
void CallForIntervals(F const & f, covering::IntervalsT const & intervals,
|
||||
void CallForIntervals(F & f, covering::IntervalsT const & intervals,
|
||||
m2::RectD const & rect, uint32_t scale) const
|
||||
{
|
||||
for (size_t i = 0; i < intervals.size(); ++i)
|
||||
|
@ -45,13 +44,13 @@ private:
|
|||
|
||||
public:
|
||||
template <typename F>
|
||||
void ForEachInRect(F const & f, m2::RectD const & rect, uint32_t scale) const
|
||||
void ForEachInRect(F & f, m2::RectD const & rect, uint32_t scale) const
|
||||
{
|
||||
CallForIntervals(f, covering::CoverViewportAndAppendLowerLevels(rect), rect, scale);
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
void ForEachInRect_TileDrawing(F const & f, m2::RectD const & rect, uint32_t scale) const
|
||||
void ForEachInRect_TileDrawing(F & f, m2::RectD const & rect, uint32_t scale) const
|
||||
{
|
||||
using namespace covering;
|
||||
|
||||
|
@ -62,15 +61,8 @@ public:
|
|||
}
|
||||
|
||||
public:
|
||||
|
||||
template <typename F>
|
||||
void ForEachInViewport(F const & f, m2::RectD const & viewport) const
|
||||
{
|
||||
ForEachInRect(f, viewport, scales::GetScaleLevel(viewport));
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
void ForEachInScale(F const & f, uint32_t scale) const
|
||||
void ForEachInScale(F & f, uint32_t scale) const
|
||||
{
|
||||
int64_t const rootId = RectId("").ToInt64();
|
||||
BaseT::ForEachInIntervalAndScale(f, rootId, rootId + RectId("").SubTreeSize(), scale,
|
||||
|
@ -101,7 +93,7 @@ public:
|
|||
}
|
||||
|
||||
template <typename F>
|
||||
void ForEachInIntervalAndScale(F const & f, int64_t beg, int64_t end, uint32_t scale,
|
||||
void ForEachInIntervalAndScale(F & f, int64_t beg, int64_t end, uint32_t scale,
|
||||
m2::RectD const & occlusionRect) const
|
||||
{
|
||||
for (size_t iIndex = 0; true;)
|
||||
|
@ -400,7 +392,7 @@ public:
|
|||
}
|
||||
|
||||
template <typename F>
|
||||
void ForEachInIntervalAndScale(F const & f, int64_t beg, int64_t end, uint32_t scale) const
|
||||
void ForEachInIntervalAndScale(F & f, int64_t beg, int64_t end, uint32_t scale) const
|
||||
{
|
||||
OffsetToFeatureReplacer<F> offsetToFeatureReplacer(m_FeatureVector, f);
|
||||
BaseT::ForEachInIntervalAndScale(offsetToFeatureReplacer, beg, end, scale);
|
||||
|
@ -413,10 +405,10 @@ private:
|
|||
class OffsetToFeatureReplacer
|
||||
{
|
||||
FeatureVectorT const & m_V;
|
||||
F const & m_F;
|
||||
F & m_F;
|
||||
|
||||
public:
|
||||
OffsetToFeatureReplacer(FeatureVectorT const & v, F const & f) : m_V(v), m_F(f) {}
|
||||
OffsetToFeatureReplacer(FeatureVectorT const & v, F & f) : m_V(v), m_F(f) {}
|
||||
void operator() (uint32_t offset) const
|
||||
{
|
||||
FeatureType feature;
|
||||
|
@ -436,7 +428,7 @@ public:
|
|||
UniqueOffsetAdapter(T1 const & t1, T2 & t2) : BaseT(t1, t2) {}
|
||||
|
||||
template <typename F>
|
||||
void ForEachInIntervalAndScale(F const & f, int64_t beg, int64_t end, uint32_t scale) const
|
||||
void ForEachInIntervalAndScale(F & f, int64_t beg, int64_t end, uint32_t scale) const
|
||||
{
|
||||
unordered_set<uint32_t> offsets;
|
||||
UniqueOffsetFunctorAdapter<F> uniqueOffsetFunctorAdapter(offsets, f);
|
||||
|
@ -447,7 +439,7 @@ private:
|
|||
template <typename F>
|
||||
struct UniqueOffsetFunctorAdapter
|
||||
{
|
||||
UniqueOffsetFunctorAdapter(unordered_set<uint32_t> & offsets, F const & f)
|
||||
UniqueOffsetFunctorAdapter(unordered_set<uint32_t> & offsets, F & f)
|
||||
: m_Offsets(offsets), m_F(f) {}
|
||||
|
||||
void operator() (uint32_t offset) const
|
||||
|
@ -457,7 +449,7 @@ private:
|
|||
}
|
||||
|
||||
unordered_set<uint32_t> & m_Offsets;
|
||||
F const & m_F;
|
||||
F & m_F;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -61,7 +61,8 @@ UNIT_TEST(BuildIndexTest)
|
|||
index.Add(fileName);
|
||||
|
||||
// Make sure that index is actually parsed.
|
||||
index.ForEachInScale(NoopFunctor(), 15);
|
||||
NoopFunctor fn;
|
||||
index.ForEachInScale(fn, 15);
|
||||
}
|
||||
|
||||
// Clean after the test.
|
||||
|
|
|
@ -13,5 +13,6 @@ UNIT_TEST(IndexParseTest)
|
|||
index.Add("minsk-pass" DATA_FILE_EXTENSION);
|
||||
|
||||
// Make sure that index is actually parsed.
|
||||
index.ForEachInScale(NoopFunctor(), 15);
|
||||
NoopFunctor fn;
|
||||
index.ForEachInScale(fn, 15);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "../indexer/index.hpp"
|
||||
#include "../indexer/scales.hpp"
|
||||
|
||||
#include "../geometry/rect2d.hpp"
|
||||
#include "../geometry/point2d.hpp"
|
||||
|
@ -39,20 +40,26 @@ namespace model
|
|||
void Clean();
|
||||
void ClearCaches();
|
||||
|
||||
// process features by param type indices
|
||||
/// @name Features enumeration.
|
||||
//@{
|
||||
template <class ToDo>
|
||||
void ForEachFeature(m2::RectD const & rect, ToDo toDo) const
|
||||
void ForEachFeature(m2::RectD const & rect, ToDo & toDo) const
|
||||
{
|
||||
m_multiIndex.ForEachInViewport(toDo, rect);
|
||||
// Uncomment to traverse all features (SLOW!!):
|
||||
// m_multiIndex.ForEachInScale(toDo, GetScaleLevel(rect));
|
||||
ForEachFeature(rect, toDo, scales::GetScaleLevel(rect));
|
||||
}
|
||||
|
||||
template <class ToDo>
|
||||
void ForEachFeature_TileDrawing(m2::RectD const & rect, ToDo const & toDo, int scale) const
|
||||
void ForEachFeature(m2::RectD const & rect, ToDo & toDo, int scale) const
|
||||
{
|
||||
m_multiIndex.ForEachInRect(toDo, rect, scale);
|
||||
}
|
||||
|
||||
template <class ToDo>
|
||||
void ForEachFeature_TileDrawing(m2::RectD const & rect, ToDo & toDo, int scale) const
|
||||
{
|
||||
m_multiIndex.ForEachInRect_TileDrawing(toDo, rect, scale);
|
||||
}
|
||||
//@}
|
||||
|
||||
index_t const & GetIndex() const { return m_multiIndex; }
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "../indexer/feature_visibility.hpp"
|
||||
#include "../indexer/string_search_utils.hpp"
|
||||
#include "../indexer/scales.hpp"
|
||||
|
||||
#include "../base/exception.hpp"
|
||||
#include "../base/stl_add.hpp"
|
||||
|
|
Loading…
Add table
Reference in a new issue