81 namespace std {}
using namespace std;
101 if (IsArgNull(
"AddFirst", obj))
return;
109 auto t = NewLink(obj);
129 if (IsArgNull(
"AddFirst", obj))
return;
134 fFirst = NewOptLink(obj, opt);
137 auto t = NewOptLink(obj, opt);
153 if (IsArgNull(
"AddLast", obj))
return;
161 fLast = NewLink(obj, fLast);
177 if (IsArgNull(
"AddLast", obj))
return;
182 fFirst = NewOptLink(obj, opt);
185 fLast = NewOptLink(obj, opt, fLast);
197 if (IsArgNull(
"AddBefore", obj))
return;
205 TObjLink *t = FindLink(before, idx);
207 Error(
"AddBefore",
"before not found, object not added");
213 NewLink(obj, t->
fPrev.lock());
229 if (IsArgNull(
"AddBefore", obj))
return;
234 if (before ==
fFirst.get())
237 NewLink(obj, before->
fPrev.lock());
251 if (IsArgNull(
"AddAfter", obj))
return;
261 Error(
"AddAfter",
"after not found, object not added");
264 if (t == fLast.get())
267 NewLink(obj, t->shared_from_this());
283 if (IsArgNull(
"AddAfter", obj))
return;
290 if (after == fLast.get())
293 NewLink(obj, after->shared_from_this());
307 if (IsArgNull(
"AddAt", obj))
return;
314 else if (lnk ==
fFirst.get())
317 NewLink(obj, lnk->
fPrev.lock());
335 auto cached = fCache.lock();
336 if (cached.get() && cached->GetObject() && cached->GetObject()->IsEqual(obj)) {
341 t = FindLink(obj, idx);
375 auto cached = fCache.lock();
376 if (cached.get() && cached->GetObject() && cached->GetObject()->IsEqual(obj)) {
381 t = FindLink(obj, idx);
406 if (!nodel && IsOwner()) {
438 auto obj = tlk->GetObject();
440 if (!obj->TestBit(kNotDeleted)) {
441 Error(
"Clear",
"A list is accessing an object (%p) already deleted (list name = %s)",
443 }
else if (obj->IsOnHeap()) {
445 if (obj->TestBit(kNotDeleted)) {
474 TList removeDirectory;
500 auto obj = tlk->GetObject();
501 if (obj && !obj->TestBit(kNotDeleted))
502 Error(
"Delete",
"A list is accessing an object (%p) already deleted (list name = %s)",
504 else if (obj && obj->IsOnHeap())
506 else if (obj && obj->IsA()->GetDirectoryAutoAdd())
507 removeDirectory.Add(obj);
528 auto obj = tlk->GetObject();
529 tlk->SetObject(
nullptr);
530 if (obj && !obj->TestBit(kNotDeleted))
531 Error(
"Delete",
"A list is accessing an object (%p) already deleted (list name = %s)",
533 else if (obj && obj->IsOnHeap())
535 else if (obj && obj->IsA()->GetDirectoryAutoAdd())
536 removeDirectory.Add(obj);
547 TIter iRemDir(&removeDirectory);
549 while ((dirRem = iRemDir())) {
550 (*dirRem->IsA()->GetDirectoryAutoAdd())(dirRem, 0);
558 void TList::DeleteLink(
TObjLink *lnk)
583 for (
TObjLink *lnk = FirstLink(); lnk !=
nullptr; lnk = lnk->
Next()) {
585 const char *objname = obj->GetName();
586 if (objname && strcmp(name, objname) == 0)
614 if (ob->
IsEqual(obj))
return ob;
642 if (object->
TestBit(kNotDeleted)) {
643 if (object->
IsEqual(obj))
return lnk;
694 if (fLast)
return fLast->GetObject();
708 while (i < idx && lnk) {
734 auto newlink = std::make_shared<TObjLink>(obj);
736 InsertAfter(newlink, prev);
749 auto newlink = std::make_shared<TObjOptLink>(obj, opt);
751 InsertAfter(newlink, prev);
769 auto cached = fCache.lock();
770 if (cached && cached->fNext.get() ==
nullptr && cached->fPrev.lock().get() ==
nullptr) {
771 TObject *ob = cached->GetObject();
772 if (ob && ob->
TestBit(kNotDeleted)) {
786 if (ob && ob->
TestBit(kNotDeleted)) {
796 }
else if (lnk == fLast) {
797 fLast = lnk->
fPrev.lock();
798 fLast->fNext.reset();
836 if (lnk ==
fFirst.get()) {
840 if (lnk == fLast.get()) {
846 }
else if (lnk == fLast.get()) {
847 fLast = lnk->
fPrev.lock();
848 fLast->fNext.reset();
876 if (lnk ==
fFirst.get()) {
880 if (lnk == fLast.get()) {
886 }
else if (lnk == fLast.get()) {
887 fLast = lnk->
fPrev.lock();
888 fLast->fNext.reset();
914 if (lnk ==
fFirst.get()) {
918 fLast = lnk->
fPrev.lock();
919 fLast->fNext.reset();
942 if (!
fFirst->GetObject()->IsSortable()) {
943 Error(
"Sort",
"objects in list are not sortable");
950 std::shared_ptr<TObjLink> ol, lnk =
fFirst;
952 if (lnk.get()) lnk->fPrev.reset();
970 Int_t cmp = l1->GetObject()->Compare(l2->GetObject());
972 if ((IsAscending() && cmp <=0) || (!IsAscending() && cmp > 0))
985 std::shared_ptr<TObjLink>
p1,
p2, *h2, *t2;
992 return &((*head)->fNext);
995 p2 = (p1 = *head)->fNext;
996 if (LnkCompare(p1, p2))
return &(p2->fNext);
997 p1->fNext = (*head =
p2)->fNext;
998 return &((p2->fNext =
p1)->fNext);
1004 t2 = DoSort(h2 = DoSort(head, n), m);
1006 if (LnkCompare((p1 = *head), (p2 = *h2))) {
1008 if (!--n)
return *h2 =
p2, t2;
1009 }
while (LnkCompare((p1 = *(head = &(p1->fNext))), p2));
1015 if (!--m)
return *h2 = *t2, *t2 =
p1, h2;
1016 }
while (!LnkCompare(p1, (p2 = *(head = &(p2->fNext)))));
1019 if (!--n)
return *h2 =
p2, t2;
1020 }
while (LnkCompare((p1 = *(head = &(p1->fNext))), p2));
1033 newlink->fNext = prev->fNext;
1034 newlink->fPrev = prev;
1035 prev->fNext = newlink;
1037 newlink->fNext->fPrev = newlink;
1051 : fList(l), fCurCursor(0), fCursor(0), fDirection(dir), fStarted(
kFALSE)
1077 if (
this != &rhs && rhs1) {
1111 if (!
fList)
return 0;
1168 if (IsA() == aIter.IsA()) {
1172 const TListIter &iter(dynamic_cast<const TListIter &>(aIter));
1203 TObject::Streamer(b);
1207 for (
Int_t i = 0; i < nobjects; i++) {
1210 if (v > 4 && nch == 255) {
1215 readOption.resize(nbig,
'\0');
1219 Add(obj,readOption.c_str());
1231 TObject::Streamer(b);
1235 for (
Int_t i = 0; i < nobjects; i++) {
1245 TObject::Streamer(b);
1247 nobjects = GetSize();
std::string GetName(const std::string &scope_name)
virtual void AddAt(TObject *obj, Int_t idx)
Insert object at position idx in the list.
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
#define R__COLLECTION_READ_GUARD()
void InsertAfter(const TObjLinkPtr_t &newlink, const TObjLinkPtr_t &prev)
Insert a new link in the chain.
virtual void RemoveLast()
Remove the last object of the list.
TObjLink * LinkAt(Int_t idx) const
sorting order (when calling Sort() or for TSortedList)
virtual TObject * Last() const
Return the last object in the list. Returns 0 when list is empty.
virtual void AddFirst(TObject *obj)
Add object at the beginning of the list.
Buffer base class used for serializing objects.
virtual Int_t CheckByteCount(UInt_t startpos, UInt_t bcnt, const TClass *clss)=0
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
virtual UInt_t WriteVersion(const TClass *cl, Bool_t useBcnt=kFALSE)=0
TObject * Next()
Return next object in the list. Returns 0 when no more objects in list.
TObject ** GetObjectRef()
Iterator abstract base class.
virtual void AddLast(TObject *obj)
Add object at the end of the list.
virtual TObject * FindObject(const char *name) const
Delete a TObjLink object.
virtual void RecursiveRemove(TObject *obj)
Recursively remove this object from a list.
virtual void Sort(Bool_t order=kSortAscending)
Sort linked list.
Bool_t LnkCompare(const TObjLinkPtr_t &l1, const TObjLinkPtr_t &l2)
Compares the objects stored in the TObjLink objects.
#define R__COLLECTION_WRITE_GUARD()
static double p2(double t, double a, double b, double c)
#define R__COLLECTION_READ_LOCKGUARD(mutex)
R__EXTERN TVirtualRWMutex * gCoreMutex
const Bool_t kIterForward
std::shared_ptr< TObjLink > TObjLinkPtr_t
TObjLinkPtr_t NewOptLink(TObject *obj, Option_t *opt, const TObjLinkPtr_t &prev=nullptr)
Return a new TObjOptLink (a TObjLink that also stores the option).
void Error(const char *location, const char *msgfmt,...)
virtual Bool_t IsEqual(const TObject *obj) const
Default equal comparison (objects are equal if they have the same address in memory).
virtual TIterator * MakeIterator(Bool_t dir=kIterForward) const
Return a list iterator.
virtual ~TList()
Delete the list.
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
virtual TObject * Remove(TObject *obj)
Remove object from the list.
virtual TObject * Before(const TObject *obj) const
Returns the object before object obj.
virtual void SetByteCount(UInt_t cntpos, Bool_t packInVersion=kFALSE)=0
virtual TObject * After(const TObject *obj) const
Returns the object after object obj.
static double p1(double t, double a, double b)
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
virtual void AddBefore(const TObject *before, TObject *obj)
Insert object before object before in the list.
virtual void ReadFastArray(Bool_t *b, Int_t n)=0
virtual void WriteFastArray(const Bool_t *b, Int_t n)=0
static void GarbageCollect(TObject *obj)
Add to the list of things to be cleaned up.
#define R__COLLECTION_ITER_GUARD(collection)
void Add(THist< DIMENSIONS, PRECISION_TO, STAT_TO... > &to, const THist< DIMENSIONS, PRECISION_FROM, STAT_FROM... > &from)
Add two histograms.
TObjLinkPtr_t * DoSort(TObjLinkPtr_t *head, Int_t n)
Sort linked list.
Wrapper around a TObject so it can be stored in a TList.
virtual void Clear(Option_t *option="")
Remove all objects from the list.
void SetOption(Option_t *option)
Sets the object option stored in the list.
virtual void AddAfter(const TObject *after, TObject *obj)
Insert object after object after in the list.
Mother of all ROOT objects.
TObject * GetObject() const
virtual void RecursiveRemove(TObject *obj)
Remove object from this collection and recursively remove the object from all other objects (and coll...
virtual TIterator & operator=(const TIterator &)
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Bool_t operator!=(const TIterator &aIter) const
This operator compares two TIterator objects.
void Reset()
Reset list iterator.
#define R__COLLECTION_WRITE_LOCKGUARD(mutex)
TIterator & operator=(const TIterator &rhs)
Overridden assignment operator.
virtual TObject ** GetObjectRef(const TObject *obj) const
Return address of pointer to obj.
Option_t * GetOption() const
Returns the object option stored in the list.
virtual Option_t * GetAddOption() const
TObjLinkPtr_t fLast
pointer to first entry in linked list
void SetObject(TObject *obj)
virtual Version_t ReadVersion(UInt_t *start=0, UInt_t *bcnt=0, const TClass *cl=0)=0
TObjLink * FindLink(const TObject *obj, Int_t &idx) const
Returns the TObjLink object that contains object obj.
TObjLinkPtr_t NewLink(TObject *obj, const TObjLinkPtr_t &prev=nullptr)
Return a new TObjLink.