Libosmium
2.20.0
Fast and flexible C++ library for working with OpenStreetMap data
|
#include <callback_buffer.hpp>
Public Types | |
using | callback_func_type = std::function< void(osmium::memory::Buffer &&)> |
The type for the callback function. More... | |
Public Member Functions | |
CallbackBuffer (std::size_t initial_buffer_size=default_initial_buffer_size, std::size_t max_buffer_size=default_max_buffer_size) | |
CallbackBuffer (callback_func_type callback, std::size_t initial_buffer_size=default_initial_buffer_size, std::size_t max_buffer_size=default_max_buffer_size) | |
osmium::memory::Buffer & | buffer () noexcept |
void | set_callback (const callback_func_type &callback=nullptr) noexcept |
void | flush () |
void | possibly_flush () |
osmium::memory::Buffer | read () |
Private Types | |
enum | { default_initial_buffer_size = 1024UL * 1024UL } |
enum | { default_max_buffer_size = 800UL * 1024UL } |
Private Attributes | |
osmium::memory::Buffer | m_buffer |
std::size_t | m_initial_buffer_size |
std::size_t | m_max_buffer_size |
callback_func_type | m_callback |
This is basically a wrapper around osmium::memory::Buffer with an additional callback function that is called whenever the buffer is full.
The internal buffer is created with the initial_buffer_size
set in the constructor. When it grows beyond the max_buffer_size
set in the constructor, the callback function is called with the buffer and a new, empty buffer is created internally.
Note that the buffer can grow beyond the initial buffer size if needed. This can happen if a new object doesn't fit into the rest of the buffer available or if no callback function is set (yet).
Example:
using osmium::memory::CallbackBuffer::callback_func_type = std::function<void(osmium::memory::Buffer&&)> |
The type for the callback function.
|
inlineexplicit |
Construct a CallbackBuffer without a callback function. You can later call set the callback with set_callback().
initial_buffer_size | The initial size of newly created internal buffers. |
max_buffer_size | If the buffer grows beyond this size the callback will be called. |
|
inlineexplicit |
Construct a CallbackBuffer with a callback function.
callback | The callback function. Must be of type void(osmium::memory::Buffer&&)
|
initial_buffer_size | The initial size of newly created internal buffers. |
max_buffer_size | If the buffer grows beyond this size the callback will be called. |
|
inlinenoexcept |
Access the internal buffer. This is used to fill the buffer, the CallbackBuffer still owns the buffer.
Use read() or the callback if you need to own the buffer.
|
inline |
Flush the internal buffer regardless of how full it is. Calls the callback with the buffer and creates an new empty internal one.
This will do nothing if no callback is set or if the buffer is empty.
|
inline |
Flush the internal buffer if and only if it contains more than the max_buffer_size set in the constructor. Calls the callback with the buffer and creates an new empty internal one.
This will do nothing if no callback is set or if the buffer is empty.
|
inline |
Return the internal buffer and create a new empty internal one. You can use this as an alternative access instead of using the callback.
|
inlinenoexcept |
Set the callback. The function must take a rvalue reference to a buffer and return void.
callback | The callback function. Must be of type void(osmium::memory::Buffer&&)
|
|
private |
|
private |
|
private |
|
private |