Skip to content

Commit

Permalink
Eliminate kInitialState variable
Browse files Browse the repository at this point in the history
Provide a comfortable Start() function instead
  • Loading branch information
dziegel committed Jun 20, 2024
1 parent 7d59ac7 commit f3a0854
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 17 deletions.
6 changes: 5 additions & 1 deletion generator/src/generator/Declaration.egl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
class [%=statemachine.name%] final : public [%=statemachine.name%]Base
{
public:
static const StatePtr kInitialState;
[%
var regionTemplate : Template = TemplateFactory.load("DeclarationRegion.egl");
regionTemplate.populate("region", statemachine.region);
regionTemplate.populate("statemachine", statemachine);
%]
[%=regionTemplate.process()%]

void Start()
{
[%=statemachine.name%]Base::Start(&[%=statemachine.region.initial_variable_name%]);
}
};
2 changes: 0 additions & 2 deletions generator/src/generator/Instance.egl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@
regionTemplate.populate("region", statemachine.region);
regionTemplate.populate("statemachine", statemachine);
%]
// Initial state
const [%=statemachine.name%]::StatePtr [%=statemachine.name%]::kInitialState = &[%=statemachine.name%]::[%=statemachine.region.initial_variable_name%];
[%=regionTemplate.process()%]
2 changes: 1 addition & 1 deletion test/ScXmlFsmImpl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void ScXmlFsmImpl::Test()
assert(fsm_.CurrentState() == nullptr);

// Start FSM. Entry actions of initial states must be called.
fsm_.Start(ScXmlTest::kInitialState);
fsm_.Start();
assert(fsm_.CurrentState() == &ScXmlTest::kState_1State_2);
assert(state1_on_entry_called_);
state1_on_entry_called_ = false;
Expand Down
2 changes: 1 addition & 1 deletion test/XmiFsmImpl.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void XmiFsmImpl::Test()
assert(fsm_.CurrentState() == nullptr);

// Start FSM. Entry actions of initial states must be called.
fsm_.Start(XmiTest::kInitialState);
fsm_.Start();
assert(fsm_.CurrentState() == &XmiTest::kState_1State_2);
assert(state1_on_entry_called_);
state1_on_entry_called_ = false;
Expand Down
4 changes: 3 additions & 1 deletion test/generated/IScXmlTestImpl.hxx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Statemachine ScXmlTest implementation interface
// Generated: 26.01.24, 17:51
// Generated: 20.06.24, 10:59

#pragma once

class IScXmlTestImpl
{
public:
virtual ~IScXmlTestImpl() = default;

// Actions
virtual void State2InternalAction(ScXmlTestBase::Event event) = 0;
virtual void Transition3Action1(ScXmlTestBase::Event event) = 0;
Expand Down
4 changes: 3 additions & 1 deletion test/generated/IXmiTestImpl.hxx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Statemachine XmiTest implementation interface
// Generated: 26.01.24, 17:52
// Generated: 20.06.24, 10:59

#pragma once

class IXmiTestImpl
{
public:
virtual ~IXmiTestImpl() = default;

// Actions
virtual void ChoiceAction1(XmiTestBase::Event event) = 0;
virtual void ChoiceAction2(XmiTestBase::Event event) = 0;
Expand Down
8 changes: 6 additions & 2 deletions test/generated/ScXmlTestDeclaration.hxx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Statemachine ScXmlTest declaration
// Generated: 26.01.24, 17:51
// Generated: 20.06.24, 10:59

#pragma once

class ScXmlTest final : public ScXmlTestBase
{
public:
static const StatePtr kInitialState;

// State State_1
static const State kState_1;
Expand All @@ -25,4 +24,9 @@ class ScXmlTest final : public ScXmlTestBase

// State State_1::State_4::State_6
static const State kState_1State_4State_6;

void Start()
{
ScXmlTestBase::Start(&kState_1);
}
};
4 changes: 1 addition & 3 deletions test/generated/ScXmlTestInstance.hxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Statemachine ScXmlTest instance
// Generated: 26.01.24, 17:51
// Generated: 20.06.24, 10:59

#pragma once

Expand All @@ -13,8 +13,6 @@
#define ScXmlTest_GET_STATIC_EVENT_ID(event_name) event_name::kId
#endif

// Initial state
const ScXmlTest::StatePtr ScXmlTest::kInitialState = &ScXmlTest::kState_1;

// State State_1
static ScXmlTest::Transition State_1Handler(ScXmlTest::ImplPtr impl, ScXmlTest::Event event)
Expand Down
8 changes: 6 additions & 2 deletions test/generated/XmiTestDeclaration.hxx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Statemachine XmiTest declaration
// Generated: 26.01.24, 17:52
// Generated: 20.06.24, 10:59

#pragma once

class XmiTest final : public XmiTestBase
{
public:
static const StatePtr kInitialState;

// State State_1
static const State kState_1;
Expand All @@ -25,4 +24,9 @@ class XmiTest final : public XmiTestBase

// State State_1::State_4::State_5
static const State kState_1State_4State_5;

void Start()
{
XmiTestBase::Start(&kState_1);
}
};
4 changes: 1 addition & 3 deletions test/generated/XmiTestInstance.hxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Statemachine XmiTest instance
// Generated: 26.01.24, 17:52
// Generated: 20.06.24, 10:59

#pragma once

Expand All @@ -13,8 +13,6 @@
#define XmiTest_GET_STATIC_EVENT_ID(event_name) event_name::kId
#endif

// Initial state
const XmiTest::StatePtr XmiTest::kInitialState = &XmiTest::kState_1;

// State State_1
static XmiTest::Transition State_1Handler(XmiTest::ImplPtr impl, XmiTest::Event event)
Expand Down

0 comments on commit f3a0854

Please sign in to comment.