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 589 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 592 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 591 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 793 of file PndCAArray.h.

794 {
795  Parent::fData = 0;
796  Parent::SetSize(0, 0, 0);
797  Parent::SetBounds(0, -1);
798 }

◆ 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 800 of file PndCAArray.h.

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

801 {
802  ALIHLTARRAY_STATIC_ASSERT(Dim == 1, PndCAResizableArray1_used_with_incorrect_dimension);
804  Parent::SetSize(x, 0, 0);
805  Parent::SetBounds(0, x - 1);
806 }
#define ALIHLTARRAY_STATIC_ASSERT(cond, msg)
Definition: PndCAArray.h:83
static T * Alloc(int s)
Definition: PndCAArray.h:207

◆ 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 808 of file PndCAArray.h.

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

809 {
810  ALIHLTARRAY_STATIC_ASSERT(Dim == 2, PndCAResizableArray2_used_with_incorrect_dimension);
811  Parent::fData = PndCAInternal::Allocator<T, alignment>::Alloc(x * y);
812  Parent::SetSize(x, y, 0);
813  Parent::SetBounds(0, x * y - 1);
814 }
#define ALIHLTARRAY_STATIC_ASSERT(cond, msg)
Definition: PndCAArray.h:83
static T * Alloc(int s)
Definition: PndCAArray.h:207

◆ 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 816 of file PndCAArray.h.

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

817 {
818  ALIHLTARRAY_STATIC_ASSERT(Dim == 3, PndCAResizableArray3_used_with_incorrect_dimension);
819  Parent::fData = PndCAInternal::Allocator<T, alignment>::Alloc(x * y * z);
820  Parent::SetSize(x, y, z);
821  Parent::SetBounds(0, x * y * z - 1);
822 }
#define ALIHLTARRAY_STATIC_ASSERT(cond, msg)
Definition: PndCAArray.h:83
static T * Alloc(int s)
Definition: PndCAArray.h:207

◆ ~PndCAResizableArray()

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

frees the data

Definition at line 613 of file PndCAArray.h.

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

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

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 825 of file PndCAArray.h.

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

826 {
827  ALIHLTARRAY_STATIC_ASSERT(Dim == 1, PndCAResizableArray1_resize_used_with_incorrect_dimension);
828  PndCAInternal::Allocator<T, alignment>::Free(Parent::fData, Parent::fSize);
829  Parent::fData = (x == 0) ? 0 : PndCAInternal::Allocator<T, alignment>::Alloc(x);
830  Parent::SetSize(x, 0, 0);
831  Parent::SetBounds(0, x - 1);
832 }
static void Free(T *const p, int size)
Definition: PndCAArray.h:213
#define ALIHLTARRAY_STATIC_ASSERT(cond, msg)
Definition: PndCAArray.h:83

◆ 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 834 of file PndCAArray.h.

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

835 {
836  ALIHLTARRAY_STATIC_ASSERT(Dim == 2, PndCAResizableArray2_resize_used_with_incorrect_dimension);
837  PndCAInternal::Allocator<T, alignment>::Free(Parent::fData, Parent::fSize);
838  Parent::fData = (x == 0) ? 0 : PndCAInternal::Allocator<T, alignment>::Alloc(x * y);
839  Parent::SetSize(x, y, 0);
840  Parent::SetBounds(0, x * y - 1);
841 }
static void Free(T *const p, int size)
Definition: PndCAArray.h:213
#define ALIHLTARRAY_STATIC_ASSERT(cond, msg)
Definition: PndCAArray.h:83

◆ 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 843 of file PndCAArray.h.

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

844 {
845  ALIHLTARRAY_STATIC_ASSERT(Dim == 3, PndCAResizableArray3_resize_used_with_incorrect_dimension);
846  PndCAInternal::Allocator<T, alignment>::Free(Parent::fData, Parent::fSize);
847  Parent::fData = (x == 0) ? 0 : PndCAInternal::Allocator<T, alignment>::Alloc(x * y * z);
848  Parent::SetSize(x, y, z);
849  Parent::SetBounds(0, x * y * z - 1);
850 }
static void Free(T *const p, int size)
Definition: PndCAArray.h:213
#define ALIHLTARRAY_STATIC_ASSERT(cond, msg)
Definition: PndCAArray.h:83

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