#ifndef _FINAUTO_H_
#define _FINAUTO_H_
#include "faquery.h"
// Use of the envelope/letter idiom -- methods overridden by this
// class are implemented by delegating to the letter class.
class FiniteAutomaton : protected CFAQuery
{
public:
FiniteAutomaton(CFAQuery&);
virtual ~FiniteAutomaton() {;}
// Debug method
void Dump(ostream &out);
//methods overridden from base class.
virtual bool
ToStatesForEvent(int i_from, char i_oninput, CIntSet& o_toset);
virtual int GetAcceptState();
private:
CFAQuery *pFaQuery;
};
// the AutomatonState class acts as an iterator for tracking
// the state in input matching functions.
class AutomatonState
{
friend class FiniteAutomaton;
public:
virtual ~AutomatonState();
AutomatonState(FiniteAutomaton *parent, int startState);
// Users are allowed to copy and assign iterators, though
AutomatonState(const AutomatonState &src);
AutomatonState &operator=(const AutomatonState &src);
virtual bool IsAccept();
virtual bool IsValid();
// Accepts an event and uses the state machine to move onto the
// next state Returns true if the state is non-terminal, ie not
// accept, and valid.
virtual bool NextState(char event);
// Debug method
void Dump(ostream &out);
private:
FiniteAutomaton *parent;
// current state is a set of states in a
// non-deterministic automaton
CIntSet currentState;
// Helper method to do the non-deterministic transitions
void PerformTransitionSet(char event);
void
TraverseEvents(CIntSet &source, CIntSet &target, char event);
};
#endif // _FINAUTO_H_
//End of File