c++-gtk-utils

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

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< FreeArgs >::ParamType... args) const
SafeFunctorArg & | operator= (const SafeFunctorArg &f)
SafeFunctorArg & | operator= (SafeFunctorArg &&f)
| SafeFunctorArg (const CallbackArg< FreeArgs... > *cb)
| SafeFunctorArg (const SafeFunctorArg &f)
| SafeFunctorArg (SafeFunctorArg &&f)
| SafeFunctorArg ()

## Friends
struct | std::hash< SafeFunctorArg >
bool | operator== (const SafeFunctorArg &, const SafeFunctorArg &) noexcept
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 wraps a CallbackArg object. It 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 further details. The Callback::to_safe_functor() function can be used in place of the Callback::to_functor() function when constructing a Callback::SafeFunctorArg object using the auto keyword.

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

For further background, including about the Callback::make(), Callback::make_ref() and Callback::to_safe_functor() functions, read this: Callback

## Constructor & Destructor Documentation

## ◆ SafeFunctorArg() [1/4]

Cgu::Callback::SafeFunctorArg::SafeFunctorArg | ( | const CallbackArg< FreeArgs... > * | cb | ) |
| inline

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

Parameters

  cb | The CallbackArg object which the functor is to manage.

Exceptions

  std::bad_alloc | This 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
  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.

## ◆ SafeFunctorArg() [2/4]

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

The copy constructor does not throw.

Parameters

  f | The assignor.

## ◆ SafeFunctorArg() [3/4]

Cgu::Callback::SafeFunctorArg::SafeFunctorArg | ( | SafeFunctorArg && | f | ) |
| inline

The move constructor does not throw.

Parameters

  f | The functor to be moved.

## ◆ SafeFunctorArg() [4/4]

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 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< FreeArgs >::ParamType... | args | ) | const
| inline

This will execute the function, callable object or class method represented 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, callable object 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

  args | The unbound arguments to be passed to the referenced function, callable object or class method, if any.

## ◆ operator=() [1/2]

SafeFunctorArg& Cgu::Callback::SafeFunctorArg::operator= | ( | const SafeFunctorArg & | f | ) |
| inline

This function does not throw.

Parameters

  f | The assignor.

Returns
  The functor object after assignment.

## ◆ operator=() [2/2]

SafeFunctorArg& Cgu::Callback::SafeFunctorArg::operator= | ( | SafeFunctorArg && | f | ) |
| inline

This function does not throw.

Parameters

  f | The functor to be moved.

Returns
  The functor object after the move operation.

## Friends And Related Function Documentation

## ◆ operator<

bool operator< | ( | const SafeFunctorArg & | ,
|  | const SafeFunctorArg & |
| ) |  |
| friend

One SafeFunctorArg object is less than another if the address of the CallbackArg object contained by the first is regarded by std::less as less than the address of the CallbackArg object contained by the other. This comparison operator does not throw unless std::less applied to pointer types throws (which it would not do with any sane implementation).

## ◆ operator==

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

Two SafeFunctorArg objects compare equal if the addresses of the CallbackArg objects they contain are the same. This comparison operator does not throw.

## ◆ std::hash< SafeFunctorArg >

friend struct std::hash< SafeFunctorArg >
| friend

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

- callback.h