Skip to content

Commit

Permalink
Added ability to remove transitions dynamically.
Browse files Browse the repository at this point in the history
  • Loading branch information
laszlo-kiss committed Dec 17, 2016
1 parent 0ce0d70 commit c188555
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions FSM/FiniteStateMachine.hh
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,29 @@ namespace Core
}


/**
* Removes an existing transition.
* This is a 'fancy' capability that should be used with caution.
*
* @param event The event that is to be removed from the transition table.
* @return the old state to which the removed event was transitioning
* or SentinelStateID indicating that there was no such transition.
*/
virtual StateID RemoveTransition(
const Event & event
)
{
StateID old_state{ SentinelStateID };
auto dit = transition_table.find( event );
if ( dit != transition_table.end() )
{
std::swap( dit->second, old_state );
transition_table.erase( dit );
}
return old_state;
}


/**
* Retrieves the target state if a transition was installed for the
* provided event.
Expand Down

0 comments on commit c188555

Please sign in to comment.