forked from osm2pgsql-dev/osm2pgsql
-
Notifications
You must be signed in to change notification settings - Fork 1
/
osmtypes.hpp
123 lines (88 loc) · 2.65 KB
/
osmtypes.hpp
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
/* Data types to hold OSM node, segment, way data */
#ifndef OSMTYPES_H
#define OSMTYPES_H
// when __cplusplus is defined, we need to define this macro as well
// to get the print format specifiers in the inttypes.h header.
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include "config.h"
#include <string>
#include <vector>
#include <cmath>
typedef int64_t osmid_t;
#define strtoosmid strtoll
#define PRIdOSMID PRId64
#define POSTGRES_OSMID_TYPE "int8"
enum OsmType { OSMTYPE_WAY, OSMTYPE_NODE, OSMTYPE_RELATION };
struct osmNode {
double lon;
double lat;
osmNode() : lon(NAN), lat(NAN) {}
osmNode(double x, double y) : lon(x), lat(y) {}
};
typedef std::vector<osmNode> nodelist_t;
typedef std::vector<nodelist_t> multinodelist_t;
struct member {
OsmType type;
osmid_t id;
std::string role;
member(OsmType t, osmid_t i, const std::string &r) : type(t), id(i), role(r) {}
};
typedef std::vector<member> memberlist_t;
struct tag_t {
std::string key;
std::string value;
tag_t(const std::string &k, const std::string &v) : key(k), value(v) {}
};
class taglist_t : public std::vector<tag_t> {
typedef std::vector<tag_t> base_t;
public:
const tag_t *find(const std::string &key) const { return _find(key); }
tag_t *find(const std::string &key) { return const_cast<tag_t *>(_find(key)); }
int indexof(const std::string &key) const
{
for (size_t i = 0; i < size(); ++i)
if (at(i).key == key)
return int(i);
return -1;
}
const std::string *get(const std::string &key) const
{
for (base_t::const_iterator it = begin() ; it != end(); ++it)
if (it->key == key)
return &(it->value);
return 0;
}
bool get_bool(const std::string &key, bool defval) const
{
for (base_t::const_iterator it = begin() ; it != end(); ++it)
if (it->key == key) {
if (!defval &&
(it->value == "yes" || it->value == "true" || it->value == "1"))
return true;
if (defval &&
(it->value == "no" || it->value == "false" || it->value == "0"))
return false;
return defval;
}
return defval;
}
void push_dedupe(const tag_t& t)
{
if (find(t.key) == 0)
push_back(t);
}
bool contains(const std::string &key) const { return _find(key) != 0; }
private:
const tag_t *_find(const std::string &key) const
{
for (base_t::const_iterator it = begin() ; it != end(); ++it)
if (it->key == key)
return &(*it);
return 0;
}
};
typedef std::vector<taglist_t> multitaglist_t;
typedef std::vector<osmid_t> idlist_t;
typedef std::vector<const std::string *> rolelist_t;
#endif