powerd++  0.4.4
Public Types | Public Member Functions | Private Attributes | List of all members
anonymous_namespace{libloadplay.cpp}::Callback< FunctionArgs > Class Template Reference

Implements a recursion safe std::function wrapper. More...

Public Types

typedef std::function< void(FunctionArgs...)> function_t
 The callback function type.
 

Public Member Functions

 Callback ()
 Default constructor, creates a non-callable handle.
 
 Callback (function_t const &callback)
 Construct from function. More...
 
 Callback (function_t &&callback)
 Construct from temporary function. More...
 
void operator() (FunctionArgs... args)
 Forward call to callback functions. More...
 

Private Attributes

function_t callback
 Storage for the callback function.
 
bool called {false}
 Set if this handle is currently in use.
 

Detailed Description

template<typename... FunctionArgs>
class anonymous_namespace{libloadplay.cpp}::Callback< FunctionArgs >

Implements a recursion safe std::function wrapper.

The purpose is to prevent recursive calls of a callback function handle, in cases when a callback function performs actions that cause a successive call of the callback function.

To avoid having to return a value when a successive function call occurs only functions returning void are valid callback functions.

This is not thread safe.

Template Parameters
FunctionArgsThe argument types of the callback function

Constructor & Destructor Documentation

◆ Callback() [1/2]

template<typename... FunctionArgs>
anonymous_namespace{libloadplay.cpp}::Callback< FunctionArgs >::Callback ( function_t const &  callback)
inline

Construct from function.

Parameters
callbackThe callback function

◆ Callback() [2/2]

template<typename... FunctionArgs>
anonymous_namespace{libloadplay.cpp}::Callback< FunctionArgs >::Callback ( function_t &&  callback)
inline

Construct from temporary function.

Parameters
callbackThe callback function

Member Function Documentation

◆ operator()()

template<typename... FunctionArgs>
void anonymous_namespace{libloadplay.cpp}::Callback< FunctionArgs >::operator() ( FunctionArgs...  args)
inline

Forward call to callback functions.

Parameters
argsThe arguments to the callback function
Exceptions
std::bad_function_callIn case this handler was default constructed or constructed from a nullptr

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