Ocean
|
This class implements a data storage map that stores the data elements in a ring manner. More...
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, ValuePair > | KeyMap |
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 |
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.
TKey | Data type of the map keys |
T | Data type of the map elements |
tThreadsafe | True, to create a thread-safe object |
tOrderedKeys | True, to allow accessing the keys in order; False, if the order of the keys is not of interest |
|
protected |
Definition of a double-linked list holding the keys in order how they have been inserted.
|
protected |
Definition of a map that maps keys to value pairs.
typedef T Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::Type |
The data type of the objects that are stored in this container.
typedef TKey Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::TypeKey |
The data type of the keys that are used to address the data objects.
|
protected |
Definition of a pair combining a value with a list iterator.
enum Ocean::RingMapT::AccessMode : uint32_t |
Definition of individual element access modes.
|
default |
Creates a new ring storage object with no capacity.
|
inlinenoexcept |
Move constructor.
ringMap | Object to be moved |
|
inline |
Copy constructor.
ringMap | Object to be copied |
|
inlineexplicit |
Creates a new ring storage object with a specified capacity.
capacity | The capacity of the storage container, with range [0, infinity) |
|
inline |
Returns the capacity of this storage container.
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.
key | The key of the element to be returned |
element | Resulting element |
tAccessMode | The access mode to be used |
void Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::clear |
Clears all elements of this storage container.
bool Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::element | ( | const TKey & | key, |
T & | element | ||
) | const |
Returns an element of this storage container.
key | The key of the element to be returned |
element | Resulting element |
tAccessMode | The access mode to be used |
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.
bool Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::hasElement | ( | const TKey & | key | ) | const |
Returns whether this storage container holds a specific element.
key | The key of the element that is checked |
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'.
element | Resulting element |
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.
key | The key of the new element |
element | The element that will be inserted |
forceOverwrite | True, to overwrite an existing element with some key, False to avoid that an element is inserted if an element with same key exists already |
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.
key | The key of the new element |
element | The element that will be inserted |
forceOverwrite | True, to overwrite an existing element with some key, False to avoid that an element is inserted if an element with same key exists already |
|
inline |
Returns whether this ring map holds at least one element.
|
inlineprotected |
Returns whether the internal states of this storage container is valid.
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'.
element | Resulting element |
RingMapT< TKey, T, tThreadsafe, tOrderedKeys > & Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::operator= | ( | const RingMapT< TKey, T, tThreadsafe, tOrderedKeys > & | ringMap | ) |
Copy operator.
ringMap | The ring map to be moved |
RingMapT< TKey, T, tThreadsafe, tOrderedKeys > & Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::operator= | ( | const RingMapT< TKey, T, tThreadSafeSecond, tOrderedKeys > & | ringMap | ) |
Copy operator.
ringMap | The ring map to be moved |
tThreadSafeSecond | True, if the map to be moved is thread-safe |
|
noexcept |
Move operator.
ringMap | The ring map to be moved |
|
noexcept |
Move operator.
ringMap | The ring map to be moved |
tThreadSafeSecond | True, if the map to be moved is thread-safe |
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.
key | The key of the element that will be refreshed |
void Ocean::RingMapT< TKey, T, tThreadsafe, tOrderedKeys >::setCapacity | ( | const size_t | capacity | ) |
Sets or changes the capacity of this storage container.
capacity | The capacity to be set, with range [0, infinity) |
|
inline |
Returns the number of elements that are currently stored in this container.
|
friend |
|
protected |
The list holding the keys in order how they have been added, oldest keys first.
|
protected |
The map mapping keys to value pairs.
|
mutableprotected |
The container lock.
|
protected |
The capacity of this storage container.