Libosmium  2.20.0
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-2023 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 
37 
38 #include <cassert>
39 #include <cstdint> // IWYU pragma: keep
40 #include <iosfwd>
41 #include <stdexcept>
42 
43 namespace osmium {
44 
45  enum class item_type : uint16_t {
46 
47  undefined = 0x00,
48  node = 0x01,
49  way = 0x02,
50  relation = 0x03,
51  area = 0x04,
52  changeset = 0x05,
53  tag_list = 0x11,
54  way_node_list = 0x12,
55  relation_member_list = 0x13,
57  outer_ring = 0x40,
58  inner_ring = 0x41,
60 
61  }; // enum class item_type
62 
71  inline item_type nwr_index_to_item_type(unsigned int i) noexcept {
72  assert(i <= 2);
73  return static_cast<item_type>(i + 1);
74  }
75 
84  inline unsigned int item_type_to_nwr_index(item_type type) noexcept {
85  const auto i = static_cast<unsigned int>(type);
86  assert(i >= 1 && i <= 3);
87  return i - 1;
88  }
89 
90  inline item_type char_to_item_type(const char c) noexcept {
91  switch (c) {
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: // 'X'
117  break;
118  }
119  return item_type::undefined;
120  }
121 
122  inline char item_type_to_char(const item_type type) noexcept {
123  switch (type) {
124  case item_type::node:
125  return 'n';
126  case item_type::way:
127  return 'w';
128  case item_type::relation:
129  return 'r';
130  case item_type::area:
131  return 'a';
133  return 'c';
134  case item_type::tag_list:
135  return 'T';
137  return 'N';
139  return 'M';
141  return 'F';
143  return 'O';
145  return 'I';
147  return 'D';
148  default: // item_type::undefined
149  break;
150  }
151  return 'X';
152  }
153 
154  inline const char* item_type_to_name(const item_type type) noexcept {
155  switch (type) {
156  case item_type::node:
157  return "node";
158  case item_type::way:
159  return "way";
160  case item_type::relation:
161  return "relation";
162  case item_type::area:
163  return "area";
165  return "changeset";
166  case item_type::tag_list:
167  return "tag_list";
169  return "way_node_list";
171  return "relation_member_list";
173  return "relation_member_list_with_full_members";
175  return "outer_ring";
177  return "inner_ring";
179  return "changeset_discussion";
180  default: // item_type::undefined
181  break;
182  }
183  return "undefined";
184  }
185 
186  template <typename TChar, typename TTraits>
187  inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out, const item_type item_type) {
188  return out << item_type_to_char(item_type);
189  }
190 
197  struct OSMIUM_EXPORT unknown_type : public std::runtime_error {
198 
200  std::runtime_error{"unknown item type"} {
201  }
202 
203  }; // struct unknown_type
204 
205 } // namespace osmium
206 
207 #endif // OSMIUM_OSM_ITEM_TYPE_HPP
#define OSMIUM_EXPORT
Definition: compatibility.hpp:54
type
Definition: entity_bits.hpp:63
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
item_type char_to_item_type(const char c) noexcept
Definition: item_type.hpp:90
unsigned int item_type_to_nwr_index(item_type type) noexcept
Definition: item_type.hpp:84
item_type
Definition: item_type.hpp:45
@ relation_member_list_with_full_members
const char * item_type_to_name(const item_type type) noexcept
Definition: item_type.hpp:154
item_type nwr_index_to_item_type(unsigned int i) noexcept
Definition: item_type.hpp:71
char item_type_to_char(const item_type type) noexcept
Definition: item_type.hpp:122
std::basic_ostream< TChar, TTraits > & operator<<(std::basic_ostream< TChar, TTraits > &out, const item_type item_type)
Definition: item_type.hpp:187
Definition: location.hpp:555
Definition: item_type.hpp:197
unknown_type()
Definition: item_type.hpp:199