File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33namespace example ::pimpl
44{
5- static Fsm::Transition State1Handler ( Fsm::ImplPtr /* impl */ , Fsm:: Event event)
5+ Fsm::Transition Fsm::State1Handler ( ImplPtr /* impl */ , Event event)
66{
77 switch (event)
88 {
99 case EEvent::kGo2 :
10- return Fsm:: TransitionTo (Fsm:: kState2 );
10+ return TransitionTo (kState2 );
1111 default :
12- return Fsm:: NoTransition ();
12+ return NoTransition ();
1313 }
1414}
1515
16- static Fsm::Transition State2Handler ( Fsm::ImplPtr impl, Fsm:: Event event)
16+ Fsm::Transition Fsm::State2Handler ( ImplPtr impl, Event event)
1717{
1818 switch (event)
1919 {
2020 case EEvent::kGo1 :
2121 if (impl->SomeGuardFunction (event))
2222 {
23- return Fsm:: TransitionTo (Fsm:: kState1 , &Fsm:: Impl::State2ToState1TransitionAction);
23+ return TransitionTo (kState1 , &Impl::State2ToState1TransitionAction);
2424 }
25- return Fsm:: NoTransition ();
25+ return NoTransition ();
2626 default :
27- return Fsm:: UnhandledEvent ();
27+ return UnhandledEvent ();
2828 }
2929}
3030
Original file line number Diff line number Diff line change @@ -11,6 +11,10 @@ public:
1111 static const State kState1 ;
1212 static const State kState2 ;
1313
14+ // Handlers
15+ static Transition State1Handler (ImplPtr impl, Event event);
16+ static Transition State2Handler (ImplPtr impl, Event event);
17+
1418 inline void Start ()
1519 {
1620 FsmBase::Start (&kState1 );
Original file line number Diff line number Diff line change @@ -26,14 +26,18 @@ public:
2626
2727 void Run ();
2828
29+ private:
30+ struct Private ;
31+ std::unique_ptr<Private> private_;
32+
33+ // Give Fsm access to private entry/exit/transition actions
34+ // (This is not needed if actions are public functions)
35+ friend class Fsm ;
36+
2937 void State1Entry ();
3038
3139 void State2ToState1TransitionAction (FsmBase::Event event);
3240
3341 bool SomeGuardFunction (FsmBase::Event event);
34-
35- private:
36- struct Private ;
37- std::unique_ptr<Private> private_;
3842};
3943} // namespace example::pimpl
Original file line number Diff line number Diff line change @@ -49,29 +49,29 @@ bool FsmImpl::SomeGuardFunction(FsmBase::Event /*event*/)
4949
5050// FSM code
5151
52- static Fsm::Transition State1Handler ( Fsm::ImplPtr /* impl */ , Fsm:: Event event)
52+ Fsm::Transition Fsm::State1Handler ( ImplPtr /* impl */ , Event event)
5353{
5454 switch (event)
5555 {
5656 case EEvent::kGo2 :
57- return Fsm:: TransitionTo (Fsm:: kState2 );
57+ return TransitionTo (kState2 );
5858 default :
59- return Fsm:: NoTransition ();
59+ return NoTransition ();
6060 }
6161}
6262
63- static Fsm::Transition State2Handler ( Fsm::ImplPtr impl, Fsm:: Event event)
63+ Fsm::Transition Fsm::State2Handler ( ImplPtr impl, Event event)
6464{
6565 switch (event)
6666 {
6767 case EEvent::kGo1 :
6868 if (impl->SomeGuardFunction (event))
6969 {
70- return Fsm:: TransitionTo (Fsm:: kState1 , &Fsm:: Impl::State2ToState1TransitionAction);
70+ return TransitionTo (kState1 , &Impl::State2ToState1TransitionAction);
7171 }
72- return Fsm:: NoTransition ();
72+ return NoTransition ();
7373 default :
74- return Fsm:: UnhandledEvent ();
74+ return UnhandledEvent ();
7575 }
7676}
7777
Original file line number Diff line number Diff line change @@ -20,6 +20,10 @@ public:
2020 static const State kState1 ;
2121 static const State kState2 ;
2222
23+ // Handlers
24+ static Transition State1Handler (ImplPtr impl, Event event);
25+ static Transition State2Handler (ImplPtr impl, Event event);
26+
2327 inline void Start ()
2428 {
2529 FsmBase::Start (&kState1 );
@@ -34,13 +38,17 @@ public:
3438
3539 void Run ();
3640
41+ private:
42+ Fsm fsm_;
43+
44+ // Give Fsm access to private entry/exit/transition actions
45+ // (This is not needed if actions are public functions)
46+ friend class Fsm ;
47+
3748 void State1Entry ();
3849
3950 void State2ToState1TransitionAction (FsmBase::Event event);
4051
4152 bool SomeGuardFunction (FsmBase::Event event);
42-
43- private:
44- Fsm fsm_;
4553};
4654} // namespace example::plain
You can’t perform that action at this time.
0 commit comments