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

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

#include "storage/country_decl.hpp"

#include "geometry/region2d.hpp"

#include "coding/file_container.hpp"

#include "base/cache.hpp"


namespace storage
{
  class CountryInfoGetter
  {
    FilesContainerR m_reader;

    vector<CountryDef> m_countries;

    template <class ToDo> void ForEachCountry(string const & prefix, ToDo toDo) const;

    /// ID - is a country file name without an extension.
    map<string, CountryInfo> m_id2info;

    mutable my::Cache<uint32_t, vector<m2::RegionD> > m_cache;

    vector<m2::RegionD> const & GetRegions(size_t id) const;

    template <class ToDo>
    void ForEachCountry(m2::PointD const & pt, ToDo & toDo) const;

    class GetByPoint
    {
      CountryInfoGetter const & m_info;
      m2::PointD const & m_pt;

    public:
      size_t m_res;

      GetByPoint(CountryInfoGetter const & info, m2::PointD const & pt)
        : m_info(info), m_pt(pt), m_res(-1)
      {
      }

      /// @param[in] id Index in m_countries.
      /// @return false If point is in country.
      bool operator() (size_t id);
    };

  public:
    CountryInfoGetter(ModelReaderPtr polyR, ModelReaderPtr countryR);

    string GetRegionFile(m2::PointD const & pt) const;

    /// @param[in] pt Point inside country.
    void GetRegionInfo(m2::PointD const & pt, CountryInfo & info) const;
    /// @param[in] id Country file name without an extension.
    void GetRegionInfo(string const & id, CountryInfo & info) const;

    /// Return limit rects of USA:\n
    /// 0 - continental part;\n
    /// 1 - Alaska;\n
    /// 2 - Hawaii;\n
    void CalcUSALimitRect(m2::RectD rects[3]) const;

    m2::RectD CalcLimitRect(string const & prefix) const;

    /// @name Used for checking that objects (by point) are belong to regions.
    //@{
    /// ID of region (index in m_countries array).
    typedef size_t IDType;
    typedef vector<IDType> IDSet;

    /// @param[in]  enName  English name to match (should be in lower case).
    /// Search is case-insensitive.
    void GetMatchedRegions(string const & enName, IDSet & regions) const;
    bool IsBelongToRegion(m2::PointD const & pt, IDSet const & regions) const;
    bool IsBelongToRegion(string const & fileName, IDSet const & regions) const;
    //@}

    /// m_cache is mutable.
    void ClearCaches() const;
  };
}