I am trying to pass a method as a pointer function, so I created a binding as shown here , but as the method is defined, I cannot pass it as a parameter to the binder. The function I need to pass the method pointer is related to the Regex Lua template library for arduino, found here .
void InterpreterClass::init()
{
MatchState ms("255.255.255.255");
bind_regex_member<InterpreterClass, &InterpreterClass::MatchAddressCallback, 0> b(this);
ms.GlobalMatch("(%d%d?%d?)", b);
}
void InterpreterClass::MatchAddressCallback(const char * match, const unsigned int length, const MatchState & ms)
{
}
at the ms.GlobalMatchsecond parameter is the method that I want to execute after interpreting the string, the problem is that the function must obey a certain sequence of parameters, for example, if it has been delegated.
typedef void (*GlobalMatchCallback) (const char * match,
const unsigned int length,
const MatchState & ms);
I tried to implement a binder with all declared parameters, and a type name was also declared with it. The bolt follows the binder:
template<class T, void(T::*PTR)(const char *, const unsigned int, const MatchState &), size_t I>
struct bind_regex_member
{
typedef void(*fn_type)(const char *, const unsigned int, const MatchState &);
explicit bind_regex_member(const T* _ptr)
{
ptr = _ptr;
}
static void func(const char * match, const unsigned int length, const MatchState & ms)
{
(ptr->*PTR)(match, length, ms);
}
operator fn_type()
{
return &func;
}
private:
static const T* ptr;
};
template<class T, void(T::*PTR)(const char *, const unsigned int, const MatchState &), size_t I>
const T* bind_regex_member<T, PTR, I>::ptr = NULL;
, :
Error: `Interpreter.cpp:7:80: error: could not convert template argument ‘&InterpreterClass::MatchAddressCallback’ to ‘void (InterpreterClass::*)(const char*, unsigned int, const MatchState&)’`
GlobalMatchCallback . MatchAddressCallback?
: https://github.com/rsegecin/RegexArduino.git.
PS: , .