83 lines
2.2 KiB
C++
83 lines
2.2 KiB
C++
/*! \file pistatemachine_base.h
|
|
* \ingroup StateMachine
|
|
* \~\brief
|
|
* \~english Some template helpers for PIStateMachine
|
|
* \~russian Несколько шаблонов для PIStateMachine
|
|
*/
|
|
/*
|
|
PIP - Platform Independent Primitives
|
|
Some template helpers for PIStateMachine
|
|
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef pistatemachine_base_H
|
|
#define pistatemachine_base_H
|
|
|
|
#include "piconstchars.h"
|
|
|
|
|
|
namespace PIStateMachineHelpers {
|
|
|
|
template<typename T>
|
|
struct FunctionType {
|
|
using Type = void;
|
|
};
|
|
|
|
template<typename Ret, typename Class, typename... Args>
|
|
struct FunctionType<Ret (Class::*)(Args...) const> {
|
|
using Type = std::function<Ret(Args...)>;
|
|
};
|
|
|
|
template<typename L>
|
|
typename FunctionType<decltype(&L::operator())>::Type toStdFunction(L const & func) {
|
|
return func;
|
|
}
|
|
|
|
class FunctionBase {
|
|
public:
|
|
virtual ~FunctionBase() {}
|
|
virtual uint formatHash() = 0;
|
|
};
|
|
|
|
template<typename... Args>
|
|
class Function: public FunctionBase {
|
|
public:
|
|
uint formatHash() override {
|
|
static uint ret = PIConstChars(typeid(std::function<void(Args...)>).name()).hash();
|
|
return ret;
|
|
}
|
|
std::function<bool(Args...)> func;
|
|
};
|
|
|
|
template<typename Ret, typename... Args>
|
|
FunctionBase * makeFunction(std::function<Ret(Args...)> func) {
|
|
auto * ret = new Function<Args...>();
|
|
ret->func = func;
|
|
return ret;
|
|
}
|
|
|
|
} // namespace PIStateMachineHelpers
|
|
|
|
class PITransitionBase;
|
|
class PITransitionTimeout;
|
|
class PIStateBase;
|
|
class PIStateLambda;
|
|
class PIStateFinal;
|
|
class PIStateMachine;
|
|
|
|
|
|
#endif
|