Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FSM_INITIAL_STATE Macro only works in global namespace #44

Open
chrisg89 opened this issue Nov 8, 2024 · 0 comments
Open

FSM_INITIAL_STATE Macro only works in global namespace #44

chrisg89 opened this issue Nov 8, 2024 · 0 comments

Comments

@chrisg89
Copy link

chrisg89 commented Nov 8, 2024

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?

@chrisg89 chrisg89 changed the title FSM_INITIAL_STATE Macro doesn't work if _FSM or _STATE are defined outside the global namespace FSM_INITIAL_STATE Macro only works in global namespace Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant