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

osm_element.hpp « generator - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cca5e99717b4c832608546bea8f9b5c4282f6f51 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#pragma once

#include "base/math.hpp"
#include "base/string_utils.hpp"

#include "std/exception.hpp"
#include "std/function.hpp"
#include "std/iomanip.hpp"
#include "std/iostream.hpp"
#include "std/map.hpp"
#include "std/string.hpp"
#include "std/vector.hpp"

struct OsmElement
{
  enum class EntityType
  {
    Unknown = 0x0,
    Node = 0x6F6E, // "no"
    Way = 0x6177, // "wa"
    Relation = 0x6572, // "re"
    Tag = 0x6174, // "ta"
    Nd = 0x646E, // "nd"
    Member = 0x656D, // "me"
    Osm = 0x736F, // "os"
  };

  struct Member
  {
    uint64_t ref = 0;
    EntityType type = EntityType::Unknown;
    string role;

    Member() = default;
    Member(uint64_t ref, EntityType type, string const & role)
    : ref(ref), type(type), role(role)
    {}

    bool operator == (Member const & e) const
    {
      return ref == e.ref && type == e.type && role == e.role;
    }
  };

  struct Tag
  {
    string key;
    string value;

    Tag() = default;
    Tag(string const & k, string const & v) : key(k), value(v) {}

    bool operator == (Tag const & e) const
    {
      return key == e.key && value == e.value;
    }
    bool operator < (Tag const & e) const
    {
      if (key == e.key)
        return value < e.value;
      return key < e.key;
    }
  };

  EntityType type = EntityType::Unknown;
  uint64_t id = 0;
  double lon = 0;
  double lat = 0;
  uint64_t ref = 0;
  string k;
  string v;
  EntityType memberType = EntityType::Unknown;
  string role;

  vector<uint64_t> m_nds;
  vector<Member> m_members;
  vector<Tag> m_tags;

  void Clear()
  {
    type = EntityType::Unknown;
    id = 0;
    lon = 0;
    lat = 0;
    ref = 0;
    k.clear();
    v.clear();
    memberType = EntityType::Unknown;
    role.clear();

    m_nds.clear();
    m_members.clear();
    m_tags.clear();
  }

  string ToString(string const & shift = string()) const;

  inline vector<uint64_t> const & Nodes() const { return m_nds; }
  inline vector<Member> const & Members() const { return m_members; }
  inline vector<Tag> const & Tags() const { return m_tags; }

  static EntityType StringToEntityType(string const & t)
  {
    if (t == "way")
      return EntityType::Way;
    if (t == "node")
      return EntityType::Node;
    if (t == "relation")
      return EntityType::Relation;
    ASSERT(false, ("Unknown type", t));
    return EntityType::Unknown;
  }

  bool operator == (OsmElement const & e) const
  {
    return (
            type == e.type
            && id == e.id
            && my::AlmostEqualAbs(lon, e.lon, 1e-7)
            && my::AlmostEqualAbs(lat, e.lat, 1e-7)
            && ref == e.ref
            && k == e.k
            && v == e.v
            && memberType == e.memberType
            && role == e.role
            && m_nds == e.m_nds
            && m_members == e.m_members
            && m_tags == e.m_tags
    );
  }

  void AddNd(uint64_t ref) { m_nds.emplace_back(ref); }
  void AddMember(uint64_t ref, EntityType type, string const & role)
  {
    m_members.emplace_back(ref, type, role);
  }

  void AddTag(string const & k, string const & v);
  template <class TFn> void UpdateTag(string const & k, TFn && fn)
  {
    for (auto & tag : m_tags)
    {
      if (tag.key == k)
      {
        fn(tag.value);
        return;
      }
    }

    string v;
    fn(v);
    if (!v.empty())
      AddTag(k, v);
  }

  string GetTag(string const & key) const;
};

string DebugPrint(OsmElement const & e);
string DebugPrint(OsmElement::EntityType e);
string DebugPrint(OsmElement::Tag const & tag);