//! \addtogroup StateMachine
//! \{
//! \file pistatemachine_base.h
//! \brief
//! \~english Some template helpers for PIStateMachine
//! \~russian Несколько шаблонов для PIStateMachine
//! \details
//! \~english Contains helper classes and functions for state machine implementation
//! \~russian Содержит вспомогательные классы и функции для реализации машины состояний
//! \}
/*
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 .
*/
#ifndef pistatemachine_base_H
#define pistatemachine_base_H
#include "piconstchars.h"
namespace PIStateMachineHelpers {
//! \~english Helper namespace for state machine implementation
//! \~russian Вспомогательное пространство имён для реализации машины состояний
//! \~english Base class for function wrappers
//! \~russian Базовый класс для обёрток функций
class FunctionBase {
public:
//! \~english Virtual destructor
//! \~russian Виртуальный деструктор
virtual ~FunctionBase() {}
//! \~english Returns format hash for type checking
//! \~russian Возвращает хеш формата для проверки типов
virtual uint formatHash() = 0;
};
//! \~english Template class for function wrappers
//! \~russian Шаблонный класс для обёрток функций
template
class Function: public FunctionBase {
public:
//! \~english Returns format hash for type checking
//! \~russian Возвращает хеш формата для проверки типов
uint formatHash() override {
static uint ret = PIConstChars(typeid(std::function).name()).hash();
return ret;
}
//! \~english Stored function
//! \~russian Сохранённая функция
std::function func;
};
//! \~english Creates function wrapper from std::function
//! \~russian Создает обёртку функции из std::function
//! \tparam Ret Return type of the function
//! \tparam Args Argument types of the function
//! \param func Function to wrap
//! \return Pointer to function wrapper
template
FunctionBase * makeFunction(std::function func) {
auto * ret = new Function();
ret->func = func;
return ret;
}
} // namespace PIStateMachineHelpers
class PITransitionBase;
class PITransitionTimeout;
class PIStateBase;
class PIStateLambda;
class PIStateFinal;
class PIStateMachine;
#endif