Skip to content

Commit c188555

Browse files
committed
Added ability to remove transitions dynamically.
1 parent 0ce0d70 commit c188555

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

FSM/FiniteStateMachine.hh

+23
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,29 @@ namespace Core
216216
}
217217

218218

219+
/**
220+
* Removes an existing transition.
221+
* This is a 'fancy' capability that should be used with caution.
222+
*
223+
* @param event The event that is to be removed from the transition table.
224+
* @return the old state to which the removed event was transitioning
225+
* or SentinelStateID indicating that there was no such transition.
226+
*/
227+
virtual StateID RemoveTransition(
228+
const Event & event
229+
)
230+
{
231+
StateID old_state{ SentinelStateID };
232+
auto dit = transition_table.find( event );
233+
if ( dit != transition_table.end() )
234+
{
235+
std::swap( dit->second, old_state );
236+
transition_table.erase( dit );
237+
}
238+
return old_state;
239+
}
240+
241+
219242
/**
220243
* Retrieves the target state if a transition was installed for the
221244
* provided event.

0 commit comments

Comments
 (0)