MxEngine
Public Types | Public Member Functions | List of all members
MxEngine::Array2D< T, Base > Class Template Reference

#include <Array2D.h>

Public Types

using BaseStorage = Base< T >
 

Public Member Functions

 Array2D ()
 
 Array2D (const Array2D &)=default
 
 Array2D (Array2D &&)=default
 
Array2Doperator= (const Array2D &)=default
 
Array2Doperator= (Array2D &&)=default
 
size_t size () const
 
size_t width () const
 
size_t height () const
 
T * data ()
 
const T * data () const
 
ArrayView< T > operator[] (size_t idx)
 
ArrayView< const T > operator[] (size_t idx) const
 
void resize (size_t width, size_t height, T value=T())
 
void rearrange (size_t width, size_t height)
 
void clear ()
 
auto begin ()
 
auto end ()
 
auto begin () const
 
auto end () const
 

Detailed Description

template<typename T, template< typename > typename Base = MxVector>
class MxEngine::Array2D< T, Base >

Rectangular array sized [width * height] where all elements are fitted into one contiguous memory block Each element is accessed as Array[width_idx][height_idx], indexing Array[width_idx] requires one multiplication operation

Constructor & Destructor Documentation

§ Array2D()

template<typename T , template< typename > typename Base>
MxEngine::Array2D< T, Base >::Array2D ( )
inline

constructs zero-sized Array2D (i.e. width = height = 0)

Member Function Documentation

§ clear()

template<typename T , template< typename > typename Base>
void MxEngine::Array2D< T, Base >::clear ( )
inline

clears Array2D (height = width = 0). Behaviour of clear is same as behaviour of clear(), applied on Base container

§ data() [1/2]

template<typename T , template< typename > typename Base>
T * MxEngine::Array2D< T, Base >::data ( )
inline
Returns
pointer to underlying memory block where all elements are stored

§ data() [2/2]

template<typename T , template< typename > typename Base>
const T * MxEngine::Array2D< T, Base >::data ( ) const
inline
Returns
pointer to underlying memory block where all elements are stored

§ height()

template<typename T , template< typename > typename Base>
size_t MxEngine::Array2D< T, Base >::height ( ) const
inline
Returns
height of Array2D

§ operator[]() [1/2]

template<typename T , template< typename > typename Base>
ArrayView< T > MxEngine::Array2D< T, Base >::operator[] ( size_t  idx)
inline

returns row of Array2D. Requires one multiplication instruction. Row cannot be used if Array2D was deleted

Parameters
idxwidth index of Array2D
Returns
array_view on Array2D row

§ operator[]() [2/2]

template<typename T , template< typename > typename Base>
ArrayView< const T > MxEngine::Array2D< T, Base >::operator[] ( size_t  idx) const
inline

returns row of Array2D. Requires one multiplication instruction. Row cannot be used if Array2D was deleted

Parameters
idxwidth index of Array2D
Returns
array_view on Array2D row

§ rearrange()

template<typename T , template< typename > typename Base>
void MxEngine::Array2D< T, Base >::rearrange ( size_t  width,
size_t  height 
)
inline

rearranges array, changing its width and size as long as width * height results in same total elements. if width * height != array.width() * array.height(), result rearrange call is undefined

Parameters
widthnew array width
heightnew array height

§ resize()

template<typename T , template< typename > typename Base>
void MxEngine::Array2D< T, Base >::resize ( size_t  width,
size_t  height,
value = T() 
)
inline

resizes array, filling it with new values. All existing elements are packed into first array rows

Parameters
widthnew array width
heightnew array height
valueoptional value to fill new elements (existing are not changed)

§ size()

template<typename T , template< typename > typename Base>
size_t MxEngine::Array2D< T, Base >::size ( ) const
inline
Returns
total element count in Array2D (width * height)

§ width()

template<typename T , template< typename > typename Base>
size_t MxEngine::Array2D< T, Base >::width ( ) const
inline
Returns
width of Array2D. This operation requires branching and/or division instruction

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