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: d06128a67f63a75a321bbbf61c0fa404133fc5cb (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
#pragma once

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

#include "base/macros.hpp"

class MwmValue;

namespace search
{
namespace v2
{
struct MwmContext
{
  MwmContext(MwmSet::MwmHandle handle);

  MwmSet::MwmHandle m_handle;
  MwmValue & m_value;
  FeaturesVector m_vector;
  ScaleIndex<ModelReaderPtr> m_index;

  inline MwmSet::MwmId const & GetId() const { return m_handle.GetId(); }
  inline string const & GetName() const { return GetInfo()->GetCountryName(); }
  shared_ptr<MwmInfo> const & GetInfo() const;

  template <class TFn> void ForEachFeature(m2::RectD const & rect, TFn && fn)
  {
    feature::DataHeader const & header = m_value.GetHeader();
    covering::CoveringGetter covering(rect, covering::ViewportWithLowLevels);

    uint32_t const scale = header.GetLastScale();
    covering::IntervalsT const & interval = covering.Get(scale);

    CheckUniqueIndexes checkUnique(header.GetFormat() >= version::Format::v5);
    for (auto const & i : interval)
    {
      m_index.ForEachInIntervalAndScale([&](uint32_t index)
                                        {
                                          if (checkUnique(index))
                                          {
                                            FeatureType ft;
                                            GetFeature(index, ft);
                                            fn(ft);
                                          }
                                        }, i.first, i.second, scale);
    }
  }

  inline void GetFeature(uint32_t index, FeatureType & ft) const
  {
    m_vector.GetByIndex(index, ft);
    ft.SetID(FeatureID(GetId(), index));
  }

  DISALLOW_COPY_AND_MOVE(MwmContext);
};
}  // namespace v2
}  // namespace search