FairRoot/PandaRoot
Public Types | Public Member Functions | Private Member Functions | List of all members
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 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)
 
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
 

Private Member Functions

void * operator new (size_t)
 
 PndCAResizableArray (const PndCAResizableArray &)
 
PndCAResizableArrayoperator= (const PndCAResizableArray &)
 

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

Member Typedef Documentation

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

Definition at line 459 of file PndCAArray.h.

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

Definition at line 458 of file PndCAArray.h.

Constructor & Destructor Documentation

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

does not allocate any memory

Definition at line 671 of file PndCAArray.h.

672 {
673  Parent::fData = 0;
674  Parent::SetSize( 0, 0, 0 );
675  Parent::SetBounds( 0, -1 );
676 }
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 678 of file PndCAArray.h.

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

679 {
680  ALIHLTARRAY_STATIC_ASSERT( Dim == 1, PndCAResizableArray1_used_with_incorrect_dimension );
682  Parent::SetSize( x, 0, 0 );
683  Parent::SetBounds( 0, x - 1 );
684 }
#define ALIHLTARRAY_STATIC_ASSERT(cond, msg)
Definition: PndCAArray.h:71
static T * Alloc(int s)
Definition: PndCAArray.h:163
Double_t x
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 686 of file PndCAArray.h.

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

687 {
688  ALIHLTARRAY_STATIC_ASSERT( Dim == 2, PndCAResizableArray2_used_with_incorrect_dimension );
690  Parent::SetSize( x, y, 0 );
691  Parent::SetBounds( 0, x * y - 1 );
692 }
#define ALIHLTARRAY_STATIC_ASSERT(cond, msg)
Definition: PndCAArray.h:71
static T * Alloc(int s)
Definition: PndCAArray.h:163
Double_t x
Double_t y
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 694 of file PndCAArray.h.

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

695 {
696  ALIHLTARRAY_STATIC_ASSERT( Dim == 3, PndCAResizableArray3_used_with_incorrect_dimension );
697  Parent::fData = PndCAInternal::Allocator<T, alignment>::Alloc( x * y * z );
698  Parent::SetSize( x, y, z );
699  Parent::SetBounds( 0, x * y * z - 1 );
700 }
#define ALIHLTARRAY_STATIC_ASSERT(cond, msg)
Definition: PndCAArray.h:71
static T * Alloc(int s)
Definition: PndCAArray.h:163
Double_t z
Double_t x
Double_t y
template<typename T, int Dim = 1, int alignment = 0>
PndCAResizableArray< T, Dim, alignment >::~PndCAResizableArray ( )
inline

frees the data

Definition at line 480 of file PndCAArray.h.

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

480 { PndCAInternal::Allocator<T, alignment>::Free( Parent::fData, Parent::fSize ); }
static void Free(T *const p, int size)
Definition: PndCAArray.h:164
template<typename T, int Dim = 1, int alignment = 0>
PndCAResizableArray< T, Dim, alignment >::PndCAResizableArray ( const PndCAResizableArray< T, Dim, alignment > &  )
private

Member Function Documentation

PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type * PndCAArray< PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type , Dim >::Data ( )
inlineinherited

returns a pointer to the data This circumvents bounds checking so it should not be used.

Definition at line 398 of file PndCAArray.h.

398 { return Parent::fData; }
const PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type * PndCAArray< PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type , Dim >::Data ( ) const
inlineinherited

returns a const pointer to the data This circumvents bounds checking so it should not be used.

Definition at line 403 of file PndCAArray.h.

403 { return Parent::fData; }
bool PndCAArray< PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type , Dim >::IsValid ( ) const
inlineinherited

allows you to check for validity of the array

Definition at line 383 of file PndCAArray.h.

383 { return Parent::fData != 0; }
PndCAArray< PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type , Dim >::operator bool ( ) const
inlineinherited

allows you to check for validity of the array by casting to bool

Definition at line 379 of file PndCAArray.h.

379 { return Parent::fData != 0; }
template<typename T, int Dim = 1, int alignment = 0>
void* PndCAResizableArray< T, Dim, alignment >::operator new ( size_t  )
private
PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type & PndCAArray< PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type , Dim >::operator* ( )
inlineinherited

returns a reference to the data at index 0

Definition at line 388 of file PndCAArray.h.

388 { BOUNDS_CHECK( 0, Parent::fData[0] ); return *Parent::fData; }
#define BOUNDS_CHECK(x, y)
Definition: PndCAArray.h:118
const PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type & PndCAArray< PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type , Dim >::operator* ( ) const
inlineinherited

returns a const reference to the data at index 0

Definition at line 392 of file PndCAArray.h.

392 { BOUNDS_CHECK( 0, Parent::fData[0] ); return *Parent::fData; }
#define BOUNDS_CHECK(x, y)
Definition: PndCAArray.h:118
PndCAArray PndCAArray< PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type , Dim >::operator+ ( int  x) const
inlineinherited

moves the array base pointer so that the data that was once at index 0 will then be at index -x

PndCAArray PndCAArray< PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type , Dim >::operator- ( int  x) const
inlineinherited

moves the array base pointer so that the data that was once at index 0 will then be at index x

template<typename T, int Dim = 1, int alignment = 0>
PndCAResizableArray& PndCAResizableArray< T, Dim, alignment >::operator= ( const PndCAResizableArray< T, Dim, alignment > &  )
private
PndCAArray<Other, Dim> PndCAArray< PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type , Dim >::ReinterpretCast ( ) const
inlineinherited

Definition at line 414 of file PndCAArray.h.

414  {
416  r.fData = reinterpret_cast<Other *>( Parent::fData );
417  r.ReinterpretCast( *this, sizeof( T ), sizeof( Other ) );
418  }
double r
Definition: RiemannTest.C:14
PndCAArray< Other, Dim > ReinterpretCast() const
Definition: PndCAArray.h:414
TTree * T
Definition: anaLmdReco.C:32
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 703 of file PndCAArray.h.

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

704 {
705  ALIHLTARRAY_STATIC_ASSERT( Dim == 1, PndCAResizableArray1_resize_used_with_incorrect_dimension );
706  PndCAInternal::Allocator<T, alignment>::Free( Parent::fData, Parent::fSize );
707  Parent::fData = ( x == 0 ) ? 0 : PndCAInternal::Allocator<T, alignment>::Alloc( x );
708  Parent::SetSize( x, 0, 0 );
709  Parent::SetBounds( 0, x - 1 );
710 }
static void Free(T *const p, int size)
Definition: PndCAArray.h:164
#define ALIHLTARRAY_STATIC_ASSERT(cond, msg)
Definition: PndCAArray.h:71
Double_t x
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 712 of file PndCAArray.h.

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

713 {
714  ALIHLTARRAY_STATIC_ASSERT( Dim == 2, PndCAResizableArray2_resize_used_with_incorrect_dimension );
715  PndCAInternal::Allocator<T, alignment>::Free( Parent::fData, Parent::fSize );
716  Parent::fData = ( x == 0 ) ? 0 : PndCAInternal::Allocator<T, alignment>::Alloc( x * y );
717  Parent::SetSize( x, y, 0 );
718  Parent::SetBounds( 0, x * y - 1 );
719 }
static void Free(T *const p, int size)
Definition: PndCAArray.h:164
#define ALIHLTARRAY_STATIC_ASSERT(cond, msg)
Definition: PndCAArray.h:71
Double_t x
Double_t y
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 721 of file PndCAArray.h.

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

722 {
723  ALIHLTARRAY_STATIC_ASSERT( Dim == 3, PndCAResizableArray3_resize_used_with_incorrect_dimension );
724  PndCAInternal::Allocator<T, alignment>::Free( Parent::fData, Parent::fSize );
725  Parent::fData = ( x == 0 ) ? 0 : PndCAInternal::Allocator<T, alignment>::Alloc( x * y * z );
726  Parent::SetSize( x, y, z );
727  Parent::SetBounds( 0, x * y * z - 1 );
728 }
static void Free(T *const p, int size)
Definition: PndCAArray.h:164
#define ALIHLTARRAY_STATIC_ASSERT(cond, msg)
Definition: PndCAArray.h:71
Double_t z
Double_t x
Double_t y
int PndCAArray< PndCAInternal::TypeForAlignmentHelper< T, alignment >::Type , Dim >::Size ( ) const
inlineinherited

Returns the number of elements in the array. If it is a multi-dimensional array the size is the multiplication of the dimensions ( e.g. a 10 x 20 array returns 200 as its size ).

Definition at line 374 of file PndCAArray.h.

374 { return Parent::fSize; }

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