Skip to content

Commit bd4e965

Browse files
committed
Eliminate kInitialState pattern, use Start() function instead
1 parent 1ef247e commit bd4e965

File tree

17 files changed

+36
-18
lines changed

17 files changed

+36
-18
lines changed

examples/activeobject/Fsm.cxx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,4 @@ Fsm::Transition Fsm::State2Handler(ImplPtr impl, Event event)
3030

3131
const Fsm::State Fsm::kState1("State1", &State1Handler);
3232
const Fsm::State Fsm::kState2("State2", &State2Handler);
33-
const Fsm::StatePtr Fsm::kInitialState = &kState1; // initial state of the statemachine
3433
} // namespace example::activeobject

examples/activeobject/Fsm.hxx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ public:
1010
// States
1111
static const State kState1;
1212
static const State kState2;
13-
static const StatePtr kInitialState;
1413

1514
// Handlers
1615
static Transition State1Handler(ImplPtr impl, Event event);
1716
static Transition State2Handler(ImplPtr impl, Event event);
17+
18+
inline void Start()
19+
{
20+
FsmBase::Start(&kState1);
21+
}
1822
};
1923
} // namespace example::activeobject

examples/activeobject/FsmImpl.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ FsmImpl::FsmImpl()
2020
fsm_.on_unhandled_event_ = [](Fsm::Ref fsm, Fsm::StateRef state, Fsm::Event event)
2121
{ std::cout << fsm << " unhandled event " << event << " in state " << state << "\n"; };
2222

23-
fsm_.Start(Fsm::kInitialState);
23+
fsm_.Start();
2424
}
2525

2626
void FsmImpl::State1Entry()

examples/activeobject_embedded/Fsm.cxx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,4 @@ Fsm::Transition Fsm::State2Handler(ImplPtr impl, Event event)
3030

3131
const Fsm::State Fsm::kState1("State1", &State1Handler);
3232
const Fsm::State Fsm::kState2("State2", &State2Handler);
33-
const Fsm::StatePtr Fsm::kInitialState = &kState1; // initial state of the statemachine
3433
} // namespace example::activeobject_embedded

examples/activeobject_embedded/Fsm.hxx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ public:
1010
// States
1111
static const State kState1;
1212
static const State kState2;
13-
static const StatePtr kInitialState;
1413

1514
// Handlers
1615
static Transition State1Handler(ImplPtr impl, Event event);
1716
static Transition State2Handler(ImplPtr impl, Event event);
17+
18+
inline void Start()
19+
{
20+
FsmBase::Start(&kState1);
21+
}
1822
};
1923
} // namespace example::activeobject_embedded

examples/activeobject_embedded/FsmImpl.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ FsmImpl::FsmImpl()
88

99
// No logging because printf or std::ostream use heap memory
1010

11-
fsm_.Start(Fsm::kInitialState);
11+
fsm_.Start();
1212
}
1313

1414
void FsmImpl::State1Entry()

examples/interface/Fsm.cxx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,4 @@ Fsm::Transition Fsm::State2Handler(ImplPtr impl, Event event)
3030

3131
const Fsm::State Fsm::kState1("State1", &State1Handler);
3232
const Fsm::State Fsm::kState2("State2", &State2Handler);
33-
const Fsm::StatePtr Fsm::kInitialState = &kState1; // initial state of the statemachine
3433
} // namespace example::interface

examples/interface/Fsm.hxx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ public:
1010
// States
1111
static const State kState1;
1212
static const State kState2;
13-
static const StatePtr kInitialState;
1413

1514
// Handlers
1615
static Transition State1Handler(ImplPtr impl, Event event);
1716
static Transition State2Handler(ImplPtr impl, Event event);
17+
18+
inline void Start()
19+
{
20+
FsmBase::Start(&kState1);
21+
}
1822
};
1923
} // namespace example::interface

examples/interface/FsmImpl.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ FsmImpl::FsmImpl()
2020
fsm_.on_unhandled_event_ = [](Fsm::Ref fsm, Fsm::StateRef state, Fsm::Event event)
2121
{ std::cout << fsm << " unhandled event " << static_cast<int>(event) << " in state " << state << std::endl; };
2222

23-
fsm_.Start(Fsm::kInitialState);
23+
fsm_.Start();
2424
}
2525

2626
void FsmImpl::Run()

examples/pimpl/Fsm.cxx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,4 @@ Fsm::Transition Fsm::State2Handler(ImplPtr impl, Event event)
3030

3131
const Fsm::State Fsm::kState1("State1", &State1Handler);
3232
const Fsm::State Fsm::kState2("State2", &State2Handler);
33-
const Fsm::StatePtr Fsm::kInitialState = &kState1; // initial state of the statemachine
3433
} // namespace example::pimpl

0 commit comments

Comments
 (0)