@@ -141,9 +141,17 @@ namespace Core
141
141
, exit_function()
142
142
, dispatch_table()
143
143
, single_dispatch()
144
+ , default_handler()
145
+ , transition_table()
146
+ , forwarded_events()
147
+ , event_store()
148
+ , storeforward_table()
144
149
{ }
145
150
146
151
152
+ virtual ~State () = default ;
153
+
154
+
147
155
/* *
148
156
* Sets the function the FSM calls when the state is entered.
149
157
*
@@ -300,6 +308,21 @@ namespace Core
300
308
}
301
309
302
310
311
+ /* *
312
+ * Sets the default event handler function of the state to use when an
313
+ * event does not have a specific handler.
314
+ *
315
+ * @param handler The handler function object to set.
316
+ */
317
+ virtual State & SetDefaultEventHandler (
318
+ const EventHandler & handler
319
+ )
320
+ {
321
+ default_handler = handler;
322
+ return *this ;
323
+ }
324
+
325
+
303
326
/* *
304
327
* Replaces a potentially existing event handler function with another.
305
328
* This is a 'fancy' capability that should be used with caution.
@@ -381,7 +404,7 @@ namespace Core
381
404
const Event & event
382
405
) const
383
406
{
384
- EventHandler handler{};
407
+ EventHandler handler{ default_handler };
385
408
auto dit = dispatch_table.find ( event );
386
409
if ( dit != dispatch_table.end () )
387
410
{
@@ -400,6 +423,17 @@ namespace Core
400
423
}
401
424
402
425
426
+ /* *
427
+ * Gets the state specific default event handler function.
428
+ *
429
+ * @return The default handler function object.
430
+ */
431
+ virtual EventHandler DefaultEventHandler ()
432
+ {
433
+ return default_handler;
434
+ }
435
+
436
+
403
437
/* *
404
438
* Called by the FiniteStateMachine when a state transition is
405
439
* taking place and the state is becoming the new current state.
@@ -515,6 +549,7 @@ namespace Core
515
549
ExitFunction exit_function;
516
550
mutable DispatchTable dispatch_table;
517
551
mutable SingleDispatch single_dispatch;
552
+ EventHandler default_handler; // state specific default handler
518
553
TransitionTable transition_table;
519
554
ForwardedEvents forwarded_events;
520
555
Events event_store;
@@ -821,6 +856,26 @@ namespace Core
821
856
}
822
857
823
858
859
+ /* *
860
+ * Removes the specific event from the external event queue.
861
+ */
862
+ inline void RemoveEvent ( const Event & event )
863
+ {
864
+ auto it = std::find ( events.begin (), events.end (), (int ) event );
865
+ if ( it != events.end () ) { events.erase ( it ); }
866
+ }
867
+
868
+
869
+ /* *
870
+ * Removes the specific event from the external event queue.
871
+ */
872
+ inline void RemoveInternalEvent ( const Event & event )
873
+ {
874
+ auto it = std::find ( internal_events.begin (), internal_events.end (), (int ) event );
875
+ if ( it != internal_events.end () ) { internal_events.erase ( it ); }
876
+ }
877
+
878
+
824
879
private :
825
880
StateID previous_state; // / The state prior to the current one.
826
881
StateID current_state; // / The index into the state table.
0 commit comments