Sane C++ Libraries
C++ Platform Abstraction Libraries
SC::VectorMap< Key, Value, Container > Struct Template Reference

A map holding VectorMapItem key-value pairs in an unsorted Vector. More...

#include <VectorMap.h>

Public Types

using Item = VectorMapItem< Key, Value >
 

Public Member Functions

auto size () const
 Return the number of key-value pairs in the map. More...
 
auto isEmpty () const
 Check if the map is empty. More...
 
Itembegin ()
 
const Itembegin () const
 
Itemend ()
 
const Itemend () const
 
template<typename ComparableToKey >
bool remove (const ComparableToKey &key)
 Remove an item with matching key from the Map. More...
 
bool insertIfNotExists (Item &&item)
 Inserts an item if it doesn't exist already. More...
 
Value * insertOverwrite (Item &&item)
 Insert an item, overwriting the potentially already existing one. More...
 
Key * insertValueUniqueKey (Value &&value)
 Inserts a new value, automatically generating key with Key::generateUniqueKey (works for StrongID for example) More...
 
template<typename ComparableToKey >
bool contains (const ComparableToKey &key) const
 Check if the given key is contained in the map. More...
 
template<typename ComparableToKey >
bool contains (const ComparableToKey &key, const Value *&outValue) const
 Check if the given key is contained in the map. More...
 
template<typename ComparableToKey >
bool contains (const ComparableToKey &key, Value *&outValue)
 Check if the given key is contained in the map. More...
 
template<typename ComparableToKey >
const Value * get (const ComparableToKey &key) const
 Get the Value associated to the given key. More...
 
template<typename ComparableToKey >
Value * get (const ComparableToKey &key)
 Get the Value associated to the given key. More...
 
template<typename ComparableToKey >
Value * getOrCreate (const ComparableToKey &key)
 Get the value associated to the given key, or creates a new one if needed. More...
 

Public Attributes

Container items
 

Detailed Description

template<typename Key, typename Value, typename Container = SC::Vector<SC::VectorMapItem<Key, Value>>>
struct SC::VectorMap< Key, Value, Container >

A map holding VectorMapItem key-value pairs in an unsorted Vector.

Template Parameters
KeyType of the key (must support == comparison)
ValueValue type associated with Key
ContainerContainer used for the Map

Member Function Documentation

◆ contains() [1/3]

template<typename Key , typename Value , typename Container = SC::Vector<SC::VectorMapItem<Key, Value>>>
template<typename ComparableToKey >
bool SC::VectorMap< Key, Value, Container >::contains ( const ComparableToKey &  key) const
inline

Check if the given key is contained in the map.

◆ contains() [2/3]

template<typename Key , typename Value , typename Container = SC::Vector<SC::VectorMapItem<Key, Value>>>
template<typename ComparableToKey >
bool SC::VectorMap< Key, Value, Container >::contains ( const ComparableToKey &  key,
const Value *&  outValue 
) const
inline

Check if the given key is contained in the map.

Parameters
keyThe key to search for inside current map
outValueA reference that will receive pointer to the found element (if found)

◆ contains() [3/3]

template<typename Key , typename Value , typename Container = SC::Vector<SC::VectorMapItem<Key, Value>>>
template<typename ComparableToKey >
bool SC::VectorMap< Key, Value, Container >::contains ( const ComparableToKey &  key,
Value *&  outValue 
)
inline

Check if the given key is contained in the map.

Parameters
keyThe key to search for inside current map
outValueA reference that will receive pointer to the found element (if found)

◆ get() [1/2]

template<typename Key , typename Value , typename Container = SC::Vector<SC::VectorMapItem<Key, Value>>>
template<typename ComparableToKey >
Value * SC::VectorMap< Key, Value, Container >::get ( const ComparableToKey &  key)
inline

Get the Value associated to the given key.

Returns
A pointer to the value if it exists in the map, nullptr otherwise

◆ get() [2/2]

template<typename Key , typename Value , typename Container = SC::Vector<SC::VectorMapItem<Key, Value>>>
template<typename ComparableToKey >
const Value * SC::VectorMap< Key, Value, Container >::get ( const ComparableToKey &  key) const
inline

Get the Value associated to the given key.

Returns
A pointer to the value if it exists in the map, nullptr otherwise

◆ getOrCreate()

template<typename Key , typename Value , typename Container = SC::Vector<SC::VectorMapItem<Key, Value>>>
template<typename ComparableToKey >
Value * SC::VectorMap< Key, Value, Container >::getOrCreate ( const ComparableToKey &  key)
inline

Get the value associated to the given key, or creates a new one if needed.

Returns
A pointer to the value or nullptr if the map is full

◆ insertIfNotExists()

template<typename Key , typename Value , typename Container = SC::Vector<SC::VectorMapItem<Key, Value>>>
bool SC::VectorMap< Key, Value, Container >::insertIfNotExists ( Item &&  item)
inline

Inserts an item if it doesn't exist already.

Parameters
itemThe item to insert
Returns
false if item already exists or if insertion fails (true otherwise)

◆ insertOverwrite()

template<typename Key , typename Value , typename Container = SC::Vector<SC::VectorMapItem<Key, Value>>>
Value * SC::VectorMap< Key, Value, Container >::insertOverwrite ( Item &&  item)
inline

Insert an item, overwriting the potentially already existing one.

Parameters
itemItem to insert
Returns
A pointer to the Value if insertion succeeds, nullptr if insertion fails.

◆ insertValueUniqueKey()

template<typename Key , typename Value , typename Container = SC::Vector<SC::VectorMapItem<Key, Value>>>
Key * SC::VectorMap< Key, Value, Container >::insertValueUniqueKey ( Value &&  value)
inline

Inserts a new value, automatically generating key with Key::generateUniqueKey (works for StrongID for example)

Parameters
valueThe new value to be inserted
Returns
A pointer to the new Key or nullptr if the map is full

◆ isEmpty()

template<typename Key , typename Value , typename Container = SC::Vector<SC::VectorMapItem<Key, Value>>>
auto SC::VectorMap< Key, Value, Container >::isEmpty ( ) const
inline

Check if the map is empty.

◆ remove()

template<typename Key , typename Value , typename Container = SC::Vector<SC::VectorMapItem<Key, Value>>>
template<typename ComparableToKey >
bool SC::VectorMap< Key, Value, Container >::remove ( const ComparableToKey &  key)
inline

Remove an item with matching key from the Map.

Parameters
keyThe key that must be removed
Returns
true if the item was found

◆ size()

template<typename Key , typename Value , typename Container = SC::Vector<SC::VectorMapItem<Key, Value>>>
auto SC::VectorMap< Key, Value, Container >::size ( ) const
inline

Return the number of key-value pairs in the map.


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