PLCnext API Documentation 25.0.2.69
MethodFunctor.hxx
1
2//
3// Copyright Phoenix Contact GmbH & Co. KG
4//
6#pragma once
7#include "Arp/Base/Core/Detail/DelegateFunctorBase.hxx"
8
9namespace Arp::Base::Core
10{
11
13
14template <typename T> class MethodFunctor;
15
17template<class C, class R, class ...A>
18class MethodFunctor<R(C::*)(A...)> : public DelegateFunctorBase<MethodFunctor<R(C::*)(A...)>>
19{
20public: // usings
21 using MethodPtr = R(C::*)(A...);
22
23public: // construction/destruction
24 MethodFunctor(C* pObject, R(C::*pMethod)(A...))
25 : pObject(pObject)
26 , pMethod(pMethod)
27 {
28 }
29
30 MethodFunctor(C& object, R(C::*pMethod)(A...))
31 : pObject(&object)
32 , pMethod(pMethod)
33 {
34 }
35
36public: // static operations
37 template<class ...Args>
38 static R Invoke(IDelegateFunctor* pFunctor, Args... args)
39 {
40 auto* pThis = dynamic_cast<MethodFunctor*>(pFunctor);
41 return std::invoke(pThis->pMethod, pThis->pObject, args...);
42 }
43
44protected: // overridden operations
45 bool EqualsTo(const MethodFunctor& other)override
46 {
47 return this->pObject == other.pObject && this->pMethod == other.pMethod;
48 }
49
50private: // fields
51 C* pObject{};
52 MethodPtr pMethod{};
53};
54
56
57} // end of namespace Arp::Base::Core