This commit is contained in:
2025-11-01 11:57:49 +03:00
parent 8a202bd38c
commit a7fbae47f0
5 changed files with 56 additions and 19 deletions

View File

@@ -317,6 +317,7 @@ protected:
std::vector<std::function<void(const MccFiniteStateMachine*)>> _destroyFunc{};
std::string_view _currentStateID;
std::string_view _previousStateID;
std::vector<std::string_view> _stateID{};
std::vector<std::string_view> _eventID{};
@@ -367,7 +368,7 @@ protected:
public:
template <traits::fsm_state_c InitStateT>
constexpr MccFiniteStateMachine(InitStateT) : _currentStateID(InitStateT::ID)
constexpr MccFiniteStateMachine(InitStateT) : _currentStateID(InitStateT::ID), _previousStateID(InitStateT::ID)
{
using states_t = deduce_states_t<InitStateT>;
auto states = std::make_shared<states_t>();
@@ -417,6 +418,7 @@ public:
p_event->onTransit();
}
_previousStateID = curr_state_t::ID;
*currentState = &std::get<to_state_t>(*states);
_currentStateID = to_state_t::ID;
@@ -525,6 +527,11 @@ public:
return _currentStateID;
}
std::string_view previousStateID() const
{
return _previousStateID;
}
// returns IDs of all deduced unique states