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

#include <PndFTSArray.h>

Inheritance diagram for PndFTSResizableArray< T, Dim, alignment >:
PndFTSArray< PndFTSInternal::TypeForAlignmentHelper< T, alignment >::Type, Dim > PndFTSInternal::ArrayBase< PndFTSInternal::TypeForAlignmentHelper< T, alignment >::Type, Dim >

Public Types

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

Public Member Functions

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

Detailed Description

template<typename T, int Dim = 1, int alignment = 0>
class PndFTSResizableArray< 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( PndFTSArray<int> a, int size )
{
for ( int i = 0; i < size; ++i ) {
a[i] = i;
}
}
int size = ...;
PndFTSResizableArray<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 PndFTSArray.h.

Member Typedef Documentation

◆ Parent

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

Definition at line 592 of file PndFTSArray.h.

◆ T2

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

Definition at line 591 of file PndFTSArray.h.

Constructor & Destructor Documentation

◆ PndFTSResizableArray() [1/4]

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

does not allocate any memory

Definition at line 793 of file PndFTSArray.h.

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

◆ PndFTSResizableArray() [2/4]

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

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

Definition at line 800 of file PndFTSArray.h.

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

◆ PndFTSResizableArray() [3/4]

template<typename T , int Dim, int alignment>
PndFTSResizableArray< T, Dim, alignment >::PndFTSResizableArray ( 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 PndFTSArray.h.

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

◆ PndFTSResizableArray() [4/4]

template<typename T , int Dim, int alignment>
PndFTSResizableArray< T, Dim, alignment >::PndFTSResizableArray ( 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 PndFTSArray.h.

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

◆ ~PndFTSResizableArray()

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

frees the data

Definition at line 613 of file PndFTSArray.h.

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

Member Function Documentation

◆ Resize() [1/3]

template<typename T , int Dim, int alignment>
void PndFTSResizableArray< 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 PndFTSArray.h.

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

◆ Resize() [2/3]

template<typename T , int Dim, int alignment>
void PndFTSResizableArray< 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 PndFTSArray.h.

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

◆ Resize() [3/3]

template<typename T , int Dim, int alignment>
void PndFTSResizableArray< 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 PndFTSArray.h.

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

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