PLCnext API Documentation 25.0.2.69
ConstMethodFunctor.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 ConstMethodFunctor;
15
17template<class C, class R, class ...A>
18class ConstMethodFunctor<R(C::*)(A...)const> : public DelegateFunctorBase<ConstMethodFunctor<R(C::*)(A...)const>>
19{
20public: // usings
21 using MethodPtr = R(C::*)(A...)const;
22
23public: // construction/destruction
24 ConstMethodFunctor(const C* pObject, R(C::*pMethod)(A...)const)
25 : pObject(pObject)
26 , pMethod(pMethod)
27 {
28 }
29
30 ConstMethodFunctor(const C& object, R(C::*pMethod)(A...)const)
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<ConstMethodFunctor*>(pFunctor);
41 return std::invoke(pThis->pMethod, pThis->pObject, args...);
42 }
43
44protected: // overridden operations
45 bool EqualsTo(const ConstMethodFunctor& other)override
46 {
47 return this->pObject == other.pObject && this->pMethod == other.pMethod;
48 }
49
50private: // fields
51 const C* pObject{};
52 MethodPtr pMethod{};
53};
54
56
57} // end of namespace Arp::Base::Core