Libosmium
2.16.0
Fast and flexible C++ library for working with OpenStreetMap data
|
#include <buffer.hpp>
Public Types | |
enum | auto_grow { auto_grow::no = 0, auto_grow::yes = 1, auto_grow::internal = 2 } |
using | value_type = Item |
template<typename T > | |
using | t_iterator = osmium::memory::ItemIterator< T > |
template<typename T > | |
using | t_const_iterator = osmium::memory::ItemIterator< const T > |
using | iterator = t_iterator< osmium::OSMEntity > |
using | const_iterator = t_const_iterator< osmium::OSMEntity > |
Public Member Functions | |
Buffer () noexcept | |
Buffer (unsigned char *data, std::size_t size) | |
Buffer (unsigned char *data, std::size_t capacity, std::size_t committed) | |
Buffer (std::unique_ptr< unsigned char[]> data, std::size_t capacity, std::size_t committed) | |
Buffer (std::size_t capacity, auto_grow auto_grow=auto_grow::yes) | |
Buffer (const Buffer &)=delete | |
Buffer & | operator= (const Buffer &)=delete |
Buffer (Buffer &&other) noexcept | |
Buffer & | operator= (Buffer &&other) noexcept |
~Buffer () noexcept=default | |
void | increment_builder_count () noexcept |
void | decrement_builder_count () noexcept |
uint8_t | builder_count () const noexcept |
unsigned char * | data () const noexcept |
std::size_t | capacity () const noexcept |
std::size_t | committed () const noexcept |
std::size_t | written () const noexcept |
bool | is_aligned () const noexcept |
OSMIUM_DEPRECATED void | set_full_callback (const std::function< void(Buffer &)> &full) |
void | grow (std::size_t size) |
bool | has_nested_buffers () const noexcept |
std::unique_ptr< Buffer > | get_last_nested () |
std::size_t | commit () |
void | rollback () |
std::size_t | clear () |
template<typename T > | |
T & | get (const std::size_t offset) const |
unsigned char * | reserve_space (const std::size_t size) |
template<typename T > | |
T & | add_item (const T &item) |
void | add_buffer (const Buffer &buffer) |
void | push_back (const osmium::memory::Item &item) |
template<typename T > | |
ItemIteratorRange< T > | select () |
template<typename T > | |
ItemIteratorRange< const T > | select () const |
template<typename T > | |
t_iterator< T > | begin () |
iterator | begin () |
template<typename T > | |
t_iterator< T > | get_iterator (std::size_t offset) |
iterator | get_iterator (std::size_t offset) |
template<typename T > | |
t_iterator< T > | end () |
iterator | end () |
template<typename T > | |
t_const_iterator< T > | cbegin () const |
const_iterator | cbegin () const |
template<typename T > | |
t_const_iterator< T > | get_iterator (std::size_t offset) const |
const_iterator | get_iterator (std::size_t offset) const |
template<typename T > | |
t_const_iterator< T > | cend () const |
const_iterator | cend () const |
template<typename T > | |
t_const_iterator< T > | begin () const |
const_iterator | begin () const |
template<typename T > | |
t_const_iterator< T > | end () const |
const_iterator | end () const |
operator bool () const noexcept | |
void | swap (Buffer &other) |
template<typename TCallbackClass > | |
void | purge_removed (TCallbackClass *callback) |
Private Member Functions | |
void | grow_internal () |
Static Private Member Functions | |
static std::size_t | calculate_capacity (std::size_t capacity) noexcept |
Private Attributes | |
std::unique_ptr< Buffer > | m_next_buffer |
std::unique_ptr< unsigned char[]> | m_memory {} |
unsigned char * | m_data = nullptr |
std::size_t | m_capacity = 0 |
std::size_t | m_written = 0 |
std::size_t | m_committed = 0 |
uint8_t | m_builder_count = 0 |
auto_grow | m_auto_grow {auto_grow::no} |
std::function< void(Buffer &)> | m_full |
A memory area for storing OSM objects and other items. Each item stored has a type and a length. See the Item class for details.
Data can be added to a buffer piece by piece using reserve_space() and add_item(). After all data that together forms an item is added, it must be committed using the commit() call. Usually this is done through the Builder class and its derived classes.
You can iterate over all items in a buffer using the iterators returned by begin(), end(), cbegin(), and cend().
Buffers exist in two flavours, those with external memory management and those with internal memory management. If you already have some memory with data in it (for instance read from disk), you create a Buffer with external memory management. It is your job then to free the memory once the buffer isn't used any more. If you don't have memory already, you can create a Buffer object and have it manage the memory internally. It will dynamically allocate memory and free it again after use.
By default, if a buffer gets full it will throw a buffer_is_full exception. You can use the set_full_callback() method to set a callback functor which will be called instead of throwing an exception. The full callback functionality is deprecated and will be removed in the future. See the documentation for set_full_callback() for alternatives.
A const iterator that can be used to iterate over all OSMEntity objects in a buffer.
An iterator that can be used to iterate over all OSMEntity objects in a buffer.
using osmium::memory::Buffer::t_const_iterator = osmium::memory::ItemIterator<const T> |
A const iterator that can be used to iterate over all items of type T in a buffer.
using osmium::memory::Buffer::t_iterator = osmium::memory::ItemIterator<T> |
An iterator that can be used to iterate over all items of type T in a buffer.
|
strong |
|
inlinenoexcept |
The constructor without any parameters creates an invalid, buffer, ie an empty hull of a buffer that has no actual memory associated with it. It can be used to signify end-of-data.
Most methods of the Buffer class will not work with an invalid buffer.
|
inlineexplicit |
Constructs a valid externally memory-managed buffer using the given memory and size.
data | A pointer to some already initialized data. |
size | The size of the initialized data. |
std::invalid_argument | if the size isn't a multiple of the alignment. |
|
inlineexplicit |
Constructs a valid externally memory-managed buffer with the given capacity that already contains 'committed' bytes of data.
data | A pointer to some (possibly initialized) data. |
capacity | The size of the memory for this buffer. |
committed | The size of the initialized data. If this is 0, the buffer startes out empty. |
std::invalid_argument | if the capacity or committed isn't a multiple of the alignment or if committed is larger than capacity. |
|
inlineexplicit |
Constructs a valid internally memory-managed buffer with the given capacity that already contains 'committed' bytes of data.
data | A unique pointer to some (possibly initialized) data. The Buffer will manage this memory. |
capacity | The size of the memory for this buffer. |
committed | The size of the initialized data. If this is 0, the buffer startes out empty. |
std::invalid_argument | if the capacity or committed isn't a multiple of the alignment or if committed is larger than capacity. |
|
inlineexplicit |
Constructs a valid internally memory-managed buffer with the given capacity. Will internally get dynamic memory of the required size. The dynamic memory will be automatically freed when the Buffer is destroyed.
capacity | The (initial) size of the memory for this buffer. Actual capacity might be larger tue to alignment. |
auto_grow | Should this buffer automatically grow when it becomes to small? |
|
delete |
|
inlinenoexcept |
|
defaultnoexcept |
|
inline |
Add committed contents of the given buffer to this buffer.
Note that you have to eventually call commit() to actually commit this data.
buffer | The source of the copy. Must be valid. |
|
inline |
Add an item to the buffer. The size of the item is stored inside the item, so we know how much memory to copy.
Note that you have to eventually call commit() to actually commit this data.
T | Class of the item to be copied. |
item | Reference to the item to be copied. |
|
inline |
Get iterator for iterating over all items of type T in the buffer.
|
inline |
|
inline |
|
inline |
|
inlinenoexcept |
|
inlinestaticprivatenoexcept |
|
inlinenoexcept |
Returns the capacity of the buffer, ie how many bytes it can contain. Always returns 0 on invalid buffers.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Clear the buffer.
No-op on an invalid buffer.
|
inline |
Mark currently written bytes in the buffer as committed.
|
inlinenoexcept |
Returns the number of bytes already filled in this buffer. Always returns 0 on invalid buffers.
|
inlinenoexcept |
Return a pointer to data inside the buffer.
|
inlinenoexcept |
|
inline |
Get iterator for iterating over all items of type T in the buffer.
|
inline |
Get iterator for iterating over all objects of class OSMEntity in the buffer.
|
inline |
|
inline |
|
inline |
Get the data in the buffer at the given offset.
T | Type we want to the data to be interpreted as. |
|
inline |
Get iterator for iterating over all items of type T in the buffer.
|
inline |
|
inline |
|
inline |
|
inline |
Return the most deeply nested buffer. The buffer will be moved out.
|
inline |
Grow capacity of this buffer to the given size (which will be rounded up to the alignment needed). This works only with internally memory-managed buffers. If the given size is not larger than the current capacity, nothing is done.
size | New capacity. |
std::logic_error | if the buffer doesn't use internal memory management. |
std::bad_alloc | if there isn't enough memory available. |
|
inlineprivate |
|
inlinenoexcept |
Does this buffer have nested buffers inside. This happens when a buffer is full and auto_grow is defined as internal.
|
inlinenoexcept |
|
inlinenoexcept |
This tests if the current state of the buffer is aligned properly. Can be used for asserts.
|
inlineexplicitnoexcept |
In a bool context any valid buffer is true.
|
inline |
Purge removed items from the buffer. This is done by moving all non-removed items forward in the buffer overwriting removed items and then correcting the m_written and m_committed numbers.
Note that calling this function invalidates all iterators on this buffer and all offsets in this buffer.
For every non-removed item that moves its position, the function 'moving_in_buffer' is called on the given callback object with the old and new offsets in the buffer where the object used to be and is now, respectively. This call can be used to update any indexes.
|
inline |
Add an item to the buffer. This function is provided so that you can use std::back_inserter.
item | The item to be added. |
|
inline |
Reserve space of given size in buffer and return pointer to it. This is the only way of adding data to the buffer. You reserve the space and then fill it.
Note that you have to eventually call commit() to actually commit this data.
If there isn't enough space in the buffer, one of three things can happen:
size | Number of bytes to reserve. |
osmium::buffer_is_full | if the buffer is full there is no callback defined and the buffer isn't auto-growing. |
|
inline |
Roll back changes in buffer to last committed state.
|
inline |
|
inline |
|
inline |
Set functor to be called whenever the buffer is full instead of throwing buffer_is_full.
The behaviour is undefined if you call this on an invalid buffer.
|
inline |
|
inlinenoexcept |
Returns the number of bytes currently filled in this buffer that are not yet committed. Always returns 0 on invalid buffers.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |