Skip to content

Overview Minimal Example

Andrew Gresyk edited this page Apr 1, 2022 · 3 revisions

Minimal Example

Tests

Code

#include <assert.h>
#include <ffsm2/machine.hpp>

struct Context {
	bool on = false;
};

using Config = ffsm2::Config
					::ContextT<Context&>;

using M = ffsm2::MachineT<Config>;

using FSM = M::PeerRoot<
				struct Off,
				struct On
			>;

struct Off
	: FSM::State
{
	void enter(PlanControl& control) {
		control.context().on = false;
	}
};

struct On
	: FSM::State
{
	void enter(PlanControl& control) {
		control.context().on = true;
	}
};

int
main() {
	Context context;
	FSM::Instance machine{context};

	machine.changeTo<On>();
	machine.update();

	assert(context.on == true);

	return 0;
}