|
infinite_state_machine 1.0.0
Infinite State Machine Library
|
Public API for the infinite state machine. Provides functions to initialise, perform hierarchical transitions (goto and jump), query whether a state is active, and get the current top state. More...
#include "infinite_state.h"

Go to the source code of this file.
Classes | |
| struct | infinite_state_machine |
| Represents an infinite state machine. This structure holds the current state hierarchy and allows for transitions between states. More... | |
Macros | |
| #define | INFINITE_STATE_MACHINE_MAX_DEPTH 7 |
| Maximum depth of any infinite state machine. Defaults to 7 unless already defined before the inclusion point of this header. | |
Functions | |
| void | infinite_state_machine_init (struct infinite_state_machine *machine) |
Initialises the infinite state machine. The machine is reset to its initial state. It has an initial depth of 0. All its states are cleared to NULL for safety. | |
| void | infinite_state_machine_goto (struct infinite_state_machine *machine, struct infinite_state *state) |
| Goes to a state in the infinite state machine. | |
| void | infinite_state_machine_jump (struct infinite_state_machine *machine, struct infinite_state *state) |
| Jumps to a state in the infinite state machine. | |
| int | infinite_state_machine_in (struct infinite_state_machine *machine, struct infinite_state *state) |
| Checks if a state is currently active in the infinite state machine. | |
| struct infinite_state * | infinite_state_machine_top (const struct infinite_state_machine *machine) |
| Gets the top state of the infinite state machine. | |
Public API for the infinite state machine. Provides functions to initialise, perform hierarchical transitions (goto and jump), query whether a state is active, and get the current top state.
The machine keeps a stack (array) of active states up to INFINITE_STATE_MACHINE_MAX_DEPTH states deep. Not thread-safe; external synchronisation is required for concurrent use.
Definition in file infinite_state_machine.h.
| #define INFINITE_STATE_MACHINE_MAX_DEPTH 7 |
Maximum depth of any infinite state machine. Defaults to 7 unless already defined before the inclusion point of this header.
Why 7? There is method in the choice a maximum depth of 7. Pointers and integers are 32 bits wide on a 32-bit machine. Seven pointers and one integer occupy 8 words, or 32 bytes. If a single machine requires more than seven levels of nesting, better to refactor the design to reduce complexity.
Definition at line 31 of file infinite_state_machine.h.
| void infinite_state_machine_goto | ( | struct infinite_state_machine * | machine, |
| struct infinite_state * | state | ||
| ) |
Goes to a state in the infinite state machine.
| machine | The infinite state machine. |
| state | The state to enter. |
Going to a state in the infinite state machine transitions the machine to the new state. This will push the current state onto the stack and transition to the new state. If the new state is the same as the current state, no action is taken; likewise, if the new state is a NULL pointer, no action is taken. Otherwise, all the exit actions for the current state are run, and the new state is entered by running all enter actions.
Definition at line 66 of file infinite_state_machine.c.
| int infinite_state_machine_in | ( | struct infinite_state_machine * | machine, |
| struct infinite_state * | state | ||
| ) |
Checks if a state is currently active in the infinite state machine.
| machine | The infinite state machine. |
| state | The state to check. |
Definition at line 99 of file infinite_state_machine.c.
| void infinite_state_machine_init | ( | struct infinite_state_machine * | machine | ) |
Initialises the infinite state machine. The machine is reset to its initial state. It has an initial depth of 0. All its states are cleared to NULL for safety.
| machine | The infinite state machine to initialise. |
Definition at line 60 of file infinite_state_machine.c.
| void infinite_state_machine_jump | ( | struct infinite_state_machine * | machine, |
| struct infinite_state * | state | ||
| ) |
Jumps to a state in the infinite state machine.
| machine | The infinite state machine. |
| state | The state to jump to. |
Jumping to a state in the infinite state machine resets the machine to its initial state and then transitions to the specified state. This is useful for resetting the machine to a known state without going through the normal entry and exit actions.
Definition at line 93 of file infinite_state_machine.c.
| struct infinite_state * infinite_state_machine_top | ( | const struct infinite_state_machine * | machine | ) |
Gets the top state of the infinite state machine.
| machine | The infinite state machine. |
NULL if the machine is empty. Definition at line 157 of file infinite_state_machine.c.