Libosmium  2.10.3
Fast and flexible C++ library for working with OpenStreetMap data
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
item_type.hpp
Go to the documentation of this file.
1 #ifndef OSMIUM_OSM_ITEM_TYPE_HPP
2 #define OSMIUM_OSM_ITEM_TYPE_HPP
3 
4 /*
5 
6 This file is part of Osmium (http://osmcode.org/libosmium).
7 
8 Copyright 2013-2016 Jochen Topf <jochen@topf.org> and others (see README).
9 
10 Boost Software License - Version 1.0 - August 17th, 2003
11 
12 Permission is hereby granted, free of charge, to any person or organization
13 obtaining a copy of the software and accompanying documentation covered by
14 this license (the "Software") to use, reproduce, display, distribute,
15 execute, and transmit the Software, and to prepare derivative works of the
16 Software, and to permit third-parties to whom the Software is furnished to
17 do so, all subject to the following:
18 
19 The copyright notices in the Software and this entire statement, including
20 the above license grant, this restriction and the following disclaimer,
21 must be included in all copies of the Software, in whole or in part, and
22 all derivative works of the Software, unless such copies or derivative
23 works are solely in the form of machine-executable object code generated by
24 a source language processor.
25 
26 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32 DEALINGS IN THE SOFTWARE.
33 
34 */
35 
36 #include <cassert>
37 #include <cstdint> // IWYU pragma: keep
38 #include <iosfwd>
39 #include <stdexcept>
40 
41 namespace osmium {
42 
43  enum class item_type : uint16_t {
44 
45  undefined = 0x00,
46  node = 0x01,
47  way = 0x02,
48  relation = 0x03,
49  area = 0x04,
50  changeset = 0x05,
51  tag_list = 0x11,
52  way_node_list = 0x12,
53  relation_member_list = 0x13,
55  outer_ring = 0x40,
56  inner_ring = 0x41,
58 
59  }; // enum class item_type
60 
69  inline item_type nwr_index_to_item_type(unsigned int i) noexcept {
70  assert(i <= 2);
71  return item_type(i+1);
72  }
73 
82  inline unsigned int item_type_to_nwr_index(item_type type) noexcept {
83  unsigned int i = static_cast<unsigned int>(type);
84  assert(i >= 1 && i <= 3);
85  return i - 1;
86  }
87 
88  inline item_type char_to_item_type(const char c) noexcept {
89  switch (c) {
90  case 'X':
91  return item_type::undefined;
92  case 'n':
93  return item_type::node;
94  case 'w':
95  return item_type::way;
96  case 'r':
97  return item_type::relation;
98  case 'a':
99  return item_type::area;
100  case 'c':
101  return item_type::changeset;
102  case 'T':
103  return item_type::tag_list;
104  case 'N':
106  case 'M':
108  case 'F':
110  case 'O':
111  return item_type::outer_ring;
112  case 'I':
113  return item_type::inner_ring;
114  case 'D':
116  default:
117  return item_type::undefined;
118  }
119  }
120 
121 // avoid g++ false positive
122 #pragma GCC diagnostic push
123 #pragma GCC diagnostic ignored "-Wreturn-type"
124  inline char item_type_to_char(const item_type type) noexcept {
125  switch (type) {
127  return 'X';
128  case item_type::node:
129  return 'n';
130  case item_type::way:
131  return 'w';
132  case item_type::relation:
133  return 'r';
134  case item_type::area:
135  return 'a';
137  return 'c';
138  case item_type::tag_list:
139  return 'T';
141  return 'N';
143  return 'M';
145  return 'F';
147  return 'O';
149  return 'I';
151  return 'D';
152  }
153  }
154 
155  inline const char* item_type_to_name(const item_type type) noexcept {
156  switch (type) {
158  return "undefined";
159  case item_type::node:
160  return "node";
161  case item_type::way:
162  return "way";
163  case item_type::relation:
164  return "relation";
165  case item_type::area:
166  return "area";
168  return "changeset";
169  case item_type::tag_list:
170  return "tag_list";
172  return "way_node_list";
174  return "relation_member_list";
176  return "relation_member_list_with_full_members";
178  return "outer_ring";
180  return "inner_ring";
182  return "changeset_discussion";
183  }
184  }
185 #pragma GCC diagnostic pop
186 
187  template <typename TChar, typename TTraits>
188  inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out, const item_type item_type) {
189  return out << item_type_to_char(item_type);
190  }
191 
198  struct unknown_type : public std::runtime_error {
199 
201  std::runtime_error("unknown item type") {
202  }
203 
204  }; // struct unknown_type
205 
206 } // namespace osmium
207 
208 #endif // OSMIUM_OSM_ITEM_TYPE_HPP
const char * item_type_to_name(const item_type type) noexcept
Definition: item_type.hpp:155
Definition: item_type.hpp:198
type
Definition: entity_bits.hpp:63
item_type
Definition: item_type.hpp:43
item_type nwr_index_to_item_type(unsigned int i) noexcept
Definition: item_type.hpp:69
unsigned int item_type_to_nwr_index(item_type type) noexcept
Definition: item_type.hpp:82
Definition: reader_iterator.hpp:39
Namespace for everything in the Osmium library.
Definition: assembler.hpp:73
unknown_type()
Definition: item_type.hpp:200
item_type char_to_item_type(const char c) noexcept
Definition: item_type.hpp:88
char item_type_to_char(const item_type type) noexcept
Definition: item_type.hpp:124