KarmaEngine
Game Engine for practical learning and research purposes
Loading...
Searching...
No Matches
KarmaMap< KeyType, ValueType > Class Template Reference

Karma's std::map wrapper. More...

#include <KarmaTypes.h>

Public Types

typedef std::map< KeyType, ValueType > AMap
typedef AMap::iterator AnIterator

Public Member Functions

 KarmaMap ()
 Constructor.
void Add (const KeyType &Key, const ValueType &Value)
 Addes a key-value pair to the map.
bool Contains (const KeyType &Key) const
 Checks if the map contains a specified key.
ValueType & FindOrAdd (const KeyType &Key)
 Find the value associated with a specified key, or if none exists, adds a value using the default constructor.
ValueType * Find (const KeyType &Key)
 Find the value associated with a specified key.
ValueType & operator[] (const KeyType &Key)
 Overloaded subscript operator for accessing values by key.
const ValueType & operator[] (const KeyType &Key) const
 Overloaded subscript operator for accessing values by key (const version).
uint32_t Num () const
auto begin ()
auto end ()
auto begin () const
auto end () const

Protected Attributes

AMap m_KeyValuePair

Detailed Description

template<typename KeyType, typename ValueType>
class KarmaMap< KeyType, ValueType >

Karma's std::map wrapper.

Constructor & Destructor Documentation

◆ KarmaMap()

template<typename KeyType, typename ValueType>
KarmaMap< KeyType, ValueType >::KarmaMap ( )
inline

Constructor.

Since
Karma 1.0.0

Member Function Documentation

◆ Add()

template<typename KeyType, typename ValueType>
void KarmaMap< KeyType, ValueType >::Add ( const KeyType & Key,
const ValueType & Value )
inline

Addes a key-value pair to the map.

Since
Karma 1.0.0

◆ Contains()

template<typename KeyType, typename ValueType>
bool KarmaMap< KeyType, ValueType >::Contains ( const KeyType & Key) const
inline

Checks if the map contains a specified key.

Parameters
KeyThe key to search for.
Returns
true if the map contains the specified key, false otherwise.
Since
Karma 1.0.0

◆ Find()

template<typename KeyType, typename ValueType>
ValueType * KarmaMap< KeyType, ValueType >::Find ( const KeyType & Key)
inline

Find the value associated with a specified key.

Parameters
KeyThe key to search for.
Returns
A pointer to the value associated with the specified key, or nullptr if the key isn't contained in this map. The pointer is only valid until the next change to any key in the map.
Since
Karma 1.0.0

◆ FindOrAdd()

template<typename KeyType, typename ValueType>
ValueType & KarmaMap< KeyType, ValueType >::FindOrAdd ( const KeyType & Key)
inline

Find the value associated with a specified key, or if none exists, adds a value using the default constructor.

Algorithm courtsey: https://stackoverflow.com/a/1409465

Parameters
KeyThe key to search for.
Returns
A reference to the value associated with the specified key
Since
Karma 1.0.0

◆ operator[]() [1/2]

template<typename KeyType, typename ValueType>
ValueType & KarmaMap< KeyType, ValueType >::operator[] ( const KeyType & Key)
inline

Overloaded subscript operator for accessing values by key.

Parameters
KeyThe key whose associated value is to be accessed.
Returns
A reference to the value associated with the specified key.
Note
If the key does not exist in the map, a new entry is created with a default-constructed value. A mutable reference is returned.
Since
Karma 1.0.0

◆ operator[]() [2/2]

template<typename KeyType, typename ValueType>
const ValueType & KarmaMap< KeyType, ValueType >::operator[] ( const KeyType & Key) const
inline

Overloaded subscript operator for accessing values by key (const version).

Parameters
KeyThe key whose associated value is to be accessed.
Returns
A const reference to the value associated with the specified key.
Note
Returns immutable reference
Since
Karma 1.0.0

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