mod_servlet
C++Servlets
|
Implementation of linked associative container. More...
#include <linked_map.h>
Public Types | |
typedef _Key | key_type |
Container's key type. | |
typedef _Tp | mapped_type |
Container's mapped type. | |
typedef std::pair< const _Key &, _Tp > | value_type |
Container's value type: std::pair<const key_type&, mapped_type> | |
typedef linked_map< _Key, _Tp, _MT > | self_type |
The type of this container. More... | |
typedef std::list< value_type > | list_type |
List type to maintain the order of elements. | |
typedef _MT | map_type |
Underlying map type. | |
typedef map_type::allocator_type | allocator_type |
Container's allocator type. | |
typedef value_type & | reference |
value_type& | |
typedef const value_type & | const_reference |
const value_type& | |
typedef value_type * | pointer |
Pointer to value_type type. | |
typedef const value_type * | const_pointer |
Constant pointer to value_type type. | |
typedef map_type::size_type | size_type |
An unsigned integral type to represent the size of this container. | |
typedef map_type::difference_type | difference_type |
A signed integral type to represent distance between iterators. | |
typedef list_type::iterator | iterator |
Bidirectional iterator type. | |
typedef list_type::const_iterator | const_iterator |
Bidirectional constant iterator type. | |
typedef list_type::reverse_iterator | reverse_iterator |
Reverse iterator type. | |
typedef list_type::const_reverse_iterator | const_reverse_iterator |
Constant reverse iterator type. | |
Public Member Functions | |
linked_map ()=default | |
Constructs an empty container, with no elements. | |
linked_map (const linked_map &m)=default | |
Copy constructor. More... | |
linked_map (linked_map &&m)=default | |
Move constructor. More... | |
linked_map & | operator= (const linked_map &m)=default |
The copy assignment. More... | |
linked_map & | operator= (linked_map &&m)=default |
The move assignment. More... | |
bool | empty () const noexcept |
Test whether container is empty. More... | |
size_type | size () const noexcept |
Returns the number of elements in the container. More... | |
template<typename KeyType > | |
bool | contains_key (const KeyType &key) const |
Tests whether value with a given key exists in this container. More... | |
void | clear () |
Clear content. More... | |
template<typename KeyType > | |
optional_ref< const mapped_type > | get (const KeyType &key) const |
Returns optional_ref object to a value with a specified type, if that value exists and can be casted to the requested type. More... | |
template<typename KeyType > | |
optional_ref< mapped_type > | get (const KeyType &key) |
Returns optional_ref object to a value with a specified type, if that value exists and can be casted to the requested type. More... | |
template<class... Args> | |
bool | put (key_type &&key, Args &&...args) |
Associates a value of specified type created with a given arguments with the specified key in this map. More... | |
template<class... Args> | |
bool | put (const key_type &key, Args &&...args) |
Associates a value of specified type created with a given arguments with the specified key in this map. More... | |
template<class... Args> | |
bool | try_put (key_type &&key, Args &&...args) |
Associates a value of specified type created with a given arguments with the specified key in this map. More... | |
template<class... Args> | |
bool | try_put (const key_type &key, Args &&...args) |
Associates a value of specified type created with a given arguments with the specified key in this map. More... | |
template<typename KeyType > | |
bool | erase (const KeyType &key) |
Erase element. More... | |
iterator | begin () noexcept |
Returns iterator to beginning of the container. More... | |
iterator | end () noexcept |
Return iterator to end of the container. More... | |
const_iterator | begin () const noexcept |
Returns constant iterator to beginning of the container. More... | |
const_iterator | end () const noexcept |
Return constant iterator to end of the container. More... | |
const_iterator | cbegin () const noexcept |
Returns constant iterator to beginning of the container. More... | |
const_iterator | cend () const noexcept |
Return constant iterator to end of the container. More... | |
reverse_iterator | rbegin () noexcept |
Return reverse iterator to reverse beginning. More... | |
reverse_iterator | rend () noexcept |
Return reverse iterator to reverse end. More... | |
const_reverse_iterator | rbegin () const noexcept |
Return constant reverse iterator to reverse beginning. More... | |
const_reverse_iterator | rend () const noexcept |
Return constant reverse iterator to reverse end. More... | |
const_reverse_iterator | crbegin () const noexcept |
Return constant reverse iterator to reverse beginning. More... | |
const_reverse_iterator | crend () const noexcept |
Return constant reverse iterator to reverse end. More... | |
Protected Member Functions | |
virtual void | update (value_type &val) const |
Updates element on access. More... | |
virtual void | purge () |
Removes elements which do not confirm to the storage criteria from the container. More... | |
Implementation of linked associative container.
This class maintains the order of elements access and when iterated it iterates the elements in the same order as they were accessed (least recently accessed first).
This class can be used as a base class for various LRU container implementations (
It can be created with either std::map
or std::unordered_map
as the underlying map (3rd template parameter).
_Key | type of the key |
_Tp | type of the mapped value |
_MT | type of the base map for this class to inherit from. Currently it can be either std::map or std::unordered_map |
typedef linked_map<_Key, _Tp, _MT> servlet::linked_map< _Key, _Tp, _MT >::self_type |
The type of this container.
Defined to brievity.
|
default |
Copy constructor.
Constructs a container with a copy of each of the elements in m
.
m | linked map object to copy from. |
|
default |
Move constructor.
Constructs a container that acquires the elements of m
by moving them.
m | linked map object to move from. |
|
inlinenoexcept |
Returns iterator to beginning of the container.
Returns an iterator referring to the least recently used element of the container
|
inlinenoexcept |
Returns constant iterator to beginning of the container.
Returns a constant iterator referring to the least recently used element of the container
|
inlinenoexcept |
Returns constant iterator to beginning of the container.
Returns a constant iterator referring to the least recently used element of the container
|
inlinenoexcept |
Return constant iterator to end of the container.
Returns a constant iterator referring to the past-the-end element in the container
|
inline |
Clear content.
Removes all elements from the container (which are destroyed), leaving the container with a size of 0
|
inline |
Tests whether value with a given key exists in this container.
KeyType | a type comparable to type of this map's key (via std::less<> |
key | Key to test. |
true
if a value with a given key exists in this container, false
otherwise.
|
inlinenoexcept |
Return constant reverse iterator to reverse beginning.
Returns a constant reverse iterator pointing to the last element in the container (i.e., its reverse beginning). For this container it will be the most recently used element.
|
inlinenoexcept |
Return constant reverse iterator to reverse end.
Returns a constant reverse iterator pointing to the theoretical element right before the first element in the map container (which is considered its reverse end)
|
inlinenoexcept |
Test whether container is empty.
true
if the container size is 0
, false
otherwise.
|
inlinenoexcept |
Return iterator to end of the container.
Returns an iterator referring to the past-the-end element in the container
|
inlinenoexcept |
Return constant iterator to end of the container.
Returns a constant iterator referring to the past-the-end element in the container
|
inline |
Erase element.
Removes from the container a single element identified by a given key. Does nothing if the element with a given key is not found.
KeyType | a type comparable to type of this map's key (via std::less<> |
key | Key of the element to remove. |
true
if the element was actually removed, false
otherwise.
|
inline |
Returns optional_ref
object to a value with a specified type, if that value exists and can be casted to the requested type.
If the value with a given key doesn't exists empty optional_ref will be returned.
KeyType | a type comparable to type of this map's key (via std::less<> |
key | Key to be searched for. |
optional_ref
to the found value, or empty reference if a value with a given key doesn't exists in this container. std::bad_any_cast | if the value is found, but couldn't be casted to the requested type |
|
inline |
Returns optional_ref
object to a value with a specified type, if that value exists and can be casted to the requested type.
If the value with a given key doesn't exists empty optional_ref will be returned.
KeyType | a type comparable to type of this map's key (via std::less<> |
key | Key to be searched for. |
optional_ref
to the found value, or empty reference if a value with a given key doesn't exists in this container. std::bad_any_cast | if the value is found, but couldn't be casted to the requested type |
|
default |
The copy assignment.
Copies all the elements from m
into the container (with m
preserving its contents)
m | Map object to copy from. |
|
default |
The move assignment.
Moves the elements of m
into the container (m
is left in an unspecified but valid state).
m | Map object to move from. |
|
inlineprotectedvirtual |
Removes elements which do not confirm to the storage criteria from the container.
This method is called for each container modification by put or erase method and by default does nothing. If the particular implementation needs to remove certain elements from the container (e.q. if timestamp expired) it can do so.
Reimplemented in servlet::lru_map< _Key, _Tp, _MT >.
|
inline |
Associates a value of specified type created with a given arguments with the specified key in this map.
If the map previously contained a mapping for the key, the old value is replaced.
Args | types of the arguments to be forwarded to new mapped value constructor. |
key | key with which the specified value is to be associated |
args | arguments to create the mapped value |
bool
denoting whether the previous value was replaced.
|
inline |
Associates a value of specified type created with a given arguments with the specified key in this map.
If the map previously contained a mapping for the key, the old value is replaced.
Args | types of the arguments to be forwarded to new mapped value constructor. |
key | key with which the specified value is to be associated |
args | argument to create the mapped value |
bool
denoting whether the previous value was replaced.
|
inlinenoexcept |
Return reverse iterator to reverse beginning.
Returns a reverse iterator pointing to the last element in the container (i.e., its reverse beginning). For this container it will be the most recently used element.
|
inlinenoexcept |
Return constant reverse iterator to reverse beginning.
Returns a constant reverse iterator pointing to the last element in the container (i.e., its reverse beginning). For this container it will be the most recently used element.
|
inlinenoexcept |
Return reverse iterator to reverse end.
Returns a reverse iterator pointing to the theoretical element right before the first element in the map container (which is considered its reverse end)
|
inlinenoexcept |
Return constant reverse iterator to reverse end.
Returns a constant reverse iterator pointing to the theoretical element right before the first element in the map container (which is considered its reverse end)
|
inlinenoexcept |
Returns the number of elements in the container.
|
inline |
Associates a value of specified type created with a given arguments with the specified key in this map.
If the map previously contained a mapping for the key, does nothing.
Args | types of the arguments to be forwarded to new mapped value constructor. |
key | key with which the specified value is to be associated |
args | argument to create the mapped value |
bool
denoting whether insertion took place.
|
inline |
Associates a value of specified type created with a given arguments with the specified key in this map.
If the map previously contained a mapping for the key, does nothing.
Args | types of the arguments to be forwarded to new mapped value constructor. |
key | key with which the specified value is to be associated |
args | argument to create the mapped value |
bool
denoting whether insertion took place.
|
inlineprotectedvirtual |
Updates element on access.
This method is called for each element accessed by get method and by default does nothing. If the particular implementation needs to do any modifications to the accessed element (e.q. update timestamp) it can do so.
val | Reference to the accessed element. |
Reimplemented in servlet::lru_map< _Key, _Tp, _MT >.