OpendTect
6.6
|
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 | |
CallBacker * | cber_ |
CallBackSet & | cbs_ |
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 CallBacker > | shutdownsubscribers_ |
Class to help setup a callback handling.
The two things:
Simply declare a Notifier<T> in the interface, like:
Then users of the class can issue:
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:
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.
<>
|
inline |
|
inline |
|
inline |
Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B.V. 1995-2022