TList


class description - source file - inheritance tree

class TList : public TSeqCollection


    protected:
virtual void DeleteLink(TObjLink* lnk) TObjLink** DoSort(TObjLink** head, Int_t n) TObjLink* FindLink(TObject* obj, Int_t& idx) const TObjLink* LinkAt(Int_t idx) const Bool_t LnkCompare(TObjLink* l1, TObjLink* l2) virtual TObjLink* NewLink(TObject* obj, TObjLink* prev = 0) virtual TObjLink* NewOptLink(TObject* obj, Option_t* opt, TObjLink* prev = 0) public:
TList TList() TList TList(TObject* parent) virtual void ~TList() virtual void Add(TObject* obj) virtual void Add(TObject* obj, Option_t* opt) virtual void AddAfter(TObjLink* after, TObject* obj) virtual void AddAfter(TObject* after, TObject* obj) virtual void AddAt(TObject* obj, Int_t idx) virtual void AddBefore(TObjLink* before, TObject* obj) virtual void AddBefore(TObject* before, TObject* obj) virtual void AddFirst(TObject* obj) virtual void AddFirst(TObject* obj, Option_t* opt) virtual void AddLast(TObject* obj) virtual void AddLast(TObject* obj, Option_t* opt) virtual TObject* After(TObject* obj) const virtual TObject* At(Int_t idx) const virtual TObject* Before(TObject* obj) const TClass* Class() virtual void Clear(Option_t* option) virtual void Delete(Option_t* option) virtual TObject* FindObject(const Text_t* name) const virtual TObject* FindObject(TObject* obj) const virtual TObject* First() const virtual TObjLink* FirstLink() const virtual TClass* IsA() const Bool_t IsAscending() virtual TObject* Last() const virtual TObjLink* LastLink() const virtual TIterator* MakeIterator(Bool_t dir = kIterForward) const virtual TObject* Remove(TObject* obj) virtual TObject* Remove(TObjLink* lnk) virtual void ShowMembers(TMemberInspector& insp, char* parent) virtual void Sort(Bool_t order = kSortAscending) virtual void Streamer(TBuffer& b)

Data Members

protected:
TObjLink* fFirst pointer to first entry in linked list TObjLink* fLast pointer to last entry in linked list TObjLink* fCache cache to speedup sequential calling of Before() and After() functions Bool_t fAscending sorting order (when calling Sort() or for TSortedList)


See also

THashList, TSortedList

Class Description

                                                                      
 TList                                                                
                                                                      
 A doubly linked list. All classes inheriting from TObject can be     
 inserted in a TList. Before being inserted into the list the object  
 pointer is wrapped in a TObjLink object which contains, besides      
 the object pointer also a previous and next pointer.                 
                                                                      
 There are basically four ways to iterate over a TList (in order      
 of preference, if not forced by other constraints):                  
    1) Using the ForEach macro:                                       
         GetListOfPrimitives()->ForEach(TObject,Paint)(option);       
                                                                      
    2) Using the TList iterator TListIter (via the wrapper class      
       TIter):                                                        
         TIter next(GetListOfPrimitives());                           
         while (TObject *obj = next())                                
            obj->Draw(next.GetOption());                              
                                                                      
    3) Using the TObjLink list entries (that wrap the TObject*):      
         TObjLink *lnk = GetListOfPrimitives()->FirstLink();          
         while (lnk) {                                                
            lnk->GetObject()->Draw(lnk->GetOption());                 
            lnk = lnk->Next();                                        
         }                                                            
                                                                      
    4) Using the TList's After() and Before() member functions:       
         TFree *idcur = this;                                         
         while (idcur) {                                              
            ...                                                       
            ...                                                       
            idcur = (TFree*)GetListOfFree()->After(idcur);            
         }                                                            
                                                                      
   Methods 2, 3 and 4 can also easily iterate backwards using either  
   a backward TIter (using argument kIterBackward) or by using        
   LastLink() and lnk->Prev() or by using the Before() member.        
                             
                                                                      


~TList()
 Delete the list. Objects are not deleted.

void AddFirst(TObject *obj)
 Add object at the beginning of the list.

void AddFirst(TObject *obj, Option_t *opt)
 Add object at the beginning of the list and also store option.
 Storing an option is useful when one wants to change the behaviour
 of an object a little without having to create a complete new
 copy of the object. This feature is used, for example, by the Draw()
 method. It allows the same object to be drawn in different ways.

void AddLast(TObject *obj)
 Add object at the end of the list.

void AddLast(TObject *obj, Option_t *opt)
 Add object at the end of the list and also store option.
 Storing an option is useful when one wants to change the behaviour
 of an object a little without having to create a complete new
 copy of the object. This feature is used, for example, by the Draw()
 method. It allows the same object to be drawn in different ways.

void AddBefore(TObject *before, TObject *obj)
 Insert object before object before in the list.

void AddBefore(TObjLink *before, TObject *obj)
 Insert object before the specified ObjLink object. If before = 0 then add
 to the head of the list. An ObjLink can be obtained by looping over a list
 using the above describe iterator method 3.

void AddAfter(TObject *after, TObject *obj)
 Insert object after object after in the list.

void AddAfter(TObjLink *after, TObject *obj)
 Insert object after the specified ObjLink object. If after = 0 then add
 to the tail of the list. An ObjLink can be obtained by looping over a list
 using the above describe iterator method 3.

void AddAt(TObject *obj, Int_t idx)
 Insert object at position idx in the list.

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

TObject* At(Int_t idx) const
 Returns the object at position idx. Returns 0 if idx is out of range.

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

void Clear(Option_t *option)
 Remove all objects from the list. Does not delete the objects.

void Delete(Option_t *)
 Remove all objects from the list AND delete all heap based objects.

void DeleteLink(TObjLink *lnk)
 Delete a TObjLink object.

TObject* FindObject(const Text_t *name) const
 Find an object in this list using its name. Requires a sequential
 scan till the object has been found. Returns 0 if object with specified
 name is not found. This method overrides the generic FindObject()
 of TCollection for efficiency reasons.

TObject* FindObject(TObject *obj) const
 Find an object in this list using the object's IsEqual()
 member function. Requires a sequential scan till the object has
 been found. Returns 0 if object is not found.
 This method overrides the generic FindObject() of TCollection for
 efficiency reasons.

TObjLink* FindLink(TObject *obj, Int_t &idx) const
 Returns the TObjLink object that contains object obj. In idx it returns
 the position of the object in the list.

TObject* First() const
 Return the first object in the list. Returns 0 when list is empty.

TObject* Last() const
 Return the last object in the list. Returns 0 when list is empty.

TObjLink* LinkAt(Int_t idx) const
 Return the TObjLink object at index idx.

TIterator* MakeIterator(Bool_t dir) const
 Return a list iterator.

TObjLink* NewLink(TObject *obj, TObjLink *prev)
 Return a new TObjLink.

TObjLink* NewOptLink(TObject *obj, Option_t *opt, TObjLink *prev)
 Return a new TObjOptLink (a TObjLink that also stores the option).

TObject* Remove(TObject *obj)
 Remove object from the list.

TObject* Remove(TObjLink *lnk)
 Remove object link (and therefore the object it contains)
 from the list.

void Sort(Bool_t order)
 Sort linked list. Real sorting is done in private function DoSort().
 The list can only be sorted when is contains objects of a sortable
 class.

Bool_t LnkCompare(TObjLink *l1, TObjLink *l2)
 Compares the objects stored in the TObjLink objects.
 Depending on the flag IsAscending() the function returns
 true if the object in l1 <= l2 (ascending) or l2 <= l1 (descending).

TObjLink** DoSort(TObjLink **head, Int_t n)
 Sort linked list.



Inline Functions


              TList TList()
              TList TList(TObject* parent)
               void Add(TObject* obj)
               void Add(TObject* obj, Option_t* opt)
          TObjLink* FirstLink() const
          TObjLink* LastLink() const
             Bool_t IsAscending()
            TClass* Class()
            TClass* IsA() const
               void ShowMembers(TMemberInspector& insp, char* parent)
               void Streamer(TBuffer& b)


Author: Fons Rademakers 10/08/95
Last update: 2.23/08 01/11/99 21.38.07 by Fons Rademakers
Copyright (c) 1995-1999, The ROOT System, All rights reserved. *


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.