X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=HLT%2FBASE%2FAliHLTArray.h;h=d0d396ea8f39bed5d0d7eae055efab65551a1c5f;hb=527bcdd7271f26e5278d158c52f39cb083f6f4b7;hp=dee7d93c457a33e384a52f678355c3dac820d7cf;hpb=dd5579d1e1865835f62216004a5fe04376295b31;p=u%2Fmrichter%2FAliRoot.git diff --git a/HLT/BASE/AliHLTArray.h b/HLT/BASE/AliHLTArray.h index dee7d93c457..d0d396ea8f3 100644 --- a/HLT/BASE/AliHLTArray.h +++ b/HLT/BASE/AliHLTArray.h @@ -60,14 +60,14 @@ enum { #else namespace AliHLTArrayInternal { - template class STATIC_ASSERT_FAILURE; - template<> class STATIC_ASSERT_FAILURE {}; + template class AliHLTStaticAssertFailure; + template<> class AliHLTStaticAssertFailure {}; } #define ALIHLTARRAY_STATIC_ASSERT_CONCAT_HELPER(a, b) a##b #define ALIHLTARRAY_STATIC_ASSERT_CONCAT(a, b) ALIHLTARRAY_STATIC_ASSERT_CONCAT_HELPER(a, b) #define ALIHLTARRAY_STATIC_ASSERT_NC(cond, msg) \ - typedef AliHLTArrayInternal::STATIC_ASSERT_FAILURE ALIHLTARRAY_STATIC_ASSERT_CONCAT(_STATIC_ASSERTION_FAILED_##msg, __LINE__); \ + typedef AliHLTArrayInternal::AliHLTStaticAssertFailure ALIHLTARRAY_STATIC_ASSERT_CONCAT(_STATIC_ASSERTION_FAILED_##msg, __LINE__); \ ALIHLTARRAY_STATIC_ASSERT_CONCAT(_STATIC_ASSERTION_FAILED_##msg, __LINE__) Error_##msg #define ALIHLTARRAY_STATIC_ASSERT(cond, msg) ALIHLTARRAY_STATIC_ASSERT_NC(cond, msg); (void) Error_##msg #endif @@ -78,8 +78,8 @@ namespace AliHLTInternal { template struct Padding { char fPadding[Size]; }; template<> struct Padding<0> {}; - template struct CacheLineSizeHelperData { T fData; }; - template struct CacheLineSizeHelperEnums { + template struct AliHLTCacheLineSizeHelperData { T fData; }; + template struct AliHLTCacheLineSizeHelperEnums { enum { CacheLineSize = 64, MaskedSize = sizeof( T ) & ( CacheLineSize - 1 ), @@ -87,12 +87,12 @@ namespace AliHLTInternal PaddingSize = RequiredSize - sizeof( T ) }; }; - template class AliCacheLineSizeHelper : private CacheLineSizeHelperData, private Padding::PaddingSize> + template class AliCacheLineSizeHelper : private AliHLTCacheLineSizeHelperData, private Padding::PaddingSize> { public: - operator T &() { return CacheLineSizeHelperData::fData; } - operator const T &() const { return CacheLineSizeHelperData::fData; } - //const T &operator=( const T &rhs ) { CacheLineSizeHelperData::fData = rhs; } + operator T &() { return AliHLTCacheLineSizeHelperData::fData; } + operator const T &() const { return AliHLTCacheLineSizeHelperData::fData; } + //const T &operator=( const T &rhs ) { AliHLTCacheLineSizeHelperData::fData = rhs; } private: }; @@ -113,9 +113,9 @@ namespace AliHLTInternal protected: virtual inline ~AliArrayBoundsCheck() {} inline bool IsInBounds( int ) const { return true; } - inline void SetBounds( int, int ) {} - inline void MoveBounds( int ) {} - inline void ReinterpretCast( const AliArrayBoundsCheck &, int, int ) {} + inline void SetBounds( int, int ) const {} + inline void MoveBounds( int ) const {} + inline void ReinterpretCast( const AliArrayBoundsCheck &, int, int ) const {} }; #define BOUNDS_CHECK(x, y) #else @@ -156,17 +156,13 @@ namespace AliHLTInternal #ifdef USE_MM_MALLOC static inline T *Alloc( int s ) { T *p = reinterpret_cast( _mm_malloc( s * sizeof( T ), alignment ) ); return new( p ) T[s]; } static inline void Free( T *const p, int size ) { - for ( int i = 0; i < size; ++i ) { - p[i].~T(); - } + for ( int i = 0; i < size; ++i ) p[i].~T(); _mm_free( p ); } #else static inline T *Alloc( int s ) { T *p; posix_memalign( &p, alignment, s * sizeof( T ) ); return new( p ) T[s]; } static inline void Free( T *const p, int size ) { - for ( int i = 0; i < size; ++i ) { - p[i].~T(); - } + for ( int i = 0; i < size; ++i ) p[i].~T(); std::free( p ); } #endif @@ -178,17 +174,13 @@ namespace AliHLTInternal #ifdef USE_MM_MALLOC static inline T2 *Alloc( int s ) { T2 *p = reinterpret_cast( _mm_malloc( s * sizeof( T2 ), 128 ) ); return new( p ) T2[s]; } static inline void Free( T2 *const p, int size ) { - for ( int i = 0; i < size; ++i ) { - p[i].~T2(); - } + for ( int i = 0; i < size; ++i ) p[i].~T2(); _mm_free( p ); } #else static inline T2 *Alloc( int s ) { T2 *p; posix_memalign( &p, 128, s * sizeof( T2 ) ); return new( p ) T2[s]; } static inline void Free( T2 *const p, int size ) { - for ( int i = 0; i < size; ++i ) { - p[i].~T2(); - } + for ( int i = 0; i < size; ++i ) p[i].~T2(); std::free( p ); } #endif @@ -205,19 +197,19 @@ namespace AliHLTInternal /** * Array base class for dimension dependent behavior */ - template class ArrayBase; + template class AliHLTArrayBase; /** * 1-dim arrays only have operator[] */ template - class ArrayBase : public AliArrayBoundsCheck + class AliHLTArrayBase : public AliArrayBoundsCheck { - friend class ArrayBase; + friend class AliHLTArrayBase; // declare friend public: - ArrayBase() : fData( 0 ), fSize( 0 ) {} // XXX really shouldn't be done. But -Weffc++ wants it so - ArrayBase( const ArrayBase &rhs ) : AliArrayBoundsCheck( rhs ), fData( rhs.fData ), fSize( rhs.fSize ) {} // XXX - ArrayBase &operator=( const ArrayBase &rhs ) { AliArrayBoundsCheck::operator=( rhs ); fData = rhs.fData; return *this; } // XXX + AliHLTArrayBase() : fData( 0 ), fSize( 0 ) {} // XXX really shouldn't be done. But -Weffc++ wants it so + AliHLTArrayBase( const AliHLTArrayBase &rhs ) : AliArrayBoundsCheck( rhs ), fData( rhs.fData ), fSize( rhs.fSize ) {} // XXX + AliHLTArrayBase &operator=( const AliHLTArrayBase &rhs ) { AliArrayBoundsCheck::operator=( rhs ); fData = rhs.fData; return *this; } // XXX typedef typename ReturnTypeHelper::Type R; /** * return a reference to the value at the given index @@ -239,13 +231,13 @@ namespace AliHLTInternal * operator[] can be used to return a 1-dim array */ template - class ArrayBase : public AliArrayBoundsCheck + class AliHLTArrayBase : public AliArrayBoundsCheck { - friend class ArrayBase; + friend class AliHLTArrayBase; // declare friend public: - ArrayBase() : fData( 0 ), fSize( 0 ), fStride( 0 ) {} // XXX really shouldn't be done. But -Weffc++ wants it so - ArrayBase( const ArrayBase &rhs ) : AliArrayBoundsCheck( rhs ), fData( rhs.fData ), fSize( rhs.fSize ), fStride( rhs.fStride ) {} // XXX - ArrayBase &operator=( const ArrayBase &rhs ) { AliArrayBoundsCheck::operator=( rhs ); fData = rhs.fData; fSize = rhs.fSize; fStride = rhs.fStride; return *this; } // XXX + AliHLTArrayBase() : fData( 0 ), fSize( 0 ), fStride( 0 ) {} // XXX really shouldn't be done. But -Weffc++ wants it so + AliHLTArrayBase( const AliHLTArrayBase &rhs ) : AliArrayBoundsCheck( rhs ), fData( rhs.fData ), fSize( rhs.fSize ), fStride( rhs.fStride ) {} // XXX + AliHLTArrayBase &operator=( const AliHLTArrayBase &rhs ) { AliArrayBoundsCheck::operator=( rhs ); fData = rhs.fData; fSize = rhs.fSize; fStride = rhs.fStride; return *this; } // XXX typedef typename ReturnTypeHelper::Type R; /** * return a reference to the value at the given indexes @@ -276,12 +268,12 @@ namespace AliHLTInternal * operator[] can be used to return a 2-dim array */ template - class ArrayBase : public AliArrayBoundsCheck + class AliHLTArrayBase : public AliArrayBoundsCheck { public: - ArrayBase() : fData( 0 ), fSize( 0 ), fStrideX( 0 ), fStrideY( 0 ) {} // XXX really shouldn't be done. But -Weffc++ wants it so - ArrayBase( const ArrayBase &rhs ) : AliArrayBoundsCheck( rhs ), fData( rhs.fData ), fSize( rhs.fSize ), fStrideX( rhs.fStrideX ), fStrideY( rhs.fStrideY ) {} // XXX - ArrayBase &operator=( const ArrayBase &rhs ) { AliArrayBoundsCheck::operator=( rhs ); fData = rhs.fData; fSize = rhs.fSize; fStrideX = rhs.fStrideX; fStrideY = rhs.fStrideY; return *this; } // XXX + AliHLTArrayBase() : fData( 0 ), fSize( 0 ), fStrideX( 0 ), fStrideY( 0 ) {} // XXX really shouldn't be done. But -Weffc++ wants it so + AliHLTArrayBase( const AliHLTArrayBase &rhs ) : AliArrayBoundsCheck( rhs ), fData( rhs.fData ), fSize( rhs.fSize ), fStrideX( rhs.fStrideX ), fStrideY( rhs.fStrideY ) {} // XXX + AliHLTArrayBase &operator=( const AliHLTArrayBase &rhs ) { AliArrayBoundsCheck::operator=( rhs ); fData = rhs.fData; fSize = rhs.fSize; fStrideX = rhs.fStrideX; fStrideY = rhs.fStrideY; return *this; } // XXX // Stopped working on GCC 4.5.0 //typedef typename ReturnTypeHelper::Type R; /** @@ -320,9 +312,7 @@ namespace AliHLTInternal ~AlignedData() { const int offset = reinterpret_cast( &fUnalignedArray[0] ) & ( Alignment - 1 ); T *mem = reinterpret_cast( &fUnalignedArray[0] + ( Alignment - offset ) ); - for ( unsigned int i = 0; i < Size; ++i ) { - mem[i].~T(); - } + for ( unsigned int i = 0; i < Size; ++i ) mem[i].~T(); } private: enum { @@ -343,13 +333,13 @@ namespace AliHLTInternal } // namespace AliHLTInternal /** - * C-Array like class with the dimension dependent behavior defined in the ArrayBase class + * C-Array like class with the dimension dependent behavior defined in the AliHLTArrayBase class */ template < typename T, int Dim = 1 > -class AliHLTArray : public AliHLTInternal::ArrayBase +class AliHLTArray : public AliHLTInternal::AliHLTArrayBase { public: - typedef AliHLTInternal::ArrayBase Parent; + typedef AliHLTInternal::AliHLTArrayBase Parent; /** * Returns the number of elements in the array. If it is a multi-dimensional array the size is @@ -442,7 +432,7 @@ class AliHLTResizableArray : public AliHLTArray::Type T2; - typedef AliHLTInternal::ArrayBase Parent; + typedef AliHLTInternal::AliHLTArrayBase Parent; /** * does not allocate any memory */ @@ -523,7 +513,7 @@ class AliHLTFixedArray : public AliHLTArray::Type T2; - typedef AliHLTInternal::ArrayBase Parent; + typedef AliHLTInternal::AliHLTArrayBase Parent; inline AliHLTFixedArray() { Parent::fData = fFixedArray.ConstructAlignedData(); Parent::SetBounds( 0, Size::Size - 1 ); @@ -566,7 +556,7 @@ namespace AliHLTInternal #endif template - inline AliHLTArray ArrayBase::operator[]( int x ) + inline AliHLTArray AliHLTArrayBase::operator[]( int x ) { x *= fStride; typedef AliHLTArray AT1; @@ -579,7 +569,7 @@ namespace AliHLTInternal } template - inline const AliHLTArray ArrayBase::operator[]( int x ) const + inline const AliHLTArray AliHLTArrayBase::operator[]( int x ) const { x *= fStride; typedef AliHLTArray AT1; @@ -592,19 +582,19 @@ namespace AliHLTInternal } template - inline typename AliHLTInternal::ReturnTypeHelper::Type &ArrayBase::operator()( int x, int y, int z ) + inline typename AliHLTInternal::ReturnTypeHelper::Type &AliHLTArrayBase::operator()( int x, int y, int z ) { BOUNDS_CHECK( x * fStrideX + y + fStrideY + z, fData[0] ); return fData[x * fStrideX + y + fStrideY + z]; } template - inline const typename AliHLTInternal::ReturnTypeHelper::Type &ArrayBase::operator()( int x, int y, int z ) const + inline const typename AliHLTInternal::ReturnTypeHelper::Type &AliHLTArrayBase::operator()( int x, int y, int z ) const { BOUNDS_CHECK( x * fStrideX + y + fStrideY + z, fData[0] ); return fData[x * fStrideX + y + fStrideY + z]; } template - inline AliHLTArray ArrayBase::operator[]( int x ) + inline AliHLTArray AliHLTArrayBase::operator[]( int x ) { x *= fStrideX; typedef AliHLTArray AT2; @@ -617,7 +607,7 @@ namespace AliHLTInternal return a; } template - inline const AliHLTArray ArrayBase::operator[]( int x ) const + inline const AliHLTArray AliHLTArrayBase::operator[]( int x ) const { x *= fStrideX; typedef AliHLTArray AT2;