Uniot Core
0.8.1
Loading...
Searching...
No Matches
uniot::Map< T_Key, T_Value > Class Template Reference

#include <Map.h>

Inheritance diagram for uniot::Map< T_Key, T_Value >:
[legend]

Public Types

using MapItem = Pair<T_Key, T_Value>
 Type alias for a key-value pair in the map.
 
- Public Types inherited from ClearQueue< Pair< T_Key, T_Value > >
typedef std::function< void(const Pair< T_Key, T_Value > &)> VoidCallback
 Callback function type for forEach operations.
 

Public Member Functions

bool put (const T_Key &key, const T_Value &value)
 Inserts a key-value pair into the map.
 
const T_Value & get (const T_Key &key, const T_Value &defaultValue={}) const
 Retrieves the value associated with a key.
 
bool exist (const T_Key &key) const
 Checks if a key exists in the map.
 
bool remove (const T_Key &key)
 Removes a key-value pair from the map.
 
- Public Member Functions inherited from IterableQueue< Pair< T_Key, T_Value > >
void begin () const
 Initialize the iterator to the beginning of the queue.
 
bool isEnd () const
 Check if the iterator has reached the end of the queue.
 
const Pair< T_Key, T_Value > & next () const
 Move to the next element and return the current element.
 
const Pair< T_Key, T_Value > & current () const
 Access the current element without moving the iterator.
 
bool deleteCurrent ()
 Remove the current element from the queue.
 
- Public Member Functions inherited from ClearQueue< Pair< T_Key, T_Value > >
 ClearQueue (ClearQueue const &)=delete
 Deleted copy constructor to prevent copying.
 
 ClearQueue ()
 Constructs an empty queue.
 
void operator= (ClearQueue const &)=delete
 Deleted assignment operator to prevent copying.
 
virtual ~ClearQueue ()
 Destroys the queue and releases all allocated memory.
 
void push (const Pair< T_Key, T_Value > &value)
 Adds an element to the end of the queue.
 
bool pushUnique (const Pair< T_Key, T_Value > &value)
 Adds an element to the queue only if it doesn't already exist.
 
Pair< T_Key, T_Value > hardPop ()
 Removes and returns the element at the front of the queue.
 
const Pair< T_Key, T_Value > & hardPeek () const
 Returns the element at the front of the queue without removing it.
 
Pair< T_Key, T_Value > pop (const Pair< T_Key, T_Value > &errorCode)
 Safely removes and returns the element at the front of the queue.
 
const Pair< T_Key, T_Value > & peek (const Pair< T_Key, T_Value > &errorCode) const
 Safely returns the element at the front of the queue without removing it.
 
bool removeOne (const Pair< T_Key, T_Value > &value)
 Removes the first occurrence of a specific value from the queue.
 
bool contains (const Pair< T_Key, T_Value > &value) const
 Checks if the queue contains a specific value.
 
Pair< T_Key, T_Value > * find (const Pair< T_Key, T_Value > &value) const
 Finds and returns a pointer to the first occurrence of a value.
 
bool isEmpty () const
 Checks if the queue is empty.
 
size_t calcSize () const
 Calculate the number of elements in the queue by traversal.
 
void clean ()
 Removes all elements from the queue.
 
void forEach (VoidCallback callback) const
 Executes a callback function on each element in the queue.
 

Additional Inherited Members

- Protected Types inherited from ClearQueue< Pair< T_Key, T_Value > >
typedef struct ClearQueue::nodepnode
 Node structure for the linked list implementation.
 
- Protected Attributes inherited from IterableQueue< Pair< T_Key, T_Value > >
ClearQueue< Pair< T_Key, T_Value > >::pnode mCurrent
 Pointer to the current node during iteration.
 
- Protected Attributes inherited from ClearQueue< Pair< T_Key, T_Value > >
pnode mHead
 Pointer to the first node in the queue.
 
pnode mTail
 Pointer to the last node in the queue.
 

Member Typedef Documentation

◆ MapItem

template<typename T_Key, typename T_Value>
using uniot::Map< T_Key, T_Value >::MapItem = Pair<T_Key, T_Value>

Type alias for a key-value pair in the map.

Member Function Documentation

◆ exist()

template<typename T_Key, typename T_Value>
bool uniot::Map< T_Key, T_Value >::exist ( const T_Key & key) const
inline

Checks if a key exists in the map.

This method iterates through all key-value pairs in the map to determine if the specified key exists.

Parameters
keyThe key to check for.
Return values
trueThe key exists in the map.
falseThe key does not exist in the map.

◆ get()

template<typename T_Key, typename T_Value>
const T_Value & uniot::Map< T_Key, T_Value >::get ( const T_Key & key,
const T_Value & defaultValue = {} ) const
inline

Retrieves the value associated with a key.

This method iterates through the map to find the key. If found, it returns the associated value; otherwise, it returns the default value.

Parameters
keyThe key to search for.
defaultValueThe default value to return if the key is not found.
Return values
valueThe value associated with the key.
defaultValueThe default value if the key is not found.

◆ put()

template<typename T_Key, typename T_Value>
bool uniot::Map< T_Key, T_Value >::put ( const T_Key & key,
const T_Value & value )
inline

Inserts a key-value pair into the map.

This method checks if the key already exists in the map. If not, it adds a new key-value pair to the map.

Parameters
keyThe key to insert.
valueThe value to associate with the key.
Return values
trueInsertion was successful.
falseThe key already exists in the map.

◆ remove()

template<typename T_Key, typename T_Value>
bool uniot::Map< T_Key, T_Value >::remove ( const T_Key & key)
inline

Removes a key-value pair from the map.

This method searches for the specified key and removes the corresponding key-value pair if found.

Parameters
keyThe key of the pair to remove.
Return values
trueThe key-value pair was successfully removed.
falseThe key was not found in the map.

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