diff options
author | chatty | 2000-11-28 15:28:29 +0000 |
---|---|---|
committer | chatty | 2000-11-28 15:28:29 +0000 |
commit | 0830afbb9473c552ab021873d96324a5df4553bc (patch) | |
tree | d074053e9d44f10c0ac2f869467b47e69012d75a /dnn/Automaton.cc | |
parent | 3ee78810becfeeb3690468ac735b6ba20dc5c501 (diff) | |
download | ivy-league-0830afbb9473c552ab021873d96324a5df4553bc.zip ivy-league-0830afbb9473c552ab021873d96324a5df4553bc.tar.gz ivy-league-0830afbb9473c552ab021873d96324a5df4553bc.tar.bz2 ivy-league-0830afbb9473c552ab021873d96324a5df4553bc.tar.xz |
Archiving a file that was born dead
Diffstat (limited to 'dnn/Automaton.cc')
-rwxr-xr-x | dnn/Automaton.cc | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/dnn/Automaton.cc b/dnn/Automaton.cc new file mode 100755 index 0000000..558a0ba --- /dev/null +++ b/dnn/Automaton.cc @@ -0,0 +1,99 @@ +/* + * 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 <DnnLink> l = Links; + while (++l) + delete *l; +} + +void +DnnState :: CreateLink (DnnState* to, void* k, DnnLinkFun fn) +{ + CcuHashCellOf <DnnLink>* c = Links.Add (k); + c->SetInfo (new DnnLink (to, fn)); +} + +DnnState* +DnnState :: Next (void* k, bool peek) +{ + CcuHashCellOf <DnnLink>* 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 <DnnState> 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; +} |