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

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

#include "../base/std_serialization.hpp"
#include "../base/assert.hpp"

#include "../std/utility.hpp"
#include "../std/vector.hpp"
#include "../std/string.hpp"
#include "../std/algorithm.hpp"
#include "../std/bind.hpp"


/// Used to store all world nodes inside temporary index file.
/// To find node by id, just calculate offset inside index file:
/// offset_in_file = sizeof(LatLon) * node_ID
struct LatLon
{
  double lat;
  double lon;
};
STATIC_ASSERT(sizeof(LatLon) == 16);

struct LatLonPos
{
  uint64_t pos;
  double lat;
  double lon;
};
STATIC_ASSERT(sizeof(LatLonPos) == 24);

#define NODES_FILE "nodes.dat"
#define WAYS_FILE "ways.dat"
#define RELATIONS_FILE "relations.dat"
#define OFFSET_EXT ".offs"
#define ID2REL_EXT ".id2rel"
#define MAPPED_WAYS "mapped_ways.n2w"


class progress_policy
{
  size_t m_count;
  size_t m_factor;

public:
  size_t GetCount() const { return m_count; }

  void Begin(string const &, size_t factor);
  void Inc(size_t i = 1);
  void End();
};

struct WayElement
{
  vector<uint64_t> nodes;
  uint64_t m_wayOsmId;

  explicit WayElement(uint64_t osmId) : m_wayOsmId(osmId) {}

  bool IsValid() const { return !nodes.empty(); }

  uint64_t GetOtherEndPoint(uint64_t id) const
  {
    if (id == nodes.front())
      return nodes.back();
    else
    {
      ASSERT ( id == nodes.back(), () );
      return nodes.front();
    }
  }

  template <class ToDo> void ForEachPoint(ToDo & toDo) const
  {
    for_each(nodes.begin(), nodes.end(), bind<void>(ref(toDo), _1));
  }

  template <class ToDo> void ForEachPointOrdered(uint64_t start, ToDo & toDo)
  {
    if (start == nodes.front())
      for_each(nodes.begin(), nodes.end(), bind<void>(ref(toDo), _1));
    else
      for_each(nodes.rbegin(), nodes.rend(), bind<void>(ref(toDo), _1));
  }
};

struct RelationElement
{
  typedef vector<pair<uint64_t, string> > ref_vec_t;
  ref_vec_t nodes, ways;
  map<string, string> tags;

  bool IsValid() const { return !(nodes.empty() && ways.empty()); }

  string GetType() const;
  bool FindWay(uint64_t id, string & role) const;
  bool FindNode(uint64_t id, string & role) const;

  template <class ToDo> void ForEachWay(ToDo & toDo) const
  {
    for (size_t i = 0; i < ways.size(); ++i)
      toDo(ways[i].first, ways[i].second);
  }

  void Swap(RelationElement & rhs)
  {
    nodes.swap(rhs.nodes);
    ways.swap(rhs.ways);
    tags.swap(rhs.tags);
  }
};

template <class TArchive> TArchive & operator << (TArchive & ar, WayElement const & e)
{
  ar << e.nodes;
  return ar;
}

template <class TArchive> TArchive & operator >> (TArchive & ar, WayElement & e)
{
  ar >> e.nodes;
  return ar;
}

template <class TArchive> TArchive & operator << (TArchive & ar, RelationElement const & e)
{
  ar << e.nodes << e.ways << e.tags;
  return ar;
}

template <class TArchive> TArchive & operator >> (TArchive & ar, RelationElement & e)
{
  ar >> e.nodes >> e.ways >> e.tags;
  return ar;
}