library: libCore #include "TList.h"

# TList

class description - source file - inheritance tree (.ps)

## class TList : public TSeqCollection

| Inheritance Chart:

`TObject`

<-

`TCollection`

<-

`TSeqCollection`

<-

`TList`

<-

`THashList` |

`TQCommand`

<-

`TQUndoManager` |

`TQConnection` |

`TSortedList` |

        protected:

               virtual void DeleteLink(TObjLink* lnk)
                 TObjLink** DoSort(TObjLink** head, Int_t n)
                  TObjLink* FindLink(const 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(TObject*)
                     virtual ~TList()
                virtual void Add(TObject* obj)
                virtual void Add(TObject* obj, Option_t* opt)
                virtual void AddAfter(TObject* after, TObject* obj)
                virtual void AddAfter(TObjLink* after, TObject* obj)
                virtual void AddAt(TObject* obj, Int_t idx)
                virtual void AddBefore(TObject* before, TObject* obj)
                virtual void AddBefore(TObjLink* 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
              static TClass* Class()
                virtual void Clear(Option_t* option)
                virtual void Delete(Option_t* option)
            virtual TObject* FindObject(const char* name) const
            virtual TObject* FindObject(const TObject* obj) const
            virtual TObject* First() const
           virtual TObjLink* FirstLink() const
           virtual TObject** GetObjectRef(const TObject* obj) 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)
                        void StreamerNVirtual(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)

## 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 unless the TList is the
     owner (set via SetOwner()).

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
     unless the TList is the owner (set via SetOwner()) and option
     "nodelete" is not set.
     If option="nodelete" then don't delete any heap objects that were
     marked with the kCanDelete bit, otherwise these objects will be
     deleted (this option is used by THashTable::Clear()).

void Delete(Option_t *option)

     Remove all objects from the list AND delete all heap based objects.
     If option="slow" then keep list consistent during delete. This allows
     recursive list operations during the delete (e.g. during the dtor
     of an object in this list one can still access the list to search for
     other not yet deleted objects).

void DeleteLink(TObjLink *lnk)

     Delete a TObjLink object.

TObject* FindObject(const char *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(const 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(const 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** GetObjectRef(const TObject *obj) const

     Return address of pointer to obj

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.

void Streamer(TBuffer &b)

     Stream all objects in the collection to or from the I/O buffer.

### Inline Functions

                  TList TList()
                  TList TList(TObject*)
                   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 StreamerNVirtual(TBuffer& b)

Author: Fons Rademakers 10/08/95
Last update: root/cont:$Name: $:$Id: TList.cxx,v 1.13 2002/07/29 09:22:29 rdm Exp $
Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *