Список состояний конечного автомата.


?????????? ? ??????? ??????? ? ???????? ??????? ?????? ??????? ?????? ?????????/??????? ????????? ???????? ? ????? ?????. ? ?? ?????? ??? ??????? ??????????? ?? ?????? ?????: enum, ??????????? ??????????????? ?????????, ?????? ???? ????????? ??? ???????, ??????? switch, ?????????? ??? ??????, ? ??????????? ?? ?????????…

???????? ???????? ????????? (??????????????? ?????):

#define FOR_ALL_STATES(Action) \
    Action(StateInitial) \
    Action(StateInitializing) \
    Action(StateReady) \
    Action(StateTerminating)

????? ????? ???? ????? ????????? ?????????:

#define DEFINE_ENUM(Name) Name,

enum States {
    FOR_ALL_STATES(DEFINE_ENUM)
};

#undef DEFINE_ENUM

? ????? – ???????? ????????? ???????-???????????? ??? ??????? ?? ?????????:

#define DEFINE_HANDLER(Name) \
    States On ##Name(Events Event);

FOR_ALL_STATES(DEFINE_HANDLER)

#undef DEFINE_HANDLER

??? ?????? ???? ?????????, ??????? ??? ???????:

#define DEFINE_NAME(Name) #Name,

static const char* StateNames[] = {
    FOR_ALL_STATES(DEFINE_NAME)
};

#undef DEFINE_NAME

Cross-posted from blog.not-a-kernel-guy.com.

Skip to main content