TRefArray


class description - source file - inheritance tree

class TRefArray : public TSeqCollection


    protected:
Bool_t BoundsOk(const char* where, Int_t at) const Int_t GetAbsLast() const void Init(Int_t s, Int_t lowerBound) Bool_t OutOfBoundsError(const char* where, Int_t i) const public:
TRefArray TRefArray() TRefArray TRefArray(Int_t s, Int_t lowerBound = 0) TRefArray TRefArray(const TRefArray& a) virtual void ~TRefArray() virtual void Add(TObject* obj) virtual void AddAfter(TObject* after, TObject* obj) virtual void AddAt(TObject* obj, Int_t idx) virtual void AddAtAndExpand(TObject* obj, Int_t idx) virtual Int_t AddAtFree(TObject* obj) virtual void AddBefore(TObject* before, TObject* obj) virtual void AddFirst(TObject* obj) virtual void AddLast(TObject* obj) virtual TObject* After(TObject* obj) const virtual TObject* At(Int_t idx) const virtual TObject* Before(TObject* obj) const virtual Int_t BinarySearch(TObject* obj, Int_t upto = kMaxInt) static TClass* Class() virtual void Clear(Option_t* option) virtual void Compress() virtual void Delete(Option_t* option) virtual void Expand(Int_t newSize) virtual TObject* First() const Int_t GetEntries() const Int_t GetEntriesFast() const Int_t GetLast() const virtual TObject** GetObjectRef(const TObject* obj) const TProcessID* GetPID() const UInt_t GetUID(Int_t at) const virtual Int_t IndexOf(const TObject* obj) const virtual TClass* IsA() const virtual Bool_t IsEmpty() const virtual TObject* Last() const Int_t LowerBound() const virtual TIterator* MakeIterator(Bool_t dir = kIterForward) const virtual TObject* operator[](Int_t i) const virtual TObject* Remove(TObject* obj) virtual TObject* RemoveAt(Int_t idx) void SetLast(Int_t last) virtual void ShowMembers(TMemberInspector& insp, char* parent) virtual void Sort(Int_t upto = kMaxInt) virtual void Streamer(TBuffer& b) void StreamerNVirtual(TBuffer& b)

Data Members


    protected:
TProcessID* fPID Pointer to Process Unique Identifier UInt_t* fUIDs [fSize] To store uids of referenced objects Int_t fLowerBound Lower bound of the array Int_t fLast Last element in array containing an object

Class Description

                                                                      
 TRefArray                                                            
                                                                      
 An array of references to TObjects. The array expands automatically  
 when  objects are added (shrinking can be done by hand using Expand()
                                                                      
 The TRefArray can be filled with:                                    
     array.Add(obj)                                                   
     array.AddAt(obj,i)                                               
     but not array[i] = obj  !!!                                      
                                                                      
 The array elements can be retrieved with:                            
     TObject *obj = array.At(i);                                      
                                                                      
 When a TRefArray is Streamed, only the pointer unique id is written, 
 not the referenced object. TRefArray may be assigned to different    
 branches of one Tree or several Trees.                               
 The branch containing the TRefArray can be read before or after the  
 array (eg TClonesArray, STL vector,..) of the referenced objects.    
                                                                      
 See an example in $ROOTSYS/test/Event.h                              
                                                                      
 RESTRICTIONS when using TRefArray                                    
 ---------------------------------                                    
  - Elements in a TRefArray cannot point to a TFile or TDirectory.    
  - All elements of a TRefArray must be set in the same process,      
    In particular, one cannot modify some elements of the array in    
    a different process.                                              
 Use an array of TRef when one of the above restrictions is met.      
                                                                      


TRefArray()
 default constructor

TRefArray(Int_t s, Int_t lowerBound)
 Create an object array. Using s one can set the array size
 and lowerBound can be used to set the array lowerbound
 index (default is 0).

TRefArray(const TRefArray &a) : TSeqCollection()
 Create a copy of TRefArray a. Note, does not copy the kIsOwner flag.

~TRefArray()
 Delete an array. Objects are not deleted unless the TRefArray is the
 owner (set via SetOwner()).

void AddFirst(TObject *obj)
 Add object in the first slot of the array. This will overwrite the
 first element that might have been there. To have insertion semantics
 use either a TList or a TOrdCollection.

void AddLast(TObject *obj)
 Add object in the next empty slot in the array. Expand the array
 if necessary.

void AddBefore(TObject *before, TObject *obj)
 Add object in the slot before object before. If before=0 add object
 in the first slot. Note that this will overwrite any object that
 might have already been in this slot. For insertion semantics use
 either a TList or a TOrdCollection.

void AddAfter(TObject *after, TObject *obj)
 Add object in the slot after object after. If after=0 add object in
 the last empty slot. Note that this will overwrite any object that
 might have already been in this slot. For insertion semantics use
 either a TList or a TOrdCollection.

void AddAtAndExpand(TObject *obj, Int_t idx)
 Add object at position idx. If idx is larger than the current size
 of the array, expand the array (double its size).

void AddAt(TObject *obj, Int_t idx)
 Add object at position ids. Give an error when idx is out of bounds
 (i.e. the array is not expanded).

Int_t AddAtFree(TObject *obj)
 Return the position of the new object.
 Find the first empty cell or AddLast if there is no empty cell

TObject* After(TObject *obj) const
 Return the object after obj. Returns 0 if obj is last object.

TObject* Before(TObject *obj) const
 Return the object before obj. Returns 0 if obj is first object.

void Clear(Option_t *)
 Remove all objects from the array. Does not delete the objects
 unless the TRefArray is the owner (set via SetOwner()).

void Compress()
 Remove empty slots from array.

void Delete(Option_t *)
 Remove all objects from the array.

void Expand(Int_t newSize)
 Expand or shrink the array to newSize elements.

void Streamer(TBuffer &R__b)
 Stream all objects in the array to or from the I/O buffer.

TObject* First() const
 Return the object in the first slot.

TObject* Last() const
 Return the object in the last filled slot. Returns 0 if no entries.

Int_t GetEntries() const
 Return the number of objects in array (i.e. number of non-empty slots).
 Attention: use this method ONLY if you want to know the number of
 non-empty slots. This function loops over the complete array and
 is therefore very slow when applied in a loop. Most of the time you
 better use GetLast()+1.

Int_t GetAbsLast() const
 Return absolute index to last object in array. Returns -1 in case
 array is empty.

Int_t GetLast() const
 Return index of last object in array. Returns lowerBound-1 in case
 array is empty.

TObject** GetObjectRef(const TObject *) const
 Return address of pointer obj.

UInt_t GetUID(Int_t at) const
 Return UID of element at.

Int_t IndexOf(const TObject *) const
 obj != 0 Return index of object in array.
          Returns lowerBound-1 in case array doesn't contain the obj.

 obj == 0 Return the index of the first empty slot.
          Returns lowerBound-1 in case array doesn't contain any empty slot.

void Init(Int_t s, Int_t lowerBound)
 Initialize a TRefArray.

TIterator* MakeIterator(Bool_t dir) const
 Returns an array iterator.

Bool_t OutOfBoundsError(const char *where, Int_t i) const
 Generate an out-of-bounds error. Always returns false.

TObject* RemoveAt(Int_t idx)
 Remove object at index idx.

TObject* Remove(TObject *obj)
 Remove object from array.

void SetLast(Int_t last)
 Set index of last object in array, effectively truncating the
 array. Use carefully since whenever last position has to be
 recalculated, e.g. after a Remove() or Sort() it will be reset
 to the last non-empty slot. If last is -2 this will force the
 recalculation of the last used slot.

void Sort(Int_t)
 If objects in array are sortable (i.e. IsSortable() returns true
 for all objects) then sort array.

Int_t BinarySearch(TObject *, Int_t)
 Find object using a binary search. Array must first have been sorted.
 Search can be limited by setting upto to desired index.



Inline Functions


             Bool_t BoundsOk(const char* where, Int_t at) const
              Int_t GetEntriesFast() const
        TProcessID* GetPID() const
             Bool_t IsEmpty() const
               void Add(TObject* obj)
           TObject* At(Int_t idx) const
           TObject* operator[](Int_t i) const
              Int_t LowerBound() const
            TClass* Class()
            TClass* IsA() const
               void ShowMembers(TMemberInspector& insp, char* parent)
               void StreamerNVirtual(TBuffer& b)


Author: Rene Brun 02/10/2001
Last update: root/cont:$Name: $:$Id: TRefArray.cxx,v 1.17 2002/12/02 18:50:02 rdm Exp $
Copyright (C) 1995-2001, Rene Brun and Fons Rademakers. *


ROOT page - Class index - Top of the page

This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.