Libosmium  2.3.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 (http://osmcode.org/libosmium).
7 
8 Copyright 2013-2015 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
57 
58  }; // enum class item_type
59 
64  inline item_type nwr_index_to_item_type(unsigned int i) noexcept {
65  assert(i <= 2);
66  return item_type(i+1);
67  }
68 
73  inline unsigned int item_type_to_nwr_index(item_type type) noexcept {
74  unsigned int i = static_cast<unsigned int>(type);
75  assert(i >= 1 && i <= 3);
76  return i - 1;
77  }
78 
79  inline item_type char_to_item_type(const char c) noexcept {
80  switch (c) {
81  case 'X':
82  return item_type::undefined;
83  case 'n':
84  return item_type::node;
85  case 'w':
86  return item_type::way;
87  case 'r':
88  return item_type::relation;
89  case 'a':
90  return item_type::area;
91  case 'c':
92  return item_type::changeset;
93  case 'T':
94  return item_type::tag_list;
95  case 'N':
97  case 'M':
99  case 'F':
101  case 'O':
102  return item_type::outer_ring;
103  case 'I':
104  return item_type::inner_ring;
105  default:
106  return item_type::undefined;
107  }
108  }
109 
110 // avoid g++ false positive
111 #pragma GCC diagnostic push
112 #pragma GCC diagnostic ignored "-Wreturn-type"
113  inline char item_type_to_char(const item_type type) noexcept {
114  switch (type) {
116  return 'X';
117  case item_type::node:
118  return 'n';
119  case item_type::way:
120  return 'w';
121  case item_type::relation:
122  return 'r';
123  case item_type::area:
124  return 'a';
126  return 'c';
127  case item_type::tag_list:
128  return 'T';
130  return 'N';
132  return 'M';
134  return 'F';
136  return 'O';
138  return 'I';
139  }
140  }
141 
142  inline const char* item_type_to_name(const item_type type) noexcept {
143  switch (type) {
145  return "undefined";
146  case item_type::node:
147  return "node";
148  case item_type::way:
149  return "way";
150  case item_type::relation:
151  return "relation";
152  case item_type::area:
153  return "area";
155  return "changeset";
156  case item_type::tag_list:
157  return "tag_list";
159  return "way_node_list";
161  return "relation_member_list";
163  return "relation_member_list_with_full_members";
165  return "outer_ring";
167  return "inner_ring";
168  }
169  }
170 #pragma GCC diagnostic pop
171 
172  template <typename TChar, typename TTraits>
173  inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out, const item_type item_type) {
174  return out << item_type_to_char(item_type);
175  }
176 
183  struct unknown_type : public std::runtime_error {
184 
186  std::runtime_error("unknown item type") {
187  }
188 
189  }; // struct unknown_type
190 
191 } // namespace osmium
192 
193 #endif // OSMIUM_OSM_ITEM_TYPE_HPP
const char * item_type_to_name(const item_type type) noexcept
Definition: item_type.hpp:142
Definition: item_type.hpp:183
type
Definition: entity_bits.hpp:60
item_type
Definition: item_type.hpp:43
item_type nwr_index_to_item_type(unsigned int i) noexcept
Definition: item_type.hpp:64
unsigned int item_type_to_nwr_index(item_type type) noexcept
Definition: item_type.hpp:73
Definition: reader_iterator.hpp:39
Namespace for everything in the Osmium library.
Definition: assembler.hpp:55
unknown_type()
Definition: item_type.hpp:185
item_type char_to_item_type(const char c) noexcept
Definition: item_type.hpp:79
char item_type_to_char(const item_type type) noexcept
Definition: item_type.hpp:113