#ifndef ROOT_TList
#define ROOT_TList
#ifndef ROOT_TSeqCollection
#include "TSeqCollection.h"
#endif
#ifndef ROOT_TString
#include "TString.h"
#endif
#include <iterator>
const Bool_t kSortAscending = kTRUE;
const Bool_t kSortDescending = !kSortAscending;
class TObjLink;
class TListIter;
class TList : public TSeqCollection {
friend class TListIter;
protected:
TObjLink *fFirst;
TObjLink *fLast;
TObjLink *fCache;
Bool_t fAscending;
TObjLink *LinkAt(Int_t idx) const;
TObjLink *FindLink(const TObject *obj, Int_t &idx) const;
TObjLink **DoSort(TObjLink **head, Int_t n);
Bool_t LnkCompare(TObjLink *l1, TObjLink *l2);
virtual TObjLink *NewLink(TObject *obj, TObjLink *prev = NULL);
virtual TObjLink *NewOptLink(TObject *obj, Option_t *opt, TObjLink *prev = NULL);
virtual void DeleteLink(TObjLink *lnk);
private:
TList(const TList&);
TList& operator=(const TList&);
public:
typedef TListIter Iterator_t;
TList() : fFirst(0), fLast(0), fCache(0), fAscending(kTRUE) { }
TList(TObject *) : fFirst(0), fLast(0), fCache(0), fAscending(kTRUE) { }
virtual ~TList();
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 TIterator *MakeIterator(Bool_t dir = kIterForward) const;
virtual void Add(TObject *obj) { AddLast(obj); }
virtual void Add(TObject *obj, Option_t *opt) { AddLast(obj, opt); }
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 void AddAt(TObject *obj, Int_t idx);
virtual void AddAfter(const TObject *after, TObject *obj);
virtual void AddAfter(TObjLink *after, TObject *obj);
virtual void AddBefore(const TObject *before, TObject *obj);
virtual void AddBefore(TObjLink *before, TObject *obj);
virtual TObject *Remove(TObject *obj);
virtual TObject *Remove(TObjLink *lnk);
virtual void RecursiveRemove(TObject *obj);
virtual TObject *At(Int_t idx) const;
virtual TObject *After(const TObject *obj) const;
virtual TObject *Before(const TObject *obj) const;
virtual TObject *First() const;
virtual TObjLink *FirstLink() const { return fFirst; }
virtual TObject **GetObjectRef(const TObject *obj) const;
virtual TObject *Last() const;
virtual TObjLink *LastLink() const { return fLast; }
virtual void Sort(Bool_t order = kSortAscending);
Bool_t IsAscending() { return fAscending; }
ClassDef(TList,5)
};
class TObjLink {
friend class TList;
private:
TObjLink *fNext;
TObjLink *fPrev;
TObject *fObject;
TObjLink(const TObjLink&);
TObjLink& operator=(const TObjLink&);
protected:
TObjLink() : fNext(NULL), fPrev(NULL), fObject(NULL) { fNext = fPrev = this; }
public:
TObjLink(TObject *obj) : fNext(NULL), fPrev(NULL), fObject(obj) { }
TObjLink(TObject *obj, TObjLink *lnk);
virtual ~TObjLink() { }
TObject *GetObject() const { return fObject; }
TObject **GetObjectRef() { return &fObject; }
void SetObject(TObject *obj) { fObject = obj; }
virtual Option_t *GetAddOption() const { return ""; }
virtual Option_t *GetOption() const { return fObject->GetOption(); }
virtual void SetOption(Option_t *) { }
TObjLink *Next() { return fNext; }
TObjLink *Prev() { return fPrev; }
};
class TObjOptLink : public TObjLink {
private:
TString fOption;
public:
TObjOptLink(TObject *obj, Option_t *opt) : TObjLink(obj), fOption(opt) { }
TObjOptLink(TObject *obj, TObjLink *lnk, Option_t *opt) : TObjLink(obj, lnk), fOption(opt) { }
~TObjOptLink() { }
Option_t *GetAddOption() const { return fOption.Data(); }
Option_t *GetOption() const { return fOption.Data(); }
void SetOption(Option_t *option) { fOption = option; }
};
class TListIter : public TIterator,
public std::iterator<std::bidirectional_iterator_tag,
TObject*, std::ptrdiff_t,
const TObject**, const TObject*&> {
protected:
const TList *fList;
TObjLink *fCurCursor;
TObjLink *fCursor;
Bool_t fDirection;
Bool_t fStarted;
TListIter() : fList(0), fCurCursor(0), fCursor(0), fDirection(kIterForward),
fStarted(kFALSE) { }
public:
TListIter(const TList *l, Bool_t dir = kIterForward);
TListIter(const TListIter &iter);
~TListIter() { }
TIterator &operator=(const TIterator &rhs);
TListIter &operator=(const TListIter &rhs);
const TCollection *GetCollection() const { return fList; }
Option_t *GetOption() const;
void SetOption(Option_t *option);
TObject *Next();
void Reset();
bool operator!=(const TIterator &aIter) const;
bool operator!=(const TListIter &aIter) const;
TObject *operator*() const { return (fCurCursor ? fCurCursor->GetObject() : nullptr); }
ClassDef(TListIter,0)
};
#endif