| OpendTect 8.0

Loading...
Searching...
No Matches
Public Member Functions | List of all members
Notifier< T > Class Template Reference
Basic

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

`#include <notify.h>`

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.
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_

## Detailed Description

template<class T>
class Notifier< T >

Class to help setup a callback handling.

The two things:

- providing a notification of an event to the outside world
- asking a notification of a certain object are strongly coupled. Qt has its Signal/Slot pair, but we found that too inflexible. Enter Notifier. You declare a Notifier to announce to the world that they can be notified of something. The 'receiving' object can then call the notify() method to 'register' the event notification. The sending object just calls trigger(). Note that it is most used in the UI, but it is equally usable in batch stuff. In general, it provides a rigorous uncoupling.

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

Notifier<MyClass> buttonClicked;
Notifier
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();
Notifier::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-2025