Elaztek Developer Hub
Blamite Game Engine - Strings  00402.09.29.23.0627.blamite
A library containing general purpose utilities and classes for use in multiple projects.
BlamMap< KeyType, ValueType > Class Template Reference

Class representing a BlamMap. More...

#include <map.h>

Public Member Functions

 BlamMap ()
 Constructs a new BlamMap. More...
 
 BlamMap (std::map< KeyType, ValueType > std_map)
 Constructs a new BlamMap. More...
 
int Size ()
 Returns the number of pairs within the map. More...
 
ValueType At (KeyType key)
 Retrieves the value associated with the specified key. More...
 
BlamMapPair< KeyType, ValueType > * PairAt (int index)
 Retrieves the pair at the specified index. More...
 
void Add (std::pair< KeyType, ValueType > pair)
 Adds a new key/value pair to the map. More...
 
void Add (KeyType key, ValueType value)
 Adds a new key/value pair to the map. More...
 
bool Contains (KeyType key)
 Checks if the map has a pair with the given key. More...
 
std::vector< KeyType > KeySet ()
 Creates a list of all keys within the map. More...
 
std::vector< ValueType > Values ()
 Creates a list of all values within the map. More...
 
std::map< KeyType, ValueType > ToStdMap ()
 Converts the map to a std::map. More...
 
bool GetFirstKey (ValueType value, KeyType *out_key)
 Attempts to locate a pair within the map with a specified value. More...
 
bool Erase (KeyType key)
 Removes the item in the map with the specified key. More...
 
bool EraseAt (int index)
 Removes the item in the map at the specified index. More...
 
int EraseValues (ValueType value)
 Removes all items in the map with the specified value. More...
 
void Clear ()
 Removes all items within the map. More...
 

Detailed Description

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

Class representing a BlamMap.

BlamMaps are functionally identical to a std::map. However, they are designed to be simpler to use overall, and require less code to interact with. They also provide a number of unique methods that are normally not part of a typical map class.

Constructor & Destructor Documentation

◆ BlamMap() [1/2]

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

Constructs a new BlamMap.

◆ BlamMap() [2/2]

template<typename KeyType , typename ValueType >
BlamMap< KeyType, ValueType >::BlamMap ( std::map< KeyType, ValueType >  std_map)
inline

Constructs a new BlamMap.

Parameters
std_map- An existing std::map to load data from.
+ Here is the call graph for this function:

Member Function Documentation

◆ Add() [1/2]

template<typename KeyType , typename ValueType >
void BlamMap< KeyType, ValueType >::Add ( KeyType  key,
ValueType  value 
)
inline

Adds a new key/value pair to the map.

If the provided key is already contained within the map, then the original pair's value is updated with the new value.

Parameters
key- The key to add to the map.
value- The value to add to the map.

◆ Add() [2/2]

template<typename KeyType , typename ValueType >
void BlamMap< KeyType, ValueType >::Add ( std::pair< KeyType, ValueType >  pair)
inline

Adds a new key/value pair to the map.

Parameters
pair- The std::pair to add.
+ Here is the caller graph for this function:

◆ At()

template<typename KeyType , typename ValueType >
ValueType BlamMap< KeyType, ValueType >::At ( KeyType  key)
inline

Retrieves the value associated with the specified key.

If no matching key/value pair was found, then an exception is thrown. It is encouraged to use the Contains() method prior to using this method.

Parameters
key- The key to check for.
Returns
The value associated with the specified key.

◆ Clear()

template<typename KeyType , typename ValueType >
void BlamMap< KeyType, ValueType >::Clear ( )
inline

Removes all items within the map.

◆ Contains()

template<typename KeyType , typename ValueType >
bool BlamMap< KeyType, ValueType >::Contains ( KeyType  key)
inline

Checks if the map has a pair with the given key.

Parameters
key- The key to search for.
Returns
true if the map contains the specified key, otherwise returns false.

◆ Erase()

template<typename KeyType , typename ValueType >
bool BlamMap< KeyType, ValueType >::Erase ( KeyType  key)
inline

Removes the item in the map with the specified key.

Parameters
key- The key to search for.
Returns
true if a matching item was found and removed, otherwise returns false.

◆ EraseAt()

template<typename KeyType , typename ValueType >
bool BlamMap< KeyType, ValueType >::EraseAt ( int  index)
inline

Removes the item in the map at the specified index.

Parameters
index- The index of the pair to remove.
Returns
true if a matching pair was found and removed, otherwise returns false.

◆ EraseValues()

template<typename KeyType , typename ValueType >
int BlamMap< KeyType, ValueType >::EraseValues ( ValueType  value)
inline

Removes all items in the map with the specified value.

Parameters
value- The value to search for.
Returns
The number of items removed that matched the specified value.

◆ GetFirstKey()

template<typename KeyType , typename ValueType >
bool BlamMap< KeyType, ValueType >::GetFirstKey ( ValueType  value,
KeyType *  out_key 
)
inline

Attempts to locate a pair within the map with a specified value.

This does not search for a value at the specified key - rather, it acts in reverse - looking for a key with the specified value. Note that a value may correlate to multiple keys. As such, this method will return the first matching value - even if there are other possible matches.

Parameters
value- The value to search for.
out_key- Output parameter. If a matching value is found, this will be set to the associated key.
Returns
true if the desired key was located. If out_key was nullptr, or if the map did not have any pairs with the specified value, then this will return false.

◆ KeySet()

template<typename KeyType , typename ValueType >
std::vector<KeyType> BlamMap< KeyType, ValueType >::KeySet ( )
inline

Creates a list of all keys within the map.

Returns
A list of all keys contained within the map.

◆ PairAt()

template<typename KeyType , typename ValueType >
BlamMapPair<KeyType, ValueType>* BlamMap< KeyType, ValueType >::PairAt ( int  index)
inline

Retrieves the pair at the specified index.

If the provided index was out of range, then an exception is thrown. It is encouraged to use the Size() method prior to using this method.

Parameters
index- The index of the desired key/value pair.
Returns
The pair at the specified index.
+ Here is the call graph for this function:

◆ Size()

template<typename KeyType , typename ValueType >
int BlamMap< KeyType, ValueType >::Size ( )
inline

Returns the number of pairs within the map.

Returns
The number of pairs within the map.
+ Here is the caller graph for this function:

◆ ToStdMap()

template<typename KeyType , typename ValueType >
std::map<KeyType, ValueType> BlamMap< KeyType, ValueType >::ToStdMap ( )
inline

Converts the map to a std::map.

Returns
A new std::map containing the same key/value pairs as the current map.

◆ Values()

template<typename KeyType , typename ValueType >
std::vector<ValueType> BlamMap< KeyType, ValueType >::Values ( )
inline

Creates a list of all values within the map.

Returns
A list of allv alues contained within the map.

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