Libosmium  2.11.4
Fast and flexible C++ library for working with OpenStreetMap data
builder_helper.hpp
Go to the documentation of this file.
1 #ifndef OSMIUM_BUILDER_BUILDER_HELPER_HPP
2 #define OSMIUM_BUILDER_BUILDER_HELPER_HPP
3 
4 /*
5 
6 This file is part of Osmium (http://osmcode.org/libosmium).
7 
8 Copyright 2013-2017 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 <cstddef>
37 #include <initializer_list>
38 #include <functional>
39 #include <map>
40 #include <utility>
41 
43 #include <osmium/memory/buffer.hpp>
45 
46 namespace osmium {
47 
48  class NodeRef;
49  class TagList;
50  class WayNodeList;
51 
52  namespace builder {
53 
58  OSMIUM_DEPRECATED inline const osmium::WayNodeList& build_way_node_list(osmium::memory::Buffer& buffer, const std::initializer_list<osmium::NodeRef>& nodes) {
59  const size_t pos = buffer.committed();
60  {
61  osmium::builder::WayNodeListBuilder wnl_builder(buffer);
62  for (const auto& node_ref : nodes) {
63  wnl_builder.add_node_ref(node_ref);
64  }
65  }
66  buffer.commit();
67  return buffer.get<const osmium::WayNodeList>(pos);
68  }
69 
74  inline const osmium::TagList& build_tag_list(osmium::memory::Buffer& buffer, const std::initializer_list<std::pair<const char*, const char*>>& tags) {
75  const size_t pos = buffer.committed();
76  {
77  osmium::builder::TagListBuilder tl_builder(buffer);
78  for (const auto& p : tags) {
79  tl_builder.add_tag(p.first, p.second);
80  }
81  }
82  buffer.commit();
83  return buffer.get<const osmium::TagList>(pos);
84  }
85 
90  inline const osmium::TagList& build_tag_list_from_map(osmium::memory::Buffer& buffer, const std::map<const char*, const char*>& tags) {
91  const size_t pos = buffer.committed();
92  {
93  osmium::builder::TagListBuilder tl_builder(buffer);
94  for (const auto& p : tags) {
95  tl_builder.add_tag(p.first, p.second);
96  }
97  }
98  buffer.commit();
99  return buffer.get<const osmium::TagList>(pos);
100  }
101 
107  const size_t pos = buffer.committed();
108  {
109  osmium::builder::TagListBuilder tl_builder(buffer);
110  func(tl_builder);
111  }
112  buffer.commit();
113  return buffer.get<const osmium::TagList>(pos);
114  }
115 
116  } // namespace builder
117 
118 } // namespace osmium
119 
120 #endif // OSMIUM_BUILDER_BUILDER_HELPER_HPP
#define OSMIUM_DEPRECATED
Definition: compatibility.hpp:50
Definition: tag.hpp:107
const osmium::TagList & build_tag_list_from_func(osmium::memory::Buffer &buffer, std::function< void(osmium::builder::TagListBuilder &)> func)
Definition: builder_helper.hpp:106
const osmium::TagList & build_tag_list(osmium::memory::Buffer &buffer, const std::initializer_list< std::pair< const char *, const char *>> &tags)
Definition: builder_helper.hpp:74
OSMIUM_DEPRECATED const osmium::WayNodeList & build_way_node_list(osmium::memory::Buffer &buffer, const std::initializer_list< osmium::NodeRef > &nodes)
Definition: builder_helper.hpp:58
Definition: osm_object_builder.hpp:182
Definition: way.hpp:55
Namespace for everything in the Osmium library.
Definition: assembler.hpp:73
const osmium::TagList & build_tag_list_from_map(osmium::memory::Buffer &buffer, const std::map< const char *, const char *> &tags)
Definition: builder_helper.hpp:90
size_t committed() const noexcept
Definition: buffer.hpp:268
Definition: buffer.hpp:97
T & get(const size_t offset) const
Definition: buffer.hpp:413
void add_tag(const char *key, const char *value)
Definition: osm_object_builder.hpp:95
Definition: osm_object_builder.hpp:71
size_t commit()
Definition: buffer.hpp:363
void add_node_ref(const NodeRef &node_ref)
Definition: osm_object_builder.hpp:200