Libosmium: include/osmium/osm/item_type.hpp Source File

Libosmium 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-2026 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 <osmium/util/compatibility.hpp>
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,
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::area
Code related to the building of areas (multipolygons) from relations.
Definition assembler.hpp:55
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
Definition item_type.hpp:53
osmium::item_type::relation_member_list
@ relation_member_list
Definition item_type.hpp:55
osmium::item_type::way_node_list
@ way_node_list
Definition item_type.hpp:54
osmium::item_type::changeset_discussion
@ changeset_discussion
Definition item_type.hpp:59
osmium::item_type::relation_member_list_with_full_members
@ relation_member_list_with_full_members
Definition item_type.hpp:56
osmium::item_type::relation
@ relation
Definition item_type.hpp:50
osmium::item_type::node
@ node
Definition item_type.hpp:48
osmium::item_type::changeset
@ changeset
Definition item_type.hpp:52
osmium::item_type::area
@ area
Definition item_type.hpp:51
osmium::item_type::undefined
@ undefined
Definition item_type.hpp:47
osmium::item_type::way
@ way
Definition item_type.hpp:49
osmium::item_type::outer_ring
@ outer_ring
Definition item_type.hpp:57
osmium::item_type::inner_ring
@ inner_ring
Definition item_type.hpp:58
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:654
osmium::unknown_type::unknown_type
unknown_type()
Definition item_type.hpp:199