Milo  0.1
Milo:EquationManipulationProgram
Public Member Functions | Private Member Functions | Private Attributes | List of all members
XML::FSM Class Reference

#include <xml.h>

Public Member Functions

 FSM ()
 
State getState ()
 
const std::string & getTag ()
 
void next (State new_state, const std::string &tag=std::string())
 
bool finished ()
 

Private Member Functions

void advance (State new_state)
 

Private Attributes

State m_state
 Current state. Initialized to NEW.
 
std::stack< std::string > m_tags
 Stack of header name tags.
 
const std::vector< std::array< int, 2 > > transitions
 

Detailed Description

XML Finite State Machine. This class used for both input and output to keep track of current state of XML and to make sure the next state is a legal transition

Constructor & Destructor Documentation

XML::FSM::FSM ( )
inline

Default constructor for FSM class. Initialize FSM to state NEW. Only time FSM is in this state.

Member Function Documentation

void XML::FSM::advance ( State  new_state)
private

Check the transition of old state (m_state) => new_state is legal. If legal, m_state is new_state otherwise it is set to illegal.

bool XML::FSM::finished ( )
inline

Check if FSM is finished when last closing footer is encountered.

Returns
True if there no more tags to be processed.
State XML::FSM::getState ( )
inline

Return current state of FSM.

Returns
Current state of FSM.
const std::string& XML::FSM::getTag ( )
inline

Return string with tag last added or next to be processed.

Returns
Return top of tag stack.
void XML::FSM::next ( State  new_state,
const std::string &  tag = std::string() 
)

Advance FSM to new_state and check if this is a legal transition. If tag is non-empty it also checked. Either m_state is set to new_state or ILLEGAL.

Parameters
new_stateExpected next state after transition
tagExpected next tag (may be empty if not relevent).

Member Data Documentation

const std::vector<std::array<int, 2> > XML::FSM::transitions
private
Initial value:
= {
{ NEW, HEADER },
{ ATOM_END|FOOTER, FOOTER|HEADER },
{ HEADER, NAME_VALUE|HEADER_END|ATOM_END },
{ NAME_VALUE, HEADER_END|ATOM_END|NAME_VALUE },
{ HEADER_END, ELEMENT|HEADER },
{ ELEMENT, FOOTER }
}

The array transitions implments the following state machine to check XML syntax.

     +---—+      NEW  +-----—+
     ^      |       |   |        |
     |      V       V   V        |
   FOOTER<–+---—>HEADER--—+ |
     ^      ^        |  |      | |
     |      |   +-—+  |  +-+ | |
     |      |   |       |  | | | |
     |      |   V       V  V | | |
     |    ATOM_END<-NAME_VALUE | |
     |                 |       | |
     |                 V       | |
     +–ELEMENT<—HEADER_END<-+ |
                       |         |
                       +------—+

The documentation for this class was generated from the following files: