MotorControlModuleSDFM_TMS3.../Projects/EFC_Communication/UMLibrary/systemic/MemberFuntion.hpp
2024-06-07 11:12:56 +03:00

97 lines
2.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* MemberFuntion.hpp
*
* Created on: 4 мар. 2020 г.
* Author: titov
*/
#ifndef UMLIBRARY_SYSTEMIC_MEMBERFUNTION_HPP_
#define UMLIBRARY_SYSTEMIC_MEMBERFUNTION_HPP_
#include "IFunctor.hh"
#include "IValue.hpp"
namespace systemic { namespace detail {
template<typename T, typename ResultType, ResultType (T::* pf)()>
struct MemberFuntion : public systemic::IFunctor<ResultType> {
private:
T & object;
public:
MemberFuntion( T & obj );
ResultType operator()() final;
MemberFuntion(const MemberFuntion &) = delete;
MemberFuntion & operator=(const MemberFuntion &) = delete;
};
template<typename T, typename ResultType, typename ... Args>
struct MemberArgsFuntion : public systemic::IFunctor<ResultType, Args ...> {
private:
T & object;
ResultType ( T::* const pf )( Args ... );
public:
typedef systemic::IFunctor<ResultType, Args ...> FunctorInterface;
MemberArgsFuntion( T & obj, ResultType ( T::* method )( Args ... ) );
ResultType operator()( Args ... ) final;
MemberArgsFuntion(const MemberArgsFuntion &) = delete;
MemberArgsFuntion & operator=(const MemberArgsFuntion &) = delete;
};
template<typename T, typename ResultType, void (T::* pf)()>
struct MemberFuntionExternalResult : public systemic::IFunctor<ResultType> {
private:
T & object;
IValue<ResultType> & result;
public:
MemberFuntionExternalResult( T & obj, IValue<ResultType> & result );
ResultType operator()() final;
MemberFuntionExternalResult(const MemberFuntionExternalResult &) = delete;
MemberFuntionExternalResult & operator=(const MemberFuntionExternalResult &) = delete;
~MemberFuntionExternalResult() = default;
};
}
}
template<typename T, typename ResultType, ResultType (T::*pf)()>
inline systemic::detail::MemberFuntion<T, ResultType, pf>::MemberFuntion( T & obj) : object(obj) {}
template<typename T, typename ResultType, ResultType (T::*pf)()>
inline ResultType systemic::detail::MemberFuntion<T, ResultType, pf>::operator()() {
return (object.*pf)();
}
template<typename T, typename ResultType, void (T::*pf)()>
inline systemic::detail::MemberFuntionExternalResult<T, ResultType, pf>::MemberFuntionExternalResult(
T & obj, IValue<ResultType> & result) : object(obj), result(result) {}
template<typename T, typename ResultType, void (T::*pf)()>
inline ResultType systemic::detail::MemberFuntionExternalResult<T, ResultType,pf>::operator()() {
return (object.*pf)(), result;
}
template<typename T, typename ResultType, typename ... Args>
inline systemic::detail::MemberArgsFuntion<T, ResultType, Args...>::MemberArgsFuntion(
T & obj, ResultType ( T::* method )( Args ... ) ) : object(obj), pf(method) {}
template<typename T, typename ResultType, typename ... Args>
inline ResultType systemic::detail::MemberArgsFuntion<T, ResultType, Args...>::operator()( Args ... args ) {
return (object.*pf)( args... );
}
#endif /* UMLIBRARY_SYSTEMIC_MEMBERFUNTION_HPP_ */