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

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

#include "indexer/index.hpp"

#include "geometry/point2d.hpp"
#include "geometry/rect2d.hpp"
#include "geometry/tree4d.hpp"

#include "std/set.hpp"


class Index;

namespace search
{

struct LocalityItem
{
  string m_name;
  uint32_t m_population;

  typedef uint32_t ID;
  ID m_id;

  LocalityItem(uint32_t population, ID id, string const & name);

  friend string DebugPrint(LocalityItem const & item);
};

class LocalityFinder
{
  struct Cache
  {
    m4::Tree<LocalityItem> m_tree;
    set<LocalityItem::ID> m_loaded;
    size_t m_usage;
    m2::RectD m_rect;

    Cache() : m_usage(0) {}

    void Clear();
    void GetLocality(m2::PointD const & pt, string & name);
  };

public:
  LocalityFinder(Index const * pIndex);

  void SetLanguage(int8_t lang)
  {
    if (m_lang != lang)
    {
      ClearCache();
      m_lang = lang;
    }
  }

  void GetLocality(m2::PointD const & pt, string & name);
  void ClearCache();

protected:
  void UpdateCache(Cache & cache, m2::PointD const & pt) const;

private:
  friend class DoLoader;

  Index const * m_pIndex;

  Cache m_caches[10];

  int8_t m_lang;
};

} // namespace search