VISR  0.12.0
Versatile Interactive Scene Renderer
visr::efl::AlignedArray< ElementType > Class Template Reference

#include <aligned_array.hpp>

Public Member Functions

 AlignedArray (std::size_t alignmentElements)
 
 AlignedArray (std::size_t length, std::size_t alignmentElements)
 
 AlignedArray (AlignedArray< ElementType > &&rhs)
 
AlignedArray< ElementType > & operator= (AlignedArray< ElementType > &&rhs)
 
 ~AlignedArray ()
 
void resize (std::size_t newLength)
 
void swap (AlignedArray< ElementType > &rhs)
 
std::size_t size () const
 
std::size_t alignmentElements () const
 
std::size_t alignmentBytes () const
 
ElementType * data ()
 
ElementType const * data () const
 
ElementType & operator[] (std::size_t index)
 
ElementType const & operator[] (std::size_t index) const
 
ElementType & at (std::size_t index)
 
ElementType const & at (std::size_t index) const
 

Detailed Description

template<typename ElementType>
class visr::efl::AlignedArray< ElementType >

A template class to provide memory that is aligned in memory. Alignment is an important property for speed. The aligement is given as a number of elements. This means that the pointer to the aligned memory is divisable by alignmentElements*sizeof(T) .

Template Parameters
ElementTypeThe type of the array elements

Constructor & Destructor Documentation

template<typename ElementType >
visr::efl::AlignedArray< ElementType >::AlignedArray ( std::size_t  alignmentElements)
explicit

Constructor, constructs an empty array and sets the alignment. Note that this array cannot be dereferenced, and data() returns a null pointer.

Parameters
alignmentElementsThe requested alignment of the array which will be used if the array is resized to a non-zero length. The alignment must be a one or an integral power of two. A value of zero is supported, but transformed to 2 internally.
Exceptions
std::invalid_argumentIf the alignment value is not an integer power of 2 (or 0 or 1)
template<typename ElementType >
visr::efl::AlignedArray< ElementType >::AlignedArray ( std::size_t  length,
std::size_t  alignmentElements 
)
explicit

Constructor, create an array with a specified number of elements and the given alignment.

Parameters
lengthThe requested length of the array, given as number of elements.
alignmentElementsThe requested alignment of the array. The alignment must be a one or an integral power of two. A value of zero is supported, but transformed to 2 internally.
Exceptions
std::invalid_argumentIf the alignment value is not an integer power of 2 (or 0 or 1)
template<typename ElementType>
visr::efl::AlignedArray< ElementType >::AlignedArray ( AlignedArray< ElementType > &&  rhs)

Move constructor, takes over the contents of an rvalue rhs and leaves rhs in an empty, but valid state.

template<typename ElementType >
visr::efl::AlignedArray< ElementType >::~AlignedArray ( )

Member Function Documentation

template<typename ElementType>
std::size_t visr::efl::AlignedArray< ElementType >::alignmentBytes ( ) const
inline

Return the alignment of the the data structure (measured in bytes) as determined in the constructor.

template<typename ElementType>
std::size_t visr::efl::AlignedArray< ElementType >::alignmentElements ( ) const
inline

Return the alignment of the the data structure (measured in number of elements) as determined in the constructor.

template<typename ElementType>
ElementType& visr::efl::AlignedArray< ElementType >::at ( std::size_t  index)
inline

Indexed access, return a modifiable reference to the element addressed by index. The function variant provides range checking.

Parameters
indexZero-offset index into the array
Exceptions
std::out_of_rangeif index exceeds the allocated length of the array.
template<typename ElementType>
ElementType const& visr::efl::AlignedArray< ElementType >::at ( std::size_t  index) const
inline

Indexed access, return a constant reference to the element addressed by index. The function variant provides range checking.

Parameters
indexZero-offset index into the array
Exceptions
std::out_of_rangeif index exceeds the allocated length of the array.
template<typename ElementType>
ElementType* visr::efl::AlignedArray< ElementType >::data ( )
inline

Return a writable pointer to the data elements.

template<typename ElementType>
ElementType const* visr::efl::AlignedArray< ElementType >::data ( ) const
inline

Return a constant pointer to the data elements.

template<typename ElementType>
AlignedArray< ElementType > & visr::efl::AlignedArray< ElementType >::operator= ( AlignedArray< ElementType > &&  rhs)

Move assignment operator from a rvalue rhs.

Note
The alignment of rhs must match the alignment of this object.
Exceptions
std::logic_errorif the alignment of rhs does not match this object.
template<typename ElementType>
ElementType& visr::efl::AlignedArray< ElementType >::operator[] ( std::size_t  index)
inline

Indexed access, return a modifiable reference to the element addressed by index.

Parameters
indexZero-offset index into the array
template<typename ElementType>
ElementType const& visr::efl::AlignedArray< ElementType >::operator[] ( std::size_t  index) const
inline

Indexed access, return a constant reference to the element addressed by index.

Parameters
indexZero-offset index into the array
template<typename ElementType >
void visr::efl::AlignedArray< ElementType >::resize ( std::size_t  newLength)

Change the number of elements in the array. The old content of the array is not retained, but the new content is initialized with arbitrary values.

Parameters
newLengthThe allocated length of the array (in bytes)
template<typename ElementType>
std::size_t visr::efl::AlignedArray< ElementType >::size ( ) const
inline

Return the size of the array (in elements). This value may differ from the allocated length in order to ensure the prescribed alignment.

template<typename ElementType>
void visr::efl::AlignedArray< ElementType >::swap ( AlignedArray< ElementType > &  rhs)

Exchange the contents of this object with that of rhs. Does not throw, thus enabling exception safety for classes using AlignedArray.

Swap the content with another AlignedArray object. This method has strong exception safety and does not involve memory allocation or vector copy operations.

Parameters
rhsThe object to be swapped with.
Exceptions
std::logic_errorIf the objects do not have the same alignment.

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