Fsm.hpp had grown to ~1200 lines holding everything. Split it behind the
same <Void/Fsm/Fsm.hpp> umbrella (which now just includes Machine.hpp), with
no behaviour change:
- Machine.hpp — the Machine<Derived,ResultT> template: States list, nested
State/Reactive bases, lifecycle, events, nesting, persistence.
- Detail/Reactive.hpp — the declarative transition DSL lifted to standalone
templates (TransitionTable/EventEntry/EventClause/AfterClause/
TransitionBuilder parameterised by Derived/ResultT); Machine::Reactive
aliases TransitionTable/TransitionBuilder.
- Detail/Awaiter.hpp — one EventAwaiter built on
ExecutionContext::{try_take_any,set_waiter}; the four near-identical inline
awaiters (await_event / await_event_for / await_any / await_any_event)
collapse to make_event_awaiter wrappers with per-call projections.
- Detail/Introspect.hpp — namespace-scope StateInfo/EdgeInfo + free
to_mermaid(span<StateInfo>); describe() returns the shared structs,
to_mermaid() delegates.
- Detail/TypeName.hpp — shared Detail::type_name<T>() (P2996 identifier_of,
typeid fallback), replacing the per-class state_type_name helper.
982 green, ASan clean, -Werror Fsm build clean. No test changes needed.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
50 lines
1.2 KiB
C++
50 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <span>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace Void::Fsm
|
|
{
|
|
/// A declarable transition edge (from a reactive state's table).
|
|
struct EdgeInfo {
|
|
std::string event; // event type name, or "(timeout)"
|
|
std::string target; // target state, "(success)"/"(fail)"
|
|
bool guarded{false};
|
|
};
|
|
|
|
/// A registered state plus the edges that are statically knowable
|
|
/// (reactive states only; imperative run()-chosen edges are not).
|
|
struct StateInfo {
|
|
std::string name;
|
|
bool reactive{false};
|
|
bool initial{false};
|
|
std::vector<EdgeInfo> edges;
|
|
};
|
|
|
|
namespace Detail
|
|
{
|
|
/// Render a state description as a Mermaid `stateDiagram-v2` string.
|
|
[[nodiscard]] inline std::string
|
|
to_mermaid(std::span<const StateInfo> states)
|
|
{
|
|
std::string out = "stateDiagram-v2\n";
|
|
for (const auto& s : states) {
|
|
if (s.initial) {
|
|
out += " [*] --> " + s.name + "\n";
|
|
}
|
|
}
|
|
for (const auto& s : states) {
|
|
for (const auto& e : s.edges) {
|
|
out += " " + s.name + " --> " + e.target + " : " + e.event;
|
|
if (e.guarded) {
|
|
out += " [guard]";
|
|
}
|
|
out += "\n";
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
} // namespace Detail
|
|
} // namespace Void::Fsm
|