c++-gtk-utils
Public Member Functions
Cgu::Callback::CallbackArg< FreeArgs > Class Template Reference

The callback interface class. More...

#include <c++-gtk-utils/callback.h>

List of all members.

Public Member Functions

virtual void dispatch (typename Cgu::Param< FreeArgs >::ParamType...args) const =0
 CallbackArg ()
virtual ~CallbackArg ()

Detailed Description

template<class... FreeArgs>
class Cgu::Callback::CallbackArg< FreeArgs >

The callback interface class.

See also:
Callback namespace
FunctorArg SafeFunctorArg

This provides the basic interface class that users will generally see. The template types are the types of the unbound arguments, if any. Callback::CallbackArg<> is typedef'ed to Callback::Callback.

Usage

For a class object my_obj of type MyClass, with a method void MyClass::my_method(int, int, const char*), usage for a fully bound callback would be:

using namespace Cgu;
int arg1 = 1, arg2 = 5;
Callback::make(my_obj, &MyClass::my_method, arg1, arg2, "Hello\n");
cb->dispatch();
delete cb;

Or for a partially bound callback:

using namespace Cgu;
int arg1 = 1, arg2 = 5;
Callback::make(my_obj, &MyClass::my_method, arg1);
cb->dispatch(arg2, "Hello\n");
delete cb;

Callback/CallbackArg classes do not provide for a return value. If a result is wanted, users should pass an unbound argument by reference or pointer (or pointer to pointer).

For further background, including about the Callback::make(), Callback::make_ref() and Callback::lambda() functions, and the use of these classes with std::function objects, read this: Callback


Constructor & Destructor Documentation

template<class... FreeArgs>
Cgu::Callback::CallbackArg< FreeArgs >::CallbackArg ( )
inline

The constructor will not throw unless the copy constructor of an argument bound to the derived implementation class throws.

template<class... FreeArgs>
virtual Cgu::Callback::CallbackArg< FreeArgs >::~CallbackArg ( )
inlinevirtual

The destructor will not throw unless the destructor of an argument bound to the derived implementation class throws.


Member Function Documentation

template<class... FreeArgs>
virtual void Cgu::Callback::CallbackArg< FreeArgs >::dispatch ( typename Cgu::Param< FreeArgs >::ParamType...  args) const
pure virtual

This will execute the referenced function or class method encapsulated by this class. It will only throw if the dispatched function or class method throws, or if the copy constructor of the free or a bound argument throws and it is not a reference argument. It is thread safe if the referenced function or class method is thread safe.

Parameters:
argsThe unbound arguments to be passed to the referenced function or class method, if any.
Note:
We use dispatch() to execute the callback, because the callback would normally be invoked through a base class pointer. To invoke it through operator()(), use the FunctorArg wrapper class.

Implemented in Cgu::Callback::Callback_lambda< Lambda, FreeArgs >, Cgu::Callback::Callback_function< FreeArgs >, Cgu::Callback::Callback5_static< unref, BoundArg1, BoundArg2, BoundArg3, BoundArg4, BoundArg5, FreeArgs >, Cgu::Callback::Callback4_static< unref, BoundArg1, BoundArg2, BoundArg3, BoundArg4, FreeArgs >, Cgu::Callback::Callback3_static< unref, BoundArg1, BoundArg2, BoundArg3, FreeArgs >, Cgu::Callback::Callback2_static< unref, BoundArg1, BoundArg2, FreeArgs >, Cgu::Callback::Callback1_static< unref, BoundArg, FreeArgs >, Cgu::Callback::Callback0_static< FreeArgs >, Cgu::Callback::Callback5_const< unref, T, BoundArg1, BoundArg2, BoundArg3, BoundArg4, BoundArg5, FreeArgs >, Cgu::Callback::Callback4_const< unref, T, BoundArg1, BoundArg2, BoundArg3, BoundArg4, FreeArgs >, Cgu::Callback::Callback3_const< unref, T, BoundArg1, BoundArg2, BoundArg3, FreeArgs >, Cgu::Callback::Callback2_const< unref, T, BoundArg1, BoundArg2, FreeArgs >, Cgu::Callback::Callback1_const< unref, T, BoundArg, FreeArgs >, Cgu::Callback::Callback0_const< T, FreeArgs >, Cgu::Callback::Callback5< unref, T, BoundArg1, BoundArg2, BoundArg3, BoundArg4, BoundArg5, FreeArgs >, Cgu::Callback::Callback4< unref, T, BoundArg1, BoundArg2, BoundArg3, BoundArg4, FreeArgs >, Cgu::Callback::Callback3< unref, T, BoundArg1, BoundArg2, BoundArg3, FreeArgs >, Cgu::Callback::Callback2< unref, T, BoundArg1, BoundArg2, FreeArgs >, Cgu::Callback::Callback1< unref, T, BoundArg, FreeArgs >, and Cgu::Callback::Callback0< T, FreeArgs >.


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