1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
#pragma once
#include "search/house_to_street_table.hpp"
#include "search/lazy_centers_table.hpp"
#include "editor/osm_editor.hpp"
#include "indexer/feature_covering.hpp"
#include "indexer/feature_source.hpp"
#include "indexer/features_vector.hpp"
#include "indexer/mwm_set.hpp"
#include "indexer/scale_index.hpp"
#include "indexer/unique_index.hpp"
#include "base/macros.hpp"
#include <cstdint>
#include <memory>
#include <string>
class MwmValue;
namespace search
{
void CoverRect(m2::RectD const & rect, int scale, covering::Intervals & result);
/// @todo Move this class into "index" library and make it more generic.
/// Now it duplicates "DataSource" functionality.
class MwmContext
{
public:
explicit MwmContext(MwmSet::MwmHandle handle);
inline MwmSet::MwmId const & GetId() const { return m_handle.GetId(); }
inline string const & GetName() const { return GetInfo()->GetCountryName(); }
inline std::shared_ptr<MwmInfo> const & GetInfo() const { return GetId().GetInfo(); }
template <typename TFn>
void ForEachIndex(covering::Intervals const & intervals, uint32_t scale, TFn && fn) const
{
ForEachIndexImpl(intervals, scale, [&](uint32_t index)
{
// TODO: Optimize deleted checks by getting vector of deleted indexes from
// the Editor.
if (GetEditedStatus(index) != FeatureStatus::Deleted)
fn(index);
});
}
template <typename TFn>
void ForEachIndex(m2::RectD const & rect, TFn && fn) const
{
uint32_t const scale = m_value.GetHeader().GetLastScale();
covering::Intervals intervals;
CoverRect(rect, scale, intervals);
ForEachIndex(intervals, scale, forward<TFn>(fn));
}
template <typename TFn>
void ForEachFeature(m2::RectD const & rect, TFn && fn) const
{
uint32_t const scale = m_value.GetHeader().GetLastScale();
covering::Intervals intervals;
CoverRect(rect, scale, intervals);
ForEachIndexImpl(intervals, scale, [&](uint32_t index) {
FeatureType ft;
if (GetFeature(index, ft))
fn(ft);
});
}
// Returns false if feature was deleted by user.
WARN_UNUSED_RESULT bool GetFeature(uint32_t index, FeatureType & ft) const;
WARN_UNUSED_RESULT inline bool GetCenter(uint32_t index, m2::PointD & center)
{
return m_centers.Get(index, center);
}
MwmSet::MwmHandle m_handle;
MwmValue & m_value;
private:
FeatureStatus GetEditedStatus(uint32_t index) const
{
return osm::Editor::Instance().GetFeatureStatus(GetId(), index);
}
template <class TFn>
void ForEachIndexImpl(covering::Intervals const & intervals, uint32_t scale, TFn && fn) const
{
CheckUniqueIndexes checkUnique(m_value.GetHeader().GetFormat() >= version::Format::v5);
for (auto const & i : intervals)
m_index.ForEachInIntervalAndScale(i.first, i.second, scale,
[&](uint64_t /* key */, uint32_t value)
{
if (checkUnique(value))
fn(value);
});
}
FeaturesVector m_vector;
ScaleIndex<ModelReaderPtr> m_index;
LazyCentersTable m_centers;
DISALLOW_COPY_AND_MOVE(MwmContext);
};
} // namespace search
|