infinite_state_machine 1.0.0
Infinite State Machine Library
Loading...
Searching...
No Matches
infinite_state.c
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023, Roy Ratcliffe, Northumberland, United Kingdom
3 * SPDX-License-Identifier: MIT
4 */
28#include "infinite_state.h"
29
30#include <stddef.h>
31
32struct infinite_state **infinite_state_topology(struct infinite_state *state, int depth,
33 struct infinite_state **topology)
34{
35 /*
36 * Get the topology of the infinite state machine.
37 * This function traverses the state hierarchy and collects all states
38 * in the specified topology array.
39 */
40 if (state == NULL || depth == 0)
41 {
42 return topology;
43 }
44 struct infinite_state **sub = infinite_state_topology(state->super, depth - 1, topology);
45#ifdef DEBUG
46 for (struct infinite_state **super = topology; super != sub; super++)
47 {
48 if (*super == state)
49 {
50 // If we found the state in the super-states, we need to stop.
51 return sub;
52 }
53 }
54#endif
55 *sub = state;
56 return sub + 1;
57}
struct infinite_state ** infinite_state_topology(struct infinite_state *state, int depth, struct infinite_state **topology)
Get the topology of the infinite state machine.
Core definitions for the infinite (unbounded topology and depth albeit limited by memory resources) h...
The state structure for the infinite state. This structure represents a state in the infinite state m...
struct infinite_state * super
The parent state of this state.