Added some documentation to TaskFSM. (Not yet complete!)

This commit is contained in:
Tim Ambrogi 2022-03-18 16:06:55 -04:00
parent e2147f0a79
commit 80c6a4aa8e

View File

@ -14,8 +14,8 @@ class TaskFSM;
namespace FSM namespace FSM
{ {
// State ID wrapper
struct StateId struct StateId /// State ID handle, representing a unique state ID with "invalid id" semantics
{ {
StateId() = default; StateId() = default;
StateId(int32_t in_idx) : idx(in_idx) {} StateId(int32_t in_idx) : idx(in_idx) {}
@ -27,23 +27,23 @@ struct StateId
int32_t idx = INT32_MAX; // Default to invalid idx int32_t idx = INT32_MAX; // Default to invalid idx
}; };
// State transition debug data //--- Transition functions ---//
struct TransitionDebugData struct TransitionDebugData /// Debug state transition data (used by debug-state-transition callbacks)
{ {
FSM::StateId oldStateId; FSM::StateId oldStateId; ///< Outgoing state's id
std::string oldStateName; std::string oldStateName; ///< Outgoing state's name
FSM::StateId newStateId; FSM::StateId newStateId; ///< Incoming state's id
std::string newStateName; std::string newStateName; ///< Incoming state's name
}; };
// State transition callback function using tOnStateTransitionFn = std::function<void()>; ///< State transition callback function type (non-debug)
using tOnStateTransitionFn = std::function<void()>; using tDebugStateTransitionFn = std::function<void(TransitionDebugData)>; ///< Debug state transition callback function type
#include "Private/TaskFSMPrivate.h" // Internal use only! Do not include elsewhere! #include "Private/TaskFSMPrivate.h" // Internal use only! Do not include elsewhere!
//--- State Handle ---// //--- State Handle ---//
template<class tStateInput, class tStateConstructorFn> template<class tStateInput, class tStateConstructorFn>
class StateHandle class StateHandle /// Control handle
{ {
using tPredicateRet = typename std::conditional<!std::is_void<tStateInput>::value, std::optional<tStateInput>, bool>::type; using tPredicateRet = typename std::conditional<!std::is_void<tStateInput>::value, std::optional<tStateInput>, bool>::type;
using tPredicateFn = std::function<tPredicateRet()>; using tPredicateFn = std::function<tPredicateRet()>;
@ -51,7 +51,7 @@ public:
StateHandle(StateHandle&& in_other) = default; StateHandle(StateHandle&& in_other) = default;
StateHandle& operator=(StateHandle&& in_other) = default; StateHandle& operator=(StateHandle&& in_other) = default;
StateId GetId() const //< Get the ID of this state StateId GetId() const ///< Get the ID of this state
{ {
return m_state ? m_state->idx : StateId{}; return m_state ? m_state->idx : StateId{};
} }
@ -152,13 +152,12 @@ template<class tStateInput, class tStateConstructorFn>
using StateHandle = FSM::StateHandle<tStateInput, tStateConstructorFn>; using StateHandle = FSM::StateHandle<tStateInput, tStateConstructorFn>;
using TransitionDebugData = FSM::TransitionDebugData; using TransitionDebugData = FSM::TransitionDebugData;
using tOnStateTransitionFn = FSM::tOnStateTransitionFn; using tOnStateTransitionFn = FSM::tOnStateTransitionFn;
using tDebugStateTransitionFn = FSM::tDebugStateTransitionFn;
//--- TaskFSM ---// //--- TaskFSM ---//
class TaskFSM class TaskFSM
{ {
public: public:
using tDebugStateTransitionFn = std::function<void(TransitionDebugData)>;
// Create a new FSM state [fancy param-deducing version (hopefully) coming soon!] // Create a new FSM state [fancy param-deducing version (hopefully) coming soon!]
template<typename tStateConstructorFn> template<typename tStateConstructorFn>
auto State(std::string in_name, tStateConstructorFn in_stateCtorFn) auto State(std::string in_name, tStateConstructorFn in_stateCtorFn)