Template Class dictionary_t
Defined in File dictionary.hpp
Inheritance Relationships
Base Type
public std::map< key, value >
Class Documentation
-
template<typename key, typename value>
class dictionary_t : public std::map<key, value> Thread-safe dictionary wrapper around
std::map.It supports concurrent reads and synchronized writes.
- Template Parameters:
key – Type of the dictionary key.
value – Type of the dictionary value.
Public Types
Typedef for a shared pointer to a dictionary.
Public Functions
-
inline dictionary_t()
Default constructor initializes an empty dictionary.
-
inline dictionary_t(const std::pair<const key, value> &data_)
Construct a new dictionary_t object from a single key-value pair
- Parameters:
data_ – Initial key-value pair inserted at construction time.
-
inline dictionary_t(const dictionary_t<key, value> &other_)
Copy constructor
- Parameters:
other_ – Source dictionary copied while holding a read lock.
-
inline dictionary_t(std::initializer_list<std::pair<const key, value>> init_)
Construct a new dictionary_t object from an initializer list of key-value pairs
- Parameters:
init_ – Initial key-value pairs used to populate the dictionary.
-
inline size_t size_() const
Get the size of the dictionary in a thread-safe manner
- Returns:
Number of key-value entries currently stored.
-
inline bool contains_(const key &key_) const
Check if the dictionary contains a key in a thread-safe manner
- Parameters:
key_ – Key tested for existence in the dictionary.
- Returns:
truewhenkey_exists,falseotherwise.
-
inline value at_(const key &key_) const
Get the value associated with a key in a thread-safe manner
- Parameters:
key_ – Key whose associated value is retrieved.
- Returns:
Copy of the value stored for
key_.
-
inline void insert_(const std::pair<const key, value> &data_)
Insert a key-value pair into the dictionary in a thread-safe manner
- Parameters:
data_ – Key-value pair inserted into the dictionary.
-
inline void erase_(const key &key_)
Remove a key from the dictionary in a thread-safe manner
- Parameters:
key_ – key to be erased.
-
inline dictionary_t<key, value> &operator=(const dictionary_t<key, value> &other_)
Equal operator
- Parameters:
other_ – Source dictionary whose entries replace this dictionary.
- Returns:
Reference to this dictionary after assignment.
-
inline void lock_read() const
Lock the object for shared reading.
-
inline void unlock_read() const
Unlock the shared reading lock.
-
inline void lock() const
Lock the object for writing.
-
inline void unlock() const
Unlock the writing lock.
Private Members
-
mutable std::shared_mutex _mutex
Mutex that is used to lock the dictionary for reading and writing.