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
6This file is part of Osmium (https://osmcode.org/libosmium).
7
8Copyright 2013-2023 Jochen Topf <jochen@topf.org> and others (see README).
9
10Boost Software License - Version 1.0 - August 17th, 2003
11
12Permission is hereby granted, free of charge, to any person or organization
13obtaining a copy of the software and accompanying documentation covered by
14this license (the "Software") to use, reproduce, display, distribute,
15execute, and transmit the Software, and to prepare derivative works of the
16Software, and to permit third-parties to whom the Software is furnished to
17do so, all subject to the following:
18
19The copyright notices in the Software and this entire statement, including
20the above license grant, this restriction and the following disclaimer,
21must be included in all copies of the Software, in whole or in part, and
22all derivative works of the Software, unless such copies or derivative
23works are solely in the form of machine-executable object code generated by
24a source language processor.
25
26THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
29SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
30FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
31ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
32DEALINGS IN THE SOFTWARE.
33
34*/
35
37
38#include <cassert>
39#include <cstdint> // IWYU pragma: keep
40#include <iosfwd>
41#include <stdexcept>
42
43namespace 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,
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':
98 case 'a':
99 return item_type::area;
100 case 'c':
102 case 'T':
103 return item_type::tag_list;
104 case 'N':
106 case 'M':
108 case 'F':
110 case 'O':
112 case 'I':
114 case 'D':
116 default: // 'X'
117 break;
118 }
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';
129 return 'r';
130 case item_type::area:
131 return 'a';
133 return 'c';
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";
161 return "relation";
162 case item_type::area:
163 return "area";
165 return "changeset";
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
const char * item_type_to_name(const item_type type) noexcept
Definition: item_type.hpp:154
item_type
Definition: item_type.hpp:45
@ relation_member_list_with_full_members
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