Skip to content
This repository was archived by the owner on Nov 16, 2025. It is now read-only.

FiniteStateMachine ctor()

ged edited this page Sep 9, 2024 · 10 revisions

Definition

Initializes a FiniteStateMachine<TContext> instance that has a specified context.

template<class TContext>
FiniteStateMachine(TContext* context)

Type Parameters

  • TContext: The type of the context, which holds data or behavior relevant to the state machine.

Parameters

  • context: The context to be used by the state machine.

Remarks

The state machine uses a context of type TContext to share information between states.
The context is passed to each state's callback, allowing the states to modify or query shared data.

Usage

// primitive context
int foo1 = 5;
FiniteStateMachine<int> foo1SM(&foo1);

float foo2 = 1.0f;
FiniteStateMachine<float> foo2SM(&foo2);

// user-defined context
struct FooStructContext; // implementation omitted for brevity
auto fooContext1 = FooStructContext();
auto fooContext1SM = FiniteStateMachine<FooStructContext>(&fooContext1);

class FooClassContext; // implementation omitted for brevity
auto fooContext2 = FooClassContext();
auto fooContext2SM = FiniteStateMachine<FooClassContext>(&fooContext2);

Clone this wiki locally