/* * DNN - Data News Network * * by Stephane Chatty * * Copyright 1993-1995 * Centre d'Etudes de la Navigation Aerienne (CENA) * * Automata. * * $Id$ * $CurLog$ */ #include "Automaton.h" DnnState :: DnnState (const char* name, int sz, DnnStateFun* in, DnnStateFun* out) : Name (name), InFun (in), OutFun (out), Links (sz) { } DnnState :: ~DnnState () { CcuHashIterOf l = Links; while (++l) delete *l; } void DnnState :: CreateLink (DnnState* to, void* k, DnnLinkFun fn) { CcuHashCellOf * c = Links.Add (k); c->SetInfo (new DnnLink (to, fn)); } DnnState* DnnState :: Next (void* k, bool peek) { CcuHashCellOf * c = Links.Get (k); if (!c) return 0; DnnLink* l = c->GetInfo (); DnnState* to = l->To; if (!peek) { if (OutFun) (*OutFun) (this); if (l->Fun) l->Fun (this, to, k); if (to->InFun) (*to->InFun) (to); } return to; } DnnAutomaton :: DnnAutomaton (int sz) : Initial (0), Size (sz) { } DnnAutomaton :: ~DnnAutomaton () { CcuListIterOf s = AllStates; while (++s) delete *s; } DnnState* DnnAutomaton :: CreateState (const char* n, DnnStateFun in, DnnStateFun out) { DnnState* s = new DnnState (n, Size, in, out); AllStates.Append (s); return s; } DnnAutomIter :: DnnAutomIter (DnnAutomaton& a) : TheAutomaton (&a), CurState (a.GetInitial ()) { } DnnAutomIter :: ~DnnAutomIter () { } bool DnnAutomIter :: Step (void* k) { if (!CurState && !(CurState = TheAutomaton->GetInitial ())) return false; DnnState* n = CurState->Next (k); if (!n) return false; CurState = n; return true; }