DynExp
Highly flexible laboratory automation for dynamically changing experiments.
Loading...
Searching...
No Matches
DynExp::TaskBase::CallbackType Class Reference

Type owning a callback function which is invoked when a task has finished, failed, or has been aborted. It is ensured that the callback function is invoked latest upon destruction of the respective CallbackType instance. A callback function can only be invoked once through a CallbackType instance. More...

#include <Instrument.h>

Public Types

using FuncType = std::function< void(const TaskBase *, ExceptionContainer &)>
 Type of the owned callback function. The function receives a pointer to the task the CallbackType instance is owned by. If it has no owner, nullptr is passed. The second parameter is a reference to a wrapper holding an exception which might have occurred while executing the owning task.
 

Public Member Functions

 CallbackType ()
 Constructs a CallbackType instance with an empty CallbackFunc.
 
 CallbackType (std::nullptr_t)
 Constructs a CallbackType instance with an empty CallbackFunc.
 
 CallbackType (FuncType &&CallbackFunc)
 Constructs a CallbackType instance owning a callback function.
 
 CallbackType (CallbackType &&Other)
 Copies CallbackFunc and HasBeenCalled from other and ensures that Other will never be invoked.
 
 ~CallbackType ()
 Calls operator()() passing nullptr to the first argument of FuncType. Swallows all exceptions possibly occuring during the execution of CallbackFunc.
 
template<typename... ArgTs>
void operator() (ArgTs &&...Args)
 Invokes CallbackFunc if it has not been invoked before.
 
 operator bool () const noexcept
 Returns false if CallbackFunc is empty, true otherwise.
 

Private Attributes

const FuncType CallbackFunc
 Pointer to the owned callback function.
 
bool HasBeenCalled = false
 Indicates whether CallbackFunc has been invoked already.
 

Detailed Description

Type owning a callback function which is invoked when a task has finished, failed, or has been aborted. It is ensured that the callback function is invoked latest upon destruction of the respective CallbackType instance. A callback function can only be invoked once through a CallbackType instance.

Definition at line 977 of file Instrument.h.

Member Typedef Documentation

◆ FuncType

Type of the owned callback function. The function receives a pointer to the task the CallbackType instance is owned by. If it has no owner, nullptr is passed. The second parameter is a reference to a wrapper holding an exception which might have occurred while executing the owning task.

Definition at line 986 of file Instrument.h.

Constructor & Destructor Documentation

◆ CallbackType() [1/4]

DynExp::TaskBase::CallbackType::CallbackType ( )
inline

Constructs a CallbackType instance with an empty CallbackFunc.

Definition at line 991 of file Instrument.h.

◆ CallbackType() [2/4]

DynExp::TaskBase::CallbackType::CallbackType ( std::nullptr_t  )
inline

Constructs a CallbackType instance with an empty CallbackFunc.

Definition at line 996 of file Instrument.h.

◆ CallbackType() [3/4]

DynExp::TaskBase::CallbackType::CallbackType ( FuncType &&  CallbackFunc)
inline

Constructs a CallbackType instance owning a callback function.

Parameters
CallbackFuncPointer to the callback function to take ownership of.

Definition at line 1002 of file Instrument.h.

◆ CallbackType() [4/4]

DynExp::TaskBase::CallbackType::CallbackType ( CallbackType &&  Other)

Copies CallbackFunc and HasBeenCalled from other and ensures that Other will never be invoked.

Parameters
OtherCallbackType instance to move from.

Definition at line 496 of file Instrument.cpp.

◆ ~CallbackType()

DynExp::TaskBase::CallbackType::~CallbackType ( )

Calls operator()() passing nullptr to the first argument of FuncType. Swallows all exceptions possibly occuring during the execution of CallbackFunc.

Definition at line 502 of file Instrument.cpp.

Member Function Documentation

◆ operator bool()

DynExp::TaskBase::CallbackType::operator bool ( ) const
inlinenoexcept

Returns false if CallbackFunc is empty, true otherwise.

Definition at line 1036 of file Instrument.h.

◆ operator()()

template<typename... ArgTs>
void DynExp::TaskBase::CallbackType::operator() ( ArgTs &&...  Args)
inline

Invokes CallbackFunc if it has not been invoked before.

Template Parameters
...ArgTsTypes of arguments to pass to CallbackFunc. Refer to FuncType.
Parameters
...ArgsArguments to forward to CallbackFunc.

Definition at line 1023 of file Instrument.h.

Member Data Documentation

◆ CallbackFunc

const FuncType DynExp::TaskBase::CallbackType::CallbackFunc
private

Pointer to the owned callback function.

Definition at line 1039 of file Instrument.h.

◆ HasBeenCalled

bool DynExp::TaskBase::CallbackType::HasBeenCalled = false
private

Indicates whether CallbackFunc has been invoked already.

Definition at line 1041 of file Instrument.h.


The documentation for this class was generated from the following files: