Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TNotifyLink.h
Go to the documentation of this file.
1// @(#)root/base:$Id$
2// Author: Philippe Canal 2019
3
4/*************************************************************************
5 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_TNotifyLink
13#define ROOT_TNotifyLink
14
15#include <TObject.h>
16#include <TError.h> // for R__ASSERT
17
18/** \class TNotifyLink
19\ingroup Base
20
21Links multiple listeners to be notified on TChain file changes.
22
23Neither TChain::SetNotify() nor this TNotifyLink take ownership of the object to be notified.
24
25eg.
26```
27auto notify = new TNotifyLink(object, fChain->GetNotify());
28fChain->SetNotify(notify);
29```
30**/
31
32class TNotifyLinkBase : public TObject {
33protected:
35 TObject *fNext = nullptr;
36
37public:
38 // TTree status bits
40 kLinked = BIT(11) // Used when the TNotifyLink is connected to a TTree.
41 };
42
43 void Clear(Option_t * /*option*/ ="") override
44 {
45 auto current = this;
46 do {
47 auto next = dynamic_cast<TNotifyLinkBase*>(fNext);
48 current->ResetBit(kLinked);
49 current->fPrevious = nullptr;
50 current->fNext = nullptr;
51 current = next;
52 } while(current);
53 }
54
55 template <class Notifier>
56 void PrependLink(Notifier &notifier)
57 {
59
60 fNext = notifier.GetNotify();
61 if (auto link = dynamic_cast<TNotifyLinkBase*>(fNext)) {
62 link->fPrevious = this;
63 }
64 notifier.SetNotify(this);
65 }
66
67 template <class Notifier>
68 void RemoveLink(Notifier &notifier)
69 {
71
72 if (notifier.GetNotify() == this) {
73 R__ASSERT(fPrevious == nullptr && "The TNotifyLink head node should not have a previous element.");
74 notifier.SetNotify(fNext);
75 } else if (fPrevious) {
77 }
78 if (auto link = dynamic_cast<TNotifyLinkBase*>(fNext)) {
79 link->fPrevious = fPrevious;
80 }
81 fPrevious = nullptr;
82 fNext = nullptr;
83 }
84
86 {
87 return TestBit(kLinked);
88 }
89
91};
92
93template <class Type>
95private:
96 Type *fCurrent;
97
98public:
99 TNotifyLink(Type *current) : fCurrent(current) {}
100
101 // Call Notify on the current and next object.
102 Bool_t Notify() override
103 {
104 auto result = fCurrent ? fCurrent->Notify() : kTRUE;
105 if (fNext) result &= fNext->Notify();
106 return result;
107 }
108
110};
111
112#endif // ROOT_TNotifyLink
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
const char Option_t
Definition RtypesCore.h:66
#define BIT(n)
Definition Rtypes.h:85
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
#define R__ASSERT(e)
Definition TError.h:117
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
TNotifyLinkBase * fPrevious
Definition TNotifyLink.h:34
TObject * fNext
Definition TNotifyLink.h:35
void RemoveLink(Notifier &notifier)
Definition TNotifyLink.h:68
void PrependLink(Notifier &notifier)
Definition TNotifyLink.h:56
void Clear(Option_t *="") override
Definition TNotifyLink.h:43
Bool_t IsLinked()
Definition TNotifyLink.h:85
Mother of all ROOT objects.
Definition TObject.h:41
virtual Bool_t Notify()
This method must be overridden to handle object notification.
Definition TObject.cxx:588
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:201
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
Definition TObject.cxx:774
void ResetBit(UInt_t f)
Definition TObject.h:200