OpendTect  7.0
Public Member Functions | List of all members
Notifier< T > Class Template Reference

Class to help setup a callback handling. More...

Inherits NotifierAccess.

Public Member Functions

 Notifier (T *c)
 
void trigger ()
 
void trigger (CallBacker *c)
 
void trigger (T &t)
 
- Public Member Functions inherited from NotifierAccess
 NotifierAccess ()
 
 NotifierAccess (const NotifierAccess &)
 
virtual ~NotifierAccess ()
 
void disable ()
 
void enable (bool yn=true)
 
bool isEmpty () const
 
bool isEnabled () const
 
bool isShutdownSubscribed (const CallBacker *) const
 Only for debugging purposes, don't use. More...
 
void notify (const CallBack &, bool first=false) const
 
bool notifyIfNotNotified (const CallBack &) const
 
void remove (const CallBack &) const
 
bool removeWith (const CallBacker *, bool wait=true) const
 
void setEmpty ()
 
void transferCBSTo (const NotifierAccess &, const CallBacker *only_for, const CallBacker *not_for=0) const
 
bool willCall (const CallBacker *) const
 

Additional Inherited Members

- Public Attributes inherited from NotifierAccess
CallBackercber_
 
CallBackSetcbs_
 
- Protected Member Functions inherited from NotifierAccess
void addShutdownSubscription (const CallBacker *) const
 
bool removeShutdownSubscription (const CallBacker *, bool wait) const
 
- Static Protected Member Functions inherited from NotifierAccess
static void doTrigger (CallBackSet &, const CallBacker *)
 
- Protected Attributes inherited from NotifierAccess
Threads::Lock shutdownsubscriberlock_
 
ObjectSet< const CallBackershutdownsubscribers_
 

Detailed Description

template<class T>
class Notifier< T >

Class to help setup a callback handling.

The two things:

Simply declare a Notifier<T> in the interface, like:

Notifier<MyClass> buttonClicked;
Class to help setup a callback handling.
Definition: notify.h:122

Then users of the class can issue:

mAttachCB( myclass.buttonClicked, TheClassOfThis::theMethodToBeCalle );

The notifier is then attached, the connection will be remove when either the notifier or the called object is deleted.

The callback is issued when you call the trigger() method, like:

buttonClicked.trigger();
void trigger()
Definition: notify.h:128

The notification can be temporary stopped using disable()/enable() pair, or by use of a NotifyStopper, which automatically restores the callback when going out of scope.

The best practice is to remove the callbacks in the destructor, as otherwise, you may get random crashes. Either, remove them one by one in the destructor, or call detachAllNotifiers(), which will remove notifiers that are attached using the mAttachCB macro.

Note that the Notifier system circumvents the const system. Why? This makes gettting and sending callbacks to/from const objects possible without difficult const_casts.

<>

Constructor & Destructor Documentation

◆ Notifier()

template<class T >
Notifier< T >::Notifier ( T *  c)
inline

Member Function Documentation

◆ trigger() [1/3]

template<class T >
void Notifier< T >::trigger ( )
inline

◆ trigger() [2/3]

template<class T >
void Notifier< T >::trigger ( CallBacker c)
inline

◆ trigger() [3/3]

template<class T >
void Notifier< T >::trigger ( T &  t)
inline

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B.V. 1995-2024