Ocean
Ocean::NonconstArrayAccessor< T > Class Template Reference

This class implements an accessor providing direct access to an array of elements. More...

Inheritance diagram for Ocean::NonconstArrayAccessor< T >:

Public Member Functions

 NonconstArrayAccessor ()=default
 Creates a new empty accessor. More...
 
 NonconstArrayAccessor (NonconstArrayAccessor< T > &&accessor) noexcept
 Move constructor. More...
 
 NonconstArrayAccessor (T *elements, const size_t size)
 Creates a new accessor object. More...
 
 NonconstArrayAccessor (std::vector< T > &elements)
 Creates a new accessor object. More...
 
 NonconstArrayAccessor (std::vector< T > &elements, const size_t resizeSize)
 Creates a new accessor object. More...
 
 NonconstArrayAccessor (std::vector< T > *elements, const size_t resizeSize=0)
 Creates a new accessor object. More...
 
virtual T * data ()
 Returns a pointer to the elements of this accessor if the data exists within one memory block without gaps. More...
 
virtual size_t size () const
 Returns the number of accessible elements of this accessor object. More...
 
virtual const T & operator[] (const size_t &index) const
 Returns one element of this accessor object. More...
 
virtual T & operator[] (const size_t &index)
 Returns one element of this accessor object. More...
 
NonconstArrayAccessor< T > & operator= (NonconstArrayAccessor< T > &&accessor) noexcept
 Move operator. More...
 
- Public Member Functions inherited from Ocean::NonconstIndexedAccessor< T >
virtual bool canAccess (const size_t &index) const
 Returns whether this accessor has a specific element. More...
 
virtual bool firstElement (T &element, size_t &index) const
 Returns the first element of this accessor. More...
 
virtual 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...
 
NonconstIndexedAccessor< T > * pointer ()
 Returns the pointer to this object if this accessor holds at least one element (if this accessor is not empty). More...
 
- Public Member Functions inherited from Ocean::ConstAccessor< T, size_t >
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

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

Additional Inherited Members

- Public Types inherited from Ocean::ConstAccessor< T, size_t >
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...
 
- 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::NonconstIndexedAccessor< T >
 NonconstIndexedAccessor ()=default
 Creates a new accessor object. More...
 
- Protected Member Functions inherited from Ocean::NonconstAccessor< T, size_t >
 NonconstAccessor ()=default
 Creates a new indexed-based accessor object. More...
 
- Protected Member Functions inherited from Ocean::ConstAccessor< T, size_t >
 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>
class Ocean::NonconstArrayAccessor< T >

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

Template Parameters
TThe data type of the elements of the accessor

Constructor & Destructor Documentation

◆ NonconstArrayAccessor() [1/6]

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

Creates a new empty accessor.

◆ NonconstArrayAccessor() [2/6]

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

Move constructor.

Parameters
accessorAccessor to be moved

◆ NonconstArrayAccessor() [3/6]

template<typename T >
Ocean::NonconstArrayAccessor< T >::NonconstArrayAccessor ( 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

◆ NonconstArrayAccessor() [4/6]

template<typename T >
Ocean::NonconstArrayAccessor< T >::NonconstArrayAccessor ( 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

◆ NonconstArrayAccessor() [5/6]

template<typename T >
Ocean::NonconstArrayAccessor< T >::NonconstArrayAccessor ( std::vector< T > &  elements,
const size_t  resizeSize 
)
inline

Creates a new accessor object.

This constructor simplifies the creation of an optional NonconstArrayAccessor object by allowing to provide an empty vector object while defining an explicit resize value.
Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.

Parameters
elementsA vector holding all elements
resizeSizeAn explicit resize value that will invoke a resizing of the given vector before the vector is connected with the accessor, with range [1, infinity), 0 to avoid any resizing

◆ NonconstArrayAccessor() [6/6]

template<typename T >
Ocean::NonconstArrayAccessor< T >::NonconstArrayAccessor ( std::vector< T > *  elements,
const size_t  resizeSize = 0 
)
inlineexplicit

Creates a new accessor object.

This constructor simplifies the creation of an optional NonconstArrayAccessor object.
Beware: The given elements are not copied, they must not be deleted before the accessor is disposed.

Parameters
elementsAn optional vector holding all elements, nullptr to create an empty invalid accessor
resizeSizeAn optional possibility to resize the provided elements vector (if defined - otherwise nothing happens), with range [1, infinity), 0 to avoid any resizing

Member Function Documentation

◆ data()

template<typename T >
T * Ocean::NonconstArrayAccessor< T >::data
virtual

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

See also
NonconstAccessor::data().

Reimplemented from Ocean::NonconstAccessor< T, size_t >.

◆ operator=()

template<typename T >
NonconstArrayAccessor< T > & Ocean::NonconstArrayAccessor< T >::operator= ( NonconstArrayAccessor< T > &&  accessor)
inlinenoexcept

Move operator.

Parameters
accessorAccessor to be moved
Returns
Reference to this accessor

◆ operator[]() [1/2]

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

Returns one element of this accessor object.

See also
ConstAccessor::operator[].

Implements Ocean::NonconstIndexedAccessor< T >.

◆ operator[]() [2/2]

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

Returns one element of this accessor object.

See also
ConstAccessor::operator[].

Implements Ocean::NonconstIndexedAccessor< T >.

◆ size()

template<typename T >
size_t Ocean::NonconstArrayAccessor< T >::size
virtual

Returns the number of accessible elements of this accessor object.

See also
ConstAccessor::size().

Implements Ocean::Accessor.

Field Documentation

◆ elements_

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

The elements of this accessor.

◆ size_

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

The number of elements that can be accessed.


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