From f3a08548647df382622d8b0c589cfdb81bb32aa0 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Thu, 20 Jun 2024 11:00:52 +0200 Subject: [PATCH] Eliminate kInitialState variable Provide a comfortable Start() function instead --- generator/src/generator/Declaration.egl | 6 +++++- generator/src/generator/Instance.egl | 2 -- test/ScXmlFsmImpl.cxx | 2 +- test/XmiFsmImpl.cxx | 2 +- test/generated/IScXmlTestImpl.hxx | 4 +++- test/generated/IXmiTestImpl.hxx | 4 +++- test/generated/ScXmlTestDeclaration.hxx | 8 ++++++-- test/generated/ScXmlTestInstance.hxx | 4 +--- test/generated/XmiTestDeclaration.hxx | 8 ++++++-- test/generated/XmiTestInstance.hxx | 4 +--- 10 files changed, 27 insertions(+), 17 deletions(-) diff --git a/generator/src/generator/Declaration.egl b/generator/src/generator/Declaration.egl index fa87859..1027aae 100644 --- a/generator/src/generator/Declaration.egl +++ b/generator/src/generator/Declaration.egl @@ -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%]); + } }; diff --git a/generator/src/generator/Instance.egl b/generator/src/generator/Instance.egl index 09900b0..3288fe5 100644 --- a/generator/src/generator/Instance.egl +++ b/generator/src/generator/Instance.egl @@ -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()%] \ No newline at end of file diff --git a/test/ScXmlFsmImpl.cxx b/test/ScXmlFsmImpl.cxx index 8ed4a28..1120fb9 100644 --- a/test/ScXmlFsmImpl.cxx +++ b/test/ScXmlFsmImpl.cxx @@ -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; diff --git a/test/XmiFsmImpl.cxx b/test/XmiFsmImpl.cxx index 185245f..b9b039e 100644 --- a/test/XmiFsmImpl.cxx +++ b/test/XmiFsmImpl.cxx @@ -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; diff --git a/test/generated/IScXmlTestImpl.hxx b/test/generated/IScXmlTestImpl.hxx index c9b2fbd..10f2338 100644 --- a/test/generated/IScXmlTestImpl.hxx +++ b/test/generated/IScXmlTestImpl.hxx @@ -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; diff --git a/test/generated/IXmiTestImpl.hxx b/test/generated/IXmiTestImpl.hxx index 39a5801..9338e02 100644 --- a/test/generated/IXmiTestImpl.hxx +++ b/test/generated/IXmiTestImpl.hxx @@ -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; diff --git a/test/generated/ScXmlTestDeclaration.hxx b/test/generated/ScXmlTestDeclaration.hxx index 97995d0..c02bbfa 100644 --- a/test/generated/ScXmlTestDeclaration.hxx +++ b/test/generated/ScXmlTestDeclaration.hxx @@ -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; @@ -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); + } }; \ No newline at end of file diff --git a/test/generated/ScXmlTestInstance.hxx b/test/generated/ScXmlTestInstance.hxx index 9840513..541c3dd 100644 --- a/test/generated/ScXmlTestInstance.hxx +++ b/test/generated/ScXmlTestInstance.hxx @@ -1,5 +1,5 @@ // Statemachine ScXmlTest instance -// Generated: 26.01.24, 17:51 +// Generated: 20.06.24, 10:59 #pragma once @@ -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) diff --git a/test/generated/XmiTestDeclaration.hxx b/test/generated/XmiTestDeclaration.hxx index ad0ed96..2e2d120 100644 --- a/test/generated/XmiTestDeclaration.hxx +++ b/test/generated/XmiTestDeclaration.hxx @@ -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; @@ -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); + } }; \ No newline at end of file diff --git a/test/generated/XmiTestInstance.hxx b/test/generated/XmiTestInstance.hxx index 05b681f..01a23f0 100644 --- a/test/generated/XmiTestInstance.hxx +++ b/test/generated/XmiTestInstance.hxx @@ -1,5 +1,5 @@ // Statemachine XmiTest instance -// Generated: 26.01.24, 17:52 +// Generated: 20.06.24, 10:59 #pragma once @@ -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)