17 #ifndef IOX_UTILS_CXX_METHOD_CALLBACK_HPP
18 #define IOX_UTILS_CXX_METHOD_CALLBACK_HPP
20 #include "iceoryx_utils/cxx/expected.hpp"
21 #include "iceoryx_utils/cxx/function_ref.hpp"
22 #include "iceoryx_utils/cxx/helplets.hpp"
35 enum class MethodCallbackError
38 UNINITIALIZED_CALLBACK
41 template <
typename ReturnValue,
typename... Args>
46 using ConstMethodPointer = ReturnValue (T::*)(Args...)
const;
57 template <
typename ClassType>
58 ConstMethodCallback(
const ClassType& objectRef, ConstMethodPointer<ClassType>
const methodPtr) noexcept;
74 template <
typename... MethodArguments>
75 expected<ReturnValue, MethodCallbackError>
operator()(MethodArguments&&... args)
const noexcept;
87 explicit operator bool() const noexcept;
96 template <typename ClassType>
97 void setCallback(const ClassType& objectRef, ConstMethodPointer<ClassType> methodPtr) noexcept;
100 template <typename ClassType>
104 template <typename ClassType>
108 const
void* m_objectPtr{
nullptr};
109 ConstMethodPointer<internal::GenericClass> m_methodPtr{
nullptr};
110 cxx::function_ref<ReturnValue(
const void*, ConstMethodPointer<internal::GenericClass>, Args...)> m_callback;
113 template <
typename ReturnValue,
typename... Args>
117 template <
typename T>
118 using MethodPointer = ReturnValue (T::*)(Args...);
129 template <
typename ClassType>
130 MethodCallback(ClassType& objectRef, MethodPointer<ClassType> methodPtr) noexcept;
146 template <
typename... MethodArguments>
147 expected<ReturnValue, MethodCallbackError>
operator()(MethodArguments&&... args) noexcept;
159 explicit operator bool()
const noexcept;
168 template <
typename ClassType>
169 void setCallback(ClassType& objectRef, MethodPointer<ClassType> methodPtr) noexcept;
172 template <
typename ClassType>
176 template <
typename ClassType>
180 void* m_objectPtr{
nullptr};
181 MethodPointer<internal::GenericClass> m_methodPtr{
nullptr};
182 cxx::function_ref<ReturnValue(
void*, MethodPointer<internal::GenericClass>, Args...)> m_callback;
188 #include "iceoryx_utils/internal/cxx/method_callback.inl"
Definition: method_callback.hpp:43
const ClassType * getObjectPointer() const noexcept
Returns object pointer.
Definition: method_callback.inl:151
bool operator!=(const ConstMethodCallback &rhs) const noexcept
Inequality operator. Two ConstMethodCallback are not equal if they have different object or method po...
Definition: method_callback.inl:121
auto getMethodPointer() const noexcept -> ConstMethodPointer< ClassType >
Returns cond method pointer.
Definition: method_callback.inl:158
bool operator==(const ConstMethodCallback &rhs) const noexcept
Comparison operator. Two ConstMethodCallbacks are equal if they have the same object pointer and meth...
Definition: method_callback.inl:115
bool isValid() const noexcept
Verifies if the ConstMethodCallback is valid.
Definition: method_callback.inl:127
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...
Definition: method_callback.inl:103
void setCallback(const ClassType &objectRef, ConstMethodPointer< ClassType > methodPtr) noexcept
Sets a new callback.
Definition: method_callback.inl:140
Definition: method_callback.hpp:115
expected< ReturnValue, MethodCallbackError > operator()(MethodArguments &&... args) noexcept
Calls the method if the MethodCallback is valid, otherwise it will return MethodCallbackError::UNINIT...
Definition: method_callback.inl:200
bool operator==(const MethodCallback &rhs) const noexcept
Comparison operator. Two MethodCallbacks are equal if they have the same object pointer and method po...
Definition: method_callback.inl:212
bool operator!=(const MethodCallback &rhs) const noexcept
Inequality operator. Two MethodCallbacks are not equal if they have different object or method pointe...
Definition: method_callback.inl:218
auto getMethodPointer() const noexcept -> MethodPointer< ClassType >
Returns cond method pointer.
Definition: method_callback.inl:255
void setCallback(ClassType &objectRef, MethodPointer< ClassType > methodPtr) noexcept
Sets a new callback.
Definition: method_callback.inl:237
ClassType * getObjectPointer() const noexcept
Returns objectRef.
Definition: method_callback.inl:248
bool isValid() const noexcept
Verifies if the MethodCallback is valid.
Definition: method_callback.inl:224
Definition: function_ref.hpp:32
Definition: method_callback.hpp:31
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:28