Modules
ADT Database GTK2 GUI IP PiJAX Public Sql Stdio Subversion System Tools Xosd lua v4l2 wx
Recent Changes
Public.Parser.XML2 1.50
Public.ZeroMQ 1.1
Public.Template.Mustache 1.0
Public.Protocols.XMPP 1.4
Sql.Provider.jdbc 1.0
Popular Downloads
Public.Parser.JSON2 1.0
Public.Parser.JSON 0.2
GTK2 2.23
Public.Web.FCGI 1.8
Public.Parser.XML2 1.48
|
Pike Module Reference: module version 1.3, prepared
MODULE Public.ADT.StateMachine |
Classes StateMachine
|
Description
A module implimenting state machines and other automata.
-
Constants
constant
Public.ADT.StateMachine.__version
constant
Public.ADT.StateMachine.__author
|
CLASS Public.ADT.StateMachine.StateMachine |
Methods clear_transitions() create() get_current_state() get_transition() process() reset() set_default_transition() set_transition() set_transition_any()
|
- Description
A simple deterministic finite state machine (FSM)
-
Method create
void Public.ADT.StateMachine.StateMachine()->create(string _begin_state)
- Description
create a new Finite State Machine with the initial state _begin_state.
-
Method reset
void Public.ADT.StateMachine.StateMachine()->reset()
- Description
reset the current state to the beginning state.
-
Method clear_transitions
void Public.ADT.StateMachine.StateMachine()->clear_transitions()
- Description
clear all definied transitions, not including the default.
-
Method set_transition
void Public.ADT.StateMachine.StateMachine()->set_transition(string symbol, string state, function|void action, string new_state)
- Description
set a transition where the current state is considered when
determining if a transition is available.
- Parameter symbol
the input symbol
- Parameter state
the state for which this transition will be effective.
- Parameter action
an optional function that will be called before making the state
transition. this function will take one or more arguments: the symbol
passed, as well as an arbitrary number of additional aguments.
- Parameter new_state
the new state the machine will be in after the transition. If
new_state is 0, this indicates that the state should not change.
-
Method set_transition_any
void Public.ADT.StateMachine.StateMachine()->set_transition_any(string symbol, function|void action, string new_state)
- Description
set a transition available from any state
- Parameter symbol
the input symbol
- Parameter action
an optional function that will be called before making the state
transition. this function will take one or more arguments: the symbol
passed, as well as an arbitrary number of additional aguments.
- Parameter new_state
the new state the machine will be in after the transition. If
new_state is 0, this indicates that the state should not change.
-
Method get_transition
array Public.ADT.StateMachine.StateMachine()->get_transition(string symbol, string state)
- Description
get a transition for a given state transition
this function uses the following algorithm to select a transition:
1. Check to see if a state is defined for (symbol, state).
2. Check to see if a state is defined for (symbol).
3. Check to see if a default transition is defined.
4. Throw an error indicating a transition is not defined.
- Returns
an array consisting of the action (if any), and the new state.
-
Method set_default_transition
void Public.ADT.StateMachine.StateMachine()->set_default_transition(function|void action, string new_state)
- Description
set the default transition.
useful for catching exceptions when a transition is not defined
for a given state.
-
Method get_current_state
string Public.ADT.StateMachine.StateMachine()->get_current_state()
- Description
returns the current state of the State Machine.
-
Method process
mixed Public.ADT.StateMachine.StateMachine()->process(string symbol, mixed ... args)
- Description
process a state change, given the symbol symbol.
this method will use the algorithm described in get_transition()
to determine the appropriate transition to use. if an action is
defined for the chosen transition, it will be called.
symbol and args will be passed to the action function.
state will then be advanced to the next state defined in the
transition.
|
|