Skip to content

Is there a way to access a state through its ID? #102

Answered by andrew-gresyk
ari-sc asked this question in Q&A
Discussion options

You must be logged in to vote

It's doable with a simple wrapper, e.g.:

struct StateBase {};

struct A
	: FSM::StateT<StateBase>
{};

struct B
	: FSM::StateT<StateBase>
{};

StateBase& access(FSM::Instance& instance, const hfsm2::StateID id) {
	switch (id) {
	case FSM::Instance::stateId<A>():
		return instance.access<A>();
		break;
	case FSM::Instance::stateId<B>():
		return instance.access<B>();
		break;
	default:
		/* ... */
	}
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ari-sc
Comment options

Answer selected by ari-sc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants