Ocean
Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys > Class Template Reference

This class implements a data storage map that stores the data elements in a ring manner. More...

Inheritance diagram for Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >:

Public Types

enum  AccessMode : uint32_t { AM_MATCH = 0u , AM_MATCH_OR_HIGHEST , AM_MATCH_OR_LOWEST }
 Definition of individual element access modes. More...
 
typedef T Type
 The data type of the objects that are stored in this container. More...
 
typedef TKey TypeKey
 The data type of the keys that are used to address the data objects. More...
 

Public Member Functions

 RingMapT ()=default
 Creates a new ring storage object with no capacity. More...
 
 RingMapT (RingMapT< TKey, T, tThreadsafe, tOrderedKeys > &&ringMap) noexcept
 Move constructor. More...
 
 RingMapT (const RingMapT< TKey, T, tThreadsafe, tOrderedKeys > &ringMap)
 Copy constructor. More...
 
 RingMapT (const size_t capacity)
 Creates a new ring storage object with a specified capacity. More...
 
size_t capacity () const
 Returns the capacity of this storage container. More...
 
size_t size () const
 Returns the number of elements that are currently stored in this container. More...
 
void setCapacity (const size_t capacity)
 Sets or changes the capacity of this storage container. More...
 
bool insertElement (const TKey &key, const T &element, const bool forceOverwrite=false)
 Inserts a new element into this storage container. More...
 
bool insertElement (const TKey &key, T &&element, const bool forceOverwrite=false)
 Inserts a new element into this storage container. More...
 
template<AccessMode tAccessMode = AM_MATCH>
bool element (const TKey &key, T &element) const
 Returns an element of this storage container. More...
 
bool highestElement (T &element) const
 Returns the element with highest key. More...
 
bool lowestElement (T &element) const
 Returns the element with lowest key. More...
 
template<AccessMode tAccessMode = AM_MATCH>
bool checkoutElement (const TKey &key, T &element)
 Returns an element of this storage container and removes the element from the container. More...
 
bool hasElement (const TKey &key) const
 Returns whether this storage container holds a specific element. More...
 
bool refreshElement (const TKey &key)
 Checks whether a specified element exists and changes the age of this element. More...
 
std::vector< T > elements () const
 Returns all elements of this map as a vector. More...
 
void clear ()
 Clears all elements of this storage container. More...
 
bool isEmpty () const
 Returns whether this ring map holds at least one element. More...
 
RingMapT< TKey, T, tThreadsafe, tOrderedKeys > & operator= (RingMapT< TKey, T, tThreadsafe, tOrderedKeys > &&ringMap) noexcept
 Move operator. More...
 
template<bool tThreadSafeSecond>
RingMapT< TKey, T, tThreadsafe, tOrderedKeys > & operator= (RingMapT< TKey, T, tThreadSafeSecond, tOrderedKeys > &&ringMap) noexcept
 Move operator. More...
 
RingMapT< TKey, T, tThreadsafe, tOrderedKeys > & operator= (const RingMapT< TKey, T, tThreadsafe, tOrderedKeys > &ringMap)
 Copy operator. More...
 
template<bool tThreadSafeSecond>
RingMapT< TKey, T, tThreadsafe, tOrderedKeys > & operator= (const RingMapT< TKey, T, tThreadSafeSecond, tOrderedKeys > &ringMap)
 Copy operator. More...
 

Protected Types

using KeyList = std::list< TKey >
 Definition of a double-linked list holding the keys in order how they have been inserted. More...
 
using ValuePair = std::pair< T, typename KeyList::iterator >
 Definition of a pair combining a value with a list iterator. More...
 
typedef MapTyper< tOrderedKeys >::template TMap< TKey, ValuePairKeyMap
 Definition of a map that maps keys to value pairs. More...
 

Protected Member Functions

bool isValid () const
 Returns whether the internal states of this storage container is valid. More...
 

Protected Attributes

KeyMap keyMap_
 The map mapping keys to value pairs. More...
 
KeyList keyList_
 The list holding the keys in order how they have been added, oldest keys first. More...
 
size_t storageCapacity_ = 0
 The capacity of this storage container. More...
 
Lock lock_
 The container lock. More...
 

Friends

template<typename TKey2 , typename T2 , bool tThreadsafe2, bool tOrderedKeys2>
class RingMapT
 

Detailed Description

template<typename TKey, typename T, bool tThreadsafe, bool tOrderedKeys = false>
class Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >

This class implements a data storage map that stores the data elements in a ring manner.

The map can hold a maximal number of elements and exchanges the oldest object by a new object if this map is full.
Each stored object is connected with a key so that the object can be addressed.

Template Parameters
TKeyData type of the map keys
TData type of the map elements
tThreadsafeTrue, to create a thread-safe object
tOrderedKeysTrue, to allow accessing the keys in order; False, if the order of the keys is not of interest

Member Typedef Documentation

◆ KeyList

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys = false>
using Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::KeyList = std::list<TKey>
protected

Definition of a double-linked list holding the keys in order how they have been inserted.

◆ KeyMap

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys = false>
typedef MapTyper<tOrderedKeys>::template TMap<TKey, ValuePair> Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::KeyMap
protected

Definition of a map that maps keys to value pairs.

◆ Type

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys = false>
typedef T Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::Type

The data type of the objects that are stored in this container.

◆ TypeKey

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys = false>
typedef TKey Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::TypeKey

The data type of the keys that are used to address the data objects.

◆ ValuePair

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys = false>
using Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::ValuePair = std::pair<T, typename KeyList::iterator>
protected

Definition of a pair combining a value with a list iterator.

Member Enumeration Documentation

◆ AccessMode

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys = false>
enum Ocean::RingMapT::AccessMode : uint32_t

Definition of individual element access modes.

Enumerator
AM_MATCH 

The element's key must be a perfect match.

AM_MATCH_OR_HIGHEST 

The element with highest key is returned if no perfect match can be found, only if 'tOrderedKeys == true'.

AM_MATCH_OR_LOWEST 

The element with lowest key is returned if no perfect match can be found, only if 'tOrderedKeys == true'.

Constructor & Destructor Documentation

◆ RingMapT() [1/4]

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys = false>
Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::RingMapT ( )
default

Creates a new ring storage object with no capacity.

◆ RingMapT() [2/4]

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys>
Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::RingMapT ( RingMapT< TKey, T, tThreadsafe, tOrderedKeys > &&  ringMap)
inlinenoexcept

Move constructor.

Parameters
ringMapObject to be moved

◆ RingMapT() [3/4]

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys>
Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::RingMapT ( const RingMapT< TKey, T, tThreadsafe, tOrderedKeys > &  ringMap)
inline

Copy constructor.

Parameters
ringMapObject to be copied

◆ RingMapT() [4/4]

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys>
Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::RingMapT ( const size_t  capacity)
inlineexplicit

Creates a new ring storage object with a specified capacity.

Parameters
capacityThe capacity of the storage container, with range [0, infinity)

Member Function Documentation

◆ capacity()

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys>
size_t Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::capacity
inline

Returns the capacity of this storage container.

Returns
Capacity of this storage container

◆ checkoutElement()

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys>
template<typename RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::AccessMode tAccessMode>
bool Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::checkoutElement ( const TKey &  key,
T &  element 
)

Returns an element of this storage container and removes the element from the container.

Parameters
keyThe key of the element to be returned
elementResulting element
Returns
True, if the requested element exists
Template Parameters
tAccessModeThe access mode to be used
See also
element().

◆ clear()

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys>
void Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::clear

Clears all elements of this storage container.

◆ element()

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys>
template<typename RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::AccessMode tAccessMode>
bool Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::element ( const TKey &  key,
T &  element 
) const

Returns an element of this storage container.

Parameters
keyThe key of the element to be returned
elementResulting element
Returns
True, if the requested element exists
Template Parameters
tAccessModeThe access mode to be used
See also
checkoutElement().

◆ elements()

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys>
std::vector< T > Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::elements

Returns all elements of this map as a vector.

In case 'tOrderedKeys == true', the resulting elements will be in order based on their corresponding keys.

Returns
The map's element

◆ hasElement()

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys>
bool Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::hasElement ( const TKey &  key) const

Returns whether this storage container holds a specific element.

Parameters
keyThe key of the element that is checked
Returns
True, if so

◆ highestElement()

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys>
bool Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::highestElement ( T &  element) const

Returns the element with highest key.

The map must be created with 'tOrderedKeys == true'.

Parameters
elementResulting element
Returns
True, if the requested element exists
See also
element().

◆ insertElement() [1/2]

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys>
bool Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::insertElement ( const TKey &  key,
const T &  element,
const bool  forceOverwrite = false 
)

Inserts a new element into this storage container.

Parameters
keyThe key of the new element
elementThe element that will be inserted
forceOverwriteTrue, to overwrite an existing element with some key, False to avoid that an element is inserted if an element with same key exists already
Returns
True, if the element has been inserted

◆ insertElement() [2/2]

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys>
bool Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::insertElement ( const TKey &  key,
T &&  element,
const bool  forceOverwrite = false 
)

Inserts a new element into this storage container.

This function moves the new element.

Parameters
keyThe key of the new element
elementThe element that will be inserted
forceOverwriteTrue, to overwrite an existing element with some key, False to avoid that an element is inserted if an element with same key exists already
Returns
True, if the element has been inserted

◆ isEmpty()

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys>
bool Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::isEmpty
inline

Returns whether this ring map holds at least one element.

Returns
True, if so

◆ isValid()

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys>
bool Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::isValid
inlineprotected

Returns whether the internal states of this storage container is valid.

Returns
True, if so

◆ lowestElement()

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys>
bool Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::lowestElement ( T &  element) const

Returns the element with lowest key.

The map must be created with 'tOrderedKeys == true'.

Parameters
elementResulting element
Returns
True, if the requested element exists
See also
element().

◆ operator=() [1/4]

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys>
RingMapT< TKey, T, tThreadsafe, tOrderedKeys > & Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::operator= ( const RingMapT< TKey, T, tThreadsafe, tOrderedKeys > &  ringMap)

Copy operator.

Parameters
ringMapThe ring map to be moved
Returns
Reference to this object

◆ operator=() [2/4]

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys>
template<bool tThreadSafeSecond>
RingMapT< TKey, T, tThreadsafe, tOrderedKeys > & Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::operator= ( const RingMapT< TKey, T, tThreadSafeSecond, tOrderedKeys > &  ringMap)

Copy operator.

Parameters
ringMapThe ring map to be moved
Returns
Reference to this object
Template Parameters
tThreadSafeSecondTrue, if the map to be moved is thread-safe

◆ operator=() [3/4]

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys>
RingMapT< TKey, T, tThreadsafe, tOrderedKeys > & Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::operator= ( RingMapT< TKey, T, tThreadsafe, tOrderedKeys > &&  ringMap)
noexcept

Move operator.

Parameters
ringMapThe ring map to be moved
Returns
Reference to this object

◆ operator=() [4/4]

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys>
template<bool tThreadSafeSecond>
RingMapT< TKey, T, tThreadsafe, tOrderedKeys > & Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::operator= ( RingMapT< TKey, T, tThreadSafeSecond, tOrderedKeys > &&  ringMap)
noexcept

Move operator.

Parameters
ringMapThe ring map to be moved
Returns
Reference to this object
Template Parameters
tThreadSafeSecondTrue, if the map to be moved is thread-safe

◆ refreshElement()

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys>
bool Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::refreshElement ( const TKey &  key)

Checks whether a specified element exists and changes the age of this element.

If the specified element exists, the age of the element will be changed so that the element is the newest element in the database.

Parameters
keyThe key of the element that will be refreshed
Returns
True, if the element exists

◆ setCapacity()

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys>
void Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::setCapacity ( const size_t  capacity)

Sets or changes the capacity of this storage container.

Parameters
capacityThe capacity to be set, with range [0, infinity)

◆ size()

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys>
size_t Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::size
inline

Returns the number of elements that are currently stored in this container.

Returns
Number of elements, with range [0, capacity()]

Friends And Related Function Documentation

◆ RingMapT

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys = false>
template<typename TKey2 , typename T2 , bool tThreadsafe2, bool tOrderedKeys2>
friend class RingMapT
friend

Field Documentation

◆ keyList_

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys = false>
KeyList Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::keyList_
protected

The list holding the keys in order how they have been added, oldest keys first.

◆ keyMap_

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys = false>
KeyMap Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::keyMap_
protected

The map mapping keys to value pairs.

◆ lock_

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys = false>
Lock Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::lock_
mutableprotected

The container lock.

◆ storageCapacity_

template<typename TKey , typename T , bool tThreadsafe, bool tOrderedKeys = false>
size_t Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::storageCapacity_ = 0
protected

The capacity of this storage container.


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