Libosmium 2.22.0 Fast and flexible C++ library for working with OpenStreetMap data

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Private Types | Private Attributes | List of all members
osmium::memory::CallbackBuffer Class Reference

`#include <callback_buffer.hpp>`

## Public Types
using | callback_func_type = std::function<void(osmium::memory::Buffer&&)>
| The type for the callback function.

## 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

## Detailed Description

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:

CallbackBuffer cb;
cb.set_callback([&](osmium::memory::Buffer&& buffer) {
...handle buffer...
}
osmium::builder::add_node(cb.buffer(), _id(9), ...);
osmium::builder::add_way(cb.buffer(), _id(27), ...);
osmium::memory::CallbackBuffer
Definition callback_buffer.hpp:70
osmium::memory::CallbackBuffer::buffer
osmium::memory::Buffer & buffer() noexcept
Definition callback_buffer.hpp:133
osmium::memory::CallbackBuffer::set_callback
void set_callback(const callback_func_type &callback=nullptr) noexcept
Definition callback_buffer.hpp:144

## Member Typedef Documentation

## ◆ callback_func_type

using osmium::memory::CallbackBuffer::callback_func_type = std::function<void(osmium::memory::Buffer&&)>

The type for the callback function.

## Member Enumeration Documentation

## ◆ anonymous enum

anonymous enum
| private

Enumerator
default_initial_buffer_size |

## ◆ anonymous enum

anonymous enum
| private

Enumerator
default_max_buffer_size |

## Constructor & Destructor Documentation

## ◆ CallbackBuffer() [1/2]

osmium::memory::CallbackBuffer::CallbackBuffer | ( | std::size_t | initial_buffer_size = default_initial_buffer_size,
|  | std::size_t | max_buffer_size = default_max_buffer_size )
| inline explicit

Construct a CallbackBuffer without a callback function. You can later call set the callback with set_callback().

Parameters

  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.

## ◆ CallbackBuffer() [2/2]

osmium::memory::CallbackBuffer::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 )
| inline explicit

Construct a CallbackBuffer with a callback function.

Parameters

  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.

## Member Function Documentation

## ◆ buffer()

osmium::memory::Buffer & osmium::memory::CallbackBuffer::buffer | ( |  | ) |
| inline noexcept

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.

## ◆ flush()

void osmium::memory::CallbackBuffer::flush | ( |  | ) |
| 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.

## ◆ possibly_flush()

void osmium::memory::CallbackBuffer::possibly_flush | ( |  | ) |
| 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.

## ◆ read()

osmium::memory::Buffer osmium::memory::CallbackBuffer::read | ( |  | ) |
| 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.

## ◆ set_callback()

void osmium::memory::CallbackBuffer::set_callback | ( | const callback_func_type & | callback = nullptr | ) |
| inline noexcept

Set the callback. The function must take a rvalue reference to a buffer and return void.

Parameters

  callback | The callback function. Must be of type void(osmium::memory::Buffer&&)

## Member Data Documentation

## ◆ m_buffer

osmium::memory::Buffer osmium::memory::CallbackBuffer::m_buffer
| private

## ◆ m_callback

callback_func_type osmium::memory::CallbackBuffer::m_callback
| private

## ◆ m_initial_buffer_size

std::size_t osmium::memory::CallbackBuffer::m_initial_buffer_size
| private

## ◆ m_max_buffer_size

std::size_t osmium::memory::CallbackBuffer::m_max_buffer_size
| private

The documentation for this class was generated from the following file:

- include/osmium/memory/callback_buffer.hpp