sptk2 logo
SPTK Home Page
Public Types | Public Member Functions | List of all members
sptk::SynchronizedMap< K, T > Class Template Reference

#include <SynchronizedMap.h>

Public Types

using CallbackFunction = std::function< bool(const K &key, T &item)>
 

Public Member Functions

virtual void insert (const K &key, const T &data)
 
virtual bool get (const K &key, T &item, bool remove=false)
 
virtual bool remove (const K &key)
 
bool empty () const
 
size_t size () const
 
void clear ()
 
bool for_each (CallbackFunction callbackFunction)
 

Detailed Description

template<class K, class T>
class sptk::SynchronizedMap< K, T >

Synchronized map

Simple thread-safe map

Member Typedef Documentation

◆ CallbackFunction

template<class K , class T >
using sptk::SynchronizedMap< K, T >::CallbackFunction = std::function<bool(const K& key, T& item)>

Map callback function used in each() method.

Iterates through list until false is returned.

Parameters
keyconst K&, Map item key
itemT&, Map item
datavoid*, Optional function-specific data

Member Function Documentation

◆ clear()

template<class K , class T >
void sptk::SynchronizedMap< K, T >::clear ( )
inline

Removes all items from the list

◆ empty()

template<class K , class T >
bool sptk::SynchronizedMap< K, T >::empty ( ) const
inline

Returns true if the list is empty

◆ for_each()

template<class K , class T >
bool sptk::SynchronizedMap< K, T >::for_each ( CallbackFunction  callbackFunction)
inline

Calls callbackFunction() for every list until false is returned

Parameters
callbackFunctionCallback function that is executed for list items
Returns
true if every list item was processed

◆ get()

template<class K , class T >
virtual bool sptk::SynchronizedMap< K, T >::get ( const K &  key,
T &  item,
bool  remove = false 
)
inlinevirtual

Finds a data item from the list front

Returns true if key exists and data populated.

Parameters
keyA data key
itemA list item (output)
removeIf true, then item is removed from map

References sptk::SynchronizedMap< K, T >::remove().

◆ insert()

template<class K , class T >
virtual void sptk::SynchronizedMap< K, T >::insert ( const K &  key,
const T &  data 
)
inlinevirtual

Inserts data item to the map

Parameters
keyconst K&, A data key
dataconst T&, A data item

◆ remove()

template<class K , class T >
virtual bool sptk::SynchronizedMap< K, T >::remove ( const K &  key)
inlinevirtual

Removes data with matching key

Returns true if key existed.

Parameters
keyconst K&, A data key

Referenced by sptk::SynchronizedMap< K, T >::get().

◆ size()

template<class K , class T >
size_t sptk::SynchronizedMap< K, T >::size ( ) const
inline

Returns number of items in the list


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

Fri Oct 14 2022 09:58:45: SPTK 5.4.1