PLCnext API Documentation  22.9.0.33
Public Member Functions | Static Public Member Functions | List of all members
Arp::delegate< R(A...)> Class Template Reference

This class represents a delegate, that is a compound of an object reference and a member function pointer. The generic type of a delegate just depends on the signature of the (member) function pointer but not on the type of the object on which the member function pointer is invoked. More...

#include <delegate.hxx>

Public Member Functions

template<class Lambda >
 delegate (Lambda f)
 Constructs a delegate through a lambda expression implicitly. More...
 
 delegate (void)=default
 The default constructor. More...
 
 delegate (const delegate &arg)=default
 The default copy constructor. More...
 
 delegate (delegate &&arg) noexcept=default
 The default move constructor. More...
 
delegateoperator= (const delegate &arg)=default
 The default assign operator. More...
 
delegateoperator= (delegate &&arg) noexcept=default
 The default move assign operator. More...
 
bool operator== (const delegate &rhs) const noexcept
 Compares this instance to the as argument passed rhs . More...
 
bool operator!= (const delegate &rhs) const noexcept
 Compares this instance to the as argument passed rhs . More...
 
 delegate (std::nullptr_t) noexcept
 Constructs an empty delegate representing a nullptr. More...
 
bool operator== (std::nullptr_t const) const noexcept
 Compares this instance to a nullptr. More...
 
bool operator!= (std::nullptr_t const) const noexcept
 Compares this instance to a nullptr. More...
 
 operator bool () const noexcept
 Converts this instance explicitly to bool. More...
 
bool is_lambda (void) const
 Determines if this instance wraps a lamda expression or std::function More...
 
operator() (A... args) const
 The functor operator invokes the adapted callable target. More...
 
void reset ()
 Resets this instance. More...
 

Static Public Member Functions

static delegate create (R(*const pFunction)(A...))
 Creates a delegate from a static function. More...
 
template<class C >
static delegate create (C *pObject, R(C::*pMethod)(A...)) noexcept
 Creates a delegate from a member function and object pointer. More...
 
template<class C >
static delegate create (C &object, R(C::*pMethod)(A...)) noexcept
 Creates a delegate from a member function and object reference. More...
 
template<class C >
static delegate create (const C *pObject, R(C::*pMethod)(A...) const) noexcept
 Creates a delegate from a const member function and const object pointer. More...
 
template<class C >
static delegate create (const C &object, R(C::*pMethod)(A...) const) noexcept
 Creates a delegate from a const member function and const object reference. More...
 
static delegate create (std::function< R(A...)> &&f)
 Creates a delegate from a lambda expression or std::function. More...
 
static delegate create (const std::function< R(A...)> &f)
 Creates a delegate from a lambda expression or std::function. More...
 

Detailed Description

template<class R, class ... A>
class Arp::delegate< R(A...)>

This class represents a delegate, that is a compound of an object reference and a member function pointer. The generic type of a delegate just depends on the signature of the (member) function pointer but not on the type of the object on which the member function pointer is invoked.

A delegate might be seen as a generalized function pointer (callback) in OOP design. It might invoke the following callable targets:

The make_delegate function shall be used to create delegates from these callable targets.

Constructor & Destructor Documentation

◆ delegate() [1/5]

template<class R , class ... A>
template<class Lambda >
Arp::delegate< R(A...)>::delegate ( Lambda  f)
inline

Constructs a delegate through a lambda expression implicitly.

◆ delegate() [2/5]

template<class R , class ... A>
Arp::delegate< R(A...)>::delegate ( void  )
default

The default constructor.

◆ delegate() [3/5]

template<class R , class ... A>
Arp::delegate< R(A...)>::delegate ( const delegate< R(A...)> &  arg)
default

The default copy constructor.

Parameters
argThe argument to copy.

◆ delegate() [4/5]

template<class R , class ... A>
Arp::delegate< R(A...)>::delegate ( delegate< R(A...)> &&  arg)
defaultnoexcept

The default move constructor.

Parameters
argThe argument to copy.

◆ delegate() [5/5]

template<class R , class ... A>
Arp::delegate< R(A...)>::delegate ( std::nullptr_t  )
inlinenoexcept

Constructs an empty delegate representing a nullptr.

Member Function Documentation

◆ create() [1/7]

template<class R , class ... A>
template<class C >
static delegate Arp::delegate< R(A...)>::create ( C &  object,
R(C::*)(A...)  pMethod 
)
inlinestaticnoexcept

Creates a delegate from a member function and object reference.

Parameters
pMethodThe member function to invoke.
objectThe object to invoke the member function on.
Returns
A new delegate instance created by the arguments.

◆ create() [2/7]

template<class R , class ... A>
template<class C >
static delegate Arp::delegate< R(A...)>::create ( C *  pObject,
R(C::*)(A...)  pMethod 
)
inlinestaticnoexcept

Creates a delegate from a member function and object pointer.

Parameters
pMethodThe member function to invoke.
pObjectThe object pointer to invoke the member function on.
Returns
A new delegate instance created by the arguments.

◆ create() [3/7]

template<class R , class ... A>
template<class C >
static delegate Arp::delegate< R(A...)>::create ( const C &  object,
R(C::*)(A...) const  pMethod 
)
inlinestaticnoexcept

Creates a delegate from a const member function and const object reference.

Parameters
pMethodThe member function to invoke.
objectThe object to invoke the member function on.
Returns
A new delegate instance created by the arguments.

◆ create() [4/7]

template<class R , class ... A>
template<class C >
static delegate Arp::delegate< R(A...)>::create ( const C *  pObject,
R(C::*)(A...) const  pMethod 
)
inlinestaticnoexcept

Creates a delegate from a const member function and const object pointer.

Parameters
pMethodThe member function to invoke.
pObjectThe object pointer to invoke the member function on.
Returns
A new delegate instance created by the arguments.

◆ create() [5/7]

template<class R , class ... A>
static delegate Arp::delegate< R(A...)>::create ( const std::function< R(A...)> &  f)
inlinestatic

Creates a delegate from a lambda expression or std::function.

Parameters
fThe function to invoke.
Returns
A new delegate instance created by the arguments.

◆ create() [6/7]

template<class R , class ... A>
static delegate Arp::delegate< R(A...)>::create ( R(*)(A...)  pFunction)
inlinestatic

Creates a delegate from a static function.

Parameters
pFunctionThe static function to invoke.
Returns
A new delegate instance created by the arguments.

◆ create() [7/7]

template<class R , class ... A>
static delegate Arp::delegate< R(A...)>::create ( std::function< R(A...)> &&  f)
inlinestatic

Creates a delegate from a lambda expression or std::function.

Parameters
fThe function to invoke.
Returns
A new delegate instance created by the arguments.

◆ is_lambda()

template<class R , class ... A>
bool Arp::delegate< R(A...)>::is_lambda ( void  ) const
inline

Determines if this instance wraps a lamda expression or std::function

Returns
true if this instance is a lambda expression, otherwise false

◆ operator bool()

template<class R , class ... A>
Arp::delegate< R(A...)>::operator bool ( ) const
inlineexplicitnoexcept

Converts this instance explicitly to bool.

Returns
false if this instance is empty (nullptr), otherwise true

◆ operator!=() [1/2]

template<class R , class ... A>
bool Arp::delegate< R(A...)>::operator!= ( const delegate< R(A...)> &  rhs) const
inlinenoexcept

Compares this instance to the as argument passed rhs .

Parameters
rhsThe argument to compare this instance to.
Returns
true if rhs is not equal, otherwise false

◆ operator!=() [2/2]

template<class R , class ... A>
bool Arp::delegate< R(A...)>::operator!= ( std::nullptr_t const  ) const
inlinenoexcept

Compares this instance to a nullptr.

Returns
true if nullptr is not equal, otherwise false

◆ operator()()

template<class R , class ... A>
R Arp::delegate< R(A...)>::operator() ( A...  args) const
inline

The functor operator invokes the adapted callable target.

Parameters
argsThe arguments to pass to the callable target with the same signature.
Returns
Returns the result of the invoked target.

◆ operator=() [1/2]

template<class R , class ... A>
delegate& Arp::delegate< R(A...)>::operator= ( const delegate< R(A...)> &  arg)
default

The default assign operator.

Parameters
argThe argument to assign to this instance.
Returns
This instance as reference.

◆ operator=() [2/2]

template<class R , class ... A>
delegate& Arp::delegate< R(A...)>::operator= ( delegate< R(A...)> &&  arg)
defaultnoexcept

The default move assign operator.

Parameters
argThe argument to move to this instance.
Returns
This instance as reference.

◆ operator==() [1/2]

template<class R , class ... A>
bool Arp::delegate< R(A...)>::operator== ( const delegate< R(A...)> &  rhs) const
inlinenoexcept

Compares this instance to the as argument passed rhs .

Parameters
rhsThe argument to compare this instance to.
Returns
true if rhs is equal, otherwise false

◆ operator==() [2/2]

template<class R , class ... A>
bool Arp::delegate< R(A...)>::operator== ( std::nullptr_t const  ) const
inlinenoexcept

Compares this instance to a nullptr.

Returns
true if nullptr is equal, otherwise false

◆ reset()

template<class R , class ... A>
void Arp::delegate< R(A...)>::reset ( )
inline

Resets this instance.

After resetting this instance, this instance is not invokable any more. if(*this) will return false

.


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