|
ROOT
Reference Guide |
|
Go to the documentation of this file.
104 if (IsArgNull(
"AddFirst", obj))
return;
112 auto t = NewLink(obj);
132 if (IsArgNull(
"AddFirst", obj))
return;
137 fFirst = NewOptLink(obj, opt);
140 auto t = NewOptLink(obj, opt);
156 if (IsArgNull(
"AddLast", obj))
return;
164 fLast = NewLink(obj, fLast);
180 if (IsArgNull(
"AddLast", obj))
return;
185 fFirst = NewOptLink(obj, opt);
188 fLast = NewOptLink(obj, opt, fLast);
200 if (IsArgNull(
"AddBefore", obj))
return;
208 TObjLink *t = FindLink(before, idx);
210 Error(
"AddBefore",
"before not found, object not added");
216 NewLink(obj, t->
fPrev.lock());
232 if (IsArgNull(
"AddBefore", obj))
return;
237 if (before ==
fFirst.get())
240 NewLink(obj, before->
fPrev.lock());
254 if (IsArgNull(
"AddAfter", obj))
return;
264 Error(
"AddAfter",
"after not found, object not added");
267 if (t == fLast.get())
270 NewLink(obj, t->shared_from_this());
286 if (IsArgNull(
"AddAfter", obj))
return;
293 if (after == fLast.get())
296 NewLink(obj, after->shared_from_this());
310 if (IsArgNull(
"AddAt", obj))
return;
317 else if (lnk ==
fFirst.get())
320 NewLink(obj, lnk->
fPrev.lock());
338 auto cached = fCache.lock();
339 if (cached.get() && cached->GetObject() && cached->GetObject()->IsEqual(obj)) {
344 t = FindLink(obj, idx);
378 auto cached = fCache.lock();
379 if (cached.get() && cached->GetObject() && cached->GetObject()->IsEqual(obj)) {
384 t = FindLink(obj, idx);
409 if (!nodel && IsOwner()) {
441 auto obj = tlk->GetObject();
443 if (!obj->TestBit(kNotDeleted)) {
444 Error(
"Clear",
"A list is accessing an object (%p) already deleted (list name = %s)",
446 }
else if (obj->IsOnHeap()) {
448 if (obj->TestBit(kNotDeleted)) {
477 TList removeDirectory;
503 auto obj = tlk->GetObject();
504 if (obj && !obj->TestBit(kNotDeleted))
505 Error(
"Delete",
"A list is accessing an object (%p) already deleted (list name = %s)",
507 else if (obj && obj->IsOnHeap())
509 else if (obj && obj->IsA()->GetDirectoryAutoAdd())
510 removeDirectory.Add(obj);
531 auto obj = tlk->GetObject();
532 tlk->SetObject(
nullptr);
533 if (obj && !obj->TestBit(kNotDeleted))
534 Error(
"Delete",
"A list is accessing an object (%p) already deleted (list name = %s)",
536 else if (obj && obj->IsOnHeap())
538 else if (obj && obj->IsA()->GetDirectoryAutoAdd())
539 removeDirectory.Add(obj);
550 TIter iRemDir(&removeDirectory);
552 while ((dirRem = iRemDir())) {
553 (*dirRem->IsA()->GetDirectoryAutoAdd())(dirRem, 0);
562 void TList::DeleteLink(
TObjLink *lnk)
587 for (
TObjLink *lnk = FirstLink(); lnk !=
nullptr; lnk = lnk->
Next()) {
588 if (
TObject *obj = lnk->GetObject()) {
589 const char *objname = obj->GetName();
590 if (objname && strcmp(
name, objname) == 0)
618 if (ob->
IsEqual(obj))
return ob;
646 if (
object->TestBit(kNotDeleted)) {
647 if (
object->IsEqual(obj))
return lnk;
698 if (fLast)
return fLast->GetObject();
712 while (i < idx && lnk) {
738 auto newlink = std::make_shared<TObjLink>(obj);
740 InsertAfter(newlink, prev);
753 auto newlink = std::make_shared<TObjOptLink>(obj, opt);
755 InsertAfter(newlink, prev);
773 auto cached = fCache.lock();
774 if (cached && cached->fNext.get() ==
nullptr && cached->fPrev.lock().get() ==
nullptr) {
775 TObject *ob = cached->GetObject();
776 if (ob && ob->
TestBit(kNotDeleted)) {
789 TObject *ob = lnk->GetObject();
790 if (ob && ob->
TestBit(kNotDeleted)) {
792 lnk->SetObject(
nullptr);
800 }
else if (lnk == fLast) {
801 fLast = lnk->fPrev.lock();
802 fLast->fNext.reset();
805 lnk->Prev()->fNext = next;
806 lnk->Next()->fPrev = lnk->fPrev;
840 if (lnk ==
fFirst.get()) {
844 if (lnk == fLast.get()) {
850 }
else if (lnk == fLast.get()) {
851 fLast = lnk->
fPrev.lock();
852 fLast->fNext.reset();
880 if (lnk ==
fFirst.get()) {
884 if (lnk == fLast.get()) {
890 }
else if (lnk == fLast.get()) {
891 fLast = lnk->
fPrev.lock();
892 fLast->fNext.reset();
918 if (lnk ==
fFirst.get()) {
922 fLast = lnk->
fPrev.lock();
923 fLast->fNext.reset();
946 if (!
fFirst->GetObject()->IsSortable()) {
947 Error(
"Sort",
"objects in list are not sortable");
954 std::shared_ptr<TObjLink> ol, lnk =
fFirst;
956 if (lnk.get()) lnk->fPrev.reset();
974 Int_t cmp = l1->GetObject()->Compare(l2->GetObject());
976 if ((IsAscending() && cmp <=0) || (!IsAscending() && cmp > 0))
989 std::shared_ptr<TObjLink> p1, p2, *h2, *t2;
996 return &((*head)->fNext);
999 p2 = (p1 = *head)->fNext;
1000 if (LnkCompare(p1, p2))
return &(p2->fNext);
1001 p1->fNext = (*head = p2)->fNext;
1002 return &((p2->fNext = p1)->fNext);
1008 t2 = DoSort(h2 = DoSort(head,
n),
m);
1010 if (LnkCompare((p1 = *head), (p2 = *h2))) {
1012 if (!--
n)
return *h2 = p2, t2;
1013 }
while (LnkCompare((p1 = *(head = &(p1->fNext))), p2));
1019 if (!--
m)
return *h2 = *t2, *t2 = p1, h2;
1020 }
while (!LnkCompare(p1, (p2 = *(head = &(p2->fNext)))));
1023 if (!--
n)
return *h2 = p2, t2;
1024 }
while (LnkCompare((p1 = *(head = &(p1->fNext))), p2));
1037 newlink->fNext = prev->fNext;
1038 newlink->fPrev = prev;
1039 prev->fNext = newlink;
1041 newlink->fNext->fPrev = newlink;
1055 : fList(
l), fCurCursor(0), fCursor(0), fDirection(dir), fStarted(
kFALSE)
1081 if (
this != &rhs && rhs1) {
1115 if (!
fList)
return 0;
1172 if (IsA() == aIter.IsA()) {
1203 if (
b.IsReading()) {
1207 TObject::Streamer(
b);
1211 for (
Int_t i = 0; i < nobjects; i++) {
1214 if (
v > 4 && nch == 255) {
1219 readOption.resize(nbig,
'\0');
1220 b.ReadFastArray((
char*) readOption.data(),nbig);
1223 Add(obj,readOption.c_str());
1229 b.CheckByteCount(R__s, R__c,TList::IsA());
1235 TObject::Streamer(
b);
1239 for (
Int_t i = 0; i < nobjects; i++) {
1243 b.CheckByteCount(R__s, R__c,TList::IsA());
1248 R__c =
b.WriteVersion(TList::IsA(),
kTRUE);
1249 TObject::Streamer(
b);
1272 b.SetByteCount(R__c,
kTRUE);
virtual void AddAt(TObject *obj, Int_t idx)
Insert object at position idx in the list.
#define R__COLLECTION_WRITE_LOCKGUARD(mutex)
void InsertAfter(const TObjLinkPtr_t &newlink, const TObjLinkPtr_t &prev)
Insert a new link in the chain.
virtual TObject ** GetObjectRef(const TObject *obj) const
Return address of pointer to obj.
virtual void RemoveLast()
Remove the last object of the list.
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
virtual void AddFirst(TObject *obj)
Add object at the beginning of the list.
void SetOption(Option_t *option)
Sets the object option stored in the list.
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
#define R__COLLECTION_READ_GUARD()
#define R__COLLECTION_READ_LOCKGUARD(mutex)
Option_t * GetOption() const
Returns the object option stored in 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.
R__EXTERN TVirtualRWMutex * gCoreMutex
Buffer base class used for serializing objects.
virtual void AddLast(TObject *obj)
Add object at the end of the list.
Bool_t LnkCompare(const TObjLinkPtr_t &l1, const TObjLinkPtr_t &l2)
Compares the objects stored in the TObjLink objects.
Bool_t operator!=(const TIterator &aIter) const
This operator compares two TIterator objects.
virtual void RecursiveRemove(TObject *obj)
Recursively remove this object from a list.
Iterator abstract base class.
virtual void Sort(Bool_t order=kSortAscending)
Sort linked list.
const Bool_t kIterForward
void SetObject(TObject *obj)
TObject ** GetObjectRef()
TObject * Next()
Return next object in the list. Returns 0 when no more objects in list.
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
virtual TIterator * MakeIterator(Bool_t dir=kIterForward) const
Return a list iterator.
virtual TObject * At(Int_t idx) const
Returns the object at position idx. Returns 0 if idx is out of range.
virtual TObject * After(const TObject *obj) const
Returns the object after object obj.
virtual ~TList()
Delete the list.
static void GarbageCollect(TObject *obj)
Add to the list of things to be cleaned up.
virtual TObject * Before(const TObject *obj) const
Returns the object before object obj.
TObjLinkPtr_t NewOptLink(TObject *obj, Option_t *opt, const TObjLinkPtr_t &prev=nullptr)
Return a new TObjOptLink (a TObjLink that also stores the option).
virtual void AddBefore(const TObject *before, TObject *obj)
Insert object before object before in the list.
std::shared_ptr< TObjLink > TObjLinkPtr_t
virtual Bool_t IsEqual(const TObject *obj) const
Default equal comparison (objects are equal if they have the same address in memory).
void Reset()
Reset list iterator.
TObjLinkPtr_t * DoSort(TObjLinkPtr_t *head, Int_t n)
Sort linked list.
virtual void AddAfter(const TObject *after, TObject *obj)
Insert object after object after in the list.
virtual TIterator & operator=(const TIterator &)
virtual TObject * Remove(TObject *obj)
Remove object from the list.
virtual Int_t GetSize() const
Return the capacity of the collection, i.e.
virtual Option_t * GetAddOption() const
virtual void Add(TObject *obj)
TObject * GetObject() const
Mother of all ROOT objects.
TObjLinkPtr_t fLast
pointer to first entry in linked list
virtual void Clear(Option_t *option="")
Remove all objects from the list.
#define R__COLLECTION_WRITE_GUARD()
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.
Wrapper around a TObject so it can be stored in a TList.
virtual void RecursiveRemove(TObject *obj)
Remove object from this collection and recursively remove the object from all other objects (and coll...
TIterator & operator=(const TIterator &rhs)
Overridden assignment operator.
#define R__COLLECTION_ITER_GUARD(collection)
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.