first state machine code, exclusive already works
need to make final, parallel, timeouts
This commit is contained in:
31
libs/main/state_machine/pistatemachine.cpp
Normal file
31
libs/main/state_machine/pistatemachine.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
State machine
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#include "pistatemachine.h"
|
||||
|
||||
|
||||
PIStateMachine::PIStateMachine(const PIString & n): PIStateBase(n) {
|
||||
is_root = true;
|
||||
}
|
||||
|
||||
|
||||
bool PIStateMachine::start() {
|
||||
setActiveRecursive(false);
|
||||
return PIStateBase::start();
|
||||
}
|
||||
61
libs/main/state_machine/pistatemachine.h
Normal file
61
libs/main/state_machine/pistatemachine.h
Normal file
@@ -0,0 +1,61 @@
|
||||
/*! \file pistatemachine.h
|
||||
* \ingroup StateMachine
|
||||
* \~\brief
|
||||
* \~english State machine.
|
||||
* \~russian Машина состояний.
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
State machine
|
||||
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_H
|
||||
#define pistatemachine_H
|
||||
|
||||
#include "pistatemachine_state.h"
|
||||
#include "pistatemachine_transition.h"
|
||||
|
||||
|
||||
//! \ingroup StateMachine
|
||||
//! \~\brief
|
||||
//! \~english
|
||||
//! \~russian
|
||||
class PIP_EXPORT PIStateMachine: public PIStateBase {
|
||||
public:
|
||||
PIStateMachine(const PIString & n = {});
|
||||
|
||||
bool start();
|
||||
|
||||
template<typename... Args>
|
||||
bool postEvent(int event_id, Args... args) {
|
||||
PIVector<PIStateBase *> active_states;
|
||||
gatherActiveStates(active_states);
|
||||
for (auto * s: active_states) {
|
||||
for (auto * t: s->transitions) {
|
||||
if (t->eventID != event_id) continue;
|
||||
if (t->testGuard(args...)) {
|
||||
t->trigger();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
79
libs/main/state_machine/pistatemachine_base.h
Normal file
79
libs/main/state_machine/pistatemachine_base.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/*! \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 PIStateBase;
|
||||
class PIStateMachine;
|
||||
|
||||
|
||||
#endif
|
||||
154
libs/main/state_machine/pistatemachine_state.cpp
Normal file
154
libs/main/state_machine/pistatemachine_state.cpp
Normal file
@@ -0,0 +1,154 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
State machine
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#include "pistatemachine_state.h"
|
||||
|
||||
#include "pistatemachine_transition.h"
|
||||
|
||||
|
||||
PIStateBase::~PIStateBase() {
|
||||
piDeleteAll(children);
|
||||
piDeleteAll(transitions);
|
||||
}
|
||||
|
||||
|
||||
void PIStateBase::addState(PIStateBase * s) {
|
||||
children << s;
|
||||
s->parent_state = this;
|
||||
propagateRoot(root);
|
||||
}
|
||||
|
||||
|
||||
void PIStateBase::addStates(PIVector<PIStateBase *> s) {
|
||||
children << s;
|
||||
for (auto * i: s)
|
||||
i->parent_state = this;
|
||||
propagateRoot(root);
|
||||
}
|
||||
|
||||
|
||||
void PIStateBase::setInitialState(PIStateBase * s) {
|
||||
if (children.contains(s))
|
||||
initial_state = s;
|
||||
else
|
||||
initial_state = nullptr;
|
||||
}
|
||||
|
||||
|
||||
PITransitionBase * PIStateBase::addTransition(PIStateBase * target, int event_id) {
|
||||
PITransitionBase * ret = new PITransitionBase(this, target, event_id);
|
||||
ret->root = root;
|
||||
transitions << ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void PIStateBase::print(PIString prefix) {
|
||||
PICout(PICoutManipulators::AddNewLine) << prefix << "[" << (isActive() ? "*" : " ") << "] " << getName();
|
||||
prefix += " ";
|
||||
for (auto * c: children)
|
||||
c->print(prefix);
|
||||
}
|
||||
|
||||
|
||||
bool PIStateBase::start() {
|
||||
if (isAtomic()) {
|
||||
setActive(true);
|
||||
return true;
|
||||
} else {
|
||||
if (initial_state) {
|
||||
setActive(true);
|
||||
return initial_state->start();
|
||||
} else
|
||||
piCout << "error:" << getName() << "no initial state!";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void PIStateBase::setActive(bool yes) {
|
||||
bool prev_active = is_active;
|
||||
is_active = yes;
|
||||
if (!prev_active && is_active) onEnter();
|
||||
if (prev_active && !is_active) onExit();
|
||||
}
|
||||
|
||||
|
||||
void PIStateBase::setActiveRecursive(bool yes) {
|
||||
if (yes) setActive(true);
|
||||
for (auto * c: children)
|
||||
c->setActiveRecursive(yes);
|
||||
if (!yes) setActive(false);
|
||||
}
|
||||
|
||||
|
||||
void PIStateBase::setChildActiveRecursive(bool yes) {
|
||||
for (auto * c: children)
|
||||
c->setActiveRecursive(yes);
|
||||
}
|
||||
|
||||
|
||||
void PIStateBase::setChildActive(PIStateBase * s) {
|
||||
if (isAtomic()) return;
|
||||
if (!s) s = initial_state;
|
||||
if (!s) {
|
||||
piCout << "error:" << getName() << "no initial state!";
|
||||
return;
|
||||
}
|
||||
for (auto * c: children)
|
||||
c->setActive(false);
|
||||
if (active_state) {
|
||||
if (active_state != s) active_state->setActive(false);
|
||||
}
|
||||
active_state = s;
|
||||
if (active_state) active_state->setActive(true);
|
||||
}
|
||||
|
||||
|
||||
void PIStateBase::propagateRoot(PIStateMachine * r) {
|
||||
if (is_root)
|
||||
root = reinterpret_cast<PIStateMachine *>(this);
|
||||
else
|
||||
root = r;
|
||||
for (auto * t: transitions)
|
||||
t->root = root;
|
||||
for (auto * c: children)
|
||||
c->propagateRoot(root);
|
||||
}
|
||||
|
||||
|
||||
void PIStateBase::gatherActiveStates(PIVector<PIStateBase *> & output) {
|
||||
for (auto * c: children)
|
||||
c->gatherActiveStates(output);
|
||||
if (is_active) output << this;
|
||||
}
|
||||
|
||||
|
||||
void PIStateBase::gatherPathToMachine(PIVector<PIStateBase *> & output) {
|
||||
if (isStateMachine()) return;
|
||||
output << this;
|
||||
if (parent()) parent()->gatherPathToMachine(output);
|
||||
}
|
||||
|
||||
|
||||
PIVector<PIStateBase *> PIStateBase::pathToMachine() {
|
||||
PIVector<PIStateBase *> ret;
|
||||
gatherPathToMachine(ret);
|
||||
return ret;
|
||||
}
|
||||
126
libs/main/state_machine/pistatemachine_state.h
Normal file
126
libs/main/state_machine/pistatemachine_state.h
Normal file
@@ -0,0 +1,126 @@
|
||||
/*! \file pistatemachine_state.h
|
||||
* \ingroup StateMachine
|
||||
* \~\brief
|
||||
* \~english State machine node
|
||||
* \~russian Узел машины состояний
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
State machine node
|
||||
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_state_H
|
||||
#define pistatemachine_state_H
|
||||
|
||||
#include "pistatemachine_base.h"
|
||||
#include "pistring.h"
|
||||
|
||||
|
||||
//! \ingroup StateMachine
|
||||
//! \~\brief
|
||||
//! \~english
|
||||
//! \~russian
|
||||
class PIP_EXPORT PIStateBase {
|
||||
friend class PIStateMachine;
|
||||
friend class PITransitionBase;
|
||||
|
||||
public:
|
||||
PIStateBase(const PIString & n = {}): name_(n) { ; }
|
||||
virtual ~PIStateBase();
|
||||
|
||||
virtual void onEnter() {}
|
||||
virtual void onExit() {}
|
||||
|
||||
PIStateMachine * machine() const { return root; }
|
||||
PIStateBase * parent() const { return parent_state; }
|
||||
|
||||
void addState(PIStateBase * s);
|
||||
void addStates(PIVector<PIStateBase *> s);
|
||||
void setInitialState(PIStateBase * s);
|
||||
|
||||
PITransitionBase * addTransition(PIStateBase * target, int event_id);
|
||||
|
||||
void setParallel(bool yes) { is_parallel = yes; }
|
||||
|
||||
const PIString & getName() const { return name_; }
|
||||
bool isStateMachine() const { return is_root; }
|
||||
bool isActive() const { return is_active; }
|
||||
bool isParallel() const { return is_parallel; }
|
||||
bool isAtomic() const { return children.isEmpty(); }
|
||||
bool isCompound() const { return children.isNotEmpty(); }
|
||||
const PIVector<PIStateBase *> & getChildren() const { return children; }
|
||||
const PIVector<PITransitionBase *> & getTransitions() const { return transitions; }
|
||||
|
||||
void print(PIString prefix = {});
|
||||
|
||||
protected:
|
||||
bool start();
|
||||
void setActive(bool yes);
|
||||
void setActiveRecursive(bool yes);
|
||||
void setChildActiveRecursive(bool yes);
|
||||
void setChildActive(PIStateBase * s);
|
||||
void propagateRoot(PIStateMachine * r);
|
||||
void gatherActiveStates(PIVector<PIStateBase *> & output);
|
||||
void gatherPathToMachine(PIVector<PIStateBase *> & output);
|
||||
PIVector<PIStateBase *> pathToMachine();
|
||||
|
||||
bool is_active = false, is_root = false, is_parallel = false;
|
||||
PIVector<PIStateBase *> children;
|
||||
PIVector<PITransitionBase *> transitions;
|
||||
PIStateBase *active_state = nullptr, *initial_state = nullptr, *parent_state = nullptr;
|
||||
PIStateMachine * root = nullptr;
|
||||
PIString name_;
|
||||
};
|
||||
|
||||
|
||||
class PIP_EXPORT PIStateLambda: public PIStateBase {
|
||||
public:
|
||||
PIStateLambda(std::function<void()> on_enter, std::function<void()> on_exit = nullptr, const PIString & n = {}): PIStateBase(n) {
|
||||
enter = on_enter;
|
||||
exit = on_exit;
|
||||
}
|
||||
void onEnter() override {
|
||||
if (enter) enter();
|
||||
}
|
||||
void onExit() override {
|
||||
if (exit) exit();
|
||||
}
|
||||
|
||||
private:
|
||||
std::function<void()> enter, exit;
|
||||
};
|
||||
|
||||
|
||||
class PIP_EXPORT PIStateFinal: public PIStateBase {
|
||||
public:
|
||||
PIStateFinal(std::function<void()> on_enter, std::function<void()> on_exit = nullptr, const PIString & n = {}): PIStateBase(n) {
|
||||
enter = on_enter;
|
||||
exit = on_exit;
|
||||
}
|
||||
void onEnter() override {
|
||||
if (enter) enter();
|
||||
}
|
||||
void onExit() override {
|
||||
if (exit) exit();
|
||||
}
|
||||
|
||||
private:
|
||||
std::function<void()> enter, exit;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
81
libs/main/state_machine/pistatemachine_transition.cpp
Normal file
81
libs/main/state_machine/pistatemachine_transition.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
State machine
|
||||
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/>.
|
||||
*/
|
||||
|
||||
#include "pistatemachine_transition.h"
|
||||
|
||||
#include "pistatemachine_state.h"
|
||||
|
||||
|
||||
PITransitionBase::PITransitionBase(PIStateBase * source, PIStateBase * target, int event_id) {
|
||||
target_state = target;
|
||||
source_state = source;
|
||||
eventID = event_id;
|
||||
}
|
||||
|
||||
|
||||
PITransitionBase::~PITransitionBase() {
|
||||
piDeleteSafety(guard);
|
||||
}
|
||||
|
||||
|
||||
PITransitionBase * PITransitionBase::addAction(std::function<void()> a) {
|
||||
action = a;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
void PITransitionBase::makeAction() {
|
||||
if (action) action();
|
||||
}
|
||||
|
||||
|
||||
void PITransitionBase::trigger() {
|
||||
if (!target_state || (source_state == target_state)) {
|
||||
makeAction();
|
||||
return;
|
||||
}
|
||||
// source_state->setActiveRecursive(false);
|
||||
auto source_path = source_state->pathToMachine();
|
||||
auto target_path = target_state->pathToMachine();
|
||||
auto source_target_path = target_path;
|
||||
source_target_path.reverse();
|
||||
// piCout << "source_path" << source_path;
|
||||
// piCout << "target_path" << target_path;
|
||||
ssize_t common_count = 0;
|
||||
for (common_count = 0; common_count < piMini(source_path.size_s(), target_path.size_s()); ++common_count) {
|
||||
// piCout << "check" << source_path[source_path.size_s() - common_count - 1] << target_path[target_path.size_s() - common_count -
|
||||
// 1];
|
||||
if (source_path[source_path.size_s() - common_count - 1] != target_path[target_path.size_s() - common_count - 1]) {
|
||||
// piCout << "diff" << common_count;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// piCout << "common" << common_count;
|
||||
source_path.remove(source_path.size_s() - common_count, common_count);
|
||||
target_path.remove(target_path.size_s() - common_count, common_count);
|
||||
// piCout << "source_path" << source_path;
|
||||
// piCout << "target_path" << target_path;
|
||||
source_state->setChildActiveRecursive(false);
|
||||
for (auto * s: source_path)
|
||||
s->setActive(false);
|
||||
makeAction();
|
||||
for (auto * s: source_target_path)
|
||||
s->setActive(true);
|
||||
if (target_state->isCompound()) target_state->start();
|
||||
}
|
||||
84
libs/main/state_machine/pistatemachine_transition.h
Normal file
84
libs/main/state_machine/pistatemachine_transition.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/*! \file pistatemachine_transition.h
|
||||
* \ingroup StateMachine
|
||||
* \~\brief
|
||||
* \~english State machine transition
|
||||
* \~russian Переход машины состояний
|
||||
*/
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
State machine transition
|
||||
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_transition_H
|
||||
#define pistatemachine_transition_H
|
||||
|
||||
#include "pistatemachine_base.h"
|
||||
|
||||
|
||||
//! \ingroup StateMachine
|
||||
//! \~\brief
|
||||
//! \~english
|
||||
//! \~russian
|
||||
class PIP_EXPORT PITransitionBase {
|
||||
friend class PIStateMachine;
|
||||
friend class PIStateBase;
|
||||
|
||||
public:
|
||||
PITransitionBase(PIStateBase * source, PIStateBase * target, int event_id);
|
||||
~PITransitionBase();
|
||||
|
||||
PIStateMachine * machine() const { return root; }
|
||||
PIStateBase * source() const { return source_state; }
|
||||
PIStateBase * target() const { return target_state; }
|
||||
|
||||
template<typename R, typename... Args>
|
||||
PITransitionBase * addGuard(std::function<R(Args...)> f) {
|
||||
static_assert(std::is_same<R, bool>::value, "guard function should return bool!");
|
||||
piDeleteSafety(guard);
|
||||
guard = PIStateMachineHelpers::makeFunction(f);
|
||||
return this;
|
||||
}
|
||||
|
||||
template<typename L>
|
||||
PITransitionBase * addGuard(L f) {
|
||||
return addGuard(PIStateMachineHelpers::toStdFunction(f));
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
bool testGuard(Args... args) {
|
||||
if (!guard) return true;
|
||||
if (guard->formatHash() != PIStateMachineHelpers::Function<Args...>().formatHash()) {
|
||||
piCout << "invalid arguments format!";
|
||||
return false;
|
||||
}
|
||||
return reinterpret_cast<PIStateMachineHelpers::Function<Args...> *>(guard)->func(args...);
|
||||
}
|
||||
|
||||
PITransitionBase * addAction(std::function<void()> a);
|
||||
void makeAction();
|
||||
|
||||
void trigger();
|
||||
|
||||
protected:
|
||||
int eventID = 0;
|
||||
PIStateBase *source_state = nullptr, *target_state = nullptr;
|
||||
PIStateMachine * root = nullptr;
|
||||
PIStateMachineHelpers::FunctionBase * guard = nullptr;
|
||||
std::function<void()> action;
|
||||
};
|
||||
|
||||
#endif
|
||||
56
libs/main/state_machine/pistatemachinemodule.h
Normal file
56
libs/main/state_machine/pistatemachinemodule.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Module includes
|
||||
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/>.
|
||||
*/
|
||||
//! \defgroup StateMachine StateMachine
|
||||
//! \~\brief
|
||||
//! \~english State machine.
|
||||
//! \~russian Машина состояний.
|
||||
//!
|
||||
//! \~\details
|
||||
//! \~english \section cmake_module_StateMachine Building with CMake
|
||||
//! \~russian \section cmake_module_StateMachine Сборка с использованием CMake
|
||||
//!
|
||||
//! \~\code
|
||||
//! find_package(PIP REQUIRED)
|
||||
//! target_link_libraries([target] PIP)
|
||||
//! \endcode
|
||||
//!
|
||||
//! \~english \par Common
|
||||
//! \~russian \par Общее
|
||||
//!
|
||||
//! \~english
|
||||
//!
|
||||
//! \~russian
|
||||
//!
|
||||
//! \~\authors
|
||||
//! \~english
|
||||
//! Ivan Pelipenko peri4ko@yandex.ru;
|
||||
//! Andrey Bychkov work.a.b@yandex.ru;
|
||||
//! \~russian
|
||||
//! Иван Пелипенко peri4ko@yandex.ru;
|
||||
//! Андрей Бычков work.a.b@yandex.ru;
|
||||
//!
|
||||
|
||||
#ifndef PISTATEMACHINEMODULE_H
|
||||
#define PISTATEMACHINEMODULE_H
|
||||
|
||||
#include "pistatemachine.h"
|
||||
#include "pistatemachine_state.h"
|
||||
#include "pistatemachine_transition.h"
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user