soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SCmnMap< TObj, TKey > Class Template Reference

Template class for managing a map of objects with keys. More...

#include <SCmnMap.h>

Public Member Functions

 SCmnMap (void(*funOnKeyRemoved)(const TObj &)=NULL)
 Constructor.
 
virtual ~SCmnMap ()
 Destructor.
 
bool HasKey (const TKey &key) const
 Checks if a key exists in the map.
 
bool GetKeyObject (const TKey &key, TObj &obj) const
 Retrieves an object associated with a key.
 
TObj & GetKeyObject (const TKey &key) const
 Retrieves an object associated with a key.
 
bool AddKeyObject (const TKey &key, const TObj &obj)
 Adds a key-object pair to the map.
 
void SetKeyObject (const TKey &key, const TObj &obj)
 Sets an object for a key, replacing any existing object.
 
bool RemoveKeyObject (const TKey &key)
 Removes a key-object pair from the map.
 
void RemoveAll ()
 Removes all key-object pairs from the map.
 
size_t GetCount ()
 Gets the number of key-object pairs in the map.
 

Protected Attributes

void(* m_pFunOnKeyRemoved )(const TObj &obj)
 
SMap< TKey, TObj > * m_mapNamedObj
 

Detailed Description

template<class TObj, class TKey = SStringA>
class SCmnMap< TObj, TKey >

Template class for managing a map of objects with keys.

This template class provides a map-like structure to store and manage objects associated with keys. It includes methods for adding, retrieving, and removing objects, as well as handling key removal callbacks.

Template Parameters
TObjType of the objects stored in the map
TKeyType of the keys used to identify objects (default is SStringA)

Definition at line 20 of file SCmnMap.h.

Constructor & Destructor Documentation

◆ SCmnMap()

template<class TObj, class TKey = SStringA>
SCmnMap< TObj, TKey >::SCmnMap ( void(* funOnKeyRemoved )(const TObj &) = NULL)
inline

Constructor.

Parameters
funOnKeyRemovedCallback function to be called when a key is removed

Initializes the map and sets the callback function for key removal.

Definition at line 28 of file SCmnMap.h.

◆ ~SCmnMap()

template<class TObj, class TKey = SStringA>
virtual SCmnMap< TObj, TKey >::~SCmnMap ( )
inlinevirtual

Destructor.

Cleans up the map and deletes the internal map object.

Definition at line 39 of file SCmnMap.h.

Member Function Documentation

◆ AddKeyObject()

template<class TObj, class TKey = SStringA>
bool SCmnMap< TObj, TKey >::AddKeyObject ( const TKey & key,
const TObj & obj )
inline

Adds a key-object pair to the map.

Parameters
keyKey to add
objObject to associate with the key
Returns
TRUE if the key was added successfully, otherwise FALSE

Adds a new key-object pair to the map. Returns FALSE if the key already exists.

Definition at line 94 of file SCmnMap.h.

◆ GetCount()

template<class TObj, class TKey = SStringA>
size_t SCmnMap< TObj, TKey >::GetCount ( )
inline

Gets the number of key-object pairs in the map.

Returns
Number of key-object pairs

Returns the total number of key-object pairs in the map.

Definition at line 161 of file SCmnMap.h.

◆ GetKeyObject() [1/2]

template<class TObj, class TKey = SStringA>
TObj & SCmnMap< TObj, TKey >::GetKeyObject ( const TKey & key) const
inline

Retrieves an object associated with a key.

Parameters
keyKey to look up
Returns
Reference to the object associated with the key

Returns a reference to the object associated with the specified key. Note: This method does not check if the key exists.

Definition at line 81 of file SCmnMap.h.

◆ GetKeyObject() [2/2]

template<class TObj, class TKey = SStringA>
bool SCmnMap< TObj, TKey >::GetKeyObject ( const TKey & key,
TObj & obj ) const
inline

Retrieves an object associated with a key.

Parameters
keyKey to look up
objObject to store the retrieved value
Returns
TRUE if the key exists and the object is retrieved, otherwise FALSE

Retrieves the object associated with the specified key and stores it in the provided object.

Definition at line 65 of file SCmnMap.h.

◆ HasKey()

template<class TObj, class TKey = SStringA>
bool SCmnMap< TObj, TKey >::HasKey ( const TKey & key) const
inline

Checks if a key exists in the map.

Parameters
keyKey to check
Returns
TRUE if the key exists, otherwise FALSE

Returns whether the specified key is present in the map.

Definition at line 52 of file SCmnMap.h.

◆ RemoveAll()

template<class TObj, class TKey = SStringA>
void SCmnMap< TObj, TKey >::RemoveAll ( )
inline

Removes all key-object pairs from the map.

Removes all key-object pairs from the map and calls the callback function for each removed object if it is set.

Definition at line 141 of file SCmnMap.h.

◆ RemoveKeyObject()

template<class TObj, class TKey = SStringA>
bool SCmnMap< TObj, TKey >::RemoveKeyObject ( const TKey & key)
inline

Removes a key-object pair from the map.

Parameters
keyKey to remove
Returns
TRUE if the key was removed successfully, otherwise FALSE

Removes the key-object pair associated with the specified key. Calls the callback function if it is set.

Definition at line 123 of file SCmnMap.h.

◆ SetKeyObject()

template<class TObj, class TKey = SStringA>
void SCmnMap< TObj, TKey >::SetKeyObject ( const TKey & key,
const TObj & obj )
inline

Sets an object for a key, replacing any existing object.

Parameters
keyKey to set
objObject to associate with the key

Sets the object for the specified key, removing any existing object associated with the key.

Definition at line 109 of file SCmnMap.h.

Member Data Documentation

◆ m_mapNamedObj

template<class TObj, class TKey = SStringA>
SMap<TKey, TObj>* SCmnMap< TObj, TKey >::m_mapNamedObj
protected

Internal map object.

Definition at line 168 of file SCmnMap.h.

◆ m_pFunOnKeyRemoved

template<class TObj, class TKey = SStringA>
void(* SCmnMap< TObj, TKey >::m_pFunOnKeyRemoved) (const TObj &obj)
protected

Callback function for key removal.

Definition at line 167 of file SCmnMap.h.


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