PandaRoot
PndCAResizableArray< T, Dim, alignment > Class Template Reference

#include <PndCAArray.h>

Inheritance diagram for PndCAResizableArray< T, Dim, alignment >:
PndCAArray< PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type, Dim > PndCAInternal::ArrayBase< PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type, Dim >

Public Types

typedef PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type T2
 
typedef PndCAInternal::ArrayBase< T2, Dim > Parent
 
- Public Types inherited from PndCAArray< PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type, Dim >
typedef PndCAInternal::ArrayBase< PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type, Dim > Parent
 

Public Member Functions

 PndCAResizableArray ()
 
 PndCAResizableArray (int x)
 
 PndCAResizableArray (int x, int y)
 
 PndCAResizableArray (int x, int y, int z)
 
 ~PndCAResizableArray ()
 
void Resize (int x)
 
void Resize (int x, int y)
 
void Resize (int x, int y, int z)
 
- Public Member Functions inherited from PndCAArray< PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type, Dim >
int Size () const
 
 operator bool () const
 
bool IsValid () const
 
PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type & operator* ()
 
const PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type & operator* () const
 
PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type * Data ()
 
const PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type * Data () const
 
PndCAArray operator+ (int x) const
 
PndCAArray operator- (int x) const
 
PndCAArray< Other, Dim > ReinterpretCast () const
 

Detailed Description

template<typename T, int Dim = 1, int alignment = 0>
class PndCAResizableArray< T, Dim, alignment >

Owns the data. When it goes out of scope the data is freed.

The memory is allocated on the heap.

Instantiate this class on the stack. Allocation on the heap is disallowed.

Parameters
Ttype of the entries in the array.
Dimselects the operator[]/operator() behavior it should have. I.e. makes it behave like a 1-, 2- or 3-dim array. (defaults to 1)
alignmentDefaults to 0 (default alignment). Other valid values are any multiples of 2. This is especially useful for aligning data for SIMD vectors.
Warning
when using alignment the type T may not have a destructor (well it may, but it won't be called)

Example:

void init( PndCAArray<int> a, int size )
{
for ( int i = 0; i < size; ++i ) {
a[i] = i;
}
}
int size = ...;
PndCAResizableArray<int> foo( size ); // notice that size doesn't have to be a constant like it
// has to be for C-Arrays in ISO C++
init( foo, size );
// now foo[i] == i

Definition at line 577 of file PndCAArray.h.

Member Typedef Documentation

◆ Parent

template<typename T, int Dim = 1, int alignment = 0>
typedef PndCAInternal::ArrayBase<T2, Dim> PndCAResizableArray< T, Dim, alignment >::Parent

Definition at line 580 of file PndCAArray.h.

◆ T2

template<typename T, int Dim = 1, int alignment = 0>
typedef PndCAInternal::TypeForAlignmentHelper<T, alignment>::Type PndCAResizableArray< T, Dim, alignment >::T2

Definition at line 579 of file PndCAArray.h.

Constructor & Destructor Documentation

◆ PndCAResizableArray() [1/4]

template<typename T , int Dim, int alignment>
PndCAResizableArray< T, Dim, alignment >::PndCAResizableArray ( )
inline

does not allocate any memory

Definition at line 781 of file PndCAArray.h.

782 {
783  Parent::fData = 0;
784  Parent::SetSize(0, 0, 0);
785  Parent::SetBounds(0, -1);
786 }

◆ PndCAResizableArray() [2/4]

template<typename T , int Dim, int alignment>
PndCAResizableArray< T, Dim, alignment >::PndCAResizableArray ( int  x)
inline

use for 1-dim arrays: allocates x * sizeof(T) bytes for the array

Definition at line 788 of file PndCAArray.h.

References ALIHLTARRAY_STATIC_ASSERT, and PndCAInternal::Allocator< T, alignment >::Alloc().

789 {
790  ALIHLTARRAY_STATIC_ASSERT(Dim == 1, PndCAResizableArray1_used_with_incorrect_dimension);
792  Parent::SetSize(x, 0, 0);
793  Parent::SetBounds(0, x - 1);
794 }
#define ALIHLTARRAY_STATIC_ASSERT(cond, msg)
Definition: PndCAArray.h:71
static T * Alloc(int s)
Definition: PndCAArray.h:195

◆ PndCAResizableArray() [3/4]

template<typename T , int Dim, int alignment>
PndCAResizableArray< T, Dim, alignment >::PndCAResizableArray ( int  x,
int  y 
)
inline

use for 2-dim arrays: allocates x * y * sizeof(T) bytes for the array

Definition at line 796 of file PndCAArray.h.

References ALIHLTARRAY_STATIC_ASSERT, and PndCAInternal::Allocator< T, alignment >::Alloc().

797 {
798  ALIHLTARRAY_STATIC_ASSERT(Dim == 2, PndCAResizableArray2_used_with_incorrect_dimension);
799  Parent::fData = PndCAInternal::Allocator<T, alignment>::Alloc(x * y);
800  Parent::SetSize(x, y, 0);
801  Parent::SetBounds(0, x * y - 1);
802 }
#define ALIHLTARRAY_STATIC_ASSERT(cond, msg)
Definition: PndCAArray.h:71
static T * Alloc(int s)
Definition: PndCAArray.h:195

◆ PndCAResizableArray() [4/4]

template<typename T , int Dim, int alignment>
PndCAResizableArray< T, Dim, alignment >::PndCAResizableArray ( int  x,
int  y,
int  z 
)
inline

use for 3-dim arrays: allocates x * y * z * sizeof(T) bytes for the array

Definition at line 804 of file PndCAArray.h.

References ALIHLTARRAY_STATIC_ASSERT, and PndCAInternal::Allocator< T, alignment >::Alloc().

805 {
806  ALIHLTARRAY_STATIC_ASSERT(Dim == 3, PndCAResizableArray3_used_with_incorrect_dimension);
807  Parent::fData = PndCAInternal::Allocator<T, alignment>::Alloc(x * y * z);
808  Parent::SetSize(x, y, z);
809  Parent::SetBounds(0, x * y * z - 1);
810 }
#define ALIHLTARRAY_STATIC_ASSERT(cond, msg)
Definition: PndCAArray.h:71
static T * Alloc(int s)
Definition: PndCAArray.h:195

◆ ~PndCAResizableArray()

template<typename T, int Dim = 1, int alignment = 0>
PndCAResizableArray< T, Dim, alignment >::~PndCAResizableArray ( )
inline

frees the data

Definition at line 601 of file PndCAArray.h.

References PndCAInternal::Allocator< T, alignment >::Free().

601 { PndCAInternal::Allocator<T, alignment>::Free(Parent::fData, Parent::fSize); }
static void Free(T *const p, int size)
Definition: PndCAArray.h:201

Member Function Documentation

◆ Resize() [1/3]

template<typename T , int Dim, int alignment>
void PndCAResizableArray< T, Dim, alignment >::Resize ( int  x)
inline

use for 1-dim arrays: resizes the memory for the array to x * sizeof(T) bytes.

Warning
this does not keep your previous data. If you were looking for this you probably want to use std::vector instead.

Definition at line 813 of file PndCAArray.h.

References ALIHLTARRAY_STATIC_ASSERT, and PndCAInternal::Allocator< T, alignment >::Free().

814 {
815  ALIHLTARRAY_STATIC_ASSERT(Dim == 1, PndCAResizableArray1_resize_used_with_incorrect_dimension);
816  PndCAInternal::Allocator<T, alignment>::Free(Parent::fData, Parent::fSize);
817  Parent::fData = (x == 0) ? 0 : PndCAInternal::Allocator<T, alignment>::Alloc(x);
818  Parent::SetSize(x, 0, 0);
819  Parent::SetBounds(0, x - 1);
820 }
static void Free(T *const p, int size)
Definition: PndCAArray.h:201
#define ALIHLTARRAY_STATIC_ASSERT(cond, msg)
Definition: PndCAArray.h:71

◆ Resize() [2/3]

template<typename T , int Dim, int alignment>
void PndCAResizableArray< T, Dim, alignment >::Resize ( int  x,
int  y 
)
inline

use for 2-dim arrays: resizes the memory for the array to x * y * sizeof(T) bytes.

Warning
this does not keep your previous data. If you were looking for this you probably want to use std::vector instead.

Definition at line 822 of file PndCAArray.h.

References ALIHLTARRAY_STATIC_ASSERT, and PndCAInternal::Allocator< T, alignment >::Free().

823 {
824  ALIHLTARRAY_STATIC_ASSERT(Dim == 2, PndCAResizableArray2_resize_used_with_incorrect_dimension);
825  PndCAInternal::Allocator<T, alignment>::Free(Parent::fData, Parent::fSize);
826  Parent::fData = (x == 0) ? 0 : PndCAInternal::Allocator<T, alignment>::Alloc(x * y);
827  Parent::SetSize(x, y, 0);
828  Parent::SetBounds(0, x * y - 1);
829 }
static void Free(T *const p, int size)
Definition: PndCAArray.h:201
#define ALIHLTARRAY_STATIC_ASSERT(cond, msg)
Definition: PndCAArray.h:71

◆ Resize() [3/3]

template<typename T , int Dim, int alignment>
void PndCAResizableArray< T, Dim, alignment >::Resize ( int  x,
int  y,
int  z 
)
inline

use for 3-dim arrays: resizes the memory for the array to x * y * z * sizeof(T) bytes.

Warning
this does not keep your previous data. If you were looking for this you probably want to use std::vector instead.

Definition at line 831 of file PndCAArray.h.

References ALIHLTARRAY_STATIC_ASSERT, and PndCAInternal::Allocator< T, alignment >::Free().

832 {
833  ALIHLTARRAY_STATIC_ASSERT(Dim == 3, PndCAResizableArray3_resize_used_with_incorrect_dimension);
834  PndCAInternal::Allocator<T, alignment>::Free(Parent::fData, Parent::fSize);
835  Parent::fData = (x == 0) ? 0 : PndCAInternal::Allocator<T, alignment>::Alloc(x * y * z);
836  Parent::SetSize(x, y, z);
837  Parent::SetBounds(0, x * y * z - 1);
838 }
static void Free(T *const p, int size)
Definition: PndCAArray.h:201
#define ALIHLTARRAY_STATIC_ASSERT(cond, msg)
Definition: PndCAArray.h:71

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