General purpose safe callback wrapper. Expects either c-style or c++ style function pointer, depending on if the C++ STL has been implemented on the given device or not. Simply wraps that function pointer and before calling it ensures it is valid.
More...
#include <Callback.h>
|
| | Callback ()=default |
| | Constructs empty callback, will result in never being called. Internals are simply default constructed as nullptr. More...
|
| |
| | Callback (function callback) |
| | Constructor. More...
|
| |
| virtual | ~Callback ()=default |
| | Virtual default destructor, created to ensure that if a pointer to this class is used and deleted, we will also call the derived base class destructor. More...
|
| |
| return_type | Call_Callback (argument_types const &... arguments) const |
| | Calls the callback that was subscribed, when this class instance was initally created. More...
|
| |
| void | Set_Callback (function callback) |
| | Sets the callback method that will be called upon data arrival with the given data that was received. If nullptr is passed the callback will never be called and instead return with a defaulted instance of the requested return variable. More...
|
| |
template<typename return_type, typename... argument_types>
class Callback< return_type, argument_types >
General purpose safe callback wrapper. Expects either c-style or c++ style function pointer, depending on if the C++ STL has been implemented on the given device or not. Simply wraps that function pointer and before calling it ensures it is valid.
- Template Parameters
-
| return_type | Type the given callback method should return |
| argument_types | Types the given callback method should receive |
◆ function
template<typename return_type , typename... argument_types>
| using Callback< return_type, argument_types >::function = std::function<return_type(argument_types... arguments)> |
◆ Callback() [1/2]
template<typename return_type , typename... argument_types>
Constructs empty callback, will result in never being called. Internals are simply default constructed as nullptr.
◆ Callback() [2/2]
template<typename return_type , typename... argument_types>
Constructor.
- Parameters
-
| callback | Callback method that will be called upon data arrival with the given data that was received. If nullptr is passed the callback will never be called and instead return with a defaulted instance of the requested return variable |
◆ ~Callback()
template<typename return_type , typename... argument_types>
Virtual default destructor, created to ensure that if a pointer to this class is used and deleted, we will also call the derived base class destructor.
- Note
- Deleting a base class destructor that does not have a virtual destructor is undefined behaviour, because the derived class destructor originally instantiated with new is never called. This can cause potential memory leaks, because derived classes can not clean up their internal members as expected and instead simply leak them
◆ Call_Callback()
template<typename return_type , typename... argument_types>
| return_type Callback< return_type, argument_types >::Call_Callback |
( |
argument_types const &... |
arguments | ) |
const |
|
inline |
Calls the callback that was subscribed, when this class instance was initally created.
- Note
- If the default constructor was used or a nullptr was passed instead of a valid function pointer, this method will simply return a defaulted instance of the requested return variable instead
- Parameters
-
| ...arguments | Optional additional arguments that are simply formwarded to the subscribed callback if it exists |
- Returns
- Argument returned by the previously subscribed callback or if none or nullptr is subscribed we instead return a defaulted instance of the requested return variable
◆ Set_Callback()
template<typename return_type , typename... argument_types>
Sets the callback method that will be called upon data arrival with the given data that was received. If nullptr is passed the callback will never be called and instead return with a defaulted instance of the requested return variable.
- Parameters
-
| callback | callback method that will be called upon data arrival with the given data that was received |
The documentation for this class was generated from the following file: