Skip to main content

StateTransitionRule.ixx File

Definition of a state transition rule. More...

Included Headers

Namespaces Index

namespacehelios
namespaceengine

Main engine module aggregating core infrastructure and game systems. More...

namespacestate

Generic, template-based state management system. More...

namespacetypes

Type definitions for state transitions. More...

Classes Index

classStateTransitionRule<StateType>

Defines a valid state transition with optional guard. More...

Description

Definition of a state transition rule.

File Listing

The file content with the documentation metadata removed is:

1/**
2 * @file StateTransitionRule.ixx
3 * @brief Definition of a state transition rule.
4 */
5module;
6
7#include <functional>
8
9export module helios.engine.state.types.StateTransitionRule;
10
11import helios.engine.state.types.StateTransitionRequest;
12import helios.engine.state.types.StateTransitionId;
13import helios.engine.state.types.StateTransitionType;
14
15
16import helios.engine.runtime.world.UpdateContext;
17
18export namespace helios::engine::state::types {
19
20 /**
21 * @brief Function pointer type for transition guards.
22 *
23 * @details Guards are called before a transition executes. If the guard
24 * returns false, the transition is blocked.
25 *
26 * @tparam StateType The state enum type.
27 */
28 template<typename StateType>
29 using GuardCallback = bool(*)(
32 );
33
34 /**
35 * @brief Defines a valid state transition with optional guard.
36 *
37 * @details Rules are registered with the StateManager and define which
38 * transitions are valid. Each rule specifies a source state, transition
39 * ID, target state, and an optional guard callback.
40 *
41 * @tparam StateType The state enum type.
42 *
43 * @see StateManager
44 * @see GuardCallback
45 */
46 template<typename StateType>
48
49 using StateTransitionIdType = StateTransitionIdType<StateType>;
50
51 /**
52 * @brief The state this rule applies to.
53 */
54 StateType from_;
55
56 /**
57 * @brief The transition ID that triggers this rule.
58 */
59 StateTransitionIdType transitionId_;
60
61 /**
62 * @brief The target state after transition.
63 */
64 StateType to_;
65
66 /**
67 * @brief Optional guard callback.
68 */
69 GuardCallback<StateType> guard_ = nullptr;
70
71 public:
72
73 /**
74 * @brief Constructs a transition rule.
75 *
76 * @param from The source state.
77 * @param transitionId The transition that triggers this rule.
78 * @param to The target state.
79 * @param guard Optional guard callback (default: nullptr).
80 */
82 const StateType from,
83 const StateTransitionIdType transitionId,
84 const StateType to,
86 ) : from_(from), transitionId_(transitionId), to_(to) {
87 if (guard != nullptr) {
88 guard_ = std::move(guard);
89 }
90 }
91
92 /**
93 * @brief Returns the source state.
94 *
95 * @return The state this rule applies to.
96 */
97 [[nodiscard]] StateType from() const noexcept {
98 return from_;
99 }
100
101 /**
102 * @brief Returns the target state.
103 *
104 * @return The state after transition.
105 */
106 [[nodiscard]] StateType to() const noexcept { return to_; }
107
108 /**
109 * @brief Returns the transition identifier.
110 *
111 * @return The transition ID that triggers this rule.
112 */
113 [[nodiscard]] StateTransitionIdType transitionId() const noexcept {
114 return transitionId_;
115 }
116
117 /**
118 * @brief Returns the guard callback.
119 *
120 * @return The guard function pointer, or nullptr if no guard.
121 */
122 [[nodiscard]] GuardCallback<StateType> guard() const noexcept {
123 return guard_;
124 }
125
126 };
127
128}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.