mod_servlet
C++Servlets
 All Classes Files Functions Variables Typedefs Macros Pages
servlet::linked_map< _Key, _Tp, _MT > Class Template Reference

Implementation of linked associative container. More...

#include <linked_map.h>

Inheritance diagram for servlet::linked_map< _Key, _Tp, _MT >:
servlet::lru_map< _Key, _Tp, _MT >

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_typelist_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_typereference
 value_type&
 
typedef const value_typeconst_reference
 const value_type&
 
typedef value_typepointer
 Pointer to value_type type.
 
typedef const value_typeconst_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_mapoperator= (const linked_map &m)=default
 The copy assignment. More...
 
linked_mapoperator= (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_typeget (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_typeget (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...
 

Detailed Description

template<typename _Key, typename _Tp, typename _MT>
class servlet::linked_map< _Key, _Tp, _MT >

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 (

See Also
timed_lru_map). To facilitate the implementations there are two protected methods:
  1. update - is called on every access to the element.
  2. purge - is called on every modification of the container.

It can be created with either std::map or std::unordered_map as the underlying map (3rd template parameter).

Template Parameters
_Keytype of the key
_Tptype of the mapped value
_MTtype of the base map for this class to inherit from. Currently it can be either std::map or std::unordered_map
See Also
timed_lru_map

Member Typedef Documentation

template<typename _Key , typename _Tp , typename _MT >
typedef linked_map<_Key, _Tp, _MT> servlet::linked_map< _Key, _Tp, _MT >::self_type

The type of this container.

Defined to brievity.

Constructor & Destructor Documentation

template<typename _Key , typename _Tp , typename _MT >
servlet::linked_map< _Key, _Tp, _MT >::linked_map ( const linked_map< _Key, _Tp, _MT > &  m)
default

Copy constructor.

Constructs a container with a copy of each of the elements in m.

Parameters
mlinked map object to copy from.
template<typename _Key , typename _Tp , typename _MT >
servlet::linked_map< _Key, _Tp, _MT >::linked_map ( linked_map< _Key, _Tp, _MT > &&  m)
default

Move constructor.

Constructs a container that acquires the elements of m by moving them.

Parameters
mlinked map object to move from.

Member Function Documentation

template<typename _Key , typename _Tp , typename _MT >
iterator servlet::linked_map< _Key, _Tp, _MT >::begin ( )
inlinenoexcept

Returns iterator to beginning of the container.

Returns an iterator referring to the least recently used element of the container

Returns
An iterator to the least recently used element of the container.
template<typename _Key , typename _Tp , typename _MT >
const_iterator servlet::linked_map< _Key, _Tp, _MT >::begin ( ) const
inlinenoexcept

Returns constant iterator to beginning of the container.

Returns a constant iterator referring to the least recently used element of the container

Returns
An const_iterator to the least recently used element of the container.
template<typename _Key , typename _Tp , typename _MT >
const_iterator servlet::linked_map< _Key, _Tp, _MT >::cbegin ( ) const
inlinenoexcept

Returns constant iterator to beginning of the container.

Returns a constant iterator referring to the least recently used element of the container

Returns
An const_iterator to the least recently used element of the container.
template<typename _Key , typename _Tp , typename _MT >
const_iterator servlet::linked_map< _Key, _Tp, _MT >::cend ( ) const
inlinenoexcept

Return constant iterator to end of the container.

Returns a constant iterator referring to the past-the-end element in the container

Returns
An const_iterator to the past-the-end element in the container.
template<typename _Key , typename _Tp , typename _MT >
void servlet::linked_map< _Key, _Tp, _MT >::clear ( )
inline

Clear content.

Removes all elements from the container (which are destroyed), leaving the container with a size of 0

template<typename _Key , typename _Tp , typename _MT >
template<typename KeyType >
bool servlet::linked_map< _Key, _Tp, _MT >::contains_key ( const KeyType &  key) const
inline

Tests whether value with a given key exists in this container.

Template Parameters
KeyTypea type comparable to type of this map's key (via std::less<>
Parameters
keyKey to test.
Returns
true if a value with a given key exists in this container, false otherwise.
template<typename _Key , typename _Tp , typename _MT >
const_reverse_iterator servlet::linked_map< _Key, _Tp, _MT >::crbegin ( ) const
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.

Returns
A const_reverse_iterator to the reverse beginning of the sequence container
template<typename _Key , typename _Tp , typename _MT >
const_reverse_iterator servlet::linked_map< _Key, _Tp, _MT >::crend ( ) const
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)

Returns
A const_reverse_iterator to the reverse end of the sequence container.
template<typename _Key , typename _Tp , typename _MT >
bool servlet::linked_map< _Key, _Tp, _MT >::empty ( ) const
inlinenoexcept

Test whether container is empty.

Returns
true if the container size is 0, false otherwise.
template<typename _Key , typename _Tp , typename _MT >
iterator servlet::linked_map< _Key, _Tp, _MT >::end ( )
inlinenoexcept

Return iterator to end of the container.

Returns an iterator referring to the past-the-end element in the container

Returns
An iterator to the past-the-end element in the container.
template<typename _Key , typename _Tp , typename _MT >
const_iterator servlet::linked_map< _Key, _Tp, _MT >::end ( ) const
inlinenoexcept

Return constant iterator to end of the container.

Returns a constant iterator referring to the past-the-end element in the container

Returns
An const_iterator to the past-the-end element in the container.
template<typename _Key , typename _Tp , typename _MT >
template<typename KeyType >
bool servlet::linked_map< _Key, _Tp, _MT >::erase ( const KeyType &  key)
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.

Template Parameters
KeyTypea type comparable to type of this map's key (via std::less<>
Parameters
keyKey of the element to remove.
Returns
true if the element was actually removed, false otherwise.
template<typename _Key , typename _Tp , typename _MT >
template<typename KeyType >
optional_ref<const mapped_type> servlet::linked_map< _Key, _Tp, _MT >::get ( const KeyType &  key) const
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.

Template Parameters
KeyTypea type comparable to type of this map's key (via std::less<>
Parameters
keyKey to be searched for.
Returns
optional_ref to the found value, or empty reference if a value with a given key doesn't exists in this container.
Exceptions
std::bad_any_castif the value is found, but couldn't be casted to the requested type
template<typename _Key , typename _Tp , typename _MT >
template<typename KeyType >
optional_ref<mapped_type> servlet::linked_map< _Key, _Tp, _MT >::get ( const KeyType &  key)
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.

Template Parameters
KeyTypea type comparable to type of this map's key (via std::less<>
Parameters
keyKey to be searched for.
Returns
optional_ref to the found value, or empty reference if a value with a given key doesn't exists in this container.
Exceptions
std::bad_any_castif the value is found, but couldn't be casted to the requested type
template<typename _Key , typename _Tp , typename _MT >
linked_map& servlet::linked_map< _Key, _Tp, _MT >::operator= ( const linked_map< _Key, _Tp, _MT > &  m)
default

The copy assignment.

Copies all the elements from m into the container (with m preserving its contents)

Parameters
mMap object to copy from.
Returns
reference to self
template<typename _Key , typename _Tp , typename _MT >
linked_map& servlet::linked_map< _Key, _Tp, _MT >::operator= ( linked_map< _Key, _Tp, _MT > &&  m)
default

The move assignment.

Moves the elements of m into the container (m is left in an unspecified but valid state).

Parameters
mMap object to move from.
Returns
reference to self
template<typename _Key , typename _Tp , typename _MT >
virtual void servlet::linked_map< _Key, _Tp, _MT >::purge ( )
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 >.

template<typename _Key , typename _Tp , typename _MT >
template<class... Args>
bool servlet::linked_map< _Key, _Tp, _MT >::put ( key_type &&  key,
Args &&...  args 
)
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.

Template Parameters
Argstypes of the arguments to be forwarded to new mapped value constructor.
Parameters
keykey with which the specified value is to be associated
argsarguments to create the mapped value
Returns
bool denoting whether the previous value was replaced.
See Also
try_put
template<typename _Key , typename _Tp , typename _MT >
template<class... Args>
bool servlet::linked_map< _Key, _Tp, _MT >::put ( const key_type key,
Args &&...  args 
)
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.

Template Parameters
Argstypes of the arguments to be forwarded to new mapped value constructor.
Parameters
keykey with which the specified value is to be associated
argsargument to create the mapped value
Returns
bool denoting whether the previous value was replaced.
See Also
try_put
template<typename _Key , typename _Tp , typename _MT >
reverse_iterator servlet::linked_map< _Key, _Tp, _MT >::rbegin ( )
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.

Returns
A reverse_iterator to the reverse beginning of the sequence container
template<typename _Key , typename _Tp , typename _MT >
const_reverse_iterator servlet::linked_map< _Key, _Tp, _MT >::rbegin ( ) const
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.

Returns
A const_reverse_iterator to the reverse beginning of the sequence container
template<typename _Key , typename _Tp , typename _MT >
reverse_iterator servlet::linked_map< _Key, _Tp, _MT >::rend ( )
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)

Returns
A reverse_iterator to the reverse end of the sequence container.
template<typename _Key , typename _Tp , typename _MT >
const_reverse_iterator servlet::linked_map< _Key, _Tp, _MT >::rend ( ) const
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)

Returns
A const_reverse_iterator to the reverse end of the sequence container.
template<typename _Key , typename _Tp , typename _MT >
size_type servlet::linked_map< _Key, _Tp, _MT >::size ( ) const
inlinenoexcept

Returns the number of elements in the container.

Returns
The number of elements in the container.
template<typename _Key , typename _Tp , typename _MT >
template<class... Args>
bool servlet::linked_map< _Key, _Tp, _MT >::try_put ( key_type &&  key,
Args &&...  args 
)
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.

Template Parameters
Argstypes of the arguments to be forwarded to new mapped value constructor.
Parameters
keykey with which the specified value is to be associated
argsargument to create the mapped value
Returns
bool denoting whether insertion took place.
See Also
put
template<typename _Key , typename _Tp , typename _MT >
template<class... Args>
bool servlet::linked_map< _Key, _Tp, _MT >::try_put ( const key_type key,
Args &&...  args 
)
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.

Template Parameters
Argstypes of the arguments to be forwarded to new mapped value constructor.
Parameters
keykey with which the specified value is to be associated
argsargument to create the mapped value
Returns
bool denoting whether insertion took place.
See Also
put
template<typename _Key , typename _Tp , typename _MT >
virtual void servlet::linked_map< _Key, _Tp, _MT >::update ( value_type val) const
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.

Parameters
valReference to the accessed element.

Reimplemented in servlet::lru_map< _Key, _Tp, _MT >.


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