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

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

#include "params.hpp"
#include "result.hpp"
#include "search_query_factory.hpp"

#include "geometry/rect2d.hpp"

#include "coding/reader.hpp"

#include "base/mutex.hpp"

#include "std/unique_ptr.hpp"
#include "std/string.hpp"
#include "std/function.hpp"
#include "std/atomic.hpp"


class Index;

namespace search
{

class Query;

class EngineData;

class Engine
{
  typedef function<void (Results const &)> SearchCallbackT;
  Results m_searchResults;

public:
  typedef Index IndexType;

  // Doesn't take ownership of @pIndex. Takes ownership of pCategories
  Engine(IndexType const * pIndex, Reader * pCategoriesR, ModelReaderPtr polyR,
         ModelReaderPtr countryR, string const & locale, unique_ptr<SearchQueryFactory> && factory);
  ~Engine();

  void SupportOldFormat(bool b);

  void PrepareSearch(m2::RectD const & viewport);
  bool Search(SearchParams const & params, m2::RectD const & viewport);

  void GetResults(Results & res);

  string GetCountryFile(m2::PointD const & pt);
  string GetCountryCode(m2::PointD const & pt);

  int8_t GetCurrentLanguage() const;

private:
  template <class T> string GetCountryNameT(T const & t);
public:
  string GetCountryName(m2::PointD const & pt);
  string GetCountryName(string const & id);

  bool GetNameByType(uint32_t type, int8_t lang, string & name) const;

  m2::RectD GetCountryBounds(string const & file) const;

  void ClearViewportsCache();
  void ClearAllCaches();

private:
  static const int RESULTS_COUNT = 30;

  void SetRankPivot(SearchParams const & params,
                    m2::RectD const & viewport, bool viewportSearch);
  void SetViewportAsync(m2::RectD const & viewport);
  void SearchAsync();

  void EmitResults(SearchParams const & params, Results & res);

  threads::Mutex m_searchMutex, m_updateMutex;
  atomic_flag m_isReadyThread;

  SearchParams m_params;
  m2::RectD m_viewport;

  unique_ptr<Query> m_pQuery;
  unique_ptr<SearchQueryFactory> m_pFactory;
  unique_ptr<EngineData> const m_pData;
};

}  // namespace search