Ocean
Ocean::ConstTemplateArraySubsetAccessor< T, TIndex > Class Template Reference

This class implements an indexed-based constant accessor providing access to a subset of elements stored in an array. More...

Public Types

typedef T Type
 Definition of the element type of this accessor. More...
 
typedef size_t KeyType
 Definition of the key (or e.g., index) type of this accessor. More...
 
typedef TIndex IndexType
 Definition of the data type of the indices. More...
 

Public Member Functions

 ConstTemplateArraySubsetAccessor ()=default
 Creates a new empty accessor. More...
 
 ConstTemplateArraySubsetAccessor (ConstTemplateArraySubsetAccessor< T, TIndex > &&accessor) noexcept
 Move constructor. More...
 
 ConstTemplateArraySubsetAccessor (const T *elements, const TIndex *subsetIndices, const size_t subsetSize)
 Creates a new accessor object. More...
 
 ConstTemplateArraySubsetAccessor (const T *elements, const std::vector< TIndex > &subsetIndices)
 Creates a new accessor object. More...
 
 ConstTemplateArraySubsetAccessor (const std::vector< T > &elements, const std::vector< TIndex > &subsetIndices)
 Creates a new accessor object. More...
 
const T * data () const
 Returns a pointer to the elements of this accessor if the data exists within one memory block without gaps. More...
 
size_t size () const
 Returns the number of accessible elements of this accessor object. More...
 
bool isEmpty () const
 Returns whether this accessor provides no elements. More...
 
bool canAccess (const size_t &index) const
 Returns whether this accessor has a specific element. More...
 
bool firstElement (T &element, size_t &index) const
 Returns the first element of this accessor. More...
 
bool nextElement (const size_t &previousIndex, T &nextElement, size_t &nextIndex) const
 Returns the next element which follows a given key of the previous element. More...
 
const T & operator[] (const size_t &index) const
 Returns one element of this accessor object. More...
 
ConstTemplateArraySubsetAccessor< T, TIndex > & operator= (ConstTemplateArraySubsetAccessor< T, TIndex > &&accessor) noexcept
 Move operator. More...
 

Protected Attributes

const T * elements_ = nullptr
 The elements of this accessor. More...
 
const TIndex * subsetIndices_ = nullptr
 The subset indices of this accessor. More...
 
size_t subsetSize_ = 0
 The number of elements that can be accessed. More...
 

Detailed Description

template<typename T, typename TIndex>
class Ocean::ConstTemplateArraySubsetAccessor< T, TIndex >

This class implements an indexed-based constant accessor providing access to a subset of elements stored in an array.

The subset is defined by a set of indices defining also the order of the accessible elements.
An instance of this accessor does not copy the elements or the subset indices, thus the caller has to ensure that the actual elements exist as long as the instance of the accessor exists.
This class is not derived from Accessor (or any other Accessor class) to avoid virtual functions ensuring higher element-access performances.
Thus, this class will mainly be applied in template functions where the type of the accessor is defined at compile time.

Template Parameters
TThe data type of the elements of the accessor
TIndexThe data type of the indices defining the subset of elements
See also
ConstTemplateArrayAccessor.

Member Typedef Documentation

◆ IndexType

template<typename T , typename TIndex >
typedef TIndex Ocean::ConstTemplateArraySubsetAccessor< T, TIndex >::IndexType

Definition of the data type of the indices.

◆ KeyType

template<typename T , typename TIndex >
typedef size_t Ocean::ConstTemplateArraySubsetAccessor< T, TIndex >::KeyType

Definition of the key (or e.g., index) type of this accessor.

◆ Type

template<typename T , typename TIndex >
typedef T Ocean::ConstTemplateArraySubsetAccessor< T, TIndex >::Type

Definition of the element type of this accessor.

Constructor & Destructor Documentation

◆ ConstTemplateArraySubsetAccessor() [1/5]

template<typename T , typename TIndex >
Ocean::ConstTemplateArraySubsetAccessor< T, TIndex >::ConstTemplateArraySubsetAccessor ( )
default

Creates a new empty accessor.

◆ ConstTemplateArraySubsetAccessor() [2/5]

template<typename T , typename TIndex >
Ocean::ConstTemplateArraySubsetAccessor< T, TIndex >::ConstTemplateArraySubsetAccessor ( ConstTemplateArraySubsetAccessor< T, TIndex > &&  accessor)
inlinenoexcept

Move constructor.

Parameters
accessorAccessor to be moved

◆ ConstTemplateArraySubsetAccessor() [3/5]

template<typename T , typename TIndex >
Ocean::ConstTemplateArraySubsetAccessor< T, TIndex >::ConstTemplateArraySubsetAccessor ( const T *  elements,
const TIndex *  subsetIndices,
const size_t  subsetSize 
)
inline

Creates a new accessor object.

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

Parameters
elementsThe elements that can be accessed, may be nullptr if size is equal 0
subsetIndicesThe indices that define a subset of the elements to be accessed, the maximal index must be smaller than the number of given elements
subsetSizeThe number of indices (not the number of elements) that define the subset, may be 0 if indices is nullptr

◆ ConstTemplateArraySubsetAccessor() [4/5]

template<typename T , typename TIndex >
Ocean::ConstTemplateArraySubsetAccessor< T, TIndex >::ConstTemplateArraySubsetAccessor ( const T *  elements,
const std::vector< TIndex > &  subsetIndices 
)
inline

Creates a new accessor object.

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

Parameters
elementsThe elements that can be accessed, may be nullptr if size is equal 0
subsetIndicesThe indices that define a subset of the elements to be accessed, the maximal index must be smaller than the number of given elements

◆ ConstTemplateArraySubsetAccessor() [5/5]

template<typename T , typename TIndex >
Ocean::ConstTemplateArraySubsetAccessor< T, TIndex >::ConstTemplateArraySubsetAccessor ( const std::vector< T > &  elements,
const std::vector< TIndex > &  subsetIndices 
)
inline

Creates a new accessor object.

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

Parameters
elementsThe elements that can be accessed, may be nullptr if size is equal 0
subsetIndicesThe indices that define a subset of the elements to be accessed, the maximal index must be smaller than the number of given elements

Member Function Documentation

◆ canAccess()

template<typename T , typename TIndex >
bool Ocean::ConstTemplateArraySubsetAccessor< T, TIndex >::canAccess ( const size_t &  index) const
inline

Returns whether this accessor has a specific element.

See also
ConstAccessor::canAccess().

◆ data()

template<typename T , typename TIndex >
const T * Ocean::ConstTemplateArraySubsetAccessor< T, TIndex >::data
inline

Returns a pointer to the elements of this accessor if the data exists within one memory block without gaps.

See also
ConstAccessor::data().

◆ firstElement()

template<typename T , typename TIndex >
bool Ocean::ConstTemplateArraySubsetAccessor< T, TIndex >::firstElement ( T &  element,
size_t &  index 
) const
inline

Returns the first element of this accessor.

See also
ConstAccessor:firstElement().

◆ isEmpty()

template<typename T , typename TIndex >
bool Ocean::ConstTemplateArraySubsetAccessor< T, TIndex >::isEmpty
inline

Returns whether this accessor provides no elements.

Returns
True, if so

◆ nextElement()

template<typename T , typename TIndex >
bool Ocean::ConstTemplateArraySubsetAccessor< T, TIndex >::nextElement ( const size_t &  previousIndex,
T &  nextElement,
size_t &  nextIndex 
) const
inline

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

See also
ConstAccessor::nextElement().

◆ operator=()

template<typename T , typename TIndex >
ConstTemplateArraySubsetAccessor< T, TIndex > & Ocean::ConstTemplateArraySubsetAccessor< T, TIndex >::operator= ( ConstTemplateArraySubsetAccessor< T, TIndex > &&  accessor)
inlinenoexcept

Move operator.

Parameters
accessorAccessor to be moved
Returns
Reference to this object

◆ operator[]()

template<typename T , typename TIndex >
const T & Ocean::ConstTemplateArraySubsetAccessor< T, TIndex >::operator[] ( const size_t &  index) const
inline

Returns one element of this accessor object.

See also
ConstAccessor::operator[].

◆ size()

template<typename T , typename TIndex >
size_t Ocean::ConstTemplateArraySubsetAccessor< T, TIndex >::size
inline

Returns the number of accessible elements of this accessor object.

See also
ConstAccessor::size().

Field Documentation

◆ elements_

template<typename T , typename TIndex >
const T* Ocean::ConstTemplateArraySubsetAccessor< T, TIndex >::elements_ = nullptr
protected

The elements of this accessor.

◆ subsetIndices_

template<typename T , typename TIndex >
const TIndex* Ocean::ConstTemplateArraySubsetAccessor< T, TIndex >::subsetIndices_ = nullptr
protected

The subset indices of this accessor.

◆ subsetSize_

template<typename T , typename TIndex >
size_t Ocean::ConstTemplateArraySubsetAccessor< T, TIndex >::subsetSize_ = 0
protected

The number of elements that can be accessed.


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