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 577 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 580 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 579 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 781 of file PndFTSArray.h.

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

◆ 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 788 of file PndFTSArray.h.

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

◆ 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 796 of file PndFTSArray.h.

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

◆ 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 804 of file PndFTSArray.h.

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

◆ ~PndFTSResizableArray()

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

frees the data

Definition at line 601 of file PndFTSArray.h.

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

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 813 of file PndFTSArray.h.

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

◆ 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 822 of file PndFTSArray.h.

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

◆ 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 831 of file PndFTSArray.h.

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

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