Libosmium  2.17.0
Fast and flexible C++ library for working with OpenStreetMap data
Loading...
Searching...
No Matches
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-2021 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
36#include <cassert>
37#include <cstdint> // IWYU pragma: keep
38#include <iosfwd>
39#include <stdexcept>
40
41namespace 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,
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':
96 case 'a':
97 return item_type::area;
98 case 'c':
100 case 'T':
101 return item_type::tag_list;
102 case 'N':
104 case 'M':
106 case 'F':
108 case 'O':
110 case 'I':
112 case 'D':
114 default: // 'X'
115 break;
116 }
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';
127 return 'r';
128 case item_type::area:
129 return 'a';
131 return 'c';
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";
159 return "relation";
160 case item_type::area:
161 return "area";
163 return "changeset";
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
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:88
unsigned int item_type_to_nwr_index(item_type type) noexcept
Definition: item_type.hpp:82
const char * item_type_to_name(const item_type type) noexcept
Definition: item_type.hpp:152
item_type
Definition: item_type.hpp:43
@ relation_member_list_with_full_members
item_type nwr_index_to_item_type(unsigned int i) noexcept
Definition: item_type.hpp:69
char item_type_to_char(const item_type type) noexcept
Definition: item_type.hpp:120
std::basic_ostream< TChar, TTraits > & operator<<(std::basic_ostream< TChar, TTraits > &out, const item_type item_type)
Definition: item_type.hpp:185
Definition: location.hpp:551
Definition: item_type.hpp:195
unknown_type()
Definition: item_type.hpp:197