Ocean
Ocean::ConstMapAccessor< T, TKey > Class Template Reference

This class implements an accessor providing direct access to a constant (unordered) map of elements. More...

Inheritance diagram for Ocean::ConstMapAccessor< T, TKey >:

Public Member Functions

 ConstMapAccessor ()=default
 Creates a new empty accessor. More...
 
 ConstMapAccessor (ConstMapAccessor< T, TKey > &&accessor) noexcept
 Move constructor. More...
 
 ConstMapAccessor (const std::unordered_map< TKey, T > &elements)
 Creates a new accessor object. More...
 
virtual size_t size () const
 Returns the number of accessible elements of this accessor object. More...
 
virtual bool canAccess (const TKey &key) const
 Returns whether this accessor has a specific element. More...
 
virtual bool firstElement (T &element, TKey &key) const
 Returns the first element of this accessor. More...
 
virtual bool nextElement (const TKey &previousKey, T &nextElement, TKey &nextKey) const
 Returns the next element which follows a given key of the previous element. More...
 
virtual const T & operator[] (const TKey &key) const
 Returns one element of this accessor object. More...
 
ConstMapAccessor< T, TKey > & operator= (ConstMapAccessor< T, TKey > &&accessor) noexcept
 Move operator. More...
 
- Public Member Functions inherited from Ocean::ConstAccessor< T, TKey >
virtual const T * data () const
 Returns a pointer to the elements of this accessor if the data exists within one memory block without gaps. More...
 
- Public Member Functions inherited from Ocean::Accessor
virtual ~Accessor ()=default
 Default destructor. More...
 
bool isEmpty () const
 Returns whether this accessor provides no elements. More...
 

Protected Attributes

const std::unordered_map< TKey, T > * elementMap_ = nullptr
 The elements of this accessor. More...
 

Additional Inherited Members

- Public Types inherited from Ocean::ConstAccessor< T, TKey >
typedef T Type
 Definition of the element type of this accessor. More...
 
typedef TKey KeyType
 Definition of the key (or e.g., index) type of this accessor. More...
 
- Static Public Member Functions inherited from Ocean::Accessor
template<typename TAccessor >
static std::vector< typename TAccessor::Type > accessor2elements (const TAccessor &accessor)
 Returns all elements of a given accessor (as a block). More...
 
template<typename TAccessor >
static std::unordered_map< typename TAccessor::KeyType, typename TAccessor::Type > accessor2map (const TAccessor &accessor)
 Returns all elements of a given accessor as a map with key and elements. More...
 
template<typename TAccessor , typename TIndex >
static std::vector< typename TAccessor::Type > accessor2subsetElements (const TAccessor &accessor, const std::vector< TIndex > &subset)
 Returns a subset of all elements of a given accessor (as a block). More...
 
- Protected Member Functions inherited from Ocean::ConstAccessor< T, TKey >
 ConstAccessor ()=default
 Protected default constructor. More...
 
- Protected Member Functions inherited from Ocean::Accessor
 Accessor ()=default
 Protected default constructor. More...
 
 Accessor (const Accessor &accessor)=default
 Protected copy constructor. More...
 
Accessoroperator= (const Accessor &accessor)=delete
 Deleted assign operator. More...
 

Detailed Description

template<typename T, typename TKey>
class Ocean::ConstMapAccessor< T, TKey >

This class implements an accessor providing direct access to a constant (unordered) map of elements.

An instance of this accessor does not copy the elements, thus the caller has to ensure that the actual elements exist as long as the instance of the accessor exists.

Template Parameters
TThe data type of the elements of the accessor
TKeyThe data type of the keys of the accessor

Constructor & Destructor Documentation

◆ ConstMapAccessor() [1/3]

template<typename T , typename TKey >
Ocean::ConstMapAccessor< T, TKey >::ConstMapAccessor ( )
default

Creates a new empty accessor.

◆ ConstMapAccessor() [2/3]

template<typename T , typename TKey >
Ocean::ConstMapAccessor< T, TKey >::ConstMapAccessor ( ConstMapAccessor< T, TKey > &&  accessor)
inlinenoexcept

Move constructor.

Parameters
accessorAccessor to be moved

◆ ConstMapAccessor() [3/3]

template<typename T , typename TKey >
Ocean::ConstMapAccessor< T, TKey >::ConstMapAccessor ( const std::unordered_map< TKey, T > &  elements)
inlineexplicit

Creates a new accessor object.

Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.

Parameters
elementsA map holding all elements

Member Function Documentation

◆ canAccess()

template<typename T , typename TKey >
bool Ocean::ConstMapAccessor< T, TKey >::canAccess ( const TKey &  key) const
virtual

Returns whether this accessor has a specific element.

See also
ConstAccessor::canAccess().

Implements Ocean::ConstAccessor< T, TKey >.

◆ firstElement()

template<typename T , typename TKey >
bool Ocean::ConstMapAccessor< T, TKey >::firstElement ( T &  element,
TKey &  key 
) const
virtual

Returns the first element of this accessor.

See also
ConstAccessor::firstElement().

Implements Ocean::ConstAccessor< T, TKey >.

◆ nextElement()

template<typename T , typename TKey >
bool Ocean::ConstMapAccessor< T, TKey >::nextElement ( const TKey &  previousKey,
T &  nextElement,
TKey &  nextKey 
) const
virtual

Returns the next element which follows a given key of the previous element.

See also
ConstAccessor::nextElement().

Implements Ocean::ConstAccessor< T, TKey >.

◆ operator=()

template<typename T , typename TKey >
ConstMapAccessor< T, TKey > & Ocean::ConstMapAccessor< T, TKey >::operator= ( ConstMapAccessor< T, TKey > &&  accessor)
inlinenoexcept

Move operator.

Parameters
accessorAccessor to be moved
Returns
Reference to this accessor

◆ operator[]()

template<typename T , typename TKey >
const T & Ocean::ConstMapAccessor< T, TKey >::operator[] ( const TKey &  key) const
virtual

Returns one element of this accessor object.

See also
ConstAccessor::operator[].

Implements Ocean::ConstAccessor< T, TKey >.

◆ size()

template<typename T , typename TKey >
size_t Ocean::ConstMapAccessor< T, TKey >::size
virtual

Returns the number of accessible elements of this accessor object.

See also
ConstAccessor::size().

Implements Ocean::Accessor.

Field Documentation

◆ elementMap_

template<typename T , typename TKey >
const std::unordered_map<TKey, T>* Ocean::ConstMapAccessor< T, TKey >::elementMap_ = nullptr
protected

The elements of this accessor.


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