Skip to content

FSM_INITIAL_STATE Macro only works in global namespace #44

@chrisg89

Description

@chrisg89

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions