//! \~\file pistatemachine_base.h
//! \~\ingroup StateMachine
//! \~\brief
//! \~english Declares helper types shared by the state machine API
//! \~russian Объявляет вспомогательные типы, общие для API машины состояний
/*
    PIP - Platform Independent Primitives
	Some template helpers for PIStateMachine
	Ivan Pelipenko peri4ko@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 {

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  = std::move(func);
	return ret;
}

} // namespace PIStateMachineHelpers

class PITransitionBase;
class PITransitionTimeout;
class PIStateBase;
class PIStateLambda;
class PIStateFinal;
class PIStateMachine;


#endif
