@@ -16,25 +16,26 @@ namespace max {
1616namespace Containers {
1717namespace StateMachine {
1818
19- template <typename ... TransitionTypes>
19+ template <typename NodeIndexType, typename ... TransitionTypes>
2020 class Node {
2121 public:
2222
23- constexpr explicit Node (std::tuple<TransitionTypes...> outbound_transitions) noexcept
24- : outbound_transitions_(std::move(outbound_transitions))
23+ constexpr explicit Node (NodeIndexType this_node, std::tuple<TransitionTypes...> outbound_transitions) noexcept
24+ : this_node_(std::move(this_node))
25+ , outbound_transitions_(std::move(outbound_transitions))
2526 {}
2627
27- template <typename T>
28- constexpr std::optional<size_t > AttemptTransition (const T& input) noexcept {
28+ template <typename NodeIndexType, typename T>
29+ constexpr std::optional<NodeIndexType > AttemptTransition (const T& input) noexcept {
2930 auto transition_happened = false ;
30- auto new_node_index = std::optional<size_t >{std::nullopt };
31+ auto new_node_index = std::optional<NodeIndexType >{std::nullopt };
3132
3233 auto attempt_transition = [&transition_happened, &new_node_index, &input](auto && arg) {
3334 // TODO: I added .value_ to RangeMatcher because I couldn't get this line to work
3435 // if constexpr (std::is_same_v<T, decltype(arg.matcher_)::parameter_type>) {
3536 if constexpr (std::is_same_v<T, decltype (arg.matcher_ .value_ )>) {
3637 if (!transition_happened) {
37- auto possible_new_node_index = arg.AttemptTransition (input);
38+ auto possible_new_node_index = arg.AttemptTransition <NodeIndexType> (input);
3839 if (possible_new_node_index) {
3940 transition_happened = true ;
4041 new_node_index = std::move (possible_new_node_index);
@@ -50,13 +51,14 @@ namespace StateMachine {
5051 return new_node_index;
5152 }
5253
54+ NodeIndexType this_node_;
5355 std::tuple<TransitionTypes...> outbound_transitions_;
5456
5557 };
5658
57- template <typename ... TransitionTypes>
58- constexpr Node<TransitionTypes...> MakeNode (TransitionTypes... outbound_transitions) noexcept {
59- return Node{std::make_tuple (std::move (outbound_transitions) ...)};
59+ template <typename NodeIndexType, typename ... TransitionTypes>
60+ constexpr Node<NodeIndexType, TransitionTypes...> MakeNode (NodeIndexType this_node, TransitionTypes... outbound_transitions) noexcept {
61+ return Node{std::move (this_node), std:: make_tuple (std::move (outbound_transitions) ...)};
6062 }
6163
6264} // namespace StateMachine
0 commit comments