Loading...
Searching...
No Matches
osmium::ItemStash Class Reference

`#include <item_stash.hpp>`

## Classes

class | cleanup_helper
class | handle_type

## Public Member Functions

| ItemStash ()
std::size_t | used_memory () const noexcept
std::size_t | size () const noexcept
std::size_t | count_removed () const noexcept
void | clear ()
handle_type | add_item (const osmium::memory::Item &item)
osmium::memory::Item & | get_item (handle_type handle) const
template<typename T>
T & | get (handle_type handle) const
void | garbage_collect ()
void | remove_item (handle_type handle)

## Private Types

enum | { initial_buffer_size = 1024UL * 1024UL }
enum | { removed_item_offset = std::numeric_limits<std::size_t>::max() }

## Private Member Functions

std::size_t & | get_item_offset_ref (handle_type handle) noexcept
std::size_t | get_item_offset (handle_type handle) const noexcept
bool | should_gc () const noexcept

## Private Attributes

osmium::memory::Buffer | m_buffer
std::vector< std::size_t > | m_index
std::size_t | m_count_items = 0
std::size_t | m_count_removed = 0

## Detailed Description

Class for storing OSM data in memory. Any osmium::memory::Item can be added to the stash and it will be copied into its internal Buffer. To access the item again, an opaque handle is used.

## Member Enumeration Documentation

## anonymous enum

anonymous enum

private

Enumerator
removed_item_offset |

## anonymous enum

anonymous enum

private

Enumerator
initial_buffer_size |

## Constructor & Destructor Documentation

## ItemStash()

osmium::ItemStash::ItemStash | ( |  | ) |

inline

## Member Function Documentation

## add_item()

handle_type osmium::ItemStash::add_item | ( | const osmium::memory::Item & | item | ) |

inline

Add an item to the stash. This will invalidate any pointers and references into the stash, but handles are still valid.

Complexity: Amortized constant.

## clear()

void osmium::ItemStash::clear | ( |  | ) |

inline

Clear all items from the stash. This will not necessarily release any memory. All handles are invalidated.

## count_removed()

std::size_t osmium::ItemStash::count_removed | ( |  | ) | const

inlinenoexcept

The number of removed items currently still taking up memory in the stash. You can call garbage_collect() to remove them.

Complexity: Constant.

## garbage_collect()

void osmium::ItemStash::garbage_collect | ( |  | ) |

inline

Garbage collect the memory used by the ItemStash. This will free up memory for adding new items. No memory is actually returned to the OS. Usually you do not need to call this, because add_item() will call it for you as necessary.

Complexity: Linear in size() + count_removed().

## get()

template<typename T>

T & osmium::ItemStash::get | ( | handle_type | handle | ) | const

inline

Get a reference to an item in the stash. Note that this reference will be invalidated by any add_item() or clear() calls.

Complexity: Constant.

Parameters

  handle | A handle returned by add_item().

Template Parameters

  T | Type you want to the data to be interpreted as. You must be sure that the item has the specified type, this will not be checked!

Returns
  Reference of given type pointing to the data in the stash.

Precondition
  Handle must be a valid handle and referring to a non-removed item.

## get_item()

osmium::memory::Item & osmium::ItemStash::get_item | ( | handle_type | handle | ) | const

inline

Get a reference to an item in the stash. Note that this reference will be invalidated by any add_item() or clear() calls.

Complexity: Constant.

Parameters

  handle | A handle returned by add_item().

Precondition
  Handle must be a valid handle and referring to a non-removed item.

## get_item_offset()

std::size_t osmium::ItemStash::get_item_offset | ( | handle_type | handle | ) | const

inlineprivatenoexcept

## get_item_offset_ref()

std::size_t & osmium::ItemStash::get_item_offset_ref | ( | handle_type | handle | ) |

inlineprivatenoexcept

## remove_item()

void osmium::ItemStash::remove_item | ( | handle_type | handle | ) |

inline

Remove an item from the stash. The item will be marked as removed and the handle will be invalidated. No memory will actually be freed.

Complexity: Constant.

Parameters

  handle | A handle returned by add_item().

Precondition
  Handle must be a valid handle and referring to a non-removed item.

## should_gc()

bool osmium::ItemStash::should_gc | ( |  | ) | const

inlineprivatenoexcept

## size()

std::size_t osmium::ItemStash::size | ( |  | ) | const

inlinenoexcept

The number of items currently in the stash. This is the number added minus the number removed.

Complexity: Constant.

## used_memory()

std::size_t osmium::ItemStash::used_memory | ( |  | ) | const

inlinenoexcept

Return an estimate of the number of bytes currently used by this ItemStash instance.

Complexity: Constant.

## Member Data Documentation

## m_buffer

osmium::memory::Buffer osmium::ItemStash::m_buffer

private

## m_count_items

std::size_t osmium::ItemStash::m_count_items = 0

private

## m_count_removed

std::size_t osmium::ItemStash::m_count_removed = 0

private

## m_index

std::vector<std::size_t> osmium::ItemStash::m_index

private

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

- include/osmium/storage/item_stash.hpp