Libosmium  2.1.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 <cstdint> // IWYU pragma: keep
37 #include <iosfwd>
38 #include <stdexcept>
39 
40 namespace osmium {
41 
42  enum class item_type : uint16_t {
43 
44  undefined = 0x00,
45  node = 0x01,
46  way = 0x02,
47  relation = 0x03,
48  area = 0x04,
49  changeset = 0x05,
50  tag_list = 0x11,
51  way_node_list = 0x12,
52  relation_member_list = 0x13,
54  outer_ring = 0x40,
55  inner_ring = 0x41
56 
57  }; // enum class item_type
58 
59  inline item_type char_to_item_type(const char c) noexcept {
60  switch (c) {
61  case 'X':
62  return item_type::undefined;
63  case 'n':
64  return item_type::node;
65  case 'w':
66  return item_type::way;
67  case 'r':
68  return item_type::relation;
69  case 'a':
70  return item_type::area;
71  case 'c':
72  return item_type::changeset;
73  case 'T':
74  return item_type::tag_list;
75  case 'N':
77  case 'M':
79  case 'F':
81  case 'O':
82  return item_type::outer_ring;
83  case 'I':
84  return item_type::inner_ring;
85  default:
86  return item_type::undefined;
87  }
88  }
89 
90 // avoid g++ false positive
91 #pragma GCC diagnostic push
92 #pragma GCC diagnostic ignored "-Wreturn-type"
93  inline char item_type_to_char(const item_type type) noexcept {
94  switch (type) {
96  return 'X';
97  case item_type::node:
98  return 'n';
99  case item_type::way:
100  return 'w';
101  case item_type::relation:
102  return 'r';
103  case item_type::area:
104  return 'a';
106  return 'c';
107  case item_type::tag_list:
108  return 'T';
110  return 'N';
112  return 'M';
114  return 'F';
116  return 'O';
118  return 'I';
119  }
120  }
121 
122  inline const char* item_type_to_name(const item_type type) noexcept {
123  switch (type) {
125  return "undefined";
126  case item_type::node:
127  return "node";
128  case item_type::way:
129  return "way";
130  case item_type::relation:
131  return "relation";
132  case item_type::area:
133  return "area";
135  return "changeset";
136  case item_type::tag_list:
137  return "tag_list";
139  return "way_node_list";
141  return "relation_member_list";
143  return "relation_member_list_with_full_members";
145  return "outer_ring";
147  return "inner_ring";
148  }
149  }
150 #pragma GCC diagnostic pop
151 
152  template <typename TChar, typename TTraits>
153  inline std::basic_ostream<TChar, TTraits>& operator<<(std::basic_ostream<TChar, TTraits>& out, const item_type item_type) {
154  return out << item_type_to_char(item_type);
155  }
156 
163  struct unknown_type : public std::runtime_error {
164 
166  std::runtime_error("unknown item type") {
167  }
168 
169  }; // struct unknown_type
170 
171 } // namespace osmium
172 
173 #endif // OSMIUM_OSM_ITEM_TYPE_HPP
const char * item_type_to_name(const item_type type) noexcept
Definition: item_type.hpp:122
Definition: item_type.hpp:163
type
Definition: entity_bits.hpp:60
item_type
Definition: item_type.hpp:42
Definition: reader_iterator.hpp:39
Namespace for everything in the Osmium library.
Definition: assembler.hpp:55
unknown_type()
Definition: item_type.hpp:165
item_type char_to_item_type(const char c) noexcept
Definition: item_type.hpp:59
char item_type_to_char(const item_type type) noexcept
Definition: item_type.hpp:93