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

Private Member Functions

void * operator new (size_t)
 
 PndFTSResizableArray (const PndFTSResizableArray &)
 
PndFTSResizableArrayoperator= (const PndFTSResizableArray &)
 

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

Member Typedef Documentation

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

Definition at line 459 of file PndFTSArray.h.

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

Definition at line 458 of file PndFTSArray.h.

Constructor & Destructor Documentation

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

does not allocate any memory

Definition at line 671 of file PndFTSArray.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>
PndFTSResizableArray< T, Dim, alignment >::PndFTSResizableArray ( int  x)
inline

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

Definition at line 678 of file PndFTSArray.h.

References PndFTSInternal::Allocator< T, alignment >::Alloc(), and PNDFTSARRAY_STATIC_ASSERT.

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

References PndFTSInternal::Allocator< T, alignment >::Alloc(), and PNDFTSARRAY_STATIC_ASSERT.

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

References PndFTSInternal::Allocator< T, alignment >::Alloc(), and PNDFTSARRAY_STATIC_ASSERT.

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

frees the data

Definition at line 480 of file PndFTSArray.h.

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

Member Function Documentation

PndFTSInternal::TypeForAlignmentHelper< T, alignment >::Type * PndFTSArray< PndFTSInternal::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 PndFTSArray.h.

398 { return Parent::fData; }
const PndFTSInternal::TypeForAlignmentHelper< T, alignment >::Type * PndFTSArray< PndFTSInternal::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 PndFTSArray.h.

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

allows you to check for validity of the array

Definition at line 383 of file PndFTSArray.h.

383 { return Parent::fData != 0; }
PndFTSArray< PndFTSInternal::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 PndFTSArray.h.

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

returns a reference to the data at index 0

Definition at line 388 of file PndFTSArray.h.

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

returns a const reference to the data at index 0

Definition at line 392 of file PndFTSArray.h.

392 { BOUNDS_CHECK( 0, Parent::fData[0] ); return *Parent::fData; }
#define BOUNDS_CHECK(x, y)
Definition: PndFTSArray.h:118
PndFTSArray PndFTSArray< PndFTSInternal::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

PndFTSArray PndFTSArray< PndFTSInternal::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>
PndFTSResizableArray& PndFTSResizableArray< T, Dim, alignment >::operator= ( const PndFTSResizableArray< T, Dim, alignment > &  )
private
PndFTSArray<Other, Dim> PndFTSArray< PndFTSInternal::TypeForAlignmentHelper< T, alignment >::Type , Dim >::ReinterpretCast ( ) const
inlineinherited

Definition at line 414 of file PndFTSArray.h.

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

References PndFTSInternal::Allocator< T, alignment >::Free(), and PNDFTSARRAY_STATIC_ASSERT.

Referenced by PndFTSCAGBTracker::SetHits(), and PndFTSCAGBTracker::SetNHits().

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

References PndFTSInternal::Allocator< T, alignment >::Free(), and PNDFTSARRAY_STATIC_ASSERT.

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

References PndFTSInternal::Allocator< T, alignment >::Free(), and PNDFTSARRAY_STATIC_ASSERT.

722 {
723  PNDFTSARRAY_STATIC_ASSERT( Dim == 3, PndFTSResizableArray3_resize_used_with_incorrect_dimension );
724  PndFTSInternal::Allocator<T, alignment>::Free( Parent::fData, Parent::fSize );
725  Parent::fData = ( x == 0 ) ? 0 : PndFTSInternal::Allocator<T, alignment>::Alloc( x * y * z );
726  Parent::SetSize( x, y, z );
727  Parent::SetBounds( 0, x * y * z - 1 );
728 }
#define PNDFTSARRAY_STATIC_ASSERT(cond, msg)
Definition: PndFTSArray.h:71
static void Free(T *const p, int size)
Definition: PndFTSArray.h:164
Double_t z
Double_t x
Double_t y
int PndFTSArray< PndFTSInternal::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 PndFTSArray.h.

Referenced by PndFTSCADisplay::DrawGBPoints().

374 { return Parent::fSize; }

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