CPP-TOOLBOX
Loading...
Searching...
No Matches
ReactiveUnorderedMap< Key, Value, Hash, KeyEq > Class Template Reference

A wrapper around std::unordered_map that provides reactive signals for insertions and deletions. More...

#include <reactive_unordered_map.hpp>

Public Types

using key_type = Key
 
using mapped_type = Value
 
using value_type = std::pair<const Key, Value>
 
using size_type = std::size_t
 
using map_type = std::unordered_map<Key, Value, Hash, KeyEq>
 
using iterator = typename map_type::iterator
 
using const_iterator = typename map_type::const_iterator
 
using map_signals = MapSignals<Key, Value>
 
using inserted_signal = map_signals::Inserted
 
using erased_signal = map_signals::Erased
 

Public Member Functions

 ReactiveUnorderedMap ()=default
 
bool empty () const noexcept
 
size_type size () const noexcept
 
void reserve (size_type n)
 
iterator begin () noexcept
 
iterator end () noexcept
 
const_iterator begin () const noexcept
 
const_iterator end () const noexcept
 
iterator find (const Key &k)
 
const_iterator find (const Key &k) const
 
bool contains (const Key &k) const
 
Value & at (const Key &k)
 
const Value & at (const Key &k) const
 
std::pair< iterator, bool > insert_or_assign (const Key &key, Value &&value)
 
template<typename... Args>
std::pair< iterator, bool > try_emplace (const Key &key, Args &&...args)
 
template<class... Args>
std::pair< iterator, bool > emplace (Args &&...args)
 runs the internal call and emits an inserted signal if succeeded
 
Value & operator[] (const Key &key)
 
size_type erase (const Key &key)
 runs the internal call and emits an erased signal if succeeded
 
iterator erase (iterator pos)
 
void clear () noexcept
 
bool update_if_exists (const Key &key, Value &&new_value)
 

Public Attributes

SignalEmitter signal_emitter
 

Detailed Description

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
class ReactiveUnorderedMap< Key, Value, Hash, KeyEq >

A wrapper around std::unordered_map that provides reactive signals for insertions and deletions.

@warn not all signals are being emitted in all functions, this is being developed on an "add as you need" basis

This class behaves like a standard unordered_map with additional capabilities:

  1. Reactive Signals: Automatically emits signals when elements are inserted or erased.
  2. Standard Map Operations: Supports most operations of std::unordered_map, including:
    • Lookup (find, at, contains, operator[])
    • Iteration (begin, end)
    • Capacity queries (empty, size, reserve)
    • Modifiers (insert_or_assign, try_emplace, emplace, erase, clear, update_if_exists)
Template Parameters
KeyType of the map's keys.
ValueType of the map's values.
HashHash function used for keys. Defaults to std::hash<Key>.
KeyEqKey equality comparator. Defaults to std::equal_to<Key>.
Note
Signals are emitted through an internal SignalEmitter. Connecting to these signals allows external code to react to map changes without directly modifying the map.
Examples
/home/runner/work/website/website/code/src/utility/reactive_unordered_map/reactive_unordered_map.hpp.

Member Typedef Documentation

◆ const_iterator

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
using ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::const_iterator = typename map_type::const_iterator

◆ erased_signal

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
using ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::erased_signal = map_signals::Erased

◆ inserted_signal

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
using ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::inserted_signal = map_signals::Inserted

◆ iterator

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
using ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::iterator = typename map_type::iterator

◆ key_type

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
using ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::key_type = Key

◆ map_signals

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
using ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::map_signals = MapSignals<Key, Value>

◆ map_type

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
using ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::map_type = std::unordered_map<Key, Value, Hash, KeyEq>

◆ mapped_type

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
using ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::mapped_type = Value

◆ size_type

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
using ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::size_type = std::size_t

◆ value_type

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
using ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::value_type = std::pair<const Key, Value>

Constructor & Destructor Documentation

◆ ReactiveUnorderedMap()

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::ReactiveUnorderedMap ( )
default

Member Function Documentation

◆ at() [1/2]

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
Value & ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::at ( const Key & k)
inline

◆ at() [2/2]

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
const Value & ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::at ( const Key & k) const
inline

◆ begin() [1/2]

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
const_iterator ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::begin ( ) const
inlinenoexcept

◆ begin() [2/2]

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
iterator ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::begin ( )
inlinenoexcept

◆ clear()

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
void ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::clear ( )
inlinenoexcept

◆ contains()

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
bool ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::contains ( const Key & k) const
inline

◆ emplace()

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
template<class... Args>
std::pair< iterator, bool > ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::emplace ( Args &&... args)
inline

runs the internal call and emits an inserted signal if succeeded

Examples
/home/runner/work/website/website/code/src/utility/reactive_unordered_map/reactive_unordered_map.hpp.

◆ empty()

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
bool ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::empty ( ) const
inlinenoexcept

◆ end() [1/2]

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
const_iterator ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::end ( ) const
inlinenoexcept

◆ end() [2/2]

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
iterator ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::end ( )
inlinenoexcept

◆ erase() [1/2]

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
size_type ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::erase ( const Key & key)
inline

runs the internal call and emits an erased signal if succeeded

Examples
/home/runner/work/website/website/code/src/utility/reactive_unordered_map/reactive_unordered_map.hpp.

◆ erase() [2/2]

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
iterator ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::erase ( iterator pos)
inline

◆ find() [1/2]

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
iterator ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::find ( const Key & k)
inline

◆ find() [2/2]

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
const_iterator ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::find ( const Key & k) const
inline

◆ insert_or_assign()

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
std::pair< iterator, bool > ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::insert_or_assign ( const Key & key,
Value && value )
inline

◆ operator[]()

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
Value & ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::operator[] ( const Key & key)
inline

◆ reserve()

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
void ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::reserve ( size_type n)
inline

◆ size()

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
size_type ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::size ( ) const
inlinenoexcept

◆ try_emplace()

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
template<typename... Args>
std::pair< iterator, bool > ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::try_emplace ( const Key & key,
Args &&... args )
inline

◆ update_if_exists()

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
bool ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::update_if_exists ( const Key & key,
Value && new_value )
inline

Member Data Documentation

◆ signal_emitter

template<typename Key, typename Value, typename Hash = std::hash<Key>, typename KeyEq = std::equal_to<Key>>
SignalEmitter ReactiveUnorderedMap< Key, Value, Hash, KeyEq >::signal_emitter

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