DuxReiNummariae 1.1.0-alpha.19
Simple and powerful budgeting application
Loading...
Searching...
No Matches
drn::foundation::TypeIndexMap< KeyType, ValueType > Class Template Reference

A generic map container of typed-keys to their values. More...

#include <TypeIndexMap.hpp>

Inheritance diagram for drn::foundation::TypeIndexMap< KeyType, ValueType >:
Collaboration diagram for drn::foundation::TypeIndexMap< KeyType, ValueType >:

Public Member Functions

 TypeIndexMap ()
 Empty constructor for a valid object. Initalises all values to zero.
template<typename IndexType>
void add (const KeyType &key, ValueType val)
 Adds a value to the container. When the typed-key already exists, the value is updated. When the typed-key does not exist, a new entry is made.
template<typename IndexType>
bool has (const KeyType &key) const
 Determines if a value is located under a given typed-key.
template<typename IndexType>
void remove (const KeyType &key)
 Removes a value from the container. When the value removed is the last one, the typed element is removed as well.
std::size_t total () const
 Gives the total number of elements in the container.
template<typename IndexType>
ValueType & value (const KeyType &key)
 Mutable accessor to the value under a typed-key.
template<typename IndexType>
const ValueType & value (const KeyType &key) const
 Non-mutable accessor to the value under a typed-key.

Detailed Description

template<typename KeyType, typename ValueType>
class drn::foundation::TypeIndexMap< KeyType, ValueType >

A generic map container of typed-keys to their values.

Template Parameters
KeyTypeThe type for the typed-key.
ValueTypeThe type for the values to store under the typed-key

Constructor & Destructor Documentation

◆ TypeIndexMap()

template<typename KeyType, typename ValueType>
drn::foundation::TypeIndexMap< KeyType, ValueType >::TypeIndexMap ( )

Empty constructor for a valid object. Initalises all values to zero.

Member Function Documentation

◆ add()

template<typename KeyType, typename ValueType>
template<typename IndexType>
void drn::foundation::TypeIndexMap< KeyType, ValueType >::add ( const KeyType & key,
ValueType val )

Adds a value to the container. When the typed-key already exists, the value is updated. When the typed-key does not exist, a new entry is made.

Template Parameters
IndexTypeThe index type to place the key under.
Parameters
keyThe key to place the value under.
valThe value to place into the container.

◆ has()

template<typename KeyType, typename ValueType>
template<typename IndexType>
bool drn::foundation::TypeIndexMap< KeyType, ValueType >::has ( const KeyType & key) const
nodiscard

Determines if a value is located under a given typed-key.

Template Parameters
IndexTypeThe index type the key is expected to be under.
Parameters
keyThe key to search for in the container.
Returns
Gives true when the typed-key exists, false otherwise.

◆ remove()

template<typename KeyType, typename ValueType>
template<typename IndexType>
void drn::foundation::TypeIndexMap< KeyType, ValueType >::remove ( const KeyType & key)

Removes a value from the container. When the value removed is the last one, the typed element is removed as well.

Exceptions
ErrorWhen the typed-key is not located.
Template Parameters
IndexTypeThe index type the key is expected to be under.
Parameters
keyThe key to remove from the container.

◆ total()

template<typename KeyType, typename ValueType>
std::size_t drn::foundation::TypeIndexMap< KeyType, ValueType >::total ( ) const
nodiscard

Gives the total number of elements in the container.

Returns
The number of combined elements under each typed-key.

◆ value() [1/2]

template<typename KeyType, typename ValueType>
template<typename IndexType>
ValueType & drn::foundation::TypeIndexMap< KeyType, ValueType >::value ( const KeyType & key)
nodiscard

Mutable accessor to the value under a typed-key.

Exceptions
ErrorWhen the value is not located under a typed-key.
Template Parameters
IndexTypeThe index type the key is expected to be under.
Parameters
keyThe key to get the value from under.
Returns
Gives the value located under the typed-key.

◆ value() [2/2]

template<typename KeyType, typename ValueType>
template<typename IndexType>
const ValueType & drn::foundation::TypeIndexMap< KeyType, ValueType >::value ( const KeyType & key) const
nodiscard

Non-mutable accessor to the value under a typed-key.

Exceptions
ErrorWhen the value is not located under a typed-key.
Template Parameters
IndexTypeThe index type the key is expected to be under.
Parameters
keyThe key to get the value from under.
Returns
Gives the value located under the typed-key.