node_ref_list.hpp
Go to the documentation of this file.
#ifndef OSMIUM_OSM_NODE_REF_LIST_HPP
#define OSMIUM_OSM_NODE_REF_LIST_HPP
/*
This file is part of Osmium (http://osmcode.org/libosmium).
Copyright 2013-2016 Jochen Topf <jochen@topf.org> and others (see README).
Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include <cassert>
#include <cstddef>
#include <iterator>
#include <osmium/memory/item.hpp>
#include <osmium/osm/item_type.hpp>
#include <osmium/osm/node_ref.hpp>
namespace osmium {
class NodeRefList : public osmium::memory::Item {
public:
explicit NodeRefList(osmium::item_type itemtype) noexcept :
osmium::memory::Item(sizeof(NodeRefList), itemtype) {
}
bool empty() const noexcept {
return sizeof(NodeRefList) == byte_size();
}
size_t size() const noexcept {
auto size_node_refs = byte_size() - sizeof(NodeRefList);
assert(size_node_refs % sizeof(NodeRef) == 0);
return size_node_refs / sizeof(NodeRef);
}
const NodeRef& operator[](size_t n) const noexcept {
assert(n < size());
const NodeRef* node_ref = &*(cbegin());
return node_ref[n];
}
const NodeRef& front() const noexcept {
assert(!empty());
return operator[](0);
}
const NodeRef& back() const noexcept {
assert(!empty());
return operator[](size()-1);
}
bool is_closed() const noexcept {
return ends_have_same_id();
}
bool ends_have_same_id() const noexcept {
return front().ref() == back().ref();
}
bool ends_have_same_location() const {
assert(front().location() && back().location());
return front().location() == back().location();
}
using iterator = NodeRef*;
using const_iterator = const NodeRef*;
using const_reverse_iterator = std::reverse_iterator<const NodeRef*>;
iterator begin() noexcept {
return iterator(data() + sizeof(NodeRefList));
}
iterator end() noexcept {
return iterator(data() + byte_size());
}
const_iterator cbegin() const noexcept {
return const_iterator(data() + sizeof(NodeRefList));
}
const_iterator cend() const noexcept {
return const_iterator(data() + byte_size());
}
const_iterator begin() const noexcept {
return cbegin();
}
const_iterator end() const noexcept {
return cend();
}
const_reverse_iterator crbegin() const noexcept {
return const_reverse_iterator(cend());
}
const_reverse_iterator crend() const noexcept {
return const_reverse_iterator(cbegin());
}
}; // class NodeRefList
} // namespace osmium
#endif // OSMIUM_OSM_NODE_REF_LIST_HPP
osmium::NodeRefList::cbegin
const_iterator cbegin() const noexcept
Returns an iterator to the beginning.
Definition: node_ref_list.hpp:154
osmium::NodeRefList::const_reverse_iterator
std::reverse_iterator< const NodeRef * > const_reverse_iterator
Definition: node_ref_list.hpp:141
osmium::NodeRefList::is_closed
bool is_closed() const noexcept
Definition: node_ref_list.hpp:113
osmium::NodeRefList::crbegin
const_reverse_iterator crbegin() const noexcept
Returns a reverse_iterator to the beginning.
Definition: node_ref_list.hpp:174
osmium::item_type
item_type
Definition: item_type.hpp:43
osmium::NodeRefList::const_iterator
const NodeRef * const_iterator
Definition: node_ref_list.hpp:140
osmium::NodeRefList::size
size_t size() const noexcept
Definition: node_ref_list.hpp:68
osmium::NodeRefList::ends_have_same_location
bool ends_have_same_location() const
Definition: node_ref_list.hpp:134
osmium::NodeRefList::ends_have_same_id
bool ends_have_same_id() const noexcept
Definition: node_ref_list.hpp:123
node_ref.hpp
item_type.hpp
osmium::NodeRefList::cend
const_iterator cend() const noexcept
Returns an iterator to the end.
Definition: node_ref_list.hpp:159
osmium::NodeRef::ref
constexpr osmium::object_id_type ref() const noexcept
Definition: node_ref.hpp:65
osmium::NodeRefList::empty
bool empty() const noexcept
Definition: node_ref_list.hpp:61
osmium::memory::Item
Definition: item.hpp:97
osmium
Namespace for everything in the Osmium library.
Definition: assembler.hpp:59
osmium::NodeRefList::begin
const_iterator begin() const noexcept
Returns an iterator to the beginning.
Definition: node_ref_list.hpp:164
osmium::NodeRef::location
osmium::Location & location() noexcept
Definition: node_ref.hpp:79
osmium::memory::Item::byte_size
item_size_type byte_size() const noexcept
Definition: item.hpp:147
osmium::NodeRefList::operator[]
const NodeRef & operator[](size_t n) const noexcept
Definition: node_ref_list.hpp:81
osmium::NodeRefList::begin
iterator begin() noexcept
Returns an iterator to the beginning.
Definition: node_ref_list.hpp:144
osmium::NodeRefList::NodeRefList
NodeRefList(osmium::item_type itemtype) noexcept
Definition: node_ref_list.hpp:54
item.hpp
osmium::NodeRefList::end
iterator end() noexcept
Returns an iterator to the end.
Definition: node_ref_list.hpp:149
osmium::NodeRefList
Definition: node_ref_list.hpp:50
osmium::NodeRefList::front
const NodeRef & front() const noexcept
Definition: node_ref_list.hpp:92
osmium::NodeRefList::back
const NodeRef & back() const noexcept
Definition: node_ref_list.hpp:102
osmium::NodeRefList::iterator
NodeRef * iterator
Definition: node_ref_list.hpp:139
osmium::NodeRef
Definition: node_ref.hpp:50
osmium::NodeRefList::crend
const_reverse_iterator crend() const noexcept
Returns a reverse_iterator to the end.
Definition: node_ref_list.hpp:179
osmium::NodeRefList::end
const_iterator end() const noexcept
Returns an iterator to the end.
Definition: node_ref_list.hpp:169