Welcome to mirror list, hosted at ThFree Co, Russian Federation.

mwm_context.hpp « v2 « search - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 191d2eea69eb2a6cefea17aa9e3b77e51a98a258 (plain)
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
#pragma once

#include "search/v2/house_to_street_table.hpp"

#include "indexer/features_vector.hpp"
#include "indexer/index.hpp"
#include "indexer/scale_index.hpp"

#include "base/macros.hpp"

#include "std/unique_ptr.hpp"

class MwmValue;

namespace search
{
namespace v2
{

void CoverRect(m2::RectD const & rect, int scale, covering::IntervalsT & result);

/// @todo Move this class into "index" library and make it more generic.
/// Now it duplicates "Index" functionality.
class MwmContext
{
public:
  MwmSet::MwmHandle m_handle;
  MwmValue & m_value;

private:
  FeaturesVector m_vector;
  ScaleIndex<ModelReaderPtr> m_index;
  unique_ptr<HouseToStreetTable> m_houseToStreetTable;

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 shared_ptr<MwmInfo> const & GetInfo() const { return GetId().GetInfo(); }

  template <class TFn> void ForEachIndex(covering::IntervalsT 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) != osm::Editor::FeatureStatus::Deleted)
        fn(index);
    });
  }

  template <class TFn> void ForEachFeature(m2::RectD const & rect, TFn && fn) const
  {
    uint32_t const scale = m_value.GetHeader().GetLastScale();
    covering::IntervalsT 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.
  bool GetFeature(uint32_t index, FeatureType & ft) const;

  bool GetStreetIndex(uint32_t houseId, uint32_t & streetId);

private:
  osm::Editor::FeatureStatus GetEditedStatus(uint32_t index) const
  {
    return osm::Editor::Instance().GetFeatureStatus(GetId(), index);
  }

  template <class TFn> void ForEachIndexImpl(covering::IntervalsT 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(
            [&] (uint32_t index)
            {
              if (checkUnique(index))
                fn(index);
            }, i.first, i.second, scale);
  }

  DISALLOW_COPY_AND_MOVE(MwmContext);
};

}  // namespace v2
}  // namespace search