Skip to content

[core] AddBefore/After/At option variant, as with Add/First/Last v2 #18353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/cont/inc/THashList.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,15 @@ class THashList : public TList {
void AddLast(TObject *obj) override;
void AddLast(TObject *obj, Option_t *opt) override;
void AddAt(TObject *obj, Int_t idx) override;
void AddAt(TObject *obj, Int_t idx, Option_t *opt) override;
void AddAfter(const TObject *after, TObject *obj) override;
void AddAfter(TObjLink *after, TObject *obj) override;
void AddAfter(const TObject *after, TObject *obj, Option_t *opt) override;
void AddAfter(TObjLink *after, TObject *obj, Option_t *opt) override;
void AddBefore(const TObject *before, TObject *obj) override;
void AddBefore(TObjLink *before, TObject *obj) override;
void AddBefore(const TObject *before, TObject *obj, Option_t *opt) override;
void AddBefore(TObjLink *before, TObject *obj, Option_t *opt) override;
void RecursiveRemove(TObject *obj) override;
void Rehash(Int_t newCapacity);
TObject *Remove(TObject *obj) override;
Expand Down
5 changes: 5 additions & 0 deletions core/cont/inc/TList.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,15 @@ friend class TListIter;
void AddLast(TObject *obj) override;
virtual void AddLast(TObject *obj, Option_t *opt);
void AddAt(TObject *obj, Int_t idx) override;
virtual void AddAt(TObject *obj, Int_t idx, Option_t *opt);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than declaration this virtual we need to also update to TSeqCollection.h

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I was just copy pasting the structure from lines 85-86. AddLast overrides from TSeqCollection, AddLast with option is virtual. Otherwise it's not consistent?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if we also moved AddLast and AddFirst to TSeqCollection to be consistent, that would break user-scripts deriving from that classes since they would become purely virtual (if one wants to keep consistent style).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if we made them non-purely-virtual, then users might start getting warnings such as warning: ‘virtual void ::AddAt(TObject*, Int_t, Option_t*)’ was hidden ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise it's not consistent?

Right. I missed that.

start getting warnings such as warning: ‘virtual void ::AddAt(TObject*, Int_t, Option_t*)’ was hidden ?

To extent that is better than use that:

  • Inherits from TList
  • Does not write/override AddAt(TObject*, Int_t, Option_t*
  • Somehow starts using it ...
  • It would 'silently' fail (depending what the overload does - but for example it would/was the case for THashList)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v3 version here: #18389

void AddAfter(const TObject *after, TObject *obj) override;
virtual void AddAfter(TObjLink *after, TObject *obj);
virtual void AddAfter(const TObject *after, TObject *obj, Option_t *opt);
virtual void AddAfter(TObjLink *after, TObject *obj, Option_t *opt);
void AddBefore(const TObject *before, TObject *obj) override;
virtual void AddBefore(TObjLink *before, TObject *obj);
virtual void AddBefore(const TObject *before, TObject *obj, Option_t *opt);
virtual void AddBefore(TObjLink *before, TObject *obj, Option_t *opt);
TObject *Remove(TObject *obj) override;
virtual TObject *Remove(TObjLink *lnk);
TObject *Remove(const TObjLinkPtr_t &lnk) { return Remove(lnk.get()); }
Expand Down
5 changes: 5 additions & 0 deletions core/cont/inc/TSortedList.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ class TSortedList : public TList {
void AddLast(TObject *obj) override { Add(obj); }
void AddLast(TObject *obj, Option_t *opt) override { Add(obj, opt); }
void AddAt(TObject *obj, Int_t) override { Add(obj); }
void AddAt(TObject *obj, Int_t, Option_t* opt) override { Add(obj, opt); }
void AddAfter(const TObject *, TObject *obj) override { Add(obj); }
void AddAfter(TObjLink *, TObject *obj) override { Add(obj); }
void AddAfter(const TObject *, TObject *obj, Option_t *opt) override { Add(obj, opt); }
void AddAfter(TObjLink *, TObject *obj, Option_t *opt) override { Add(obj, opt); }
void AddBefore(const TObject *, TObject *obj) override { Add(obj); }
void AddBefore(TObjLink *, TObject *obj) override { Add(obj); }
void AddBefore(const TObject *, TObject *obj, Option_t *opt) override { Add(obj, opt); }
void AddBefore(TObjLink *, TObject *obj, Option_t *opt) override { Add(obj, opt); }
void Sort(Bool_t = kSortAscending) override { }

ClassDefOverride(TSortedList,0) //A sorted list
Expand Down
54 changes: 54 additions & 0 deletions core/cont/src/THashList.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,28 @@ void THashList::AddBefore(TObjLink *before, TObject *obj)
fTable->AddBefore(before->GetObject(), obj);
}

////////////////////////////////////////////////////////////////////////////////
/// Insert object before object before in the list, with options.

void THashList::AddBefore(const TObject *before, TObject *obj, Option_t *opt)
{
R__COLLECTION_WRITE_LOCKGUARD(ROOT::gCoreMutex);

TList::AddBefore(before, obj, opt);
fTable->AddBefore(before, obj);
}

////////////////////////////////////////////////////////////////////////////////
/// Insert object before object before in the list, with options.

void THashList::AddBefore(TObjLink *before, TObject *obj, Option_t *opt)
{
R__COLLECTION_WRITE_LOCKGUARD(ROOT::gCoreMutex);

TList::AddBefore(before, obj, opt);
fTable->AddBefore(before->GetObject(), obj);
}

////////////////////////////////////////////////////////////////////////////////
/// Insert object after object after in the list.

Expand All @@ -158,6 +180,27 @@ void THashList::AddAfter(TObjLink *after, TObject *obj)
TList::AddAfter(after, obj);
fTable->Add(obj);
}
////////////////////////////////////////////////////////////////////////////////
/// Insert object after object after in the list, with options.

void THashList::AddAfter(const TObject *after, TObject *obj, Option_t *opt)
{
R__COLLECTION_WRITE_LOCKGUARD(ROOT::gCoreMutex);

TList::AddAfter(after, obj, opt);
fTable->Add(obj);
}

////////////////////////////////////////////////////////////////////////////////
/// Insert object after object after in the list, with options.

void THashList::AddAfter(TObjLink *after, TObject *obj, Option_t *opt)
{
R__COLLECTION_WRITE_LOCKGUARD(ROOT::gCoreMutex);

TList::AddAfter(after, obj, opt);
fTable->Add(obj);
}

////////////////////////////////////////////////////////////////////////////////
/// Insert object at location idx in the list.
Expand All @@ -170,6 +213,17 @@ void THashList::AddAt(TObject *obj, Int_t idx)
fTable->Add(obj);
}

////////////////////////////////////////////////////////////////////////////////
/// Insert object at location idx in the list, with options.

void THashList::AddAt(TObject *obj, Int_t idx, Option_t *opt)
{
R__COLLECTION_WRITE_LOCKGUARD(ROOT::gCoreMutex);

TList::AddAt(obj, idx, opt);
fTable->Add(obj);
}

////////////////////////////////////////////////////////////////////////////////
/// Return the average collision rate. The higher the number the longer
/// the linked lists in the hashtable, the slower the lookup. If the number
Expand Down
133 changes: 133 additions & 0 deletions core/cont/src/TList.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,116 @@ void TList::AddAfter(TObjLink *after, TObject *obj)
}
}

////////////////////////////////////////////////////////////////////////////////
/// Insert object before object before in the list, with options.

void TList::AddBefore(const TObject *before, TObject *obj, Option_t *opt)
{
R__COLLECTION_WRITE_GUARD();

if (IsArgNull("AddBefore", obj)) return;

R__COLLECTION_WRITE_LOCKGUARD(ROOT::gCoreMutex);

if (!before)
TList::AddFirst(obj, opt);
else {
Int_t idx;
TObjLink *t = FindLink(before, idx);
if (!t) {
Error("AddBefore", "before not found, object not added");
return;
}
if (t == fFirst.get())
TList::AddFirst(obj, opt);
else {
NewOptLink(obj, opt, t->fPrev.lock());
fSize++;
Changed();
}
}
}

////////////////////////////////////////////////////////////////////////////////
/// 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. Options can be specified.

void TList::AddBefore(TObjLink *before, TObject *obj, Option_t *opt)
{
R__COLLECTION_WRITE_GUARD();

if (IsArgNull("AddBefore", obj)) return;

if (!before)
TList::AddFirst(obj, opt);
else {
if (before == fFirst.get())
TList::AddFirst(obj, opt);
else {
NewOptLink(obj, opt, before->fPrev.lock());
fSize++;
Changed();
}
}
}

////////////////////////////////////////////////////////////////////////////////
/// Insert object after object after in the list, with options.

void TList::AddAfter(const TObject *after, TObject *obj, Option_t *opt)
{
R__COLLECTION_WRITE_GUARD();

if (IsArgNull("AddAfter", obj)) return;

R__COLLECTION_WRITE_LOCKGUARD(ROOT::gCoreMutex);

if (!after)
TList::AddLast(obj, opt);
else {
Int_t idx;
TObjLink *t = FindLink(after, idx);
if (!t) {
Error("AddAfter", "after not found, object not added");
return;
}
if (t == fLast.get())
TList::AddLast(obj, opt);
else {
NewOptLink(obj, opt, t->shared_from_this());
fSize++;
Changed();
}
}
}

////////////////////////////////////////////////////////////////////////////////
/// 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. Options can be specified.

void TList::AddAfter(TObjLink *after, TObject *obj, Option_t *opt)
{
R__COLLECTION_WRITE_GUARD();

if (IsArgNull("AddAfter", obj)) return;

R__COLLECTION_WRITE_LOCKGUARD(ROOT::gCoreMutex);

if (!after)
TList::AddLast(obj, opt);
else {
if (after == fLast.get())
TList::AddLast(obj, opt);
else {
NewOptLink(obj, opt, after->shared_from_this());
fSize++;
Changed();
}
}
}

////////////////////////////////////////////////////////////////////////////////
/// Insert object at position idx in the list.

Expand All @@ -321,6 +431,29 @@ void TList::AddAt(TObject *obj, Int_t idx)
}
}

////////////////////////////////////////////////////////////////////////////////
/// Insert object at position idx in the list, with options.

void TList::AddAt(TObject *obj, Int_t idx, Option_t *opt)
{
R__COLLECTION_WRITE_GUARD();

if (IsArgNull("AddAt", obj)) return;

R__COLLECTION_WRITE_LOCKGUARD(ROOT::gCoreMutex);

TObjLink *lnk = LinkAt(idx);
if (!lnk)
TList::AddLast(obj, opt);
else if (lnk == fFirst.get())
TList::AddFirst(obj, opt);
else {
NewOptLink(obj, opt, lnk->fPrev.lock());
fSize++;
Changed();
}
}

////////////////////////////////////////////////////////////////////////////////
/// Returns the object after object obj. Obj is found using the
/// object's IsEqual() method. Returns 0 if obj is last in list.
Expand Down
5 changes: 5 additions & 0 deletions core/meta/inc/TListOfDataMembers.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,15 @@ class TListOfDataMembers : public THashList
void AddLast(TObject *obj) override;
void AddLast(TObject *obj, Option_t *opt) override;
void AddAt(TObject *obj, Int_t idx) override;
void AddAt(TObject *obj, Int_t idx, Option_t *opt) override;
void AddAfter(const TObject *after, TObject *obj) override;
void AddAfter(TObjLink *after, TObject *obj) override;
void AddAfter(const TObject *after, TObject *obj, Option_t *opt) override;
void AddAfter(TObjLink *after, TObject *obj, Option_t *opt) override;
void AddBefore(const TObject *before, TObject *obj) override;
void AddBefore(TObjLink *before, TObject *obj) override;
void AddBefore(const TObject *before, TObject *obj, Option_t *opt) override;
void AddBefore(TObjLink *before, TObject *obj, Option_t *opt) override;

TClass *GetClass() const { return fClass; }
void SetClass(TClass* cl) { fClass = cl; }
Expand Down
5 changes: 5 additions & 0 deletions core/meta/inc/TListOfEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,15 @@ class TListOfEnums : public THashList
void AddLast(TObject *obj) override;
void AddLast(TObject *obj, Option_t *opt) override;
void AddAt(TObject *obj, Int_t idx) override;
void AddAt(TObject *obj, Int_t idx, Option_t *opt) override;
void AddAfter(const TObject *after, TObject *obj) override;
void AddAfter(TObjLink *after, TObject *obj) override;
void AddAfter(const TObject *after, TObject *obj, Option_t *opt) override;
void AddAfter(TObjLink *after, TObject *obj, Option_t *opt) override;
void AddBefore(const TObject *before, TObject *obj) override;
void AddBefore(TObjLink *before, TObject *obj) override;
void AddBefore(const TObject *before, TObject *obj, Option_t *opt) override;
void AddBefore(TObjLink *before, TObject *obj, Option_t *opt) override;

void RecursiveRemove(TObject *obj) override;
TObject *Remove(TObject *obj) override;
Expand Down
7 changes: 6 additions & 1 deletion core/meta/inc/TListOfEnumsWithLock.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

//////////////////////////////////////////////////////////////////////////
// //
// TListOfEnumsWithLock //
// TListOfEnumsWithLock //
// //
// A collection of TEnum objects designed for fast access given a //
// DeclId_t and for keep track of TEnum that were described //
Expand Down Expand Up @@ -68,10 +68,15 @@ class TListOfEnumsWithLock : public TListOfEnums
void AddLast(TObject *obj) override;
void AddLast(TObject *obj, Option_t *opt) override;
void AddAt(TObject *obj, Int_t idx) override;
void AddAt(TObject *obj, Int_t idx, Option_t *opt) override;
void AddAfter(const TObject *after, TObject *obj) override;
void AddAfter(TObjLink *after, TObject *obj) override;
void AddAfter(const TObject *after, TObject *obj, Option_t *opt) override;
void AddAfter(TObjLink *after, TObject *obj, Option_t *opt) override;
void AddBefore(const TObject *before, TObject *obj) override;
void AddBefore(TObjLink *before, TObject *obj) override;
void AddBefore(const TObject *before, TObject *obj, Option_t *opt) override;
void AddBefore(TObjLink *before, TObject *obj, Option_t *opt) override;

void RecursiveRemove(TObject *obj) override;
TObject *Remove(TObject *obj) override;
Expand Down
5 changes: 5 additions & 0 deletions core/meta/inc/TListOfFunctionTemplates.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,15 @@ class TListOfFunctionTemplates : public THashList
void AddLast(TObject *obj) override;
void AddLast(TObject *obj, Option_t *opt) override;
void AddAt(TObject *obj, Int_t idx) override;
void AddAt(TObject *obj, Int_t idx, Option_t *opt) override;
void AddAfter(const TObject *after, TObject *obj) override;
void AddAfter(TObjLink *after, TObject *obj) override;
void AddAfter(const TObject *after, TObject *obj, Option_t *opt) override;
void AddAfter(TObjLink *after, TObject *obj, Option_t *opt) override;
void AddBefore(const TObject *before, TObject *obj) override;
void AddBefore(TObjLink *before, TObject *obj) override;
void AddBefore(const TObject *before, TObject *obj, Option_t *opt) override;
void AddBefore(TObjLink *before, TObject *obj, Option_t *opt) override;

void RecursiveRemove(TObject *obj) override;
TObject *Remove(TObject *obj) override;
Expand Down
5 changes: 5 additions & 0 deletions core/meta/inc/TListOfFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,15 @@ class TListOfFunctions : public THashList
void AddLast(TObject *obj) override;
void AddLast(TObject *obj, Option_t *opt) override;
void AddAt(TObject *obj, Int_t idx) override;
void AddAt(TObject *obj, Int_t idx, Option_t *opt) override;
void AddAfter(const TObject *after, TObject *obj) override;
void AddAfter(TObjLink *after, TObject *obj) override;
void AddAfter(const TObject *after, TObject *obj, Option_t *opt) override;
void AddAfter(TObjLink *after, TObject *obj, Option_t *opt) override;
void AddBefore(const TObject *before, TObject *obj) override;
void AddBefore(TObjLink *before, TObject *obj) override;
void AddBefore(const TObject *before, TObject *obj, Option_t *opt) override;
void AddBefore(TObjLink *before, TObject *obj, Option_t *opt) override;

void RecursiveRemove(TObject *obj) override;
TObject *Remove(TObject *obj) override;
Expand Down
Loading
Loading