17#ifndef IOX_HOOFS_CXX_METHOD_CALLBACK_HPP
18#define IOX_HOOFS_CXX_METHOD_CALLBACK_HPP
20#include "iceoryx_hoofs/cxx/expected.hpp"
21#include "iceoryx_hoofs/cxx/function_ref.hpp"
22#include "iceoryx_hoofs/cxx/helplets.hpp"
35enum class MethodCallbackError
37 UNINITIALIZED_CALLBACK
40template <
typename ReturnValue,
typename... Args>
45 using ConstMethodPointer = ReturnValue (T::*)(Args...)
const;
56 template <
typename ClassType>
57 ConstMethodCallback(
const ClassType& objectRef, ConstMethodPointer<ClassType>
const methodPtr)
noexcept;
73 template <
typename... MethodArguments>
74 expected<ReturnValue, MethodCallbackError>
operator()(MethodArguments&&... args)
const noexcept;
86 explicit operator bool() const noexcept;
95 template <typename ClassType>
96 void setCallback(const ClassType& objectRef, ConstMethodPointer<ClassType> methodPtr) noexcept;
99 template <typename ClassType>
103 template <typename ClassType>
107 const
void* m_objectPtr{
nullptr};
108 ConstMethodPointer<internal::GenericClass> m_methodPtr{
nullptr};
109 cxx::function_ref<ReturnValue(
const void*, ConstMethodPointer<internal::GenericClass>, Args...)> m_callback;
112template <
typename ReturnValue,
typename... Args>
116 template <
typename T>
117 using MethodPointer = ReturnValue (T::*)(Args...);
128 template <
typename ClassType>
129 MethodCallback(ClassType& objectRef, MethodPointer<ClassType> methodPtr)
noexcept;
145 template <
typename... MethodArguments>
146 expected<ReturnValue, MethodCallbackError>
operator()(MethodArguments&&... args)
noexcept;
158 explicit operator bool() const noexcept;
167 template <typename ClassType>
168 void setCallback(ClassType& objectRef, MethodPointer<ClassType> methodPtr) noexcept;
171 template <typename ClassType>
175 template <typename ClassType>
179 void* m_objectPtr{
nullptr};
180 MethodPointer<internal::GenericClass> m_methodPtr{
nullptr};
181 cxx::function_ref<ReturnValue(
void*, MethodPointer<internal::GenericClass>, Args...)> m_callback;
187#include "iceoryx_hoofs/internal/cxx/method_callback.inl"
Definition method_callback.hpp:42
ConstMethodCallback & operator=(ConstMethodCallback &&rhs) noexcept
Move assignment operator.
const ClassType * getObjectPointer() const noexcept
Returns object pointer.
bool operator!=(const ConstMethodCallback &rhs) const noexcept
Inequality operator. Two ConstMethodCallback are not equal if they have different object or method po...
auto getMethodPointer() const noexcept -> ConstMethodPointer< ClassType >
Returns cond method pointer.
bool operator==(const ConstMethodCallback &rhs) const noexcept
Comparison operator. Two ConstMethodCallbacks are equal if they have the same object pointer and meth...
bool isValid() const noexcept
Verifies if the ConstMethodCallback is valid.
ConstMethodCallback(ConstMethodCallback &&rhs) noexcept
Move constructor.
ConstMethodCallback(const ClassType &objectRef, ConstMethodPointer< ClassType > const methodPtr) noexcept
Constructs a ConstMethodCallback from a pointer to a specific object and a pointer to a method of tha...
expected< ReturnValue, MethodCallbackError > operator()(MethodArguments &&... args) const noexcept
Calls the method if the ConstMethodCallback is valid, otherwise it will return MethodCallbackError::U...
void setCallback(const ClassType &objectRef, ConstMethodPointer< ClassType > methodPtr) noexcept
Sets a new callback.
Definition method_callback.hpp:114
expected< ReturnValue, MethodCallbackError > operator()(MethodArguments &&... args) noexcept
Calls the method if the MethodCallback is valid, otherwise it will return MethodCallbackError::UNINIT...
bool operator==(const MethodCallback &rhs) const noexcept
Comparison operator. Two MethodCallbacks are equal if they have the same object pointer and method po...
bool operator!=(const MethodCallback &rhs) const noexcept
Inequality operator. Two MethodCallbacks are not equal if they have different object or method pointe...
auto getMethodPointer() const noexcept -> MethodPointer< ClassType >
Returns cond method pointer.
void setCallback(ClassType &objectRef, MethodPointer< ClassType > methodPtr) noexcept
Sets a new callback.
MethodCallback & operator=(MethodCallback &&rhs) noexcept
Move assignment operator.
ClassType * getObjectPointer() const noexcept
Returns objectRef.
MethodCallback(MethodCallback &&rhs) noexcept
Move constructor.
MethodCallback(ClassType &objectRef, MethodPointer< ClassType > methodPtr) noexcept
Constructs a MethodCallback from a pointer to a specific object and a pointer to a method of that obj...
bool isValid() const noexcept
Verifies if the MethodCallback is valid.
Definition function_ref.hpp:34
building block to easily create free function for logging in a library context
Definition lockfree_queue.hpp:29