Libosmium
2.15.6
Fast and flexible C++ library for working with OpenStreetMap data
|
Go to the documentation of this file. 1 #ifndef OSMIUM_MEMORY_BUFFER_HPP
2 #define OSMIUM_MEMORY_BUFFER_HPP
61 std::runtime_error{
"Osmium buffer is full"} {
137 assert(
m_data &&
"This must be a valid buffer");
139 throw std::logic_error{
"Can't grow Buffer if it doesn't use internal memory management."};
185 throw std::invalid_argument{
"buffer size needs to be multiple of alignment"};
208 throw std::invalid_argument{
"buffer capacity needs to be multiple of alignment"};
211 throw std::invalid_argument{
"buffer parameter 'committed' needs to be multiple of alignment"};
214 throw std::invalid_argument{
"buffer parameter 'committed' can not be larger than capacity"};
239 throw std::invalid_argument{
"buffer capacity needs to be multiple of alignment"};
242 throw std::invalid_argument{
"buffer parameter 'committed' needs to be multiple of alignment"};
245 throw std::invalid_argument{
"buffer parameter 'committed' can not be larger than capacity"};
276 m_memory(std::move(other.m_memory)),
285 m_full(std::move(other.m_full)) {
286 other.m_data =
nullptr;
287 other.m_capacity = 0;
289 other.m_committed = 0;
291 other.m_builder_count = 0;
297 m_memory = std::move(other.m_memory);
306 m_full = std::move(other.m_full);
307 other.m_data =
nullptr;
308 other.m_capacity = 0;
310 other.m_committed = 0;
312 other.m_builder_count = 0;
339 unsigned char*
data() const noexcept {
340 assert(
m_data &&
"This must be a valid buffer");
376 assert(
m_data &&
"This must be a valid buffer");
396 assert(
m_data &&
"This must be a valid buffer");
416 assert(
m_data &&
"This must be a valid buffer");
418 throw std::logic_error{
"Can't grow Buffer if it doesn't use internal memory management."};
422 std::unique_ptr<unsigned char[]> memory{
new unsigned char[size]};
469 assert(
m_data &&
"This must be a valid buffer");
470 assert(
m_builder_count == 0 &&
"Make sure there are no Builder objects still in scope");
485 assert(
m_data &&
"This must be a valid buffer");
486 assert(
m_builder_count == 0 &&
"Make sure there are no Builder objects still in scope");
500 assert(
m_builder_count == 0 &&
"Make sure there are no Builder objects still in scope");
517 template <
typename T>
518 T&
get(
const std::size_t offset)
const {
519 assert(
m_data &&
"This must be a valid buffer");
520 assert(offset %
alignof(T) == 0 &&
"Wrong alignment");
521 return *
reinterpret_cast<T*
>(&
m_data[offset]);
558 assert(
m_data &&
"This must be a valid buffer");
574 while (
m_written + size > new_capacity) {
600 template <
typename T>
602 assert(
m_data &&
"This must be a valid buffer");
604 std::copy_n(
reinterpret_cast<const unsigned char*
>(&item), item.padded_size(), target);
605 return *
reinterpret_cast<T*
>(target);
620 assert(
m_data &&
"This must be a valid buffer");
621 assert(buffer &&
"Buffer parameter must be a valid buffer");
622 assert(
m_builder_count == 0 &&
"Make sure there are no Builder objects still in scope");
637 assert(
m_data &&
"This must be a valid buffer");
638 assert(
m_builder_count == 0 &&
"Make sure there are no Builder objects still in scope");
647 template <
typename T>
654 template <
typename T>
669 template <
typename T>
674 template <
typename T>
687 template <
typename T>
689 assert(
m_data &&
"This must be a valid buffer");
702 assert(
m_data &&
"This must be a valid buffer");
715 template <
typename T>
717 assert(
m_data &&
"This must be a valid buffer");
718 assert(offset %
alignof(T) == 0 &&
"Wrong alignment");
732 assert(
m_data &&
"This must be a valid buffer");
733 assert(offset %
alignof(
OSMEntity) == 0 &&
"Wrong alignment");
745 template <
typename T>
747 assert(
m_data &&
"This must be a valid buffer");
760 assert(
m_data &&
"This must be a valid buffer");
764 template <
typename T>
766 assert(
m_data &&
"This must be a valid buffer");
771 assert(
m_data &&
"This must be a valid buffer");
775 template <
typename T>
777 assert(
m_data &&
"This must be a valid buffer");
778 assert(offset %
alignof(T) == 0 &&
"Wrong alignment");
783 assert(
m_data &&
"This must be a valid buffer");
784 assert(offset %
alignof(
OSMEntity) == 0 &&
"Wrong alignment");
788 template <
typename T>
790 assert(
m_data &&
"This must be a valid buffer");
795 assert(
m_data &&
"This must be a valid buffer");
799 template <
typename T>
808 template <
typename T>
820 explicit operator bool() const noexcept {
853 template <
typename TCallbackClass>
855 assert(
m_data &&
"This must be a valid buffer");
864 next = std::next(it_read);
865 if (!it_read->removed()) {
866 if (it_read != it_write) {
867 assert(it_read.data() >=
data());
869 const auto old_offset =
static_cast<std::size_t
>(it_read.data() -
data());
870 const auto new_offset =
static_cast<std::size_t
>(it_write.
data() -
data());
871 callback->moving_in_buffer(old_offset, new_offset);
872 std::memmove(it_write.
data(), it_read.data(), it_read->padded_size());
900 return lhs.data() == rhs.data() && lhs.capacity() == rhs.capacity() && lhs.committed() == rhs.committed();
904 return !(lhs == rhs);
911 #endif // OSMIUM_MEMORY_BUFFER_HPP
std::size_t written() const noexcept
Definition: buffer.hpp:365
data_type data() noexcept
Definition: item_iterator.hpp:135
std::size_t m_committed
Definition: buffer.hpp:117
Buffer & operator=(Buffer &&other) noexcept
Definition: buffer.hpp:295
std::unique_ptr< unsigned char[]> m_memory
Definition: buffer.hpp:113
t_iterator< T > get_iterator(std::size_t offset)
Definition: buffer.hpp:716
unsigned char * data() const noexcept
Definition: buffer.hpp:339
ItemIteratorRange< T > select()
Definition: buffer.hpp:670
bool operator==(const Buffer &lhs, const Buffer &rhs) noexcept
Definition: buffer.hpp:896
#define OSMIUM_DEPRECATED
Definition: compatibility.hpp:51
bool operator!=(const Buffer &lhs, const Buffer &rhs) noexcept
Definition: buffer.hpp:903
Buffer & operator=(const Buffer &)=delete
t_const_iterator< T > get_iterator(std::size_t offset) const
Definition: buffer.hpp:776
unsigned char * reserve_space(const std::size_t size)
Definition: buffer.hpp:557
void rollback()
Definition: buffer.hpp:484
std::unique_ptr< Buffer > get_last_nested()
Definition: buffer.hpp:447
const_iterator begin() const
Definition: buffer.hpp:804
t_iterator< T > end()
Definition: buffer.hpp:746
const_iterator cbegin() const
Definition: buffer.hpp:770
void purge_removed(TCallbackClass *callback)
Definition: buffer.hpp:854
std::size_t committed() const noexcept
Definition: buffer.hpp:356
T & add_item(const T &item)
Definition: buffer.hpp:601
Definition: buffer.hpp:58
Buffer(std::size_t capacity, auto_grow auto_grow=auto_grow::yes)
Definition: buffer.hpp:261
Buffer(std::unique_ptr< unsigned char[]> data, std::size_t capacity, std::size_t committed)
Definition: buffer.hpp:231
Buffer(unsigned char *data, std::size_t size)
Definition: buffer.hpp:178
ItemIteratorRange< const T > select() const
Definition: buffer.hpp:675
void add_buffer(const Buffer &buffer)
Definition: buffer.hpp:619
std::unique_ptr< Buffer > m_next_buffer
Definition: buffer.hpp:112
t_const_iterator< T > cend() const
Definition: buffer.hpp:789
iterator end()
Definition: buffer.hpp:759
std::size_t m_capacity
Definition: buffer.hpp:115
void grow_internal()
Definition: buffer.hpp:136
t_const_iterator< T > end() const
Definition: buffer.hpp:809
Definition: buffer.hpp:97
bool has_nested_buffers() const noexcept
Definition: buffer.hpp:437
static std::size_t calculate_capacity(std::size_t capacity) noexcept
Definition: buffer.hpp:124
t_const_iterator< T > cbegin() const
Definition: buffer.hpp:765
Namespace for everything in the Osmium library.
Definition: assembler.hpp:53
void increment_builder_count() noexcept
Definition: buffer.hpp:320
buffer_is_full()
Definition: buffer.hpp:60
std::size_t clear()
Definition: buffer.hpp:499
Buffer(unsigned char *data, std::size_t capacity, std::size_t committed)
Definition: buffer.hpp:201
OSMIUM_DEPRECATED void set_full_callback(const std::function< void(Buffer &)> &full)
Definition: buffer.hpp:395
Buffer(const Buffer &)=delete
Definition: item_iterator.hpp:59
Buffer(Buffer &&other) noexcept
Definition: buffer.hpp:274
T & get(const std::size_t offset) const
Definition: buffer.hpp:518
const_iterator cend() const
Definition: buffer.hpp:794
std::function< void(Buffer &)> m_full
Definition: buffer.hpp:122
std::size_t commit()
Definition: buffer.hpp:468
auto_grow m_auto_grow
Definition: buffer.hpp:121
uint8_t m_builder_count
Definition: buffer.hpp:119
Definition: location.hpp:551
std::size_t capacity() const noexcept
Definition: buffer.hpp:348
void swap(Buffer &lhs, Buffer &rhs)
Definition: buffer.hpp:885
std::size_t m_written
Definition: buffer.hpp:116
ItemIterator< TMember > & advance_once() noexcept
Definition: item_iterator.hpp:114
void decrement_builder_count() noexcept
Definition: buffer.hpp:324
auto_grow
Definition: buffer.hpp:104
uint8_t builder_count() const noexcept
Definition: buffer.hpp:329
unsigned char * m_data
Definition: buffer.hpp:114
iterator get_iterator(std::size_t offset)
Definition: buffer.hpp:731
t_iterator< T > begin()
Definition: buffer.hpp:688
constexpr std::size_t padded_length(std::size_t length) noexcept
Definition: item.hpp:64
iterator begin()
Definition: buffer.hpp:701
const_iterator get_iterator(std::size_t offset) const
Definition: buffer.hpp:782
Buffer() noexcept
Definition: buffer.hpp:164
const_iterator end() const
Definition: buffer.hpp:813
@ align_bytes
Definition: item.hpp:61
bool is_aligned() const noexcept
Definition: buffer.hpp:375
t_const_iterator< T > begin() const
Definition: buffer.hpp:800
~Buffer() noexcept=default
void swap(Buffer &other)
Definition: buffer.hpp:824
Definition: item_iterator.hpp:175
void grow(std::size_t size)
Definition: buffer.hpp:415
OSMEntity is the abstract base class for the OSMObject and Changeset classes.
Definition: entity.hpp:64
void push_back(const osmium::memory::Item &item)
Definition: buffer.hpp:636