-
Notifications
You must be signed in to change notification settings - Fork 185
Open
Description
I observed that the macro FSM_INITIAL_STATE
doesn't compile if invoked outside of the global namespace. The examples I looked at all use the global namespace so it isn't clear to me if much though was given to namespaces by the author.
example code that wont compile:
#include <tinyfsm.hpp>
namespace xxx::yyy {
// ----------------------------------------------------------------------------
// 1. Event Declarations
//
struct AAA : tinyfsm::Event { };
struct BBB : tinyfsm::Event { };
// ----------------------------------------------------------------------------
// 2. State Machine Base Class Declaration
//
struct SM : tinyfsm::MealyMachine<SM>
{
virtual void react(AAA const &) { };
virtual void react(BBB const &) { };
};
// ----------------------------------------------------------------------------
// 3. State Declarations
//
struct Wait : SM
{};
struct Off : SM
{};
FSM_INITIAL_STATE(SM, Off)
} // namespace xxx::yyy
Solution is to use the macro in the global namespace and fully qualify the state machine and state types:
#include <tinyfsm.hpp>
namespace xxx::yyy {
// ----------------------------------------------------------------------------
// 1. Event Declarations
//
struct AAA : tinyfsm::Event { };
struct BBB : tinyfsm::Event { };
// ----------------------------------------------------------------------------
// 2. State Machine Base Class Declaration
//
struct SM : tinyfsm::MealyMachine<SM>
{
virtual void react(AAA const &) { };
virtual void react(BBB const &) { };
};
// ----------------------------------------------------------------------------
// 3. State Declarations
//
struct Wait : SM
{
};
struct Off : SM
{
};
} // namespace xxx::yyy
FSM_INITIAL_STATE(xxx::yyy::SM, xxx::yyy::Off)
Is it possible to rework FSM_INITIAL_STATE to allow invocation within a custom namespace?
vecljox
Metadata
Metadata
Assignees
Labels
No labels