Ocean
Ocean::ConstTemplateArrayAccessor< T > Class Template Reference

This class implements an accessor providing direct access to a constant array of elements. 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...
 

Public Member Functions

 ConstTemplateArrayAccessor ()=default
 Creates a new empty accessor. More...
 
 ConstTemplateArrayAccessor (ConstTemplateArrayAccessor< T > &&accessor) noexcept
 Move constructor. More...
 
 ConstTemplateArrayAccessor (const T *elements, const size_t size)
 Creates a new accessor object. More...
 
 ConstTemplateArrayAccessor (const std::vector< T > &elements)
 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...
 
ConstTemplateArrayAccessor< T > & operator= (ConstArrayAccessor< T > &&accessor) noexcept
 Move operator. More...
 

Protected Attributes

const T * elements_ = nullptr
 The elements of this accessor. More...
 
size_t size_ = 0
 The number of elements that can be accessed. More...
 

Detailed Description

template<typename T>
class Ocean::ConstTemplateArrayAccessor< T >

This class implements an accessor providing direct access to a constant array 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.
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.

The application of the this class is demonstrated in the following code example (compare the code example for ConstArrayAccessor):

// the parameter type is a template type allowing for fast but not flexible application of this function
template <typename TAccessor>
void iterate(const TAccessor& accessor)
{
for (size_t n = 0; n < accessor.size(); ++n)
{
// access the object by application of the !inlined! index operator
const Object& object = accessor[n];
// ... do something with the object ...
}
}
void main()
{
std::vector<Object> objects;
// ... add some objects ...
// iterate over all objects
iterate(ConstTemplateArrayAccessor<Object>(objects));
}
Template Parameters
TThe data type of the elements of the accessor
See also
ConstArrayAccessor, NonconstTemplateArrayAccessor.

Member Typedef Documentation

◆ KeyType

template<typename T >
typedef size_t Ocean::ConstTemplateArrayAccessor< T >::KeyType

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

◆ Type

template<typename T >
typedef T Ocean::ConstTemplateArrayAccessor< T >::Type

Definition of the element type of this accessor.

Constructor & Destructor Documentation

◆ ConstTemplateArrayAccessor() [1/4]

template<typename T >
Ocean::ConstTemplateArrayAccessor< T >::ConstTemplateArrayAccessor ( )
default

Creates a new empty accessor.

◆ ConstTemplateArrayAccessor() [2/4]

template<typename T >
Ocean::ConstTemplateArrayAccessor< T >::ConstTemplateArrayAccessor ( ConstTemplateArrayAccessor< T > &&  accessor)
inlinenoexcept

Move constructor.

Parameters
accessorAccessor to be moved

◆ ConstTemplateArrayAccessor() [3/4]

template<typename T >
Ocean::ConstTemplateArrayAccessor< T >::ConstTemplateArrayAccessor ( const T *  elements,
const size_t  size 
)
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
sizeThe number of elements that can be accessed, may be 0 if elements is nullptr

◆ ConstTemplateArrayAccessor() [4/4]

template<typename T >
Ocean::ConstTemplateArrayAccessor< T >::ConstTemplateArrayAccessor ( const std::vector< 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 vector holding all elements

Member Function Documentation

◆ canAccess()

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

Returns whether this accessor has a specific element.

See also
ConstAccessor::canAccess().

◆ data()

template<typename T >
const T * Ocean::ConstTemplateArrayAccessor< T >::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 >
bool Ocean::ConstTemplateArrayAccessor< T >::firstElement ( T &  element,
size_t &  index 
) const
inline

Returns the first element of this accessor.

See also
ConstAccessor:firstElement().

◆ isEmpty()

template<typename T >
bool Ocean::ConstTemplateArrayAccessor< T >::isEmpty
inline

Returns whether this accessor provides no elements.

See also
Accessor::isEmpty().

◆ nextElement()

template<typename T >
bool Ocean::ConstTemplateArrayAccessor< T >::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 >
ConstTemplateArrayAccessor< T > & Ocean::ConstTemplateArrayAccessor< T >::operator= ( ConstArrayAccessor< T > &&  accessor)
inlinenoexcept

Move operator.

Parameters
accessorAccessor to be moved
Returns
Reference to this accessor

◆ operator[]()

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

Returns one element of this accessor object.

See also
ConstAccessor::operator[].

◆ size()

template<typename T >
size_t Ocean::ConstTemplateArrayAccessor< T >::size
inline

Returns the number of accessible elements of this accessor object.

See also
ConstAccessor::size().

Field Documentation

◆ elements_

template<typename T >
const T* Ocean::ConstTemplateArrayAccessor< T >::elements_ = nullptr
protected

The elements of this accessor.

◆ size_

template<typename T >
size_t Ocean::ConstTemplateArrayAccessor< T >::size_ = 0
protected

The number of elements that can be accessed.


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