Libosmium  2.15.6
Fast and flexible C++ library for working with OpenStreetMap data
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 (https://osmcode.org/libosmium).
7 
8 Copyright 2013-2020 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  const auto 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 'n':
91  return item_type::node;
92  case 'w':
93  return item_type::way;
94  case 'r':
95  return item_type::relation;
96  case 'a':
97  return item_type::area;
98  case 'c':
99  return item_type::changeset;
100  case 'T':
101  return item_type::tag_list;
102  case 'N':
104  case 'M':
106  case 'F':
108  case 'O':
109  return item_type::outer_ring;
110  case 'I':
111  return item_type::inner_ring;
112  case 'D':
114  default: // 'X'
115  break;
116  }
117  return item_type::undefined;
118  }
119 
120  inline char item_type_to_char(const item_type type) noexcept {
121  switch (type) {
122  case item_type::node:
123  return 'n';
124  case item_type::way:
125  return 'w';
126  case item_type::relation:
127  return 'r';
128  case item_type::area:
129  return 'a';
131  return 'c';
132  case item_type::tag_list:
133  return 'T';
135  return 'N';
137  return 'M';
139  return 'F';
141  return 'O';
143  return 'I';
145  return 'D';
146  default: // item_type::undefined
147  break;
148  }
149  return 'X';
150  }
151 
152  inline const char* item_type_to_name(const item_type type) noexcept {
153  switch (type) {
154  case item_type::node:
155  return "node";
156  case item_type::way:
157  return "way";
158  case item_type::relation:
159  return "relation";
160  case item_type::area:
161  return "area";
163  return "changeset";
164  case item_type::tag_list:
165  return "tag_list";
167  return "way_node_list";
169  return "relation_member_list";
171  return "relation_member_list_with_full_members";
173  return "outer_ring";
175  return "inner_ring";
177  return "changeset_discussion";
178  default: // item_type::undefined
179  break;
180  }
181  return "undefined";
182  }
183 
184  template <typename TChar, typename TTraits>
185  inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out, const item_type item_type) {
186  return out << item_type_to_char(item_type);
187  }
188 
195  struct unknown_type : public std::runtime_error {
196 
198  std::runtime_error("unknown item type") {
199  }
200 
201  }; // struct unknown_type
202 
203 } // namespace osmium
204 
205 #endif // OSMIUM_OSM_ITEM_TYPE_HPP
const char * item_type_to_name(const item_type type) noexcept
Definition: item_type.hpp:152
Definition: item_type.hpp:195
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: location.hpp:551
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
unknown_type()
Definition: item_type.hpp:197
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:120