Skip to content

Commit fb7aaee

Browse files
committed
Remove possibility to use delegates as actions. Not useful enough.
1 parent 1bf81de commit fb7aaee

3 files changed

Lines changed: 8 additions & 66 deletions

File tree

README.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ Header-only C++ event, statemachine and active object framework
2525
- Designed to call member functions of a C++ interface
2626
- It is fairly simple to write statemachines "by hand" without a code generator
2727
- Suitable for small systems: state declarations can be const and in RO section
28-
- Allow non-capturing lambdas as transition action
2928
- Logging support (state entry/exit/handler events)
3029
- States have names for logging (and an ostream operator<<)
3130
- Statemachines have names for logging (and an ostream operator<<)
@@ -315,10 +314,6 @@ The predefined HeapAllocator is simply an allocator based on std::pmr::new_delet
315314
// Using class StatemachineImplementation member function
316315
return Fsm::TransitionTo(Fsm::kState1, &StatemachineImplementation::SomeAction);
317316

318-
// using non-capturing lambda
319-
return Fsm::TransitionTo(Fsm::kState1,
320-
[](Fsm::ImplPtr, Fsm::Event) { std::cout << "Transition action" << std::endl; });
321-
322317
3) No transition - event is handled, but no state transition occurs:
323318

324319
return Fsm::NoTransition();
@@ -328,9 +323,6 @@ The predefined HeapAllocator is simply an allocator based on std::pmr::new_delet
328323
// Using class StatemachineImplementation member function
329324
return Fsm::NoTransition(&StatemachineImplementation::SomeAction);
330325

331-
// using non-capturing lambda
332-
return Fsm::NoTransition([](Fsm::ImplPtr, Fsm::Event) { std::cout << "Transition action" << std::endl; });
333-
334326
5) Event is not handled in this state. In hierarchical statemachines, the event will be passed to parent state handler.
335327
When topmost state does not handle the event, fsm_.on_unhandled_event_ is called.
336328

@@ -420,10 +412,9 @@ Example:
420412

421413
void (Fsm::ImplPtr)()
422414

423-
- Transition actions. The signature allows to use class member functions and non-capturing lambdas as actions. The argument "event" may be useful in actions because the action may depend on the event type or attributes of the event.
415+
- Transition actions. The signature allows to use class/interface member functions as actions. The argument "event" may be useful in actions because the action may depend on the event type or attributes of the event.
424416

425-
void (*)(Fsm::ImplPtr impl, Fsm::Event event) // Non-capturing lambda
426-
void (Fsm::ImplPtr)(Fsm::Event event) // C++
417+
void (Fsm::ImplPtr)(Fsm::Event event)
427418

428419
### Logging
429420

include/cpp_event_framework/Statemachine.hxx

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,6 @@ public:
146146
*/
147147
using ActionType = void (ImplType::*)(Event);
148148

149-
/**
150-
* @brief Type of action handler
151-
*
152-
*/
153-
using DelegateActionType = void (*)(ImplPtr, Event);
154-
155149
/**
156150
* @brief State machine transition class, used internally
157151
*/
@@ -164,12 +158,6 @@ public:
164158
*/
165159
using ActionType = Statemachine::ActionType;
166160

167-
/**
168-
* @brief Type of action handler (for compatibility, use Statemachine::DelegateActionType instead)
169-
*
170-
*/
171-
using DelegateActionType = Statemachine::DelegateActionType;
172-
173161
private:
174162
// this class is for internal use by Statemachine only
175163
friend class Statemachine;
@@ -187,10 +175,6 @@ public:
187175
*/
188176
void ExecuteActions(ImplPtr impl, Event event)
189177
{
190-
if (delegate_action_ != nullptr)
191-
{
192-
delegate_action_(impl, event);
193-
}
194178
if (single_action_ != nullptr)
195179
{
196180
(impl->*single_action_)(event);
@@ -216,17 +200,6 @@ public:
216200
constexpr explicit Transition(StateRef target) noexcept : target_(&target)
217201
{
218202
}
219-
/**
220-
* @brief Construct a new Statemachine Transition object
221-
* Use Statemachine::TransitionTo() instead
222-
*
223-
* @param target Target state
224-
* @param action Transition action
225-
*/
226-
constexpr Transition(StateRef target, DelegateActionType action) noexcept
227-
: target_(&target), delegate_action_(action)
228-
{
229-
}
230203
/**
231204
* @brief Construct a new Statemachine Transition object
232205
* Use Statemachine::TransitionTo() instead
@@ -255,12 +228,6 @@ public:
255228
* Provides storage for single transition actions
256229
*/
257230
ActionType single_action_ = nullptr;
258-
/**
259-
* @brief Optional single lambda transition action
260-
*
261-
* std::function<> cannot be used here - not longer possible to store Transition in RO section!
262-
*/
263-
DelegateActionType delegate_action_ = nullptr;
264231
/**
265232
* @brief Optional transition actions
266233
*
@@ -629,16 +596,6 @@ public:
629596
{
630597
return Transition(kNone);
631598
}
632-
/**
633-
* @brief Event was handled, but no transition shall be executed, with action
634-
*
635-
* @param action Action to execute
636-
* @return Transition
637-
*/
638-
static inline Transition NoTransition(DelegateActionType action)
639-
{
640-
return Transition(kNone, action);
641-
}
642599
/**
643600
* @brief Event was handled, but no transition shall be executed, with action
644601
*
@@ -670,17 +627,6 @@ public:
670627
{
671628
return Transition(target);
672629
}
673-
/**
674-
* @brief Create transition to target state, with action
675-
*
676-
* @param target Target state
677-
* @param action Action to execute on transition
678-
* @return Transition
679-
*/
680-
static inline Transition TransitionTo(StateRef target, DelegateActionType action)
681-
{
682-
return Transition(target, action);
683-
}
684630
/**
685631
* @brief Create transition to target state, with action
686632
*

test/Statemachine_unittest.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ class StatemachineImpl
155155
std::cout << "Don't walk 2\n";
156156
}
157157

158+
void Walk(Fsm::Event /*event*/)
159+
{
160+
std::cout << "Walk\n";
161+
}
162+
158163
public:
159164
void Main()
160165
{
@@ -319,7 +324,7 @@ Fsm::Transition Fsm::FsmRedYellowHandler(ImplPtr /*impl*/, Event event)
319324
switch (event->Id())
320325
{
321326
case EvtGoGreen::kId:
322-
return TransitionTo(kGreen, [](ImplPtr /*impl*/, Event /*event*/) { std::cout << "Walk\n"; });
327+
return TransitionTo(kGreen, &Fsm::Impl::Walk);
323328
case EvtGoYellow::kId:
324329
return NoTransition();
325330
default:

0 commit comments

Comments
 (0)