OpendTect  6.6
Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes | List of all members
CallBack Class Reference

CallBacks object-oriented (object + method). More...

Public Member Functions

 CallBack ()
 
 CallBack (CallBacker *o, CallBackFunction f)
 
 CallBack (StaticCallBackFunction f)
 
CallBackFunction cbFn () const
 
CallBackercbObj ()
 
const CallBackercbObj () const
 
void disable (bool yn=true) const
 
void doCall (CallBacker *) const
 
void enable () const
 
bool isDisabled () const
 
bool operator!= (const CallBack &) const
 
bool operator== (const CallBack &) const
 
StaticCallBackFunction scbFn () const
 
bool willCall () const
 

Static Public Member Functions

static bool addToMainThread (const CallBack &, CallBacker *=nullptr)
 
static bool addToThread (Threads::ThreadID, const CallBack &, CallBacker *=nullptr)
 
static bool callInMainThread (const CallBack &, CallBacker *=nullptr)
 
static void initClass ()
 
static bool queueIfNotInMainThread (CallBack, CallBacker *=nullptr)
 
static void removeFromMainThread (const CallBacker *cber)
 
static void removeFromThreadCalls (const CallBacker *)
 

Private Attributes

CallBackercberobj_
 
Threads::Atomic< int > disablecount_
 
CallBackFunction fn_
 
StaticCallBackFunction sfn_
 

Static Private Attributes

static Threads::ThreadID mainthread_
 

Detailed Description

CallBacks object-oriented (object + method).

CallBack is nothing more than a function pointer + optionally an object to call it on. It may be null, in which case doCall() will simply do nothing. If you want to be able to send a CallBack, you must provide a 'sender' CallBacker* (usually 'this').

You can disable a CallBack, but if you do make sure you enable it again using disable(false), as it works with a counter (so that disabling can be nested).

<>

Constructor & Destructor Documentation

◆ CallBack() [1/3]

CallBack::CallBack ( )
inline

◆ CallBack() [2/3]

CallBack::CallBack ( CallBacker o,
CallBackFunction  f 
)
inline

◆ CallBack() [3/3]

CallBack::CallBack ( StaticCallBackFunction  f)
inline

Member Function Documentation

◆ addToMainThread()

static bool CallBack::addToMainThread ( const CallBack ,
CallBacker = nullptr 
)
static

Unconditionally add this to main event loop. For thread safety, the removeFromThreadCalls() must be called in the destructor.

◆ addToThread()

static bool CallBack::addToThread ( Threads::ThreadID  ,
const CallBack ,
CallBacker = nullptr 
)
static

Unconditionally add this to event loop of the other thread. For thread safety, the removeFromThreadCalls() must be called in the destructor.

◆ callInMainThread()

static bool CallBack::callInMainThread ( const CallBack ,
CallBacker = nullptr 
)
static

If in main thread or no event-loop is present, it will be called directly. Otherwise, it will be put on event loop. For thread safety, the removeFromThreadCalls() must be called in the destructor.

Returns
true if the callback was called directly.

◆ cbFn()

CallBackFunction CallBack::cbFn ( ) const
inline

◆ cbObj() [1/2]

CallBacker* CallBack::cbObj ( )
inline

◆ cbObj() [2/2]

const CallBacker* CallBack::cbObj ( ) const
inline

◆ disable()

void CallBack::disable ( bool  yn = true) const

◆ doCall()

void CallBack::doCall ( CallBacker ) const

◆ enable()

void CallBack::enable ( ) const
inline

◆ initClass()

static void CallBack::initClass ( )
static

◆ isDisabled()

bool CallBack::isDisabled ( ) const
inline

◆ operator!=()

bool CallBack::operator!= ( const CallBack ) const

◆ operator==()

bool CallBack::operator== ( const CallBack ) const

◆ queueIfNotInMainThread()

static bool CallBack::queueIfNotInMainThread ( CallBack  ,
CallBacker = nullptr 
)
static

If not in main thread, queue it. return whether CB was queued.

◆ removeFromMainThread()

static void CallBack::removeFromMainThread ( const CallBacker cber)
inlinestatic

◆ removeFromThreadCalls()

static void CallBack::removeFromThreadCalls ( const CallBacker )
static

◆ scbFn()

StaticCallBackFunction CallBack::scbFn ( ) const
inline

◆ willCall()

bool CallBack::willCall ( ) const

Member Data Documentation

◆ cberobj_

CallBacker* CallBack::cberobj_
private

◆ disablecount_

Threads::Atomic<int> CallBack::disablecount_
mutableprivate

◆ fn_

CallBackFunction CallBack::fn_
private

◆ mainthread_

Threads::ThreadID CallBack::mainthread_
staticprivate

◆ sfn_

StaticCallBackFunction CallBack::sfn_
private

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