Skip to main content

Callback

A Callback is basically a wrapper of a pointer-to-member-function. It is used for registering callbacks between widgets. For instance, a Button can be configured to call a member function when it is clicked.

The class is templated in order to provide the class type of the object in which the member function resides, and the argument types of the function to call.

The Callback class exists in four versions, for supporting member functions with 0, 1, 2 or 3 arguments. The compiler will infer which type to use automatically.

Template Parameters:

  • dest_type The type of the class in which the member function resides.
  • T1 The type of the first argument in the member function, or void if none.
  • T2 The type of the second argument in the member function, or void if none.
  • T3 The type of the third argument in the member function, or void if none.

Note: The member function to call must return void. The function can have zero, one, two or three arguments of any type.

Inherits from: GenericCallback< void, void, void >

Public Functions

Callback()
Initializes a new instance of the Callback class.
Callback(dest_type pObject, void(dest_type::)(T1, T2, T3) pmemfun_3)
Initializes a Callback with an object and a pointer to the member function in that object to call.
virtual voidexecute(T1 t1, T2 t2, T3 t3)
Calls the member function.
virtual boolisValid() const
Function to check whether the Callback has been initialized with values.

Additional inherited members

Public Functions inherited from GenericCallback< void, void, void >

virtual ~GenericCallback()
Finalizes an instance of the GenericCallback class.

Public Functions Documentation

Callback

Initializes a new instance of the Callback class.

Callback

Callback(dest_type *pObject ,
void(dest_type::*)(T1, T2, T3)pmemfun_3
)

Initializes a Callback with an object and a pointer to the member function in that object to call.

Initializes a Callback with an object and a pointer to the member function in that object to call.

Parameters:
pObjectPointer to the object on which the function should be called.
pmemfun_3Address of member function. This is the version where function takes three arguments.

execute

virtual void execute(T1t1 ,
T2t2 ,
T3t3
)

Calls the member function.

Do not call execute unless isValid() returns true (ie. a pointer to the object and the function has been set).

Parameters:
t1This value will be passed as the first argument in the function call.
t2This value will be passed as the second argument in the function call.
t3This value will be passed as the third argument in the function call.

isValid

virtual bool isValid()const

Function to check whether the Callback has been initialized with values.

Returns:

true If the callback is valid (i.e. safe to call execute).