3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * See cxx source for full Copyright notice */
7 ///////////////////////////////////////////////////////////////////////////////
10 // (Pseudo)Container optimised for fast random access operator[ ]. //
11 // Operator [] time doesn
\92t depend on the number of elements in container O(1) -
12 // like in standard array or like in STL vector
13 ///////////////////////////////////////////////////////////////////////////////
16 class AliMemArray: public TObject {
19 AliMemArray(Int_t objectSize, Int_t buffersize=0);
20 AliMemArray(const AliMemArray & arr);
21 AliMemArray & operator = (const AliMemArray &arr);
22 virtual ~AliMemArray();
23 void Swap(AliMemArray & arr);
25 inline void * UncheckedAt(UInt_t index) const; //
26 inline void * At(UInt_t i) const ; //controled return pointer to object
27 inline void * Unchecked1DAt(UInt_t i) const; //return pointer to the object
28 inline void * Unchecked2DAt(UInt_t i) const ; //return pointer to the object
29 inline void * Unchecked2DAt(UInt_t i, UInt_t j) const ; //return pointer to the object
31 Bool_t Is1D(){return (fBufferSize==0);} //true if 1D array
32 Bool_t Is2D(){return (fBufferSize!=0);} //true if 2D array
34 const void * GetArray()const {return fCont;} //return pointer to the buffer
35 void * GetRow(UInt_t row)const {return fBufferSize? ((void**)fCont)[row]: fCont;}
37 // return pointer to the object
39 const UInt_t GetCapacity() const {return fCapacity;} //return number of stored objects
40 const UInt_t GetSize() const {return fSize;} //return number of stored objects
42 void Delete(Option_t *option="");
43 //delete memory space occupated by the array
44 void Clear(Option_t *option="");
45 //clear memory space occupied by the array - doesn't call destructor
46 void Resize(UInt_t n);
47 void Reserve(UInt_t n);
49 const UInt_t GetBufferSize() const {return fBufferSize;}
50 const UInt_t GetObjectSize() const {return fObjectSize;}
51 const UInt_t GetNBuffers() const {return fBufferSize? fCapacity/fBufferSize :1;}
52 void SetBufferSize(UInt_t bufsize);
54 void SetObjectSize(UInt_t size);
55 void Delete2D(); //delete memory space occupated by the array
56 void Clear2D(); //clear memory space occupated by the array
57 void Resize2D(UInt_t n);
58 void Reserve2D(UInt_t n);
61 virtual void CTORBuffer(void *buffer, UInt_t size){;} //array placement constructor
62 virtual void DTORBuffer(void *buffer, UInt_t size){;} //array placement destructor
63 virtual void CopyBuffer(void *src, void *dest, UInt_t size); //array placement copy constructor
64 UInt_t fSize; //total number of valid objects
65 UInt_t fCapacity; //capacity of array
66 UInt_t fObjectSize; // object size
67 UInt_t fBufferSize; //number of object in one full buffer (0 means array in one buffer)
70 void * fCont; //!data buffer
71 ClassDef(AliMemArray,0)
74 void * AliMemArray::Unchecked1DAt(UInt_t i) const
76 return &(((char*)fCont)[fObjectSize*i]);
79 void * AliMemArray::Unchecked2DAt(UInt_t i, UInt_t j) const
81 return &( ((char**)fCont)[i] [j*fObjectSize]);
84 //********************************************************************
85 void * AliMemArray::Unchecked2DAt(UInt_t i) const
88 // called in GePointer if we have more then one buffer
89 return &( ((char**)fCont)[i/fBufferSize] [(i%fBufferSize)*fObjectSize]) ;
92 void * AliMemArray::UncheckedAt(UInt_t i) const
95 return (!fBufferSize) ?Unchecked1DAt(i): Unchecked2DAt(i);
98 void * AliMemArray::At(UInt_t i) const
100 return (i<fSize) ? UncheckedAt(i):0; //controled return pointer to object