Libosmium 2.22.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
6 This file is part of Osmium (https://osmcode.org/libosmium).
7
8 Copyright 2013-2025 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 <osmium/util/compatibility.hpp>
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,
56 relation_member_list_with_full_members = 0x23,
57 outer_ring = 0x40,
58 inner_ring = 0x41,
59 changeset_discussion = 0x80
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':
105 return item_type::way_node_list;
106 case 'M':
107 return item_type::relation_member_list;
108 case 'F':
109 return item_type::relation_member_list_with_full_members;
110 case 'O':
111 return item_type::outer_ring;
112 case 'I':
113 return item_type::inner_ring;
114 case 'D':
115 return item_type::changeset_discussion;
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';
132 case item_type::changeset:
133 return 'c';
134 case item_type::tag_list:
135 return 'T';
136 case item_type::way_node_list:
137 return 'N';
138 case item_type::relation_member_list:
139 return 'M';
140 case item_type::relation_member_list_with_full_members:
141 return 'F';
142 case item_type::outer_ring:
143 return 'O';
144 case item_type::inner_ring:
145 return 'I';
146 case item_type::changeset_discussion:
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";
164 case item_type::changeset:
165 return "changeset";
166 case item_type::tag_list:
167 return "tag_list";
168 case item_type::way_node_list:
169 return "way_node_list";
170 case item_type::relation_member_list:
171 return "relation_member_list";
172 case item_type::relation_member_list_with_full_members:
173 return "relation_member_list_with_full_members";
174 case item_type::outer_ring:
175 return "outer_ring";
176 case item_type::inner_ring:
177 return "inner_ring";
178 case item_type::changeset_discussion:
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
199 unknown_type() :
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
compatibility.hpp
OSMIUM_EXPORT
#define OSMIUM_EXPORT
Definition compatibility.hpp:45
osmium
Namespace for everything in the Osmium library.
Definition assembler.hpp:53
osmium::char_to_item_type
item_type char_to_item_type(const char c) noexcept
Definition item_type.hpp:90
osmium::item_type_to_nwr_index
unsigned int item_type_to_nwr_index(item_type type) noexcept
Definition item_type.hpp:84
osmium::item_type_to_name
const char * item_type_to_name(const item_type type) noexcept
Definition item_type.hpp:154
osmium::item_type
item_type
Definition item_type.hpp:45
osmium::item_type::tag_list
@ tag_list
osmium::item_type::relation_member_list
@ relation_member_list
osmium::item_type::way_node_list
@ way_node_list
osmium::item_type::changeset_discussion
@ changeset_discussion
osmium::item_type::relation_member_list_with_full_members
@ relation_member_list_with_full_members
osmium::item_type::relation
@ relation
osmium::item_type::node
@ node
osmium::item_type::changeset
@ changeset
osmium::item_type::area
@ area
osmium::item_type::undefined
@ undefined
osmium::item_type::way
@ way
osmium::item_type::outer_ring
@ outer_ring
osmium::item_type::inner_ring
@ inner_ring
osmium::nwr_index_to_item_type
item_type nwr_index_to_item_type(unsigned int i) noexcept
Definition item_type.hpp:71
osmium::item_type_to_char
char item_type_to_char(const item_type type) noexcept
Definition item_type.hpp:122
osmium::operator<<
std::basic_ostream< TChar, TTraits > & operator<<(std::basic_ostream< TChar, TTraits > &out, const item_type item_type)
Definition item_type.hpp:187
std
Definition location.hpp:555
osmium::unknown_type
Definition item_type.hpp:197
osmium::unknown_type::unknown_type
unknown_type()
Definition item_type.hpp:199