c++-gtk-utils
Public Member Functions | List of all members
Cgu::Callback::CallbackArg< FreeArg > Class Template Referenceabstract

The callback interface class. More...

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

Inheritance diagram for Cgu::Callback::CallbackArg< FreeArg >:
Cgu::Callback::Callback0< T > Cgu::Callback::Callback0_const< T > Cgu::Callback::Callback0_static Cgu::Callback::Callback1_< unref, T, BoundArg > Cgu::Callback::Callback1_const_< unref, T, BoundArg > Cgu::Callback::Callback1_static_< unref, BoundArg > Cgu::Callback::Callback2_< unref, T, BoundArg1, BoundArg2 > Cgu::Callback::Callback2_const_< unref, T, BoundArg1, BoundArg2 > Cgu::Callback::Callback2_static_< unref, BoundArg1, BoundArg2 > Cgu::Callback::CallbackArg0< T, FreeArg > Cgu::Callback::CallbackArg0_const< T, FreeArg > Cgu::Callback::CallbackArg0_static< FreeArg > Cgu::Callback::CallbackArg1_< unref, T, BoundArg, FreeArg > Cgu::Callback::CallbackArg1_const_< unref, T, BoundArg, FreeArg > Cgu::Callback::CallbackArg1_static_< unref, BoundArg, FreeArg > Cgu::Callback::CallbackArg2_< unref, T, BoundArg1, BoundArg2, FreeArg > Cgu::Callback::CallbackArg2_const_< unref, T, BoundArg1, BoundArg2, FreeArg > Cgu::Callback::CallbackArg2_static_< unref, BoundArg1, BoundArg2, FreeArg >

Public Member Functions

virtual void dispatch (typename Cgu::Param< FreeArg >::ParamType arg) const =0
 
 CallbackArg ()
 
virtual ~CallbackArg ()
 

Detailed Description

template<class FreeArg>
class Cgu::Callback::CallbackArg< FreeArg >

The callback interface class.

See also
Callback namespace
FunctorArg SafeFunctorArg

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

Usage

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

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

Or for a partially bound callback:

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

There may be up to two bound arguments and up to three unbound arguments. 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() and Callback::make_ref() functions, and the use of the Cgu::TypeTuple struct for calls involving two or three unbound arguments, read this: Callback

Constructor & Destructor Documentation

template<class FreeArg>
Cgu::Callback::CallbackArg< FreeArg >::CallbackArg ( )
inline

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

template<class FreeArg>
virtual Cgu::Callback::CallbackArg< FreeArg >::~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 FreeArg>
virtual void Cgu::Callback::CallbackArg< FreeArg >::dispatch ( typename Cgu::Param< FreeArg >::ParamType  arg) 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 a free or 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
argThe argument to be passed to the referenced function or class method, if any.
Note
1. 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.
2. This function is specialised for Callback::Callback (ie Callback::CallbackArg<void>) to take no argument, and for Callback::CallbackArg<TypeTuple<T1, T2> > and Callback::CallbackArg<TypeTuple<T1, T2, T3> > to take two and three arguments respectively.

Implemented in Cgu::Callback::CallbackArg2_static_< unref, BoundArg1, BoundArg2, FreeArg >, Cgu::Callback::CallbackArg1_static_< unref, BoundArg, FreeArg >, Cgu::Callback::CallbackArg0_static< FreeArg >, Cgu::Callback::CallbackArg2_const_< unref, T, BoundArg1, BoundArg2, FreeArg >, Cgu::Callback::CallbackArg1_const_< unref, T, BoundArg, FreeArg >, Cgu::Callback::CallbackArg0_const< T, FreeArg >, Cgu::Callback::CallbackArg2_< unref, T, BoundArg1, BoundArg2, FreeArg >, Cgu::Callback::CallbackArg1_< unref, T, BoundArg, FreeArg >, and Cgu::Callback::CallbackArg0< T, FreeArg >.


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