Cbeam
Loading...
Searching...
No Matches
cbeam::container::stable_interprocess_map< Key, Value > Class Template Reference

Provides a type-safe, interprocess map with stable serialization. More...

#include <stable_interprocess_map.hpp>

Inheritance diagram for cbeam::container::stable_interprocess_map< Key, Value >:
Collaboration diagram for cbeam::container::stable_interprocess_map< Key, Value >:

Public Member Functions

 stable_interprocess_map (const std::string &unique_identifier, std::size_t size)
 Constructs a stable_interprocess_map with a unique identifier and fixed size.
 
stable_interprocess_mapoperator= (const std::initializer_list< std::pair< const Key, Value > > &list)
 Assigns key-value pairs to the map from an initializer list.
 
Value at (const Key &key) const
 Retrieves the value associated with a specific key.
 
Value at_or_default (const Key &key, const Value &default_value) const
 Retrieves the value associated with a key, or a default value if the key is not found.
 
void insert (const Key &key, const Value &value)
 Inserts a key-value pair into the map.
 
void erase (const Key &key)
 Erases the element associated with a specific key.
 
std::size_t count (const Key &key) const
 Counts the number of elements with a specific key.
 
void update_or_insert (const Key &key, std::function< void(Value &)> updater, const Value &default_value)
 
const Value update (const Key &key, std::function< void(Value &)> updater, const std::string &error_string={"cbeam::stable_interprocess_map::update: key not found"})
 
- Public Member Functions inherited from cbeam::container::stable_interprocess_container< std::map< Key, Value > >
 stable_interprocess_container (const std::string &unique_identifier, std::size_t size)
 Constructs a stable_interprocess_container with a specific size and unique identifier.
 
 stable_interprocess_container (const stable_interprocess_container &)=delete
 
 stable_interprocess_container (stable_interprocess_container &&)=delete
 
stable_interprocess_containeroperator= (const stable_interprocess_container &)=delete
 
stable_interprocess_containeroperator= (stable_interprocess_container &&)=delete
 
virtual void clear ()
 Clears the contents of the container.
 
virtual bool empty () const
 Checks if the container is empty.
 
virtual size_t size () const
 Retrieves the size of the container.
 
void foreach (Func func)
 Iterates over the elements of the container and performs an action.
 
- Public Member Functions inherited from cbeam::memory::interprocess_shared_memory
 interprocess_shared_memory (const std::string &unique_identifier, std::size_t size)
 Constructor that initializes the shared memory segment.
 
virtual ~interprocess_shared_memory () noexcept
 
void * data () const
 Retrieves the starting address of the shared memory region.
 
size_t capacity () const noexcept
 Returns the size of the shared memory region.
 
lock_guard get_lock_guard () const
 Acquires a lock_guard for mutex synchronization.
 
 interprocess_shared_memory (const interprocess_shared_memory &)=delete
 
interprocess_shared_memoryoperator= (const interprocess_shared_memory &)=delete
 
 interprocess_shared_memory (interprocess_shared_memory &&)=delete
 
interprocess_shared_memoryoperator= (interprocess_shared_memory &&)=delete
 

Additional Inherited Members

- Protected Member Functions inherited from cbeam::container::stable_interprocess_container< std::map< Key, Value > >
std::map< Key, Value > deserialize () const
 Deserializes the shared memory data into a container object.
 
void serialize (const std::map< Key, Value > &container)
 Serializes a container object and stores it in shared memory.
 

Detailed Description

template<typename Key, typename Value>
class cbeam::container::stable_interprocess_map< Key, Value >

Provides a type-safe, interprocess map with stable serialization.

This template class extends the stable_interprocess_container to provide a map-like container that can be safely used across different processes and shared library boundaries. It inherits the stability and consistency features of stable_interprocess_container, making it suitable for interprocess communication and data sharing in a multi-library environment.

Serialization and deserialization of the map are automatically handled to ensure data integrity and consistency when shared across different compilers or compiler versions.

Template Parameters
KeyThe type of the keys in the map.
ValueThe type of the values in the map.

Constructor & Destructor Documentation

◆ stable_interprocess_map()

template<typename Key, typename Value>
cbeam::container::stable_interprocess_map< Key, Value >::stable_interprocess_map ( const std::string & unique_identifier,
std::size_t size )
inline

Constructs a stable_interprocess_map with a unique identifier and fixed size.

Parameters
unique_identifierA unique identifier for the shared memory segment.
sizeThe size of the shared memory segment, in bytes. This size determines the capacity of the map and cannot be altered after initialization.

Member Function Documentation

◆ at()

template<typename Key, typename Value>
Value cbeam::container::stable_interprocess_map< Key, Value >::at ( const Key & key) const
inline

Retrieves the value associated with a specific key.

Parameters
keyThe key to look up.
Returns
The value associated with the key.
Exceptions
std::out_of_rangeif the key is not found.

◆ at_or_default()

template<typename Key, typename Value>
Value cbeam::container::stable_interprocess_map< Key, Value >::at_or_default ( const Key & key,
const Value & default_value ) const
inline

Retrieves the value associated with a key, or a default value if the key is not found.

Parameters
keyThe key to look up.
default_valueThe default value to return if the key is not found.
Returns
The value associated with the key, or the default value.

◆ count()

template<typename Key, typename Value>
std::size_t cbeam::container::stable_interprocess_map< Key, Value >::count ( const Key & key) const
inline

Counts the number of elements with a specific key.

Parameters
keyThe key to count in the map.
Returns
The number of elements with the specified key.

◆ erase()

template<typename Key, typename Value>
void cbeam::container::stable_interprocess_map< Key, Value >::erase ( const Key & key)
inline

Erases the element associated with a specific key.

Parameters
keyThe key of the element to be erased.

◆ insert()

template<typename Key, typename Value>
void cbeam::container::stable_interprocess_map< Key, Value >::insert ( const Key & key,
const Value & value )
inline

Inserts a key-value pair into the map.

Parameters
keyThe key of the element to insert.
valueThe value to be associated with the key.

◆ operator=()

template<typename Key, typename Value>
stable_interprocess_map & cbeam::container::stable_interprocess_map< Key, Value >::operator= ( const std::initializer_list< std::pair< const Key, Value > > & list)
inline

Assigns key-value pairs to the map from an initializer list.

Parameters
listAn initializer list of key-value pairs.
Returns
Reference to this stable_interprocess_map object.

◆ update()

template<typename Key, typename Value>
const Value cbeam::container::stable_interprocess_map< Key, Value >::update ( const Key & key,
std::function< void(Value &)> updater,
const std::string & error_string = {"cbeam::stable_interprocess_map< Key, Value >::update: key not found"} )
inline

◆ update_or_insert()

template<typename Key, typename Value>
void cbeam::container::stable_interprocess_map< Key, Value >::update_or_insert ( const Key & key,
std::function< void(Value &)> updater,
const Value & default_value )
inline

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