c++-gtk-utils
Public Member Functions | Friends | List of all members
Cgu::Callback::SafeFunctorArg Class Reference

Functor class holding a Callback::CallbackArg object, with thread-safe reference count. More...

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

Public Member Functions

void operator() (typename Cgu::Param< FreeArg >::ParamType arg) const
 
 SafeFunctorArg (const CallbackArg< FreeArg > *cb)
 
 SafeFunctorArg (const SafeFunctorArg &f)
 
 SafeFunctorArg ()
 

Friends

bool operator== (const SafeFunctorArg &, const SafeFunctorArg &)
 
bool operator< (const SafeFunctorArg &, const SafeFunctorArg &)
 

Detailed Description

Functor class holding a Callback::CallbackArg object, with thread-safe reference count.

See also
FunctorArg
Callback namespace

This class is the same as Callback::FunctorArg except that it will provide synchronisation of the reference count between threads. Use it where a functor wrapper object is to be passed between threads. The FunctorArg documentation gives details on usage.

Callback::SafeFunctorArg<void> is typedef'ed to Callback::SafeFunctor.

For further background, read this: Callback

Constructor & Destructor Documentation

◆ SafeFunctorArg() [1/3]

Cgu::Callback::SafeFunctorArg::SafeFunctorArg ( const CallbackArg< FreeArg > *  cb)
inline

Constructor of first SafeFunctorArg holding the referenced callback. As it is not marked explicit, it is also a type conversion constructor.

Parameters
cbThe CallbackArg object which the functor is to manage.
Exceptions
std::bad_allocThis might throw std::bad_alloc if memory is exhausted and the system throws in that case. Note that if such an exception is thrown, then this constructor will clean itself up and also delete the callback object passed to it.
Note
1. std::bad_alloc will not be thrown if the library has been installed using the --with-glib-memory-slices-no-compat configuration option: instead glib will terminate the program if it is unable to obtain memory from the operating system.
2. This function is specialised for Callback::SafeFunctor (ie Callback::SafeFunctorArg<void>) to take a Callback::Callback argument, and for Callback::SafeFunctorArg<TypeTuple<T1, T2> > and Callback::SafeFunctorArg<TypeTuple<T1, T2, T3> > to take a Callback::CallbackArg<TypeTuple<T1, T2> > and Callback::CallbackArg<TypeTuple<T1, T2, T3> > argument respectively.

◆ SafeFunctorArg() [2/3]

Cgu::Callback::SafeFunctorArg::SafeFunctorArg ( const SafeFunctorArg f)
inline

The copy constructor does not throw.

Parameters
fThe assignor.

◆ SafeFunctorArg() [3/3]

Cgu::Callback::SafeFunctorArg::SafeFunctorArg ( )
inline

Default constructor, where a Callback::CallbackArg object is to be assigned later (via the type conversion constructor and/or the implicit assignment operator). This constructor does not throw.

Note
The reference count maintained with respect to the contained callback object is thread-safe, so SafeFunctorArg objects may be copied between threads by the implicit assignment operator and put in different containers in different threads. They use a SharedLockPtr object to hold the referenced callback object.

Member Function Documentation

◆ operator()()

void Cgu::Callback::SafeFunctorArg::operator() ( typename Cgu::Param< FreeArg >::ParamType  arg) const
inline

This will execute the function or class method referenced by the callback encapsulated by this object, or do nothing if this object has not been initialized with a callback. It will only throw if the executed 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
This function is specialised for Callback::SafeFunctor (ie Callback::SafeFunctorArg<void>) to take no argument, and for Callback::SafeFunctorArg<TypeTuple<T1, T2> > and Callback::SafeFunctorArg<TypeTuple<T1, T2, T3> > to take two and three arguments respectively.

Friends And Related Function Documentation

◆ operator<

bool operator< ( const SafeFunctorArg ,
const SafeFunctorArg  
)
friend

This comparison operator does not throw.

◆ operator==

bool operator== ( const SafeFunctorArg ,
const SafeFunctorArg  
)
friend

This comparison operator does not throw (this friend function is also called by operator!=<>() from version 1.2.5).


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