About
User Reference
C++ API
luafaudes
Developer
Links
libFAUDES online
libFAUDES

Sections

Index

cfl_generator.cpp

Go to the documentation of this file.
00001 /** @file cfl_generator.cpp Class vGenerator */
00002 
00003 /* FAU Discrete Event Systems Library (libfaudes)
00004 
00005    Copyright (C) 2006  Bernd Opitz
00006    Copyright (C) 2007  Thomas Moor
00007    Exclusive copyright is granted to Klaus Schmidt
00008 
00009    This library is free software; you can redistribute it and/or
00010    modify it under the terms of the GNU Lesser General Public
00011    License as published by the Free Software Foundation; either
00012    version 2.1 of the License, or (at your option) any later version.
00013 
00014    This library is distributed in the hope that it will be useful,
00015    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016    MERCHANTABILITY or FITNES FOR A PARTICULAR PURPOSE.  See the GNU
00017    Lesser General Public License for more details.
00018 
00019    You should have received a copy of the GNU Lesser General Public
00020    License along with this library; if not, write to the Free Software
00021    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00022 
00023 
00024 #include "cfl_generator.h"
00025 #include <stack>
00026 
00027 
00028 namespace faudes {
00029 
00030 // msObjectCount (static) 
00031 Idx vGenerator::msObjectCount = 0;
00032 
00033 // State names default (static) 
00034 bool vGenerator::msStateNamesEnabledDefault = true;
00035 
00036 // Reindex default (static) 
00037 bool vGenerator::msReindexOnWriteDefault = false;
00038 
00039 // static default prototypes (construct on first use design pattern)
00040 const EventSet& vGenerator::AlphabetVoid(void) {
00041   static EventSet* pstatic = new EventSet();
00042   return *pstatic;
00043 }
00044 const StateSet& vGenerator::StatesVoid(void) {
00045   static StateSet* pstatic = new StateSet();
00046   return *pstatic;
00047 }
00048 const TransSet& vGenerator::TransRelVoid(void) {
00049   static TransSet* pstatic = new TransSet();
00050   return *pstatic;
00051 }
00052 const AttributeVoid& vGenerator::GlobalVoid(void) {
00053   static AttributeVoid* pstatic = new AttributeVoid();
00054   return *pstatic;
00055 }
00056 
00057 
00058 
00059 // constructor
00060 vGenerator::vGenerator(void) : 
00061   // base
00062   Type(),
00063   // my name
00064   mMyName("Generator"),
00065   // have std symboltables
00066   mpStateSymbolTable(&mStateSymbolTable),
00067   mpEventSymbolTable(GlobalEventSymbolTablep()),
00068   // other members
00069   mStateNamesEnabled(msStateNamesEnabledDefault),  
00070   mReindexOnWrite(msReindexOnWriteDefault),  
00071   // initialise heap members
00072   mpAlphabet(0),
00073   mpStates(0),
00074   mpTransRel(0),
00075   mpGlobalAttribute(0),
00076   // initialise prototypes
00077   pAlphabetPrototype(&AlphabetVoid()),
00078   pStatesPrototype(&StatesVoid()),
00079   pTransRelPrototype(&TransRelVoid()),
00080   pGlobalPrototype(&GlobalVoid())
00081 {
00082   FAUDES_OBJCOUNT_INC("Generator");
00083   FD_DG("vGenerator(" << this << ")::vGenerator()");
00084   // track generator objects
00085   msObjectCount++; 
00086   mId = msObjectCount;
00087   // allocate core members
00088   NewCore();
00089   // fix std names
00090   mInitStates.Name("InitStates");
00091   mMarkedStates.Name("MarkedStates");
00092 }
00093 
00094 // copy constructor
00095 vGenerator::vGenerator(const vGenerator& rOtherGen) :
00096   // my name
00097   mMyName("Generator"),
00098   // have std symboltables
00099   mpStateSymbolTable(&mStateSymbolTable),
00100   mpEventSymbolTable(GlobalEventSymbolTablep()),
00101   // other members
00102   mStateNamesEnabled(msStateNamesEnabledDefault),  
00103   mReindexOnWrite(msReindexOnWriteDefault),  
00104   // initialise heap members
00105   mpAlphabet(0),
00106   mpStates(0),
00107   mpTransRel(0),
00108   mpGlobalAttribute(0),
00109   // initialise prototypes
00110   pAlphabetPrototype(&AlphabetVoid()),
00111   pStatesPrototype(&StatesVoid()),
00112   pTransRelPrototype(&TransRelVoid()),
00113   pGlobalPrototype(&GlobalVoid())
00114 {
00115   FAUDES_OBJCOUNT_INC("Generator");
00116   FD_DG("vGenerator(" << this << ")::vGenerator(" << &rOtherGen << ")");
00117   // track generator objects
00118   msObjectCount++; 
00119   mId = msObjectCount;
00120   // allocate core members
00121   NewCore();
00122   // perform copy
00123   Assign(rOtherGen);
00124 }
00125 
00126 // construct from file
00127 vGenerator::vGenerator(const std::string& rFileName) : 
00128   // my name
00129   mMyName("Generator"),
00130   // have std symboltables
00131   mpStateSymbolTable(&mStateSymbolTable),
00132   mpEventSymbolTable(GlobalEventSymbolTablep()),
00133   // other members
00134   mStateNamesEnabled(msStateNamesEnabledDefault),  
00135   mReindexOnWrite(msReindexOnWriteDefault),  
00136   // initialise heap members
00137   mpAlphabet(0),
00138   mpStates(0),
00139   mpTransRel(0),
00140   mpGlobalAttribute(0),
00141   // initialise prototypes
00142   pAlphabetPrototype(&AlphabetVoid()),
00143   pStatesPrototype(&StatesVoid()),
00144   pTransRelPrototype(&TransRelVoid()),
00145   pGlobalPrototype(&GlobalVoid())
00146 {
00147   FAUDES_OBJCOUNT_INC("Generator");
00148   FD_DG("vGenerator(" << this << ")::vGenerator(" << rFileName << ")");
00149   // track generator objects
00150   msObjectCount++; 
00151   mId = msObjectCount;
00152   // allocate core members
00153   NewCore();
00154   // fix std names
00155   mInitStates.Name("InitStates");
00156   mMarkedStates.Name("MarkedStates");
00157   // set defaults for file io
00158   mStateNamesEnabled=true;
00159   // do read
00160   Read(rFileName,"Generator");
00161   // restore defaults
00162   mStateNamesEnabled=msStateNamesEnabledDefault;
00163 }
00164 
00165 // construct on heap
00166 vGenerator* vGenerator::New(void) const {
00167   FD_DG("vGenerator(" << this << ")::New()");
00168   // allocate
00169   vGenerator* res = new vGenerator();
00170   // fix configuration
00171   res->EventSymbolTablep(mpEventSymbolTable);
00172   res->mStateNamesEnabled=mStateNamesEnabled;
00173   res->mReindexOnWrite=mReindexOnWrite;  
00174   return res;
00175 }
00176 
00177 // construct on heap
00178 vGenerator* vGenerator::Copy(void) const {
00179   FD_DG("vGenerator(" << this << ")::Copy()");
00180   // copy construct
00181   vGenerator* res = new vGenerator(*this);
00182   return res;
00183 }
00184 
00185 // cast
00186 const Type* vGenerator::Cast(const Type* pOther) const {
00187   return dynamic_cast< const vGenerator* > (pOther);
00188 }
00189 
00190 
00191 // destruct
00192 vGenerator::~vGenerator(void) {
00193   FAUDES_OBJCOUNT_DEC("Generator");
00194   // free my members
00195   DeleteCore();
00196 }
00197 
00198 // configure attribute types
00199 void vGenerator::ConfigureAttributeTypes(const AttributeVoid* pNewGlobalPrototype, 
00200     const StateSet* pNewStatesPrototype, const EventSet* pNewAlphabetPrototype, 
00201     const TransSet* pNewTransRelPrototype) {
00202   FD_DG("vGenerator(" << this << ")::ConfigureAtributes(..)");
00203   pGlobalPrototype= pNewGlobalPrototype;
00204   pStatesPrototype= pNewStatesPrototype;
00205   pAlphabetPrototype= pNewAlphabetPrototype;
00206   pTransRelPrototype= pNewTransRelPrototype;
00207   FD_DG("vGenerator(" << this << ")::ConfigureAtributes(): done");
00208 }
00209 
00210 // indicate new core
00211 void vGenerator::UpdateCore(void) {
00212   // fix std names
00213   if(mpAlphabet) mpAlphabet->Name("Alphabet");
00214   if(mpStates) mpStates->Name("States");
00215   if(mpTransRel) mpTransRel->Name("TransRel");
00216   // fix symbol table
00217   if(mpAlphabet) EventSymbolTablep(mpEventSymbolTable);
00218 }
00219 
00220 // protected helper: allocate core on heap
00221 void vGenerator::NewCore(void) {
00222   DeleteCore();
00223   // allocate (use prototypes, fallback to void attributes)
00224   if(pAlphabetPrototype) mpAlphabet= pAlphabetPrototype->New();
00225   else mpAlphabet = new EventSet();
00226   if(pStatesPrototype) mpStates=pStatesPrototype->New();
00227   else mpStates = new StateSet();
00228   if(pTransRelPrototype) mpTransRel= pTransRelPrototype->New();
00229   else mpTransRel = new TransSet();
00230   if(pGlobalPrototype) mpGlobalAttribute=pGlobalPrototype->New();
00231   else mpGlobalAttribute = new AttributeVoid();
00232   // update callback
00233   UpdateCore();
00234 }
00235   
00236 // protected helper: free core from heap
00237 void vGenerator::DeleteCore(void) {
00238   if(mpAlphabet) delete mpAlphabet; 
00239   if(mpStates) delete mpStates; 
00240   if(mpTransRel) delete mpTransRel; 
00241   if(mpGlobalAttribute) delete mpGlobalAttribute;   
00242   mpAlphabet=0;
00243   mpStates=0;
00244   mpTransRel=0;
00245   mpGlobalAttribute=0;
00246   // update callback
00247   UpdateCore();
00248 }
00249 
00250 
00251 
00252 // copy from other vGenerator (try to convert attributes)
00253 vGenerator& vGenerator::Assign(const vGenerator& rGen) {
00254   FD_DG("vGenerator(" << this << ")::Assign(" << &rGen << ")");
00255   // bail out on match
00256   if(&rGen==this) return *this;
00257   // prepare result (call clear for virtual stuff)
00258   Clear();
00259   // have same event symboltable
00260   EventSymbolTablep(rGen.mpEventSymbolTable);
00261   // copy state symboltable
00262   StateSymbolTable(rGen.mStateSymbolTable);
00263   // set other members
00264   Name(rGen.Name());
00265   StateNamesEnabled(rGen.StateNamesEnabled());
00266   ReindexOnWrite(rGen.ReindexOnWrite());
00267   InjectInitStates(rGen.mInitStates);
00268   InjectMarkedStates(rGen.mMarkedStates);
00269   // core members, try attributes
00270   InjectStates(*rGen.mpStates);
00271   InjectAlphabet(*rGen.mpAlphabet);
00272   InjectTransRel(*rGen.mpTransRel);
00273   GlobalAttributeTry(*rGen.mpGlobalAttribute);
00274 #ifdef FAUDES_DEBUG_CODE
00275   if(!Valid()) {
00276     FD_DG("vGenerator()::Copy(): invalid generator");
00277     DWrite(); 
00278     abort();
00279   }
00280 #endif
00281   return *this;
00282 } 
00283 
00284 // copy from other vGenerator (try to convert attributes)
00285 vGenerator& vGenerator::Assign(const Type& rSrc) {
00286   FD_DG("vGenerator(" << this << ")::Assign([type] " << &rSrc << ")");
00287   // bail out on match
00288   if(&rSrc==this) return *this;
00289   Clear();
00290   const vGenerator* vgen=dynamic_cast<const vGenerator*>(&rSrc);
00291   if(vgen) Assign(*vgen);
00292   return *this;
00293 }
00294 
00295 // copy from other vGenerator (clear attributes)
00296 vGenerator& vGenerator::AssignWithoutAttributes(const vGenerator& rGen) {
00297   FD_DG("vGenerator(" << this << ")::Assign(" << &rGen << ")");
00298   // prepare result (call clear for virtual stuff)
00299   Clear();
00300   // have same event symboltable
00301   EventSymbolTablep(rGen.mpEventSymbolTable);
00302   // copy state symboltable
00303   StateSymbolTable(rGen.mStateSymbolTable);
00304   // set other members
00305   Name(rGen.Name());
00306   StateNamesEnabled(rGen.StateNamesEnabled());
00307   ReindexOnWrite(rGen.ReindexOnWrite());
00308   InjectInitStates(rGen.mInitStates);
00309   InjectMarkedStates(rGen.mMarkedStates);
00310   // core members, ignore attributes
00311   mpStates->AssignWithoutAttributes(rGen.States());
00312   mpAlphabet->AssignWithoutAttributes(rGen.Alphabet());
00313   mpTransRel->AssignWithoutAttributes(rGen.TransRel());
00314 #ifdef FAUDES_DEBUG_CODE
00315   if(!Valid()) {
00316     FD_DG("vGenerator()::Copy(): invalid generator");
00317     DWrite(); 
00318     abort();
00319   }
00320 #endif
00321   return *this;
00322 } 
00323 
00324 
00325 // Move(gen) destructive copy 
00326 void vGenerator::Move(vGenerator& rGen) {
00327   FD_DG("vGenerator(" << this << ")::Move(" << &rGen << ")");
00328   // test types
00329   bool tmm=false;
00330   if(typeid(rGen.Alphabet())!=typeid(Alphabet())) tmm=true;
00331   if(typeid(rGen.States())!=typeid(States())) tmm=true;
00332   if(typeid(rGen.TransRel())!=typeid(TransRel())) tmm=true;
00333   if(typeid(rGen.GlobalAttribute())!=typeid(GlobalAttribute())) tmm=true;
00334   if(tmm) { 
00335     FD_DG("vGenerator(" << this << ")::Move(" << &rGen << "): using std copy");
00336     rGen.Assign(*this);
00337     Clear();
00338     return;
00339   }
00340   // prepare result (call clear for virtual stuff)
00341   rGen.Clear();
00342   // have same event symboltable
00343   rGen.EventSymbolTablep(mpEventSymbolTable);
00344   // copy state symboltable (todo: make this pointer based?)
00345   rGen.StateSymbolTable(mStateSymbolTable);
00346   // copy members
00347   rGen.Name(Name());
00348   rGen.StateNamesEnabled(StateNamesEnabled());
00349   rGen.ReindexOnWrite(ReindexOnWrite());
00350   rGen.InjectInitStates(InitStates());
00351   rGen.InjectMarkedStates(MarkedStates());
00352   // delete destination core
00353   if(rGen.mpStates) delete rGen.mpStates;
00354   if(rGen.mpAlphabet) delete rGen.mpAlphabet;
00355   if(rGen.mpTransRel) delete rGen.mpTransRel;
00356   if(rGen.mpGlobalAttribute) delete rGen.mpGlobalAttribute;
00357   // move and invalidate core members
00358   rGen.mpStates=mpStates;
00359   rGen.mpAlphabet=mpAlphabet;
00360   rGen.mpTransRel=mpTransRel;
00361   rGen.mpGlobalAttribute=mpGlobalAttribute;
00362   mpStates=0;
00363   mpAlphabet=0;
00364   mpTransRel=0;
00365   mpGlobalAttribute=0;
00366   // register core update
00367   rGen.UpdateCore();
00368   // install new empty core members
00369   NewCore();
00370   // clear myself (incl derived classes members)
00371   Clear();
00372 }
00373 
00374 // operator =
00375 vGenerator& vGenerator::operator = (const vGenerator& rOtherGen) {
00376   FD_DG("vGenerator(" << this << ")::operator = " << &rOtherGen);
00377   return Assign(rOtherGen);
00378 }
00379 
00380 // Version(idx)
00381 void vGenerator::Version(Idx version, vGenerator& rResGen) const {
00382   FD_DG("vGenerator(" << this << ")::Version(" << version << ")");
00383   std::ostringstream o;
00384   o << version;
00385   Version(o.str(),rResGen);
00386 }
00387 
00388 // Version(string)
00389 void vGenerator::Version(const std::string& rVersion, vGenerator& rResGen) const {
00390   FD_DG("vGenerator(" << this << ")::Version(" << rVersion << ")");
00391   // second arg must not be us 
00392   if(this==&rResGen) {
00393     std::stringstream errstr;
00394     errstr << "Destination must not match source.";
00395     throw Exception("vGenerator::Version(string)", errstr.str(), 96);
00396   }
00397   // prepare Empty generator
00398   rResGen.Clear();
00399   rResGen.GlobalAttribute(GlobalAttribute());
00400   EventSet::Iterator eit;
00401   StateSet::Iterator lit;
00402   TransSet::Iterator tit;
00403   std::map<Idx,Idx> eventoldnewmap;
00404   rResGen.Name(Name()+"_"+rVersion);
00405   // create versioned mAlphabet
00406   for (eit = AlphabetBegin(); eit != AlphabetEnd(); ++eit) {
00407     Idx newevent= rResGen.InsEvent(EventName(*eit)+"_"+rVersion); 
00408     eventoldnewmap[*eit] = newevent;
00409     rResGen.EventAttribute(newevent,EventAttribute(*eit));
00410   }
00411   // create new stateset
00412   for (lit = StatesBegin(); lit != StatesEnd(); ++lit) {
00413     rResGen.InsState(*lit);
00414     rResGen.StateAttribute(*lit,StateAttribute(*lit)); //would be faster if directly copied ?
00415     if (StateName(*lit) != "") rResGen.StateName(*lit,StateName(*lit));
00416   }
00417   // created versioned transrel
00418   for (tit = TransRelBegin(); tit != TransRelEnd(); ++tit) {
00419     Transition trans=Transition(tit->X1, eventoldnewmap[tit->Ev], tit->X2);
00420     rResGen.SetTransition(trans);
00421     rResGen.TransAttribute(trans, TransAttribute(*tit));
00422   }
00423   // set i/m states
00424   rResGen.mInitStates=mInitStates;
00425   rResGen.mMarkedStates=mMarkedStates;
00426   // behavioural flags
00427   rResGen.mStateNamesEnabled = mStateNamesEnabled;
00428   rResGen.mReindexOnWrite = mReindexOnWrite;
00429 }
00430 
00431 
00432 // Version(string,string)
00433 void vGenerator::Version(const std::string& rPattern, const std::string& rReplacement, vGenerator& rResGen) const {
00434   FD_DG("vGenerator(" << this << ")::Version(" << rPattern << ", " << rReplacement << ", ...)");
00435   // second arg must not be us 
00436   if(this==&rResGen) {
00437     std::stringstream errstr;
00438     errstr << "Destination must not match source.";
00439     throw Exception("vGenerator::Version(string,string)", errstr.str(), 96);
00440   }
00441   // ignore invalid pattern
00442   if(rPattern.empty()) {
00443     rResGen.Assign(*this);
00444     return;
00445   }
00446   // trivial case
00447   if (rPattern==rReplacement) {
00448     rResGen.Assign(*this);
00449     return;
00450   }
00451   // prepare Empty generator
00452   rResGen.Clear();
00453   rResGen.GlobalAttribute(GlobalAttribute());
00454   rResGen.Name(Name()+"_"+rReplacement);
00455   EventSet::Iterator eit;
00456   StateSet::Iterator lit;
00457   TransSet::Iterator tit;
00458   std::map<Idx,Idx> eventoldnewmap;
00459   // create versioned mAlphabet
00460   std::string newstring;
00461   std::string::size_type pos = 0;
00462   int patternlength=rPattern.size();
00463   int replacementlength=rReplacement.size();
00464   for (eit = AlphabetBegin(); eit != AlphabetEnd(); ++eit) {
00465     // search for all pattern occurences in event name and replace
00466     newstring=EventName(*eit);
00467     while ( (pos = newstring.find(rPattern, pos)) != std::string::npos ) {
00468         newstring.replace(pos, patternlength, rReplacement);
00469         //pos++;
00470         pos=pos+replacementlength;
00471     }
00472       Idx newevent= rResGen.InsEvent(newstring); 
00473       eventoldnewmap[*eit] = newevent;
00474       rResGen.EventAttribute(newevent,EventAttribute(*eit));
00475   }
00476   // create new stateset
00477   for (lit = StatesBegin(); lit != StatesEnd(); ++lit) {
00478     rResGen.InsState(*lit);
00479     rResGen.StateAttribute(*lit,StateAttribute(*lit)); //would be faster if directly copied ?
00480     if (StateName(*lit) != "") rResGen.StateName(*lit,StateName(*lit));
00481   }
00482   // created versioned transrel
00483   for (tit = TransRelBegin(); tit != TransRelEnd(); ++tit) {
00484     Transition trans=Transition(tit->X1, eventoldnewmap[tit->Ev], tit->X2);
00485     rResGen.SetTransition(trans);
00486     rResGen.TransAttribute(trans, TransAttribute(*tit));
00487   }
00488   // set i/m states
00489   rResGen.mInitStates=mInitStates;
00490   rResGen.mMarkedStates=mMarkedStates;
00491   // behavioural flags
00492   rResGen.mStateNamesEnabled = mStateNamesEnabled;
00493   rResGen.mReindexOnWrite = mReindexOnWrite;
00494 }
00495 
00496 
00497 // Name(rName)
00498 void vGenerator::Name(const std::string& rName) {
00499   FD_DV("vGenerator(" << this << ")::Name(\"" << rName << "\")");
00500   mMyName = rName;
00501 }
00502 
00503 // Name()
00504 const std::string& vGenerator::Name(void) const {
00505   return mMyName;
00506 }
00507 
00508 // Valid()
00509 bool vGenerator::Valid(void) {
00510   FD_DG("vGenerator(" << this << ")::Valid()");
00511   // core members on heap
00512   if(mpAlphabet==0) return false;
00513   if(mpStates==0) return false;
00514   if(mpTransRel==0) return false;
00515   if(mpGlobalAttribute==0) return false;
00516   // transitions to be known
00517   TransSet::Iterator tit;
00518   StateSet::Iterator lit;
00519   for(tit = TransRelBegin(); tit != TransRelEnd(); ++tit) {
00520     if(! ExistsState(tit->X1)) return false;
00521     if(! ExistsEvent(tit->Ev)) return false;
00522     if(! ExistsState(tit->X2)) return false;
00523   }
00524   // init states to be known
00525   for(lit = InitStatesBegin(); lit != InitStatesEnd(); ++lit) 
00526     if(! ExistsState(static_cast<Idx>(*lit))) return false;
00527   for(lit = MarkedStatesBegin(); lit != MarkedStatesEnd(); ++lit) 
00528     if(! ExistsState(static_cast<Idx>(*lit))) return false;
00529   // sets to have proper names
00530   if(mpAlphabet->Name() != "Alphabet") return false;
00531   if(mpStates->Name() != "States") return false;
00532   if(mInitStates.Name() != "InitStates") return false;
00533   if(mMarkedStates.Name() != "MarkedStates") return false;
00534   // event symbol table
00535   NameSet::Iterator eit;
00536   for(eit = AlphabetBegin(); eit != AlphabetEnd(); eit ++) {
00537     if(EventName(*eit)=="") return false;
00538   }
00539   // done
00540   return true;
00541 }
00542 
00543 // AlphabetSize()
00544 Idx vGenerator::AlphabetSize(void) const {
00545   return mpAlphabet->Size();
00546 }
00547 
00548 // Size()
00549 Idx vGenerator::Size(void) const {
00550   return mpStates->Size();
00551 }
00552 
00553 // Clear()
00554 void vGenerator::Clear(void) {
00555   FD_DG("vGenerator(" << this << ")::Clear()");
00556   mpAlphabet->Clear();
00557   mpStates->Clear();
00558   mpStateSymbolTable->Clear();
00559   mpTransRel->Clear();
00560   mInitStates.Clear();
00561   mMarkedStates.Clear();
00562   ClearGlobalAttribute();
00563 }
00564 
00565 // ClearGlobalAttribute()
00566 void vGenerator::ClearGlobalAttribute(void) {
00567   mpGlobalAttribute->Clear(); 
00568 }
00569 
00570 // ClearStateAttributes()
00571 void vGenerator::ClearStateAttributes(void) {
00572   mpStates->ClearAttributes();
00573 }
00574 
00575 // ClearEventAttributes()
00576 void vGenerator::ClearEventAttributes(void) {
00577   mpAlphabet->ClearAttributes();
00578 }
00579 
00580 // ClearTransAttributes()
00581 void vGenerator::ClearTransAttributes(void) {
00582   mpTransRel->ClearAttributes();
00583 }
00584 
00585 // ClearAttributes()
00586 void vGenerator::ClearAttributes(void) {
00587   ClearGlobalAttribute();
00588   ClearStateAttributes();
00589   ClearEventAttributes();
00590   ClearTransAttributes();
00591 }
00592 
00593 
00594 // ClearStates()
00595 void vGenerator::ClearStates(void) {
00596   mpStates->Clear();
00597   mpTransRel->Clear();
00598   mInitStates.Clear();
00599   mMarkedStates.Clear();
00600   mpStateSymbolTable->Clear();
00601 }
00602 
00603 // TransRelSize()
00604 Idx vGenerator::TransRelSize(void) const {
00605   return mpTransRel->Size();
00606 }
00607 
00608 // InitStatesSize()
00609 Idx vGenerator::InitStatesSize(void) const {
00610   return mInitStates.Size();
00611 }
00612 
00613 // MarkedStatesSize()
00614 Idx vGenerator::MarkedStatesSize(void) const {
00615   return mMarkedStates.Size();
00616 }
00617 
00618 // AlphabetEmpty()
00619 bool vGenerator::AlphabetEmpty(void) const {
00620   return mpAlphabet->Empty();
00621 }
00622 
00623 // Empty()
00624 bool vGenerator::Empty(void) const {
00625   return mpStates->Empty();
00626 }
00627 
00628 // TransRelEmpty()
00629 bool vGenerator::TransRelEmpty(void) const {
00630   return mpTransRel->Empty();
00631 }
00632 
00633 // InitStatesEmpty()
00634 bool vGenerator::InitStatesEmpty(void) const {
00635   return mInitStates.Empty();
00636 }
00637 
00638 // MarkedStatesEmpty()
00639 bool vGenerator::MarkedStatesEmpty(void) const {
00640   return mMarkedStates.Empty();
00641 }
00642 
00643 
00644 // ClearMinStateIndexMap()
00645 void vGenerator::ClearMinStateIndexMap(void) const {
00646   FD_DG("vGenerator::ClearMinStateIndexMap()");
00647   // fake const
00648   vGenerator* fakeconst = const_cast<vGenerator*>(this);
00649   fakeconst->mMinStateIndexMap.clear();
00650 }
00651 
00652 // MinStateIndexMap()
00653 const std::map<Idx,Idx>& vGenerator::MinStateIndexMap(void) const {
00654   return mMinStateIndexMap;
00655 }
00656 
00657 
00658 // SetMinStateIndexMap()
00659 void vGenerator::SetMinStateIndexMap(void) const {
00660   FD_DG("vGenerator::SetMinStateIndexMap()");
00661   // fake const
00662   vGenerator* fakeconst = const_cast<vGenerator*>(this);
00663   // clear map
00664   fakeconst->ClearMinStateIndexMap();
00665   StateSet::Iterator it;
00666   Idx minindex = 0;
00667   // if generator states get names
00668   if(StateNamesEnabled()) {
00669     // named initial states first
00670     for(it = InitStatesBegin(); it != InitStatesEnd(); ++it) {
00671       if(StateName(static_cast<Idx>(*it)) != "") {
00672   fakeconst->mMinStateIndexMap[*it] = ++minindex;
00673       }
00674     }
00675     // then all other named states
00676     for(it = StatesBegin(); it != StatesEnd(); ++it) {
00677       if(mMinStateIndexMap.count(*it) == 0) {
00678   if(StateName(static_cast<Idx>(*it)) != "") {
00679     fakeconst->mMinStateIndexMap[*it] = ++minindex;
00680   }
00681       }
00682     }
00683     // at last all anonymous states
00684     for(it = StatesBegin(); it != StatesEnd(); ++it) {
00685       if(mMinStateIndexMap.count(*it) == 0) {
00686   fakeconst->mMinStateIndexMap[*it] = ++minindex;
00687       }
00688     }
00689   }
00690   // if generator states are all anonymous
00691   else {
00692     // all initial states first
00693     for(it = InitStatesBegin(); it != InitStatesEnd(); ++it) {
00694       fakeconst->mMinStateIndexMap[*it] = ++minindex;
00695     }
00696     // then the rest
00697     for(it = StatesBegin(); it != StatesEnd(); ++it) {
00698       if(mMinStateIndexMap.count(*it) == 0) {
00699   fakeconst->mMinStateIndexMap[*it] = ++minindex;
00700       }
00701     }
00702   }
00703 #ifdef FAUDES_DEBUG_CONTAINER
00704   std::map<Idx,Idx>::const_iterator _it;
00705   for(_it = mMinStateIndexMap.begin(); _it != mMinStateIndexMap.end(); ++_it) {
00706     FD_DC("vGenerator::MinStateIndexMap: " << _it->first
00707     << " <-- " << SStr(_it->second));
00708   }
00709 #endif
00710 }
00711 
00712 
00713 // MinStateIndex(index)
00714 Idx vGenerator::MinStateIndex(Idx index) const {
00715   std::map<Idx,Idx>::const_iterator minit;
00716   minit = mMinStateIndexMap.find(index);
00717   if(minit != mMinStateIndexMap.end()) {
00718     return minit->second;
00719   } 
00720   return index;
00721 }
00722 
00723 
00724 // Max StateIndex
00725 Idx vGenerator::MaxStateIndex(void) const {
00726   if(mpStates->Empty()) return 0;
00727   return *(--(mpStates->End()));
00728 }
00729 
00730 // Re-enumerate states to obtain a consecutive state set
00731 void vGenerator::MinStateIndex(void) {
00732   // bail out on trivial
00733   if(MaxStateIndex()==Size()) return;
00734   // prepare buffer and index map
00735   vGenerator* dst = New();
00736   dst->InsEvents(Alphabet());
00737   SetMinStateIndexMap();
00738   // doit: states
00739   StateSet::Iterator sit;
00740   Idx s;
00741   for(sit=StatesBegin(); sit!=StatesEnd(); ++sit) {
00742     s=MinStateIndex(*sit);
00743     dst->InsState(s);
00744     dst->StateAttribute(s,StateAttribute(*sit));
00745     if(StateNamesEnabled()) 
00746       dst->StateName(s,StateName(*sit));
00747   }
00748   for(sit=InitStatesBegin(); sit!=InitStatesEnd(); ++sit) {
00749     s=MinStateIndex(*sit);
00750     dst->SetInitState(s);
00751   }
00752   for(sit=MarkedStatesBegin(); sit!=MarkedStatesEnd(); ++sit) {
00753     s=MinStateIndex(*sit);
00754     dst->SetMarkedState(s);
00755   }
00756   // doit: transitions
00757   TransSet::Iterator tit;
00758   for(tit=TransRelBegin(); tit!=TransRelEnd(); tit++) {
00759     Transition dt(MinStateIndex(tit->X1),tit->Ev,MinStateIndex(tit->X2));
00760     dst->SetTransition(dt);
00761     dst->TransAttribute(dt,TransAttribute(dt));
00762   }
00763   // move relevant core members
00764   StateSymbolTable(dst->mStateSymbolTable);
00765   delete mpStates;
00766   delete mpTransRel;
00767   mpStates=dst->mpStates;
00768   mpTransRel=dst->mpTransRel;
00769   dst->mpStates=0;
00770   dst->mpTransRel=0;
00771   // move other members
00772   mInitStates=dst->InitStates();
00773   mMarkedStates=dst->MarkedStates();
00774   // update callback
00775   UpdateCore();
00776   // delete buffer
00777   delete dst;
00778   // invalidate map
00779   ClearMinStateIndexMap();
00780 }
00781 
00782 
00783 // EventSymbolTablep() const
00784 SymbolTable* vGenerator::EventSymbolTablep(void) const {
00785   return mpEventSymbolTable;
00786 }
00787 
00788 // GlobalEventSymbolTablep() const
00789 SymbolTable* vGenerator::GlobalEventSymbolTablep(void) {
00790   return SymbolTable::GlobalEventSymbolTablep();
00791 }
00792 
00793 // EventSymbolTablep(pSymTab) 
00794 void vGenerator::EventSymbolTablep(SymbolTable* pSymTab) {
00795   mpEventSymbolTable=pSymTab;
00796   // todo: set symboltable in mpAlphabet
00797 }
00798 
00799 // EventSymbolTablep(rOtherGen) 
00800 void vGenerator::EventSymbolTablep(const vGenerator& rOtherGen) {
00801   EventSymbolTablep(rOtherGen.EventSymbolTablep());
00802 }
00803 
00804 // EventIndex(rName)
00805 Idx vGenerator::EventIndex(const std::string& rName) const {
00806   return mpEventSymbolTable->Index(rName);
00807 }
00808 
00809 // EventName(index)
00810 std::string vGenerator::EventName(Idx index) const {
00811   return mpEventSymbolTable->Symbol(index);
00812 }
00813 
00814 // EventName(index, name)
00815 void vGenerator::EventName(Idx index, const std::string& rName) {
00816   FD_DG("vGenerator(" << this << ")::EventName(" 
00817       << index << ",\"" << rName << "\")");
00818 #ifdef FAUDES_CHECKED
00819   if (! ExistsEvent(index)) {
00820     std::stringstream errstr;
00821     errstr << "event \"" << index << "\" not found in generator \""
00822      << Name() << "\"";
00823     throw Exception("vGenerator::EventName(name)", errstr.str(), 89);
00824   }
00825 #endif
00826   mpEventSymbolTable->SetEntry(index, rName);
00827 }
00828 
00829 // UniqueEventName(rName)
00830 std::string vGenerator::UniqueEventName(const std::string& rName) const {
00831   std::string name=rName;
00832   if(name=="") name="ev";
00833   return mpEventSymbolTable->UniqueSymbol(name) ;
00834 }
00835 
00836 
00837 // EventRename
00838 bool vGenerator::EventRename(Idx event, const std::string& rNewName) {
00839   // consistency
00840   FD_DG("vGenerator(" << this << ")::EventRename(" << EStr(event) << ", " << rNewName << ")");
00841 #ifdef FAUDES_CHECKED
00842   if (! ExistsEvent(event)) {
00843     std::stringstream errstr;
00844     errstr << "event \"" << event << "\" not found in generator \""
00845      << Name() << "\"";
00846     throw Exception("vGenerator::EventReame(name)", errstr.str(), 89);
00847   }
00848 #endif
00849   // prepare formal result
00850   bool res=ExistsEvent(rNewName);
00851   // insert new event
00852   Idx newidx=InsEvent(rNewName);
00853   // bail out if events are the same
00854   if(newidx==event) return true;
00855   // copy event attribute
00856   if(!res) EventAttribute(newidx,EventAttribute(event));
00857   // store new transitions (with their attributes)
00858   TransSet* newtrans= TransRel().New();
00859   // iterate over transitions
00860   TransSet::Iterator tit;
00861   for (tit = TransRelBegin(); tit != TransRelEnd(); ++tit) {
00862     if(tit->Ev!=event) continue;
00863     Transition trans= Transition(tit->X1, newidx, tit->X2);
00864     newtrans->Insert(trans);
00865     newtrans->Attribute(trans,TransAttribute(*tit));
00866     tit=ClrTransition(tit);
00867   }
00868   // merge transitions
00869   for(tit=newtrans->Begin(); tit!=newtrans->End(); tit++) {
00870     SetTransition(*tit);
00871     TransAttribute(*tit,newtrans->Attribute(*tit));
00872   }
00873   // free temp
00874   delete newtrans;
00875   // remore original event
00876   DelEvent(event);
00877   // done
00878   return res;
00879 }
00880 
00881 
00882 
00883 // NewEventSet()
00884 EventSet vGenerator::NewEventSet(void) const {
00885   EventSet res;
00886   res.SymbolTablep(mpEventSymbolTable);
00887   return res;
00888 }
00889 
00890 // NewEventSetp()
00891 EventSet* vGenerator::NewEventSetp(void) const {
00892   EventSet* res = new EventSet();
00893   res->SymbolTablep(mpEventSymbolTable);
00894   return res;
00895 }
00896 
00897 
00898 // StateSymbolTable() const
00899 const SymbolTable& vGenerator::StateSymbolTable(void) const {
00900   return mStateSymbolTable;
00901 }
00902 
00903 // StateSymbolTable(rSymTab) 
00904 void vGenerator::StateSymbolTable(const SymbolTable& rSymTab) {
00905   mStateSymbolTable=rSymTab;
00906   mpStateSymbolTable=&mStateSymbolTable;
00907 }
00908 
00909 // StateIndex(rName)
00910 Idx vGenerator::StateIndex(const std::string& rName) const {
00911    return mpStateSymbolTable->Index(rName);
00912 }
00913 
00914 // StateName(index)
00915 std::string vGenerator::StateName(Idx index) const {
00916   return mpStateSymbolTable->Symbol(index);
00917 }
00918 
00919 // StateName(index, name)
00920 void vGenerator::StateName(Idx index, const std::string& rName) {
00921   FD_DG("vGenerator(" << this << ")::StateName(" 
00922       << index << ",\"" << rName << "\")");
00923 #ifdef FAUDES_CHECKED
00924   if (! ExistsState(index)) {
00925     std::stringstream errstr;
00926     errstr << "state name \"" << rName << "\" not found in generator \""
00927      << Name() << "\"";
00928     throw Exception("vGenerator::StateName(name)", errstr.str(), 90);
00929   }
00930 #endif
00931   mpStateSymbolTable->SetEntry(index, rName);
00932 }
00933 
00934 
00935 // ClearStateNames()
00936 void vGenerator::ClearStateNames(void) {
00937   FD_DG("vGenerator(" << this << ")::ClearStateNames()");
00938   mpStateSymbolTable->Clear();
00939 }
00940 
00941 
00942 // ClrStateName(index)
00943 void vGenerator::ClrStateName(Idx index) {
00944   FD_DG("Generator(" << this << ")::ClrStateName(\"" << index << "\")");
00945 #ifdef FAUDES_CHECKED
00946   if (! ExistsState(index)) {
00947     std::stringstream errstr;
00948     errstr << "state \"" << index << "\" not found in generator \""
00949      << Name() << "\"";
00950     throw Exception("vGenerator::ClrStateName(name)", errstr.str(), 90);
00951   }
00952 #endif
00953   mpStateSymbolTable->ClrEntry(index);
00954 }
00955 
00956 // ClrStateName(rName)
00957 void vGenerator::ClrStateName(const std::string& rName) {
00958   FD_DG("vGenerator(" << this << ")::ClrStateName(\"" << rName << "\")");
00959   Idx index = StateIndex(rName);
00960   ClrStateName(index);
00961 }
00962 
00963 
00964 // StateNamesEnabled()
00965 bool vGenerator::StateNamesEnabled(void) const {
00966   return mStateNamesEnabled;
00967 }
00968 
00969 // StateNamesEnabled(flag)
00970 void vGenerator::StateNamesEnabled(bool flag) {
00971   mStateNamesEnabled = flag;
00972   if(!flag) ClearStateNames();
00973 }
00974 
00975 // StateNamesEnabled(flag)
00976 void vGenerator::StateNamesEnabledDefault(bool flag) {
00977   msStateNamesEnabledDefault = flag;
00978 }
00979 
00980 // SetDefaultStateNames()
00981 void vGenerator::SetDefaultStateNames(void) {
00982   FD_DG("vGenerator(" << this << ")::SetDefaultStateNames()");
00983   mpStateSymbolTable->Clear();
00984   StateSet::Iterator it;
00985   for (it = StatesBegin(); it != StatesEnd(); ++it) {
00986     std::string dname;
00987     dname = std::string("S")+ToStringInteger(*it);
00988     mpStateSymbolTable->SetEntry(*it,dname);
00989   }
00990 }
00991 
00992 // EnforceStateNames(rTemplate)
00993 void vGenerator::EnforceStateNames(const std::string& rTemplate) {
00994   FD_DG("vGenerator(" << this << ")::EnforceStateNames(temp)");
00995   StateSet::Iterator it;
00996   for (it = StatesBegin(); it != StatesEnd(); ++it) {
00997     if(StateName(*it)=="") {
00998       std::string name=UniqueStateName(rTemplate + "_1");
00999       StateName(*it,name);
01000     }
01001   }
01002 }
01003 
01004 // UniqueStateName(rName)
01005 std::string vGenerator::UniqueStateName(const std::string& rName) const {
01006   std::string name=rName;
01007   if(name=="") name="st";
01008   return mpStateSymbolTable->UniqueSymbol(name) ;
01009 }
01010 
01011 
01012 // iterator AlphabetBegin() const
01013 EventSet::Iterator vGenerator::AlphabetBegin(void) const {
01014   return mpAlphabet->Begin();
01015 }
01016 
01017 // iterator AlphabetEnd() const
01018 EventSet::Iterator vGenerator::AlphabetEnd(void) const {
01019   return mpAlphabet->End();
01020 }
01021 
01022 // iterator StatesBegin() const
01023 StateSet::Iterator vGenerator::StatesBegin(void) const {
01024   return mpStates->Begin();
01025 }
01026 
01027 // iterator StatesEnd() const
01028 StateSet::Iterator vGenerator::StatesEnd(void) const {
01029   return mpStates->End();
01030 }
01031 
01032 // iterator TransRelBegin() const
01033 TransSet::Iterator vGenerator::TransRelBegin(void) const {
01034   return mpTransRel->Begin();
01035 }
01036 
01037 // iterator TransRelEnd() const
01038 TransSet::Iterator vGenerator::TransRelEnd(void) const {
01039   return mpTransRel->End();
01040 }
01041 
01042 // iterator TransRelBegin(x1) const
01043 TransSet::Iterator vGenerator::TransRelBegin(Idx x1) const {
01044   return mpTransRel->Begin(x1);
01045 }
01046 
01047 // iterator TransRelEnd(x1) const
01048 TransSet::Iterator vGenerator::TransRelEnd(Idx x1) const {
01049   return mpTransRel->End(x1);
01050 }
01051 
01052 // iterator TransRelBegin(x1, ev) const
01053 TransSet::Iterator vGenerator::TransRelBegin(Idx x1, Idx ev) const {
01054   return mpTransRel->Begin(x1, ev);
01055 }
01056 
01057 // iterator TransRelEnd(x1, ev) const
01058 TransSet::Iterator vGenerator::TransRelEnd(Idx x1, Idx ev) const {
01059   return mpTransRel->End(x1, ev);
01060 }
01061 
01062 // iterator FindTransition(trans)
01063 TransSet::Iterator vGenerator::FindTransition(const Transition& rTrans) const {
01064   return mpTransRel->Find(rTrans);
01065 }
01066 
01067 // iterator FindTransition(x1, ex x2)
01068 TransSet::Iterator vGenerator::FindTransition(Idx x1, Idx ev, Idx x2) const {
01069   return mpTransRel->Find(Transition(x1, ev, x2));
01070 }
01071 
01072 // iterator FindTransition(x1, ev, x2) 
01073 TransSet::Iterator vGenerator::FindTransition(
01074    const std::string& rX1, const std::string& rEv, const std::string& rX2) const 
01075 {
01076   return mpTransRel->Find(StateIndex(rX1), EventIndex(rEv), StateIndex(rX2));
01077 }
01078 
01079 // iterator ExistsTransition(trans)
01080 bool vGenerator::ExistsTransition(const Transition& rTrans) const {
01081   return mpTransRel->Exists(rTrans);
01082 }
01083 
01084 // iterator ExistsTransition(x1, ex x2)
01085 bool vGenerator::ExistsTransition(Idx x1, Idx ev, Idx x2) const {
01086   return mpTransRel->Exists(Transition(x1, ev, x2));
01087 }
01088 
01089 // iterator ExistsTransition(x1, ev, x2)
01090 bool vGenerator::ExistsTransition(
01091   const std::string& rX1, const std::string& rEv, const std::string& rX2) const 
01092 {
01093   return mpTransRel->Exists(StateIndex(rX1), EventIndex(rEv), StateIndex(rX2));
01094 }
01095 
01096 
01097 // idx InitState() const
01098 Idx vGenerator::InitState(void) const {
01099   if(mInitStates.Size()!=1) return 0;
01100   return *mInitStates.Begin();
01101 }
01102 
01103 
01104 
01105 // iterator InitStatesBegin() const
01106 StateSet::Iterator vGenerator::InitStatesBegin(void) const {
01107   return mInitStates.Begin();
01108 }
01109 
01110 // iterator InitStatesEnd() const
01111 StateSet::Iterator vGenerator::InitStatesEnd(void) const {
01112   return mInitStates.End();
01113 }
01114 
01115 // iterator MarkedStatesBegin()
01116 StateSet::Iterator vGenerator::MarkedStatesBegin(void) const {
01117   return mMarkedStates.Begin();
01118 }
01119 
01120 // iterator MarkedStatesEnd() const
01121 StateSet::Iterator vGenerator::MarkedStatesEnd(void) const {
01122   return mMarkedStates.End(); 
01123 }
01124 
01125 // InjectAlphabet(newalphabet)
01126 void vGenerator::InjectAlphabet(const EventSet& rNewAlphabet) {
01127   FD_DG("vGenerator::InjectAlphabet()  " << rNewAlphabet.ToString());
01128 #ifdef FAUDES_CHECKED
01129   if(rNewAlphabet.SymbolTablep()!=mpEventSymbolTable) {
01130     std::stringstream errstr;
01131     errstr << "symboltable mismatch aka not implemented" << std::endl;
01132     throw Exception("vGenerator::InjectAlphabet", errstr.str(), 88);
01133   }
01134 #endif
01135   *mpAlphabet = rNewAlphabet;
01136   mpAlphabet->Name("Alphabet");
01137 }
01138 
01139 // RestrictAlphabet(newalphabet)
01140 void vGenerator::RestrictAlphabet(const EventSet& rNewAlphabet) {
01141   FD_DG("vGenerator::RestrictAlphabet()  " << rNewAlphabet.ToString());
01142 #ifdef FAUDES_CHECKED
01143   if(rNewAlphabet.SymbolTablep()!=mpEventSymbolTable) {
01144     std::stringstream errstr;
01145     errstr << "symboltable mismatch aka not implemented" << std::endl;
01146     throw Exception("vGenerator::RestrictAlphabet", errstr.str(), 88);
01147   }
01148 #endif
01149   mpAlphabet->RestrictSet(rNewAlphabet);
01150 }
01151 
01152 // InsEvent(index)
01153 bool vGenerator::InsEvent(Idx index) {
01154   FD_DG("vGenerator(" << this << ")::InsEvent(" << index << ")");
01155   return mpAlphabet->Insert(index);
01156 }
01157 
01158 // InsEvent(rName)
01159 Idx vGenerator::InsEvent(const std::string& rName) {
01160   FD_DG("vGenerator(" << this << ")::InsEvent(\"" << rName << "\")");
01161   return mpAlphabet->Insert(rName);
01162 }
01163 
01164 // InsEvents(events)
01165 void vGenerator::InsEvents(const EventSet& events) {
01166   mpAlphabet->InsertSet(events);
01167 }
01168 
01169 // DelEvent(index)
01170 bool vGenerator::DelEvent(Idx index) {
01171   FD_DG("vGenerator(" << this << ")::DelEvent(" << index << ")");
01172   mpTransRel->EraseByEv(index);
01173   return mpAlphabet->Erase(index);
01174 }
01175 
01176 // DelEvent(rName)
01177 bool vGenerator::DelEvent(const std::string& rName) {
01178   FD_DG("vGenerator(" << this << ")::DelEvent(\"" << rName << "\")");
01179   Idx index = mpAlphabet->Index(rName);
01180   mpTransRel->EraseByEv(index);
01181   return mpAlphabet->Erase(index);
01182 }
01183 
01184 // DelEvents(events)
01185 void vGenerator::DelEvents(const EventSet& rEvents) {
01186   FD_DG("vGenerator(" << this << ")::DelEvents(\"" 
01187   << rEvents.ToString() << "\")");
01188   EventSet::Iterator it;
01189   for (it = rEvents.Begin(); it != rEvents.End(); ++it) {
01190     DelEvent(*it);
01191   }
01192 }
01193 
01194 // DelEventFromAlphabet(index)
01195 bool vGenerator::DelEventFromAlphabet(Idx index) {
01196   FD_DG("vGenerator(" << this << ")::DelEventFromAlphabet(" 
01197   << index << ")");
01198   return mpAlphabet->Erase(index);
01199 }
01200 
01201 // InsState()
01202 Idx vGenerator::InsState(void) {
01203   FD_DG("vGenerator(" << this << ")::InsState()");
01204   return mpStates->Insert();
01205 }
01206 
01207 // InsState(index)
01208 bool vGenerator::InsState(Idx index) {
01209   FD_DG("vGenerator(" << this << ")::InsState(" << index << ")");
01210   return mpStates->Insert(index);
01211 }
01212 
01213 // InsState(rName)
01214 Idx vGenerator::InsState(const std::string& rName) {
01215   FD_DG("vGenerator(" << this << ")::InsState(\"" << rName << "\")");
01216   Idx index=mpStates->Insert();
01217   StateName(index,rName);
01218   return index;
01219 }
01220 
01221 // InjectState(index)
01222 void vGenerator::InjectState(Idx index) {
01223   FD_DG("vGenerator(" << this << ")::InjectState(\"" << SStr(index) << "\")");
01224   mpStates->Insert(index);
01225 }
01226 
01227 // InjectStates(rNewStates)
01228 void vGenerator::InjectStates(const StateSet& rNewStates) {
01229   FD_DG("vGenerator(" << this << ")::InjectStates(" << rNewStates.ToString() << ")");
01230   *mpStates=rNewStates;
01231   mpStates->Name("States");
01232   mpStateSymbolTable->RestrictDomain(*mpStates);
01233   FD_DG("vGenerator(" << this << ")::InjectStates(): report " << mpStates->ToString());
01234 }
01235 
01236 // InsInitState()
01237 Idx vGenerator::InsInitState(void) {
01238   FD_DG("vGenerator(" << this << ")::InsInitState()");
01239   Idx index;
01240   index = InsState();
01241   mInitStates.Insert(index);
01242   return index;
01243 }
01244 
01245 // InsInitState(name)
01246 Idx vGenerator::InsInitState(const std::string& rName) {
01247   FD_DG("vGenerator(" << this << ")::InsInitState(\"" << rName << "\")");
01248   Idx index;
01249   index = InsState(rName);
01250   mInitStates.Insert(index);
01251   return index;
01252 }
01253 
01254 // InsInitState(name)
01255 bool vGenerator::InsInitState(Idx index) {
01256   bool res=InsState(index);
01257   mInitStates.Insert(index);
01258   return res;
01259 }
01260 
01261 // InsMarkedState()
01262 Idx vGenerator::InsMarkedState(void) {
01263   FD_DG("vGenerator(" << this << ")::InsMarkedState()");
01264   Idx index;
01265   index = InsState();
01266   mMarkedStates.Insert(index);
01267   return index;
01268 }
01269 
01270 // InsInitState(name)
01271 bool vGenerator::InsMarkedState(Idx index) {
01272   bool res=InsState(index);
01273   mMarkedStates.Insert(index);
01274   return res;
01275 }
01276 
01277 // InsMarkedState(rName)
01278 Idx vGenerator::InsMarkedState(const std::string& rName) {
01279   FD_DG("vGenerator(" << this << ")::InsMarkedState(\"" << rName << "\")");
01280   Idx index;
01281   index = InsState(rName);
01282   mMarkedStates.Insert(index);
01283   return index;
01284 }
01285 
01286 // DelState(index)
01287 bool vGenerator::DelState(Idx index) {
01288   FD_DG("vGenerator(" << this << ")::DelState(" << index << ")");
01289   // mInitStates
01290   mInitStates.Erase(index);
01291   // mstates
01292   mMarkedStates.Erase(index);
01293   // transrel 
01294   mpTransRel->EraseByX1OrX2(index);
01295   // symbolic name
01296   mpStateSymbolTable->ClrEntry(index);
01297   // finally ... remove the state
01298   return mpStates->Erase(index);
01299 }
01300 
01301 // DelState(rName)
01302 bool vGenerator::DelState(const std::string& rName) {
01303   FD_DG("vGenerator(" << this << ")::DelState(\"" << rName << "\")");
01304   Idx index;
01305   index = StateIndex(rName);
01306 #ifdef FAUDES_CHECKED
01307   if (index == 0) {
01308     std::stringstream errstr;
01309     errstr << "state name \"" << rName << "\" not found in generator \""
01310      << Name() << "\"";
01311     throw Exception("vGenerator::DelState(name)", errstr.str(), 90);
01312   }
01313 #endif
01314   return DelState(index);
01315 }
01316 
01317 // DelStates(rDelStates)
01318 void vGenerator::DelStates(const StateSet& rDelStates) {
01319   FD_DG("vGenerator(" << this << ")::DelStates(" 
01320   << rDelStates.ToString() << ")");
01321   StateSet::Iterator cit;
01322   StateSet::Iterator cit_end;
01323   // symbolic state names
01324   for (cit = rDelStates.Begin(); cit != rDelStates.End(); ++cit) {
01325     mpStateSymbolTable->ClrEntry(*cit);
01326   }
01327   // statesets
01328   mpStates->EraseSet(rDelStates);
01329   mInitStates.EraseSet(rDelStates);
01330   mMarkedStates.EraseSet(rDelStates);
01331   // mpTransRel:
01332   mpTransRel->EraseByX1OrX2(rDelStates);
01333 }
01334 
01335 // DelStateFromStates(index)
01336 bool vGenerator::DelStateFromStates(Idx index) {
01337   FD_DG("vGenerator(" << this << ")::DelStateFromStates(" << index << ")");
01338   // mStates + global
01339   return mpStates->Erase(index);
01340 }
01341 
01342 // DelStateFromStates(pos)
01343 StateSet::Iterator vGenerator::DelStateFromStates(StateSet::Iterator pos) {
01344   FD_DG("vGenerator(" << this << ")::DelState(" << *pos << ")");
01345   return mpStates->Erase(pos);
01346 }
01347 
01348 // SetInitState(index)
01349 void vGenerator::SetInitState(Idx index) {
01350   FD_DG("vGenerator(" << this << ")::SetInitState(" << index << ")");
01351 #ifdef FAUDES_CHECKED
01352   if (! mpStates->Exists(index)) {
01353     std::stringstream errstr;
01354     errstr << "vGenerator::SetMarkedState: index " << index 
01355      << " not in stateset";
01356     throw Exception("vGenerator::SetInitState(..)", errstr.str(), 91);
01357   }
01358 #endif
01359   mInitStates.Insert(index);
01360 }
01361 
01362 // SetInitState(rName)
01363 void vGenerator::SetInitState(const std::string& rName) {
01364   FD_DG("vGenerator(" << this << ")::SetInitState(\"" << rName << "\")");
01365   Idx index = StateIndex(rName);
01366 #ifdef FAUDES_CHECKED
01367   if (index == 0) {
01368     std::stringstream errstr;
01369     errstr << "State name \"" << rName << "\" not known in Generator";
01370     throw Exception("vGenerator::SetInitState(..)", errstr.str(), 90);
01371   }
01372 #endif
01373   SetInitState(index);
01374 }
01375 
01376 // InjectInitStates(rNewInitStates)
01377 void vGenerator::InjectInitStates(const StateSet& rNewInitStates) {
01378   FD_DG("vGenerator(" << this << ")::InjectInitStates(" 
01379   << rNewInitStates.ToString() << ")");
01380   mInitStates = rNewInitStates;
01381   mInitStates.Name("InitStates");
01382 }
01383 
01384 // ClrInitState(index)
01385 void vGenerator::ClrInitState(Idx index) {
01386   FD_DG("vGenerator(" << this << ")::ClrInitState(" << index << ")");
01387 #ifdef FAUDES_CHECKED
01388   if (! mpStates->Exists(index)) {
01389     std::stringstream errstr;
01390     errstr << "vGenerator::SetMarkedState: index " << index 
01391      << " not in stateset";
01392     throw Exception("vGenerator::ClrInitState(..)", errstr.str(), 91);
01393   }
01394 #endif
01395   mInitStates.Erase(index);
01396 }
01397 
01398 // ClrInitState(rName)
01399 void vGenerator::ClrInitState(const std::string& rName) {
01400   FD_DG("vGenerator(" << this << ")::ClrInitState(\"" << rName << "\")");
01401   Idx index = StateIndex(rName);
01402 #ifdef FAUDES_CHECKED
01403   if (index == 0) {
01404     std::stringstream errstr;
01405     errstr << "State name \"" << rName << "\" not known in Generator";
01406     throw Exception("vGenerator::ClrInitState(..)", errstr.str(), 90);
01407   }
01408 #endif
01409   ClrInitState(index);
01410 }
01411 
01412 // ClrInitState(pos)
01413 StateSet::Iterator vGenerator::ClrInitState(StateSet::Iterator pos) {
01414   FD_DG("vGenerator(" << this << ")::ClrInitState(" << *pos << ")");
01415   return mInitStates.Erase(pos);
01416 }
01417 
01418 // ClearInitStates()
01419 void vGenerator::ClearInitStates(void) {
01420   mInitStates.Clear();
01421 }
01422 
01423 // SetMarkedState(index)
01424 void vGenerator::SetMarkedState(Idx index) {
01425   FD_DG("vGenerator(" << this << ")::SetMarkedState(" << index << ")");
01426 #ifdef FAUDES_CHECKED
01427   if (! mpStates->Exists(index)) {
01428     std::stringstream errstr;
01429     errstr << "vGenerator::SetMarkedState: index " << index 
01430      << " not in stateset";
01431     throw Exception("vGenerator::SetMarkedState(..)", errstr.str(), 91);
01432   }
01433 #endif
01434   mMarkedStates.Insert(index);
01435 }
01436 
01437 // SetMarkedState(rName)
01438 void vGenerator::SetMarkedState(const std::string& rName) {
01439   FD_DG("vGenerator(" << this << ")::SetMarkedState(\"" << rName << "\")");
01440   Idx index = StateIndex(rName);
01441 #ifdef FAUDES_CHECKED
01442   if (index == 0) {
01443     std::stringstream errstr;
01444     errstr << "State name \"" << rName << "\" not known in Generator";
01445     throw Exception("vGenerator::SetMarkedState(..)", errstr.str(), 90);
01446   }
01447 #endif
01448   SetMarkedState(index);
01449 }
01450 
01451 // InjectMarkedStates(rNewMarkedStates)
01452 void vGenerator::InjectMarkedStates(const StateSet& rNewMarkedStates) {
01453   FD_DG("vGenerator(" << this << ")::InjectMarkedStates(" 
01454   << rNewMarkedStates.ToString() << ")");
01455   mMarkedStates = rNewMarkedStates;
01456   mMarkedStates.Name("MarkedStates");
01457 }
01458 
01459 // ClrMarkedState(index)
01460 void vGenerator::ClrMarkedState(Idx index) {
01461   FD_DG("vGenerator(" << this << ")::ClrMarkedState(" << index << ")");
01462 #ifdef FAUDES_CHECKED
01463   if (! mpStates->Exists(index)) {
01464     std::stringstream errstr;
01465     errstr << "vGenerator::ClrMarkedState: index " << index 
01466      << " not in stateset";
01467     throw Exception("vGenerator::ClrMarkedState(..)", errstr.str(), 91);
01468   }
01469 #endif
01470   mMarkedStates.Erase(index);
01471 }
01472 
01473 // ClrMarkedState(rName)
01474 void vGenerator::ClrMarkedState(const std::string& rName) {
01475   FD_DG("vGenerator(" << this << ")::ClrMarkedState(\"" << rName << "\")");
01476   Idx index = StateIndex(rName);
01477 #ifdef FAUDES_CHECKED
01478   if (index == 0) {
01479     std::stringstream errstr;
01480     errstr << "State name \"" << rName << "\" not known in Generator";
01481     throw Exception("vGenerator::ClrMarkedState(..)", errstr.str(), 90);
01482   }
01483 #endif
01484   ClrMarkedState(index);
01485 }
01486 
01487 // ClrMarkedState(pos)
01488 StateSet::Iterator vGenerator::ClrMarkedState(StateSet::Iterator pos) {
01489   FD_DG("vGenerator(" << this << ")::ClrMarkedState(" << *pos << ")");
01490   return mMarkedStates.Erase(pos);
01491 }
01492 
01493 // ClearMarkedStates()
01494 void vGenerator::ClearMarkedStates(void) {
01495   mMarkedStates.Clear();
01496 }
01497 
01498 // InjectTransition(newtrans)
01499 void vGenerator::InjectTransition(const Transition& rTrans) {
01500   FD_DG("vGenerator::InjectTransition(" << TStr(rTrans) << ")");
01501   mpTransRel->Insert(rTrans);
01502 }
01503 
01504 // InjectTransRel(newtransrel)
01505 void vGenerator::InjectTransRel(const TransSet& rNewTransrel) {
01506   FD_DG("vGenerator::InjectTransRel(...)");
01507   *mpTransRel=rNewTransrel;
01508   mpTransRel->Name("TransRel");
01509 }
01510 
01511 // SetTransition(rX1, rEv, rX2)
01512 bool vGenerator::SetTransition(const std::string& rX1, const std::string& rEv, const std::string& rX2) {
01513   FD_DG("vGenerator(" << this << ")::SetTransition(\""
01514   << rX1 << "\", \"" << rEv << "\", \"" << rX2 << "\")");
01515   Idx x1 = StateIndex(rX1);
01516   Idx x2 = StateIndex(rX2);
01517 #ifdef FAUDES_CHECKED
01518   if (x1 == 0) {
01519     FD_ERR("vGenerator::SetTransition: state " << rX1 
01520      << " not in stateset");
01521     std::stringstream errstr;
01522     errstr << "State name " << rX1 << " not found in Generator";
01523     throw Exception("vGenerator::SetTransition(..)", errstr.str(), 90);
01524   }
01525   if (! mpAlphabet->Exists(rEv)) {
01526     FD_ERR("vGenerator::SetTransition: event " << rEv << " not in alphabet");
01527     std::stringstream errstr;
01528     errstr << "Event name " << rEv << " not found in event domain of Generator";
01529     throw Exception("vGenerator::SetTransition(..)", errstr.str(), 95);
01530   }
01531   if (x2 == 0) {
01532     FD_ERR("vGenerator::SetTransition: state " << rX2 << " not in stateset");
01533     std::stringstream errstr;
01534     errstr << "State name " << rX2 << " not found in Generator";
01535     throw Exception("vGenerator::SetTransition(..)", errstr.str(), 90);
01536   }
01537 #endif
01538   return SetTransition(Transition(x1, EventIndex(rEv), x2));
01539 }
01540 
01541 
01542 // SetTransition(x1, ev, x2)
01543 bool vGenerator::SetTransition(Idx x1, Idx ev, Idx x2) {
01544   return SetTransition(Transition(x1,ev,x2));
01545 }
01546 
01547 // SetTransition(rTransition)
01548 bool vGenerator::SetTransition(const Transition& rTransition) {
01549   FD_DG("vGenerator(" << this << ")::SetTransition(" << rTransition.X1 << "," 
01550   << rTransition.Ev << "," << rTransition.X2 << ")");
01551 #ifdef FAUDES_CHECKED
01552   if (! mpStates->Exists(rTransition.X1)) {
01553     std::stringstream errstr;
01554     errstr << "vGenerator::SetTransition: state " << SStr(rTransition.X1) 
01555      << " not in stateset";
01556     throw Exception("vGenerator::SetTransition(..)", errstr.str(), 95);
01557   }
01558   if (! mpAlphabet->Exists(rTransition.Ev)) {
01559     std::stringstream errstr;
01560     errstr << "vGenerator::SetTransition: event " << EStr(rTransition.Ev) 
01561      << " not in alphabet ";
01562     throw Exception("vGenerator::SetTransition(..)", errstr.str(), 95);
01563   }
01564   if (! mpStates->Exists(rTransition.X2)) {
01565     std::stringstream errstr;
01566     errstr << "vGenerator::SetTransition: state " << SStr(rTransition.X2) 
01567      << " not in stateset";
01568     throw Exception("vGenerator::SetTransition(..)", errstr.str(), 95);
01569   }
01570 #endif
01571   return mpTransRel->Insert(rTransition);
01572 }
01573 
01574 // ClrTransition.X1, ev, x2)
01575 void vGenerator::ClrTransition(Idx x1, Idx ev, Idx x2) {
01576   FD_DG("vGenerator(" << this << ")::ClrTransition(" 
01577   << x1 << "," << ev << "," << x2 << ")");
01578   mpTransRel->Erase(x1, ev, x2);
01579 }
01580 
01581 // ClrTransition(rTransition)
01582 void vGenerator::ClrTransition(const Transition& rTransition) {
01583   FD_DG("vGenerator(" << this << ")::ClrTransition(" << TStr(rTransition) << ")");
01584   mpTransRel->Erase(rTransition);
01585 }
01586 
01587 // ClrTransition(it)
01588 TransSet::Iterator vGenerator::ClrTransition(TransSet::Iterator it) {
01589   FD_DG("vGenerator(" << this << ")::ClrTransition(" << TStr(*it)<< ")" );
01590   return mpTransRel->Erase(it);
01591 }
01592 
01593 // TransAttribute(trans, attr)
01594 void vGenerator::TransAttribute(const Transition& rTrans, const Type& rAttr) {
01595   FD_DG("vGenerator(" << this << ")::TransAttribute(" 
01596   << TStr(rTrans) << ",\"" << rAttr.ToString() << "\")");
01597   mpTransRel->Attribute(rTrans, rAttr);
01598 }
01599 
01600 // TransAttributep(trans)
01601 AttributeVoid* vGenerator::TransAttributep(const Transition& rTrans)  {
01602   return mpTransRel->Attributep(rTrans);
01603 }
01604 
01605 
01606 // TransAttribute(trans)
01607 const AttributeVoid& vGenerator::TransAttribute(const Transition& rTrans) const {
01608   return mpTransRel->Attribute(rTrans);
01609 }
01610 
01611 // ClrTransAttribute(trans)
01612 void vGenerator::ClrTransAttribute(const Transition& rTrans)  {
01613   mpTransRel->ClrAttribute(rTrans);
01614 }
01615 
01616 
01617 // ClearTransRel()
01618 void vGenerator::ClearTransRel(void) {
01619   mpTransRel->Clear();
01620 }
01621 
01622 // EventAttribute(index, attr)
01623 void vGenerator::EventAttribute(Idx index, const Type& rAttr) {
01624   FD_DG("vGenerator(" << this << ")::EventAttribute(" 
01625   << EStr(index) << ",\"" << rAttr.ToString() << "\")");
01626   mpAlphabet->Attribute(index, rAttr);
01627 }
01628 
01629 
01630 // EventAttributes(set)
01631 void vGenerator::EventAttributes(const EventSet& rEventSet) {
01632   FD_DG("vGenerator(" << this << ")::EventAttributes(" 
01633   << rEventSet.ToString() << "\")");
01634   mpAlphabet->Attributes(rEventSet);
01635 }
01636 
01637 // ClrEventAttribute(index)
01638 void vGenerator::ClrEventAttribute(Idx index) {
01639   FD_DG("vGenerator(" << this << ")::ClrEventAttribute(\"" << EStr(index) << "\")");
01640   mpAlphabet->ClrAttribute(index);
01641 }
01642 
01643 // StateAttribute(index, attr)
01644 void vGenerator::StateAttribute(Idx index, const Type& rAttr) {
01645   FD_DG("vGenerator(" << this << ")::StateAttribute(" 
01646   << SStr(index) << ",\"" << rAttr.ToString() << "\")");
01647   mpStates->Attribute(index, rAttr);
01648 }
01649 
01650 // ClrStateAttribute(index)
01651 void vGenerator::ClrStateAttribute(Idx index) {
01652   FD_DG("vGenerator(" << this << ")::ClrStateAttribute(\"" << index << "\")");
01653   mpStates->ClrAttribute(index);
01654 }
01655 
01656 // ExistsEvent(index)
01657 bool vGenerator::ExistsEvent(Idx index) const {
01658   return mpAlphabet->Exists(index);
01659 }
01660 
01661 // ExistsEvent(rName)
01662 bool vGenerator::ExistsEvent(const std::string& rName) const {
01663   return mpAlphabet->Exists(rName);
01664 }
01665 
01666 // FindEvent(index) const
01667 EventSet::Iterator vGenerator::FindEvent(Idx index) const {
01668   return mpAlphabet->Find(index);
01669 }
01670 
01671 // FindEvent(rName)
01672 EventSet::Iterator vGenerator::FindEvent(const std::string& rName) const {
01673   return mpAlphabet->Find(rName);
01674 }
01675 
01676 // ExistsState(index)
01677 bool vGenerator::ExistsState(Idx index) const {
01678   return mpStates->Exists(index);
01679 }
01680 
01681 // ExistsName(name)
01682 bool vGenerator::ExistsState(const std::string& rName) const {
01683   return ExistsState(StateIndex(rName));
01684 }
01685 
01686 // FindState(rName) const
01687 StateSet::Iterator vGenerator::FindState(const std::string& rName) const {
01688   return mpStates->Find(mpStateSymbolTable->Index(rName));
01689 }
01690 
01691 // FindState(index) const
01692 StateSet::Iterator vGenerator::FindState(Idx index) const {
01693   return mpStates->Find(index);
01694 }
01695 
01696 // ExistsInitState(index)
01697 bool vGenerator::ExistsInitState(Idx index) const {
01698   return mInitStates.Exists(index);
01699 }
01700 
01701 // FindInitState(index)
01702 StateSet::Iterator vGenerator::FindInitState(Idx index) const {
01703   return mInitStates.Find(index);
01704 }
01705 
01706 // ExistsMarkedState(index)
01707 bool vGenerator::ExistsMarkedState(Idx index) const {
01708   return mMarkedStates.Exists(index);
01709 }
01710 
01711 // FindMarkedState(index)
01712 StateSet::Iterator vGenerator::FindMarkedState(Idx index) const {
01713   return mMarkedStates.Find(index);
01714 }
01715 
01716 // EventAttribute(index)
01717 const AttributeVoid&  vGenerator::EventAttribute(Idx index) const {
01718   return mpAlphabet->Attribute(index);
01719 }
01720 
01721 // EventAttributep(index)
01722 AttributeVoid* vGenerator::EventAttributep(Idx index) {
01723   return mpAlphabet->Attributep(index);
01724 }
01725 
01726 // EventAttribute(rName)
01727 const AttributeVoid&  vGenerator::EventAttribute(const std::string& rName) const {
01728   return EventAttribute(EventIndex(rName));
01729 }
01730 
01731 // EventAttributep(rName)
01732 AttributeVoid* vGenerator::EventAttributep(const std::string& rName) {
01733   return EventAttributep(EventIndex(rName));
01734 }
01735 
01736 // StateAttribute(index)
01737 const AttributeVoid&  vGenerator::StateAttribute(Idx index) const {
01738   return mpStates->Attribute(index);
01739 }
01740 
01741 // StateAttributep(index)
01742 AttributeVoid*  vGenerator::StateAttributep(Idx index) {
01743   return mpStates->Attributep(index);
01744 }
01745 
01746 // GlobalAttribute(attr)
01747 void vGenerator::GlobalAttribute(const Type& rAttr) {
01748   FD_DG("vGenerator(" << this << ")::GlobalAttribute(" 
01749   << rAttr.ToString() << "\")");
01750   // set to void is ok for silient ignore
01751   if(typeid(rAttr)==typeid(AttributeVoid)) return;
01752   // error:
01753   std::stringstream errstr;
01754   errstr << "cannot cast global attribute " << rAttr.ToString() << " for generator " << Name();
01755   throw Exception("vGenerator::GlobalAttribute", errstr.str(), 63);
01756 }
01757 
01758 // GlobalAttributeTry(attr)
01759 void vGenerator::GlobalAttributeTry(const Type& rAttr) {
01760   FD_DG("vGenerator(" << this << ")::GlobalAttributeTry(" 
01761   << rAttr.ToString() << "\")");
01762   // ignore
01763 }
01764 
01765 // GlobalAttribute()
01766 const AttributeVoid& vGenerator::GlobalAttribute(void) const {
01767   FD_DG("vGenerator(" << this << ")::GlobalAttribute()");
01768   return *mpGlobalAttribute;
01769 }
01770 
01771 // GlobalAttributep()
01772 AttributeVoid* vGenerator::GlobalAttributep(void) {
01773   FD_DG("vGenerator(" << this << ")::GlobalAttributep()");
01774   return mpGlobalAttribute;
01775 }
01776 
01777 
01778 // Alphabet()
01779 const EventSet& vGenerator::Alphabet(void) const {
01780   return *mpAlphabet;
01781 }
01782 
01783 // States()
01784 const StateSet& vGenerator::States(void) const {
01785   return *mpStates;
01786 }
01787 
01788 // TransRel()
01789 const TransSet& vGenerator::TransRel(void) const {
01790   return *mpTransRel;
01791 }
01792 
01793 
01794 // TransRel(res)
01795 void vGenerator::TransRel(TransSetX1EvX2& res) const { mpTransRel->ReSort(res); }
01796 void vGenerator::TransRel(TransSetEvX1X2& res) const { mpTransRel->ReSort(res); }
01797 void vGenerator::TransRel(TransSetEvX2X1& res) const { mpTransRel->ReSort(res); }
01798 void vGenerator::TransRel(TransSetX2EvX1& res) const { mpTransRel->ReSort(res); }
01799 void vGenerator::TransRel(TransSetX2X1Ev& res) const { mpTransRel->ReSort(res); }
01800 void vGenerator::TransRel(TransSetX1X2Ev& res) const { mpTransRel->ReSort(res); }
01801 
01802 
01803 Transition vGenerator::TransitionByNames(
01804     const std::string& rX1, const std::string& rEv, const std::string& rX2) const {
01805   return Transition(StateIndex(rX1),EventIndex(rEv),StateIndex(rX2));
01806 }
01807 
01808 // InitStates()
01809 const StateSet& vGenerator::InitStates(void) const {
01810   return mInitStates;
01811 }
01812 
01813 // MarkedStates()
01814 const StateSet& vGenerator::MarkedStates(void) const {
01815   return mMarkedStates;
01816 }
01817 
01818 // MinimizeAlphabet()
01819 void vGenerator::MinimizeAlphabet(void) {
01820   mpAlphabet->NameSet::EraseSet(UnusedEvents());
01821 }
01822 
01823 // UsedEvents()
01824 EventSet vGenerator::UsedEvents(void) const {
01825   EventSet resultset = NewEventSet();
01826   TransSet::Iterator it;
01827   for (it = mpTransRel->Begin(); it != mpTransRel->End(); ++it) {
01828     resultset.Insert(it->Ev);
01829   }
01830   return resultset;
01831 }
01832 
01833 // UnusedEvents()
01834 EventSet vGenerator::UnusedEvents(void) const {
01835   return *mpAlphabet - UsedEvents();
01836 }
01837 
01838 // ActiveEventSet(x1)
01839 EventSet vGenerator::ActiveEventSet(Idx x1) const {
01840   EventSet result = NewEventSet();
01841   TransSet::Iterator it;
01842   for (it = TransRelBegin(x1); it != TransRelEnd(x1); ++it) {
01843     result.Insert(it->Ev);
01844   }
01845   return result;
01846 }
01847 
01848 // ActiveTransSet(x1)
01849 TransSet vGenerator::ActiveTransSet(Idx x1) const {
01850   TransSet result;
01851   TransSet::Iterator it;
01852   for (it = TransRelBegin(x1); it != TransRelEnd(x1); ++it) {
01853     result.Insert(*it);
01854   }
01855   return result;
01856 }
01857 
01858 // TransRelStateSpace()
01859 StateSet vGenerator::TransRelStateSpace(void) const {
01860   StateSet states;
01861   TransSet::Iterator it;
01862   for (it=mpTransRel->Begin(); it != mpTransRel->End(); ++it) {
01863     states.Insert(it->X1);
01864     states.Insert(it->X2);
01865   }
01866   return states;
01867 }
01868 
01869 // TransRelStateSpace(x1)
01870 StateSet vGenerator::TransRelStateSpace(Idx x1) const {
01871   StateSet states;
01872   TransSet::Iterator it = mpTransRel->Begin(x1);
01873   TransSet::Iterator it_end = mpTransRel->End(x1);
01874   for (; it != it_end; ++it) {
01875     states.Insert(it->X2);
01876   }
01877   return states;
01878 }
01879 
01880 // TransRelStateSpace(x1,ev)
01881 StateSet vGenerator::TransRelStateSpace(Idx x1, Idx ev) const {
01882   StateSet states;
01883   TransSet::Iterator it = mpTransRel->Begin(x1,ev);
01884   TransSet::Iterator it_end = mpTransRel->End(x1,ev);
01885   for (; it != it_end; ++it) {
01886     states.Insert(it->X2);
01887   }
01888   return states;
01889 }
01890 
01891 
01892 // idx SuccessorState() const
01893 Idx vGenerator::SuccessorState(Idx x1, Idx ev) const {
01894   TransSet::Iterator it = mpTransRel->Begin(x1,ev);
01895   TransSet::Iterator it_end = mpTransRel->End(x1,ev);
01896   if(it==it_end) return 0;
01897   Idx res=(*it).X2;
01898 #ifdef FAUDES_CHECKED
01899   it++;
01900   if(it!=it_end) {
01901     std::stringstream errstr;
01902     errstr << "successor state does not exist uniquely" << std::endl;
01903     throw Exception("vGenerator::SuccessorState", errstr.str(), 92);
01904   }
01905 #endif
01906   return res;
01907 }
01908 
01909 
01910 // AccessibleSet()
01911 StateSet vGenerator::AccessibleSet(void) const {
01912   // initialize todo stack
01913   std::stack<Idx> todo;
01914   StateSet::Iterator sit;
01915   for(sit = InitStatesBegin(); sit != InitStatesEnd(); ++sit) 
01916     todo.push(*sit);
01917   // loop variables
01918   StateSet accessibleset;
01919   TransSet::Iterator tit;
01920   TransSet::Iterator tit_end;
01921   // loop
01922   while(!todo.empty()) {
01923     // pop
01924     Idx x1=todo.top();
01925     todo.pop();
01926     // sense known
01927     if(accessibleset.Exists(x1)) continue; 
01928     // record
01929     accessibleset.Insert(x1);
01930     // iterate/push
01931     tit=TransRelBegin(x1);
01932     tit_end=TransRelEnd(x1);
01933     for(; tit != tit_end; ++tit) 
01934       if(tit->X2 != x1) 
01935         todo.push(tit->X2);
01936   }
01937   // done
01938   accessibleset.Name("AccessibleSet");
01939   return accessibleset;
01940 }
01941 
01942 // Accessible()
01943 bool vGenerator::Accessible(void) {
01944   StateSet accessibleset = AccessibleSet();
01945   StateSet not_accessible = *mpStates - accessibleset;
01946   DelStates(not_accessible);
01947   // return true if there is an initial state
01948   if (!mInitStates.Empty()) {
01949     FD_DF("vGenerator::accessible: generator is accessible");
01950     return true;
01951   }
01952   FD_DF("vGenerator::accessible: generator is accessible but empty");
01953   return false;
01954 }
01955 
01956 // IsAccessible()
01957 bool vGenerator::IsAccessible(void) const {
01958   if(AccessibleSet() == *mpStates) {
01959     FD_DF("vGenerator::accessible: generator is accessible");
01960     return true;
01961   }
01962   FD_DF("vGenerator::accessible: generator is not accessible");
01963   return false;
01964 }
01965 
01966 // CoaccessibleSet()
01967 StateSet vGenerator::CoaccessibleSet(void) const {
01968   // build reverse transition relation
01969   TransSetX2EvX1 rtrel;
01970   TransRel(rtrel);
01971   // initialize todo stack
01972   StateSet::Iterator sit;
01973   std::stack<Idx> todo;
01974   for(sit = MarkedStatesBegin(); sit != MarkedStatesEnd(); ++sit) 
01975     todo.push(*sit);
01976   // loop variables
01977   StateSet coaccessibleset;
01978   TransSetX2EvX1::Iterator tit;
01979   TransSetX2EvX1::Iterator tit_end;
01980   // loop
01981   while(!todo.empty()) {
01982     // pop
01983     Idx x2=todo.top();
01984     todo.pop();
01985     // sense known
01986     if(coaccessibleset.Exists(x2)) continue; 
01987     // record
01988     coaccessibleset.Insert(x2);
01989     // iterate/push
01990     tit=rtrel.BeginByX2(x2);
01991     tit_end=rtrel.EndByX2(x2);
01992     for(; tit != tit_end; ++tit) 
01993       if(tit->X1 != x2) 
01994         todo.push(tit->X1);
01995   }
01996   // done
01997   coaccessibleset.Name("CoaccessibleSet");
01998   return coaccessibleset;
01999 }
02000 
02001 // Coaccessible()
02002 bool vGenerator::Coaccessible(void) {
02003   StateSet coaccessibleset = CoaccessibleSet();
02004   StateSet not_coaccessible = *mpStates - coaccessibleset;
02005   DelStates(not_coaccessible);
02006   // return true if there is a marked state
02007   if (! mMarkedStates.Empty()) {
02008     FD_DF("vGenerator::coaccessible: generator is coaccessible");
02009     return true;
02010   }
02011   FD_DF("vGenerator::coaccessible: generator is not coaccessible");
02012   return false;
02013 }
02014 
02015 // IsCoaccessible()
02016 bool vGenerator::IsCoaccessible(void) const {
02017   if (CoaccessibleSet() == *mpStates) {
02018     FD_DF("vGenerator::coaccessible: generator is coaccessible");
02019     return true;
02020   }
02021   FD_DF("vGenerator::coaccessible: generator is not coaccessible");
02022   return false;
02023 }
02024 
02025 // TrimSet()
02026 StateSet vGenerator::TrimSet(void) const {
02027   FD_DF("vGenerator::trimset: trim states: " 
02028   << StateSet(AccessibleSet() * CoaccessibleSet()).ToString());
02029   StateSet res=AccessibleSet() * CoaccessibleSet();
02030   res.Name("TrimSet");
02031   return res;
02032 }
02033 
02034 // Trim()
02035 bool vGenerator::Trim(void) {
02036   FD_DF("vGenerator::trim: generator states: " << mpStates->ToString());
02037   // better: compute sets and do one state delete
02038   bool accessiblebool = Accessible();
02039   bool coaccessiblebool = Coaccessible();
02040   FD_DF("vGenerator::trim: trim states: " << mpStates->ToString());
02041   if(accessiblebool && coaccessiblebool) {
02042     FD_DF("vGenerator::Trim(): generator is nontrivial");
02043     return true;
02044   }
02045   FD_DF("vGenerator::Trim(): generator is trivial");
02046   return false;
02047 }
02048 
02049 
02050 // IsTrim()
02051 bool vGenerator::IsTrim(void) const {
02052   bool res=true;
02053   if(!IsAccessible()) res=false;
02054   else if(!IsCoaccessible()) res=false;
02055   FD_DF("vGenerator::IsTrim(): result " << res);
02056   return res;
02057 }
02058 
02059 
02060 // BlockingStates()
02061 StateSet vGenerator::BlockingStates(void) const {
02062   FD_DF("vGenerator::BlockingSet: blocking states: " 
02063   << StateSet(AccessibleSet() - CoaccessibleSet()).ToString());
02064   return AccessibleSet() - CoaccessibleSet();
02065 }
02066 
02067 
02068 
02069 // IsComplete
02070 bool vGenerator::IsComplete(const StateSet& rStates) const {
02071   FD_DG("IsComplete(" << Name() << ")");
02072   
02073   // loop over provided states
02074   StateSet::Iterator sit=rStates.Begin();
02075   StateSet::Iterator sit_end=rStates.End();
02076   for(;sit!=sit_end;sit++){
02077     TransSet::Iterator tit=TransRelBegin(*sit);
02078     TransSet::Iterator tit_end=TransRelEnd(*sit);
02079     if(tit==tit_end) break;
02080   }
02081   // return true if no terminal state has been found
02082   return sit==sit_end;
02083 }
02084 
02085 // IsComplete
02086 bool vGenerator::IsComplete(void) const {
02087   return IsComplete(States());
02088 }
02089 
02090 // Complete
02091 bool vGenerator::Complete(void) {
02092   // states to remove
02093   StateSet termset = TerminalStates();
02094   // iterative search ...
02095   bool done;
02096   do {
02097     // ... over all states
02098     StateSet::Iterator sit = States().Begin();
02099     StateSet::Iterator sit_end = States().End();
02100     done=true;
02101     for(; sit!=sit_end; ++sit) {
02102       if(termset.Exists(*sit)) continue;
02103       TransSet::Iterator tit = TransRelBegin(*sit);
02104       TransSet::Iterator tit_end = TransRelEnd(*sit);
02105       for (; tit != tit_end; ++tit) {
02106         if(!termset.Exists(tit->X2)) break;
02107       }
02108       if(tit==tit_end) {
02109         termset.Insert(*sit);
02110   done=false;
02111       }
02112     }
02113   } while(!done);
02114   // remove those states
02115   DelStates(termset);
02116   // done
02117   return !InitStates().Empty();
02118 }
02119 
02120 
02121 // TerminalStates()
02122 StateSet vGenerator::TerminalStates(const StateSet& rStates) const {
02123   FD_DG("Generator::TerminalStates(" << Name() << ")");
02124 
02125   // prepare result
02126   StateSet res;
02127   
02128   // loop states
02129   StateSet::Iterator sit=rStates.Begin();
02130   StateSet::Iterator sit_end=rStates.End();
02131   for(;sit!=sit_end;sit++){
02132     TransSet::Iterator tit=TransRelBegin(*sit);
02133     TransSet::Iterator tit_end=TransRelEnd(*sit);
02134     if(tit==tit_end) res.Insert(*sit);
02135   }
02136   // return terminal states
02137   res.Name("TerminalStates");
02138   return res;
02139 }
02140 
02141 // TerminalStates()
02142 StateSet vGenerator::TerminalStates(void) const {
02143   return TerminalStates(States());
02144 }
02145 
02146 
02147 // OmegaTrim
02148 bool vGenerator::OmegaTrim(void) {
02149 
02150   // note: this really is inefficient; at least we should
02151   // record the inverse transition relation for the coaccessile
02152   // iteration
02153 
02154   // first we make the generator accessible
02155   Accessible();
02156   // iterate coaccessible and complete until convergence in oserved
02157   while(1) {
02158     Idx osize=States().Size();
02159     Coaccessible();
02160     Complete();
02161     if(States().Size()==osize) break;
02162   }    
02163   // done
02164   return !InitStates().Empty() && !MarkedStates().Empty();
02165 }
02166 
02167 
02168 // IsOmegaTrim()
02169 bool vGenerator::IsOmegaTrim(void) const {
02170   bool res=true;
02171   if(!IsAccessible()) res=false;
02172   else if(!IsCoaccessible()) res=false;
02173   else if(!IsComplete()) res=false;
02174   FD_DF("vGenerator::IsOmegaTrim(): result " << res);
02175   return res;
02176 }
02177 
02178 
02179 
02180 // IsDeterministic()
02181 bool vGenerator::IsDeterministic(void) const {
02182   // if there is more than one initial state ... nondet
02183   if (InitStatesSize() > 1) {
02184     FD_DG("vGenerator::IsDeterministic: more than one initial state");
02185     return false;
02186   }
02187   // if there is a state/event pair with non-unique successor ... nondet
02188   if (TransRelSize() < 2) return true;
02189   TransSet::Iterator it1;
02190   TransSet::Iterator it2;
02191   for (it1 = TransRelBegin(), it2 = it1++; it1 != TransRelEnd(); it2 = it1++) {
02192     if ((it1->X1 == it2->X1) && (it1->Ev == it2->Ev)) {
02193       FD_DG("IsDeterministic(): at least one state "
02194       << "contains more than on transition with same event: " 
02195       << TStr(*it1));
02196      return false;
02197     }
02198   }
02199   // in all other cases generator is deterministic
02200   return true;
02201 }
02202 
02203 
02204 // ReindexOnWrite()
02205 bool vGenerator::ReindexOnWrite(void) const {
02206   return mReindexOnWrite;
02207 }
02208 
02209 // ReindexOnWrite(flag)
02210 void vGenerator::ReindexOnWrite(bool flag) {
02211   mReindexOnWrite = flag;
02212 }
02213 
02214 // ReindexOnWrite(flag)
02215 void vGenerator::ReindexOnWriteDefault(bool flag) {
02216   msReindexOnWriteDefault = flag;
02217 }
02218 
02219 // ReindexOnWrite(flag)
02220 bool vGenerator::ReindexOnWriteDefault(void) {
02221   return msReindexOnWriteDefault;
02222 }
02223 
02224 
02225 
02226 // DoWrite()
02227 void vGenerator::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
02228   (void) pContext;
02229   // pre 2.20 behaviour: re-index on file output
02230   /*
02231   if(rTw.FileMode()) 
02232     SetMinStateIndexMap();
02233   */
02234   // post 2.20 beaviour: re-index by configuration
02235   if(ReindexOnWrite())
02236     SetMinStateIndexMap();
02237   // figure section
02238   std::string label=rLabel;
02239   if(label=="") label="Generator"; 
02240   FD_DG("vGenerator(" << this << ")::DoWrite(): section " << label);
02241   // write generator
02242   rTw.WriteBegin(label);
02243   rTw << mMyName;
02244   rTw << "\n";
02245   rTw << "\n";
02246   SWrite(rTw);
02247   rTw << "\n";
02248   mpAlphabet->Write(rTw);
02249   rTw << "\n";
02250   WriteStates(rTw);
02251   rTw << "\n";
02252   WriteTransRel(rTw);
02253   rTw << "\n";
02254   WriteStateSet(rTw, mInitStates);
02255   rTw << "\n";
02256   WriteStateSet(rTw, mMarkedStates);
02257   rTw << "\n";
02258   mpGlobalAttribute->Write(rTw);
02259   rTw << "\n";
02260   rTw.WriteEnd(label);
02261   // end of reindex
02262   ClearMinStateIndexMap();
02263 }
02264 
02265 // DoDWrite()
02266 void vGenerator::DoDWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
02267   (void) pContext;
02268   // figure section
02269   std::string label=rLabel;
02270   if(label=="") label="Generator"; 
02271   FD_DG("vGenerator(" << this << ")::DoDWrite(): section " << label);
02272   // write generator
02273   rTw.WriteBegin(label);
02274   rTw << mMyName;
02275   rTw << "\n";
02276   rTw << "\n";
02277   SWrite(rTw);
02278   rTw << "\n";
02279   mpAlphabet->DWrite(rTw);
02280   rTw << "\n";
02281   DWriteStateSet(rTw, *mpStates);
02282   rTw << "\n";
02283   DWriteTransRel(rTw);
02284   rTw << "\n";
02285   DWriteStateSet(rTw, mInitStates);
02286   rTw << "\n";
02287   DWriteStateSet(rTw, mMarkedStates);
02288   rTw << "\n";
02289   mpGlobalAttribute->Write(rTw);
02290   rTw << "\n";
02291   rTw.WriteEnd(label);
02292   rTw << "\n";
02293 }
02294 
02295 // DoXWrite()
02296 void vGenerator::DoXWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
02297   (void) pContext;
02298   // Set up outer tag
02299   std::string label=rLabel;
02300   std::string ftype=TypeName();
02301   if(label=="") label="Generator";
02302   Token btag;
02303   btag.SetBegin(label);
02304   if(Name()!=label && Name()!="") btag.InsAttributeString("name",Name());
02305   if(ftype!=label && ftype!="") btag.InsAttributeString("ftype",ftype);
02306   FD_DG("vGenerator(" << this << ")::DoXWrite(..): section " << btag.StringValue() << " #" << Size());
02307   rTw.Write(btag);
02308   // Optional re-indexing
02309   if(mReindexOnWrite) SetMinStateIndexMap();
02310   // Write comcponents
02311   rTw << "\n";
02312   mpAlphabet->XWrite(rTw,"Alphabet");
02313   rTw << "\n";
02314   XWriteStateSet(rTw, *mpStates,"StateSet");
02315   rTw << "\n";
02316   XWriteTransRel(rTw);
02317   rTw << "\n";
02318   mpGlobalAttribute->XWrite(rTw);
02319   if(!mpGlobalAttribute->IsDefault())
02320     rTw << "\n";
02321   // Write end
02322   rTw.WriteEnd(btag.StringValue());
02323   // End of re-index
02324   ClearMinStateIndexMap();
02325 }
02326 
02327 // WriteAlphabet() 
02328 void vGenerator::WriteAlphabet(void) const {
02329   TokenWriter tw(TokenWriter::Stdout);
02330   WriteAlphabet(tw);
02331 }
02332 
02333 // AlphabetToString()
02334 std::string vGenerator::AlphabetToString(void) const {
02335   TokenWriter tw(TokenWriter::String);
02336   WriteAlphabet(tw);
02337   return tw.Str();
02338 }
02339 
02340 // WriteAlphabet(rTw&) 
02341 void vGenerator::WriteAlphabet(TokenWriter& rTw) const { 
02342   mpAlphabet->Write(rTw);
02343 }
02344 
02345 // WriteStateSet(rStateSet&) 
02346 void vGenerator::WriteStateSet(const StateSet&  rStateSet) const {
02347   TokenWriter tw(TokenWriter::Stdout);
02348   WriteStateSet(tw,rStateSet);
02349 }
02350 
02351 // StateSetToString()
02352 std::string vGenerator::StateSetToString(const StateSet&  rStateSet) const {
02353   TokenWriter tw(TokenWriter::String);
02354   WriteStateSet(tw,rStateSet);
02355   return tw.Str();
02356 }
02357 
02358 // StateSetToText()
02359 std::string vGenerator::StateSetToText(const StateSet&  rStateSet) const {
02360   TokenWriter tw(TokenWriter::String);
02361   tw.Endl(true);
02362   WriteStateSet(tw,rStateSet);
02363   return tw.Str();
02364 }
02365 
02366 
02367 // WriteStateSet(rTw&, rStateSet&) 
02368 void vGenerator::WriteStates(TokenWriter& rTw) const {
02369   // have my section
02370   rTw.WriteBegin("States");
02371   // test whether we reindex
02372   bool reindex=mMinStateIndexMap.size()>0;
02373   // if we reindex, setup reverse map to write in strategic order
02374   // to allow for consisten read (i.e. states with symbolic name first, starting
02375   // with index 1); this is the plain faudes file format from 2005
02376   if(reindex) {
02377     // reverse map
02378     std::map<Idx,Idx> reversemap;
02379     std::map<Idx,Idx>::const_iterator minit;
02380     StateSet::Iterator sit;
02381     for (sit = StatesBegin(); sit != StatesEnd(); ++sit) 
02382       reversemap[MinStateIndex(*sit)] = *sit;
02383     // iterate states to write 
02384     for(minit = reversemap.begin(); minit != reversemap.end(); ++minit) {
02385       // identify anonymous block (consecutive state indices)
02386       std::map<Idx,Idx>::const_iterator conit=minit;
02387       Idx start = conit->first;
02388       Idx anoncount = 0;
02389       for(; conit != reversemap.end(); ++conit) {
02390         if(StateName(conit->second) != "") break;
02391         if(!StateAttribute(conit->second).IsDefault()) break;
02392         if(conit->first != start+anoncount) break;
02393         ++anoncount;
02394       }
02395       // write anonymous block
02396       if(anoncount > FD_CONSECUTIVE) {
02397         rTw.WriteBegin("Consecutive");
02398         rTw << start;
02399         rTw << start+anoncount-1;
02400         rTw.WriteEnd("Consecutive");
02401         minit=conit;
02402       } 
02403       // break loop
02404       if(minit == reversemap.end()) break;
02405       // write non anonymous state name/idx
02406       std::string statename = StateName(minit->second);
02407       if (statename != "") rTw << statename;
02408       else rTw << minit->first;
02409       // write state attribute
02410       const AttributeVoid& attr=StateAttribute(minit->second);
02411       attr.Write(rTw);
02412     }
02413   }
02414   // if we dont reindex, write symbolic names with index suffix to
02415   // enable a consistent read; this was introduced with libfaudes 2.20j
02416   if(!reindex) {
02417     // iterate states to write 
02418     bool symexpl = (States().MaxIndex() != States().Size());
02419     StateSet::Iterator sit;
02420     for(sit = StatesBegin(); sit != StatesEnd(); ++sit) {
02421       // identify anonymous block (consecutive state indices)
02422       StateSet::Iterator conit=sit;
02423       Idx start = *conit;
02424       Idx anoncount = 0;
02425       for(; conit != StatesEnd(); ++conit) {
02426         if(StateName(*conit) != "") break;
02427         if(!StateAttribute(*conit).IsDefault()) break;
02428         if(*conit != start+anoncount) break;
02429         ++anoncount;
02430       }
02431       // write anonymous block
02432       if(anoncount > FD_CONSECUTIVE) {
02433         rTw.WriteBegin("Consecutive");
02434         rTw << start;
02435         rTw << start+anoncount-1;
02436         rTw.WriteEnd("Consecutive");
02437         sit=conit;
02438       } 
02439       // break loop
02440       if(sit == StatesEnd()) break;
02441       // write index or name with index suffix
02442       std::string statename = StateName(*sit);
02443       if((statename != "") && symexpl) {
02444         rTw << (statename + "#"+ToStringInteger(*sit)) ;
02445       } else if(statename != "") {
02446         rTw << statename;
02447       } else {
02448         rTw << *sit;
02449       }
02450       // write attribute
02451       const AttributeVoid& attr=StateAttribute(*sit);
02452       attr.Write(rTw);
02453     }
02454   }
02455   // write end tag
02456   rTw.WriteEnd("States");
02457 }
02458 
02459 
02460 // WriteStateSet(rTw&, rStateSet&) 
02461 void vGenerator::WriteStateSet(TokenWriter& rTw, const StateSet&  rStateSet) const {
02462   rTw.WriteBegin(rStateSet.Name());
02463   // test whether we reindex
02464   bool reindex=mMinStateIndexMap.size()>0;
02465   // if we reindex, setup reverse map to write in strategic order;
02466   // reading back is no issue for external states, however, we would like
02467   // to provoke large consecutive blocks as a benefit from re-indexing
02468   if(reindex) {
02469     // reverse map
02470     std::map<Idx,Idx> reversemap;
02471     std::map<Idx,Idx>::const_iterator minit;
02472     StateSet::Iterator sit;
02473     for (sit = rStateSet.Begin(); sit != rStateSet.End(); ++sit) 
02474       reversemap[MinStateIndex(*sit)] = *sit;
02475     // iterate states to write 
02476     for(minit = reversemap.begin(); minit != reversemap.end(); ++minit) {
02477       // identify anonymous block (consecutive state indices)
02478       std::map<Idx,Idx>::const_iterator conit=minit;
02479       Idx start = conit->first;
02480       Idx anoncount = 0;
02481       for(; conit != reversemap.end(); ++conit) {
02482         if(StateName(conit->second) != "") break;
02483         if(!StateAttribute(conit->second).IsDefault()) break;
02484         if(conit->first != start+anoncount) break;
02485         ++anoncount;
02486       }
02487       // write anonymous block
02488       if(anoncount > FD_CONSECUTIVE) {
02489         rTw.WriteBegin("Consecutive");
02490         rTw << start;
02491         rTw << start+anoncount-1;
02492         rTw.WriteEnd("Consecutive");
02493         minit=conit;
02494       } 
02495       // break loop
02496       if(minit == reversemap.end()) break;
02497       // write non anonymous state name/idx
02498       std::string statename = StateName(minit->second);
02499       if (statename != "") rTw << statename;
02500       else rTw << minit->first;
02501       // write state attribute
02502       const AttributeVoid& attr=rStateSet.Attribute(minit->second);
02503       attr.Write(rTw);
02504     }
02505   }
02506   // if we dont reindex, we dont need the reverse map; note that
02507   // external stateset will never have an explicit symbol table
02508   if(!reindex) {
02509     // iterate states to write 
02510     StateSet::Iterator sit;
02511     for(sit = rStateSet.Begin(); sit != rStateSet.End(); ++sit) {
02512       // identify anonymous block (consecutive state indices)
02513       StateSet::Iterator conit=sit;
02514       Idx start = *conit;
02515       Idx anoncount = 0;
02516       for(; conit != rStateSet.End(); ++conit) {
02517         if(StateName(*conit) != "") break;
02518         if(!StateAttribute(*conit).IsDefault()) break;
02519         if(*conit != start+anoncount) break;
02520         ++anoncount;
02521       }
02522       // write anonymous block
02523       if(anoncount > FD_CONSECUTIVE) {
02524         rTw.WriteBegin("Consecutive");
02525         rTw << start;
02526         rTw << start+anoncount-1;
02527         rTw.WriteEnd("Consecutive");
02528         sit=conit;
02529       } 
02530       // break loop
02531       if(sit == rStateSet.End()) break;
02532       // write non anonymous state name/idx
02533       std::string statename = StateName(*sit);
02534       if (statename != "") rTw << statename;
02535       else rTw << *sit;
02536       // write attribute
02537       const AttributeVoid& attr=rStateSet.Attribute(*sit);
02538       attr.Write(rTw);
02539     }
02540   }
02541   // write end tag
02542   rTw.WriteEnd(rStateSet.Name());
02543 }
02544 
02545 
02546 // DWriteStateSet(rTw&, rStateSet&) 
02547 void vGenerator::DWriteStateSet(TokenWriter& rTw, const StateSet& rStateSet) const {
02548   rTw.WriteBegin(rStateSet.Name());
02549   StateSet::Iterator sit;
02550   for(sit = rStateSet.Begin(); sit != rStateSet.End(); ++sit) {
02551     rTw << SStr(*sit);
02552     const AttributeVoid& attr=rStateSet.Attribute(*sit);
02553     attr.Write(rTw);
02554   }
02555   rTw.WriteEnd(rStateSet.Name());
02556 }
02557 
02558 
02559 // XWriteStateSet(rTw&, rStateSet&) 
02560 void vGenerator::XWriteStateSet(TokenWriter& rTw, const StateSet&  rStateSet, const std::string& rLabel) const {
02561   // figure label
02562   std::string label=rLabel;
02563   if(label=="") label=rStateSet.Name();
02564   if(label=="") label="StateSet";
02565   rTw.WriteBegin(label);
02566   // build reverse index map of states to write ( fileidx->idx )
02567   // -- this ensures named states to be written first; see SetMinStateIndexMap()
02568   // -- this is required to figure consecutive blocks
02569   std::map<Idx,Idx> reversemap;
02570   std::map<Idx,Idx>::const_iterator minit;
02571   StateSet::Iterator sit;
02572   for (sit = rStateSet.Begin(); sit != rStateSet.End(); ++sit) {
02573     reversemap[MinStateIndex(*sit)] = *sit;
02574   }
02575   // iterate states to write 
02576   for(minit = reversemap.begin(); minit != reversemap.end(); ++minit) {
02577     // identify anonymous block (consecutive state indices, no names, no attributes)
02578     std::map<Idx,Idx>::const_iterator conit=minit;
02579     Idx start = conit->first;
02580     Idx anoncount = 0;
02581     for(; conit != reversemap.end(); ++conit) {
02582       if(StateName(conit->second) != "") break;
02583       if(!StateAttribute(conit->second).IsDefault()) break;
02584       if(ExistsInitState(conit->second)) break;
02585       if(ExistsMarkedState(conit->second)) break;
02586       if(conit->first != start+anoncount) break;
02587       ++anoncount;
02588     }
02589     // write anonymous block
02590     if(anoncount > FD_CONSECUTIVE) {
02591       Token contag;
02592       contag.SetEmpty("Consecutive");
02593       contag.InsAttributeInteger("from",start);
02594       contag.InsAttributeInteger("to",start+anoncount-1);
02595       rTw.Write(contag);
02596       minit=conit;
02597     } 
02598     // break loop
02599     if(minit == reversemap.end() )
02600       break;
02601     // prepare state token
02602     Token sttag;    
02603     std::string statename = StateName(minit->second);
02604     Idx index=minit->first;
02605     sttag.SetBegin("State");
02606     sttag.InsAttributeInteger("id",index);
02607     if(statename!="")
02608     if(&rStateSet==mpStates) 
02609       sttag.InsAttributeString("name",statename);
02610     rTw.Write(sttag);
02611     // marking
02612     if(ExistsInitState(minit->second))   { sttag.SetEmpty("Initial"); rTw.Write(sttag);}; 
02613     if(ExistsMarkedState(minit->second)) { sttag.SetEmpty("Marked");  rTw.Write(sttag);}; 
02614     // attribute
02615     const AttributeVoid& attr=rStateSet.Attribute(minit->second);
02616     if(!attr.IsDefault()) attr.XWrite(rTw);
02617     // done
02618     rTw.WriteEnd("State");
02619   }
02620   rTw.WriteEnd(label);
02621 }
02622 
02623 
02624 // StatesToString()
02625 std::string vGenerator::StatesToString(void) const {
02626   return StateSetToString(*mpStates);
02627 }
02628 
02629 // StatesToText()
02630 std::string vGenerator::StatesToText(void) const {
02631   return StateSetToText(*mpStates);
02632 }
02633 
02634 // MarkedStatesToString()
02635 std::string vGenerator::MarkedStatesToString(void) const {
02636   return StateSetToString(mMarkedStates);
02637 }
02638 
02639 // InitStatesToString()
02640 std::string vGenerator::InitStatesToString(void) const {
02641   return StateSetToString(mInitStates);
02642 }
02643 
02644 
02645 // WriteTransRel() 
02646 void vGenerator::WriteTransRel(void) const {
02647   TokenWriter tw(TokenWriter::Stdout);
02648   WriteTransRel(tw);
02649 }
02650 
02651 // TransRelToString()
02652 std::string vGenerator::TransRelToString(void) const {
02653   TokenWriter tw(TokenWriter::String);
02654   WriteTransRel(tw);
02655   return tw.Str();
02656 }
02657 
02658 // TransRelToText()
02659 std::string vGenerator::TransRelToText(void) const {
02660   TokenWriter tw(TokenWriter::String);
02661   tw.Endl(true);
02662   WriteTransRel(tw);
02663   return tw.Str();
02664 }
02665 
02666 // WriteTransRel(rTw&)
02667 void vGenerator::WriteTransRel(TokenWriter& rTw) const {
02668   TransSet::Iterator tit;
02669   int oldcolumns = rTw.Columns();
02670   rTw.Columns(3);
02671   rTw.WriteBegin("TransRel");
02672   bool smalltransrel = (Size() < FD_SMALLTRANSREL);
02673 
02674   // loop all transitions
02675   for(tit = mpTransRel->Begin(); tit != mpTransRel->End(); ++tit) {
02676 
02677     // write x1
02678     Idx x1=MinStateIndex(tit->X1);
02679     if (smalltransrel) {
02680       std::string x1name = StateName(tit->X1);
02681       if (x1name != "") {
02682   rTw << x1name;
02683       } else {
02684   rTw << x1;
02685       }
02686     } else {
02687       rTw << x1;
02688     }
02689 
02690     // write ev
02691     rTw << EventName(tit->Ev);
02692 
02693     // write x2
02694     Idx x2=MinStateIndex(tit->X2);
02695     if (smalltransrel) {
02696       std::string x2name = StateName(tit->X2);
02697       if (x2name != "") {
02698   rTw << x2name;
02699       } else {
02700   rTw << x2;
02701       }
02702     } else {
02703       rTw << x2;
02704     }
02705 
02706     // write attributes
02707     TransAttribute(*tit).Write(rTw);
02708 
02709   }
02710   rTw.WriteEnd("TransRel");
02711   rTw.Columns(oldcolumns);
02712 }
02713 
02714 // DWriteTransRel(rTw&)
02715 void vGenerator::DWriteTransRel(TokenWriter& rTw) const {
02716   TransSet::Iterator tit;
02717   int oldcolumns = rTw.Columns();
02718   rTw.Columns(3);
02719   rTw.WriteBegin("TransRel");
02720   // iterate all transitions
02721   for (tit = mpTransRel->Begin(); tit != mpTransRel->End(); ++tit) {
02722     // write x1
02723     std::ostringstream ox1;
02724     Idx x1= tit->X1;
02725     std::string x1name = StateName(x1);
02726     if (x1name != "") {
02727       ox1 << x1name << "[" << x1 << "]";
02728     } else {
02729       ox1 << x1;
02730     }
02731     rTw << ox1.str();
02732     // write ev
02733     std::ostringstream oev;
02734     Idx ev= tit->Ev;
02735     std::string evname = EventName(ev);
02736     oev << evname << "[" << ev << "]";
02737     rTw << oev.str();
02738     // write x2
02739     std::ostringstream ox2;
02740     Idx x2= tit->X2;
02741     std::string x2name = StateName(x2);
02742     if (x2name != "") {
02743       ox2 << x2name << "[" << x2 << "]";
02744     } else {
02745       ox2 << x2;
02746     }
02747     rTw << ox2.str();
02748     // attribute
02749     mpTransRel->Attribute(*tit).Write(rTw);
02750   }
02751   rTw.WriteEnd("TransRel");
02752   rTw.Columns(oldcolumns);
02753 }
02754 
02755 
02756 // XWriteTransRel(rTw&)
02757 void vGenerator::XWriteTransRel(TokenWriter& rTw) const {
02758   TransSet::Iterator tit;
02759   rTw.WriteBegin("TransitionRelation");
02760 
02761   // loop all transitions
02762   for(tit = mpTransRel->Begin(); tit != mpTransRel->End(); ++tit) {
02763 
02764     // retrieve values x1
02765     Idx x1=MinStateIndex(tit->X1);
02766     Idx x2=MinStateIndex(tit->X2);
02767     std::string ev=EventName(tit->Ev);
02768 
02769     // prepare tag
02770     Token trtag;
02771     trtag.SetEmpty("Transition");
02772     trtag.InsAttributeInteger("x1",x1);
02773     trtag.InsAttributeString("event",ev);
02774     trtag.InsAttributeInteger("x2",x2);
02775 
02776     // consider attribute
02777     const AttributeVoid& attr=TransAttribute(*tit);
02778     // case a: indeed no attribute value
02779     if(attr.IsDefault()) {
02780       rTw.Write(trtag);
02781     } 
02782     // calse b: with attribute
02783     else {
02784       trtag.ClrEnd();
02785       rTw.Write(trtag);
02786       attr.XWrite(rTw);
02787       rTw.WriteEnd(trtag.StringValue());
02788     }
02789 
02790   }
02791   rTw.WriteEnd("TransitionRelation");
02792 }
02793 
02794 // DoSWrite(rTw&)
02795 void vGenerator::DoSWrite(TokenWriter& rTw) const
02796 {
02797   Type::DoSWrite(rTw);
02798   rTw.WriteComment(" States:        " + ToStringInteger(Size()) );
02799   rTw.WriteComment(" Init/Marked:   " + ToStringInteger(mInitStates.Size()) 
02800         + "/" + ToStringInteger(mMarkedStates.Size()));
02801   rTw.WriteComment(" Events:        " + ToStringInteger(mpAlphabet->Size()) );
02802   rTw.WriteComment(" Transitions:   " + ToStringInteger(mpTransRel->Size()) );
02803   rTw.WriteComment(" StateSymbols:  " + ToStringInteger(mpStateSymbolTable->Size()) );
02804   rTw.WriteComment(" Attrib. E/S/T: " + ToStringInteger(mpAlphabet->AttributesSize()) 
02805         + "/" + ToStringInteger(mpStates->AttributesSize())
02806         + "/" + ToStringInteger(mpTransRel->AttributesSize()) );
02807   rTw.WriteComment("");
02808 }
02809 
02810 // DotWrite(rFileName)
02811 void vGenerator::DotWrite(const std::string& rFileName) const {
02812   FD_DG("vGenerator(" << this << ")::DotWrite(" << rFileName << ")");
02813   SetMinStateIndexMap();
02814   StateSet::Iterator lit;
02815   TransSet::Iterator tit;
02816   try {
02817     std::ofstream stream;
02818     stream.exceptions(std::ios::badbit|std::ios::failbit);
02819     stream.open(rFileName.c_str());
02820     stream << "// dot output generated by libFAUDES vGenerator" << std::endl;
02821     stream << "digraph \"" << Name() << "\" {" << std::endl;
02822     stream << "  rankdir=LR" << std::endl;
02823     stream << "  node [shape=circle];" << std::endl;
02824     stream << std::endl;
02825     stream << "  // initial states" << std::endl;
02826     int i = 1;
02827     for (lit = InitStatesBegin(); lit != InitStatesEnd(); ++lit) {
02828       std::string xname= StateName(*lit);
02829       if(xname=="") xname=ToStringInteger(MinStateIndex(*lit));
02830       stream << "  dot_dummyinit_" << i << " [shape=none, label=\"\", width=\"0.0\", height=\"0.0\" ];" << std::endl;
02831       stream << "  dot_dummyinit_" << i << " -> \"" << xname << "\";" << std::endl; 
02832       i++;
02833     }
02834     stream << std::endl;
02835     stream << "  // mstates" << std::endl;
02836     for (lit = MarkedStatesBegin(); lit != MarkedStatesEnd(); ++lit) {
02837       std::string xname= StateName(*lit);
02838       if(xname=="") xname=ToStringInteger(MinStateIndex(*lit));
02839       stream << "  \"" << xname << "\" [shape=doublecircle];" << std::endl;
02840     }
02841     stream << std::endl;
02842     stream << "  // rest of stateset" << std::endl;
02843     for (lit = StatesBegin(); lit != StatesEnd(); ++lit) {
02844       if (! (ExistsInitState(*lit) || ExistsMarkedState(*lit)) ) {
02845   std::string xname= StateName(*lit);
02846   if(xname=="") xname=ToStringInteger(MinStateIndex(*lit));
02847   stream << "  \"" << xname << "\";" << std::endl;
02848       }
02849     }
02850     stream << std::endl;
02851     stream << "  // transition relation" << std::endl;
02852     for(tit = TransRelBegin(); tit != TransRelEnd(); ++tit) {
02853       std::string x1name= StateName(tit->X1);
02854       if(x1name=="") x1name=ToStringInteger(MinStateIndex(tit->X1));
02855       std::string x2name= StateName(tit->X2);
02856       if(x2name=="") x2name=ToStringInteger(MinStateIndex(tit->X2));
02857       stream << "  \"" << x1name  << "\" -> \"" << x2name
02858        << "\" [label=\"" << EventName(tit->Ev) << "\"];" << std::endl;
02859     }
02860     stream << "};" << std::endl;
02861     stream.close();
02862   }
02863   catch (std::ios::failure&) {
02864     throw Exception("vGenerator::DotWrite", 
02865         "Exception opening/writing dotfile \""+rFileName+"\"", 2);
02866   }
02867   ClearMinStateIndexMap();
02868 }
02869 
02870 // DDotWrite(rFileName)
02871 void vGenerator::DDotWrite(const std::string& rFileName) const {
02872   FD_DG("vGenerator(" << this << ")::DDotWrite(" << rFileName << ")");
02873   StateSet::Iterator lit;
02874   TransSet::Iterator tit;
02875   try {
02876     std::ofstream stream;
02877     stream.exceptions(std::ios::badbit|std::ios::failbit);
02878     stream.open(rFileName.c_str());
02879     stream << "digraph \"" << Name() << "\" {" << std::endl;
02880     stream << "  rankdir=LR" << std::endl;
02881     stream << "  node [shape=circle];" << std::endl;
02882     stream << std::endl;
02883     stream << "  // istates" << std::endl;
02884     int i = 1;
02885     for (lit = InitStatesBegin(); lit != InitStatesEnd(); ++lit) {
02886       stream << "  dot_dummyinit_" << i << " [shape=none, label=\"\" ];" << std::endl;
02887       stream << "  dot_dummyinit_" << i << " -> \"" 
02888        << SStr(*lit)  << "\";" << std::endl; 
02889       i++;
02890     }
02891     stream << std::endl;
02892     stream << "  // mstates" << std::endl;
02893     for (lit = MarkedStatesBegin(); lit != MarkedStatesEnd(); ++lit) {
02894       stream << "  \"" << SStr(*lit) << "\" [shape=doublecircle];" << std::endl;
02895     }
02896     stream << std::endl;
02897     stream << "  // rest of stateset" << std::endl;
02898     for (lit = StatesBegin(); lit != StatesEnd(); ++lit) {
02899       // if not in mInitStates or mMarkedStates
02900       if (! (ExistsInitState(*lit) || ExistsMarkedState(*lit)) ) {
02901   stream << "  \"" << SStr(*lit) << "\";" << std::endl;
02902       }
02903     }
02904     stream << std::endl;
02905     stream << "  // transition relation" << std::endl;
02906     for (tit = TransRelBegin(); tit != TransRelEnd(); ++tit) {
02907       stream << "  \"" << SStr(tit->X1) 
02908        << "\" -> \"" << SStr(tit->X2)
02909        << "\" [label=\"" << EventName(tit->Ev) << "\"];" << std::endl;
02910     }
02911     stream << "};" << std::endl;
02912     stream.close();
02913   }
02914   catch (std::ios::failure&) {
02915     throw Exception("vGenerator::DotWrite", 
02916         "Exception opening/writing dotfile \""+rFileName+"\"", 2);
02917   }
02918 }
02919 
02920 
02921 // XDotWrite(rFileName)
02922 void vGenerator::XDotWrite(const std::string& rFileName) const {
02923   FD_DG("vGenerator(" << this << ")::XDotWrite(" << rFileName << ")");
02924   StateSet::Iterator lit;
02925   TransSet::Iterator tit;
02926   try {
02927     std::ofstream stream;
02928     stream.exceptions(std::ios::badbit|std::ios::failbit);
02929     stream.open(rFileName.c_str());
02930     stream << "digraph \"___" << Name() << "___\" {" << std::endl;
02931     stream << "  rankdir=LR" << std::endl;
02932     stream << "  node [shape=circle];" << std::endl;
02933     stream << std::endl;
02934     stream << "  // stateset" << std::endl;
02935     for (lit = InitStatesBegin(); lit != InitStatesEnd(); ++lit) {
02936       stream << "  \"s" << *lit << "\";" << std::endl;
02937     }
02938     for (lit = MarkedStatesBegin(); lit != MarkedStatesEnd(); ++lit) {
02939       stream << "  \"s" << *lit << "\";" << std::endl;
02940     }
02941     for (lit = StatesBegin(); lit != StatesEnd(); ++lit) {
02942       if(ExistsInitState(*lit)) continue;
02943       if(ExistsMarkedState(*lit)) continue;
02944       stream << "  \"s" << *lit << "\";" << std::endl;
02945     }
02946     stream << std::endl;
02947     stream << "  // transition relation" << std::endl;
02948     for (tit = TransRelBegin(); tit != TransRelEnd(); ++tit) {
02949       stream << "  \"s" << tit->X1 
02950        << "\" -> \"s" << tit->X2
02951        << "\" [label=\"e" << tit->Ev << "\" " << "polyline" << "];" << std::endl;
02952     }
02953     stream << "};" << std::endl;
02954     stream.close();
02955   }
02956   catch (std::ios::failure&) {
02957     throw Exception("vGenerator::XDotWrite", 
02958         "Exception opening/writing dotfile \""+rFileName+"\"", 2);
02959   }
02960 }
02961 
02962 // DoRead(tr)
02963 void vGenerator::DoRead(TokenReader& rTr,  const std::string& rLabel, const Type* pContext) {
02964   (void) pContext;
02965   std::string label=rLabel;
02966   if(label=="") label="Generator"; 
02967   FD_DG("vGenerator(" << this << ")::DoRead(): file " << rTr.FileName() << "  section " << label);
02968   // Clear old stuff
02969   Clear();
02970   // find Generator in any of our current file formats
02971   Token btag;
02972   rTr.ReadBegin(label, btag);
02973   // sense native format
02974   Token token;
02975   rTr.Peek(token);
02976   // explcit name token: native libFAUDES file
02977   if(token.IsString()) {
02978     // get the Generator "name" token
02979     ReadGeneratorName(rTr);
02980     // read mAlphabet
02981     ReadAlphabet(rTr);
02982     // read stateset
02983     ReadStates(rTr);
02984     // read transrel
02985     ReadTransRel(rTr);
02986     // read istates
02987     ReadStateSet(rTr, "InitStates", mInitStates);
02988     // read mstates
02989     ReadStateSet(rTr, "MarkedStates", mMarkedStates);
02990     // read attribute
02991     mpGlobalAttribute->Read(rTr);
02992   }
02993   // else: try XML format
02994   else {
02995     // figure generator name
02996     std::string name="generator";
02997     if(btag.ExistsAttributeString("name")) 
02998       name=btag.AttributeStringValue("name");
02999     Name(name);
03000     // read alphabet 
03001     mpAlphabet->Read(rTr,"Alphabet");
03002     // read state set
03003     XReadStateSet(rTr, *mpStates, "StateSet");
03004     mpStates->Name("States");
03005     // read trans rel
03006     XReadTransRel(rTr);
03007     // read attribute
03008     mpGlobalAttribute->Read(rTr);
03009     // fix labels
03010     mInitStates.Name("InitStates");
03011     mMarkedStates.Name("MarkedStates");
03012   }
03013   // read end 
03014   rTr.ReadEnd(label);
03015   FD_DG("vGenerator(" << this << ")::DoRead(): done");
03016 }
03017 
03018 // ReadGeneratorName(rFileName)
03019 void vGenerator::ReadGeneratorName(const std::string& rFileName) {
03020   TokenReader tr(rFileName);
03021   tr.ReadBegin("Generator");  // mimique old behaviour .. use "ReadBegin" instead   
03022   ReadGeneratorName(tr);
03023 }
03024 
03025 // ReadGeneratorName(tr)
03026 void vGenerator::ReadGeneratorName(TokenReader& rTr) {
03027   FD_DG("vGenerator(" << this << ")::ReadGeneratorName(\"" 
03028   << rTr.FileName() << "\")");
03029    mMyName=rTr.ReadString();
03030 }
03031 
03032 // ReadAlphabet(rFileName)
03033 void vGenerator::ReadAlphabet(const std::string& rFileName) {
03034   FD_DG("vGenerator(" << this << ")::ReadAlphabet(\"" << rFileName << "\")");
03035   mpAlphabet->Read(rFileName,"Alphabet");
03036 }
03037 
03038 // ReadAlphabet(rTr) 
03039 void vGenerator::ReadAlphabet(TokenReader& rTr) {
03040   FD_DG("vGenerator(" << this << ")::ReadAlphabet(\"" 
03041   << rTr.FileName() << "\")");
03042   mpAlphabet->Read(rTr,"Alphabet");
03043 }
03044 
03045 // ReadStates(rFileName) 
03046 void vGenerator::ReadStates(const std::string& rFileName) {
03047   TokenReader tr(rFileName);
03048   ReadStates(tr);
03049 }
03050 
03051 // ReadStates(tr) 
03052 void vGenerator::ReadStates(TokenReader& rTr) {
03053   FD_DG("vGenerator(" << this << ")::ReadStates(\"" << rTr.FileName() << "\")");
03054   // HELPERS:
03055   Token token;
03056   AttributeVoid* attrp = mpStates->Attribute().New();
03057   FD_DG("vGenerator(" << this << ")::ReadStates(..): attribute type " << typeid(*attrp).name());
03058   // ALGORITHM:
03059   mpStates->Clear();
03060   mpStates->Name("States");
03061   mStateSymbolTable.Clear();
03062   // track occurence of explicit symboltable
03063   bool symimpl=false;
03064   bool symexpl=false;
03065   Idx  symnext=1;
03066   // loop section
03067   rTr.ReadBegin("States");  
03068   while(!rTr.Eos("States")) {
03069     // peek
03070     rTr.Peek(token);
03071     // read state by index
03072     if(token.IsInteger()) {
03073       rTr.Get(token);
03074       Idx index = token.IntegerValue();
03075       FD_DG("vGenerator(" << this << ")::ReadStates(\"" << rTr.FileName() << "\"): by index " << index);
03076       if(mpStates->Exists(index)) {
03077         delete attrp;
03078   std::stringstream errstr;
03079   errstr << "Token " << token.IntegerValue() << " appears twice in stateset"
03080          << rTr.FileLine();
03081   throw Exception("vGenerator::ReadStates", errstr.str(), 80);
03082       }
03083       // read attribute
03084       attrp->Read(rTr,"",this);
03085       // skip unknown attributes
03086       AttributeVoid::Skip(rTr);
03087       // insert element with attribute
03088       InsState(index); 
03089       StateAttribute(index,*attrp);
03090       symnext++;
03091       continue;
03092     } 
03093     // read state by name
03094     if(token.IsString()) {
03095       rTr.Get(token);
03096       FD_DG("vGenerator(" << this << ")::ReadStates(\"" << rTr.FileName() << "\"): by name " << token.StringValue());
03097       // interpret name, sense index suffx if present
03098       std::string statename=token.StringValue();
03099       Idx index=symnext;
03100       std::size_t pos= statename.find_first_of('#');
03101       if(pos==std::string::npos) symimpl=true;
03102       if(pos!=std::string::npos) symexpl=true;
03103       if(pos!=std::string::npos && pos < statename.size()-1) {
03104   std::string suffix=statename.substr(pos+1);
03105         index=ToIdx(suffix);
03106         statename=statename.substr(0,pos);
03107         FD_DG("vGenerator(" << this << ")::ReadStates(\"" << rTr.FileName() << "\"): extracted suffix from  " << token.StringValue() << ": " << statename << " idx " << index);
03108       }      
03109       // no doublets
03110       if(ExistsState(statename) || ExistsState(index)) {
03111         delete attrp;
03112   std::stringstream errstr;
03113   errstr << "State " << statename << "(idx " << index <<") appears twice in stateset"
03114          << rTr.FileLine();
03115   throw Exception("vGenerator::ReadStates", errstr.str(), 80);
03116       }
03117       // read attribute
03118       attrp->Read(rTr,"",this);
03119       // skip unknown attributes
03120       AttributeVoid::Skip(rTr);
03121       // insert element with attribute
03122       InsState(index); 
03123       StateName(index,statename);
03124       StateAttribute(index,*attrp);
03125       symnext++;
03126       continue;
03127     } 
03128     // read consecutive block of anonymous states
03129     if(token.IsBegin("Consecutive")) {
03130       rTr.ReadBegin("Consecutive");
03131       Token token1,token2;
03132       rTr.Get(token1);
03133       rTr.Get(token2);
03134       FD_DG("vGenerator(" << this << ")::ReadStates(\"" << rTr.FileName() << "\"): consecutive range");
03135       if ((!token1.IsInteger()) || (!token2.IsInteger())) {
03136         delete attrp;
03137   std::stringstream errstr;
03138   errstr << "Invalid range of consecutive states"  << rTr.FileLine();
03139   throw Exception("vGenerator::ReadStates", errstr.str(), 80);
03140       }
03141       for(Idx index = (Idx) token1.IntegerValue(); index <= (Idx) token2.IntegerValue(); ++index) {
03142   if(mpStates->Exists(index)) {
03143           delete attrp;
03144     std::stringstream errstr;
03145     errstr << "Index " << index << " appears twice in stateset"
03146      << rTr.FileLine();
03147     throw Exception("vGenerator::ReadStates", errstr.str(), 80);
03148   }
03149   InsState(index);
03150         symnext++;
03151       }
03152       rTr.ReadEnd("Consecutive");
03153       continue;
03154     }
03155     // cannot process token
03156     delete attrp;
03157     std::stringstream errstr;
03158     errstr << "Invalid token" << rTr.FileLine();
03159     throw Exception("vGenerator::ReadStates", errstr.str(), 80);
03160   }
03161   rTr.ReadEnd("States");
03162   // test consistent explicit symboltable
03163   if(symimpl && symexpl) {
03164     delete attrp;
03165     std::stringstream errstr;
03166     errstr << "StateSet with inconsitent explicit symboltable" << rTr.FileLine();
03167     throw Exception("vGenerator::ReadStates", errstr.str(), 80);
03168   }
03169   // dispose attribute
03170   delete attrp;
03171   FD_DG("vGenerator(" << this << ")::ReadStates(\"" << rTr.FileName() << "\"): done");
03172 }
03173 
03174 
03175 // ReadStateSet(tr, rLabel, rStateSet) 
03176 void vGenerator::ReadStateSet(TokenReader& rTr, const std::string& rLabel, StateSet& rStateSet)  const {
03177   FD_DG("vGenerator(" << this << ")::ReadStateSet(\"" << rLabel<< "\")");
03178   // HELPERS:
03179   Token token;
03180   AttributeVoid* attrp = rStateSet.Attribute().New();
03181   FD_DG("vGenerator(" << this << ")::ReadStateSet(..): attribute type " << typeid(*attrp).name());
03182   // ALGORITHM:
03183   rStateSet.Clear();
03184   rTr.ReadBegin(rLabel);  
03185   rStateSet.Name(rLabel);
03186   // loop section
03187   while(!rTr.Eos(rLabel)) {
03188     // peek
03189     rTr.Peek(token);
03190     // read state by index
03191     if(token.IsInteger()) {
03192       rTr.Get(token);
03193       Idx index = token.IntegerValue();
03194       if(!ExistsState(index)) {
03195         delete attrp;
03196   std::stringstream errstr;
03197   errstr << "Token " << token.IntegerValue() << " not in stateset"
03198          << rTr.FileLine();
03199   throw Exception("vGenerator::ReadStateSet", errstr.str(), 80);
03200       }
03201       // read attribute
03202       attrp->Read(rTr,"",this);
03203       // skip unknown attributes
03204       AttributeVoid::Skip(rTr);
03205       // insert element with attribute
03206       rStateSet.Insert(index); 
03207       rStateSet.Attribute(index,*attrp);
03208       continue;
03209     } 
03210     // read state by name
03211     if(token.IsString()) {
03212       rTr.Get(token);
03213       // test validity of symbolic name (no suffixes allowed here ... simply ignore)
03214       std::string statename=token.StringValue();
03215       std::size_t pos= statename.find_first_of('#');
03216       if(pos!=std::string::npos) {
03217         delete attrp;
03218   std::stringstream errstr;
03219   errstr << "invalid symbolic name: " << token.StringValue() 
03220            << " (no suffix allowed in external state sets)" << rTr.FileLine();
03221   throw Exception("vGenerator::ReadStateSet", errstr.str(), 80);
03222       }
03223       Idx index =StateIndex(statename);
03224       if(index==0) {
03225         delete attrp;
03226   std::stringstream errstr;
03227   errstr << "Symbolic name " << token.StringValue() << " not in stateset"
03228          << rTr.FileLine();
03229   throw Exception("vGenerator::ReadStateSet", errstr.str(), 80);
03230       }
03231       // read attribute
03232       attrp->Read(rTr,"",this);
03233       // skip unknown attributes
03234       AttributeVoid::Skip(rTr);
03235       // insert element with attribute
03236       rStateSet.Insert(index); 
03237       rStateSet.Attribute(index,*attrp);
03238       continue;
03239     } 
03240     // read consecutve block of anonymous states
03241     if(token.IsBegin() && token.StringValue() == "Consecutive") {
03242       rTr.ReadBegin("Consecutive");
03243       Token token1,token2;
03244       rTr.Get(token1);
03245       rTr.Get(token2);
03246       if(!token1.IsInteger() || !token2.IsInteger()) {
03247         delete attrp;
03248   std::stringstream errstr;
03249   errstr << "Invalid range of consecutive states"  << rTr.FileLine();
03250   throw Exception("vGenerator::ReadStateSet", errstr.str(), 80);
03251       }
03252       for(Idx index = (Idx) token1.IntegerValue(); index <= (Idx) token2.IntegerValue(); ++index) {
03253   if(!ExistsState(index)) {
03254     std::stringstream errstr;
03255     errstr << "Token " << token.IntegerValue() << " not in stateset"
03256      << rTr.FileLine();
03257     throw Exception("vGenerator::ReadStateSet", errstr.str(), 80);
03258   }
03259   rStateSet.Insert(index);
03260       }
03261       rTr.ReadEnd("Consecutive");
03262       continue;
03263     }
03264     // cannot process token
03265     delete attrp;
03266     std::stringstream errstr;
03267     errstr << "Invalid token" << rTr.FileLine();
03268     throw Exception("vGenerator::ReadStateSet", errstr.str(), 50);
03269   }
03270   rTr.ReadEnd(rLabel);
03271   // dispose attribute
03272   delete attrp;
03273 }
03274 
03275 // XReadStateSet(tr, rLabel, rStateSet) 
03276 void vGenerator::XReadStateSet(TokenReader& rTr, StateSet& rStateSet, const std::string& rLabel)  const {
03277   FD_DG("vGenerator(" << this << ")::XReadStateSet(\"" << rLabel<< "\")");
03278   AttributeVoid* attrp = rStateSet.Attribute().New();
03279   FD_DG("vGenerator(" << this << ")::ReadStateSet(..): attribute type " << typeid(*attrp).name());
03280   // Clear my set
03281   rStateSet.Clear();
03282   // Figure section
03283   std::string label=rLabel;
03284   if(label=="") label=rStateSet.Name();
03285   if(label=="") label="StateSet";
03286   // Read begin
03287   Token btag;
03288   rTr.ReadBegin(label,btag);  
03289   // Use name if provided (std is no name)
03290   rStateSet.Name("");
03291   if(btag.ExistsAttributeString("name"))
03292     rStateSet.Name(btag.AttributeStringValue("name"));
03293   // Scan my section
03294   while(!rTr.Eos(label)) {
03295     Token sttag;
03296     rTr.Get(sttag);
03297     // Read consecutive block of anonymous states
03298     if(sttag.IsBegin("Consecutive")) {
03299       // Get range
03300       Idx idx1=0;
03301       Idx idx2=0;
03302       if(sttag.ExistsAttributeInteger("from"))
03303         idx1= (Idx) sttag.AttributeIntegerValue("from");
03304       if(sttag.ExistsAttributeInteger("to"))
03305         idx2= (Idx) sttag.AttributeIntegerValue("to");
03306       // Insist in valid range
03307       if(idx1==0 || idx2 < idx1) {
03308         delete attrp;
03309   std::stringstream errstr;
03310   errstr << "Invalid range of consecutive states"  << rTr.FileLine();
03311   throw Exception("vGenerator::XReadStates", errstr.str(), 80);
03312       }
03313       FD_DG("vGenerator(" << this << ")::XReadStates(\"" << rTr.FileName() << "\"): consecutive range " idx1 << " to " << idx2);
03314       for(Idx index = idx1; index <= idx2; ++index) {
03315   if(rStateSet.Exists(index)) {
03316           delete attrp;
03317     std::stringstream errstr;
03318     errstr << "Doublet state index " << index << " " << rTr.FileLine();
03319     throw Exception("vGenerator::XReadStates", errstr.str(), 80);
03320   }
03321   rStateSet.Insert(index);
03322       }
03323       // Done: consecutive
03324       rTr.ReadEnd("Consecutive");
03325       continue;
03326     }
03327     // Ignore other sections
03328     if(!sttag.IsBegin("State")) {
03329       if(sttag.IsBegin()) 
03330         rTr.ReadEnd(sttag.StringValue());
03331       continue;
03332     }
03333     // Its a state
03334     std::string name="";
03335     if(sttag.ExistsAttributeString("name"))
03336       name=sttag.AttributeStringValue("name");
03337     Idx index=0;
03338     if(sttag.ExistsAttributeInteger("id"))
03339       index=sttag.AttributeIntegerValue("id");
03340     FD_DG("vGenerator::XReadStateSet(): got idx " << index << " " << name);
03341     // reconstruct index from name if possible
03342     if(index==0) {
03343       index=StateIndex(name);
03344     }
03345     // failed to figure index
03346     if(index==0) {
03347       delete attrp;
03348       std::stringstream errstr;
03349       errstr << "Cannot figure index for state token " << sttag.Str() << rTr.FileLine();
03350       throw Exception("vGenerator::XReadStateSet", errstr.str(), 80);
03351     }
03352     // dont allow doublets
03353     if(rStateSet.Exists(index)) {
03354       delete attrp;
03355       std::stringstream errstr;
03356       errstr << "Doublet state from token " << sttag.Str() << rTr.FileLine();
03357       throw Exception("vGenerator::XReadStateSet", errstr.str(), 80);
03358     }
03359     // record state
03360     rStateSet.Insert(index);
03361     // record name if we read the core set
03362     if(&rStateSet==mpStates) 
03363     if(name!="") {
03364        mpStateSymbolTable->SetEntry(index, name);
03365     }
03366     // test for attributes and such
03367     while(!rTr.Eos("State")) {
03368       Token token;
03369       rTr.Peek(token);
03370       // marking (if this is the main state set)
03371       Token mtag; 
03372       if(token.IsBegin("Initial") && (&rStateSet==mpStates)) { 
03373         rTr.ReadBegin("Initial",mtag);  
03374         bool v=true;
03375         if(mtag.ExistsAttributeInteger("value"))
03376           v=mtag.AttributeIntegerValue("value");
03377         if(v) const_cast<vGenerator*>(this)->SetInitState(index);
03378         rTr.ReadEnd("Initial");
03379         continue;
03380       }
03381       if(token.IsBegin("Marked") && (&rStateSet==mpStates)) { 
03382         rTr.ReadBegin("Marked",mtag);  
03383         bool v=true;
03384         if(mtag.ExistsAttributeInteger("value"))
03385           v=mtag.AttributeIntegerValue("value");
03386         if(v) const_cast<vGenerator*>(this)->SetMarkedState(index);
03387         rTr.ReadEnd("Marked");
03388         continue;
03389       }
03390       // read attribute
03391       FD_DG("vGenerator(" << this << ")::XReadStates(\"" << rTr.FileName() << "\"): attribute ?");
03392       attrp->Read(rTr,"",this);
03393       rStateSet.Attribute(index,*attrp);
03394       // break on first unknown/undigested
03395       break;
03396     } 
03397     // read end
03398     rTr.ReadEnd("State");
03399   }
03400   rTr.ReadEnd(label);
03401   // dispose attribute
03402   delete attrp;
03403   FD_DG("vGenerator(" << this << ")::XReadStates(\"" << rTr.FileName() << "\"): done");
03404 }
03405 
03406 
03407 // ReadTransRel(rFileName)
03408 void vGenerator::ReadTransRel(const std::string& rFileName) {
03409   TokenReader tr(rFileName);
03410   ReadTransRel(tr);
03411 }
03412 
03413 // ReadTransRel(tr) 
03414 void vGenerator::ReadTransRel(TokenReader& rTr) {
03415   FD_DG("vGenerator(" << this << ")::ReadTransRel(\"" << rTr.FileName() << "\")");
03416   AttributeVoid* attrp = mpTransRel->Attribute().New();
03417   FD_DG("vGenerator(" << this << ")::ReadTransRel(..): attribute type " << typeid(*attrp).name());
03418   try {
03419     Token token;
03420     Token x1t;
03421     Token x2t;
03422     Token evt;
03423     rTr.ReadBegin("TransRel");
03424     // Read tokens
03425     while (rTr.Peek(token)) {
03426 
03427       // clear my transition
03428       Idx x1 = 0, ev = 0, x2 = 0;
03429 
03430       // 0: end of transition relation
03431       if(token.IsEnd()) break;
03432 
03433 
03434       // 1: the x1 token
03435       rTr >> x1t;
03436       if(x1t.IsInteger()) {
03437   x1=x1t.IntegerValue();
03438       } else if (x1t.IsString()) {
03439   x1t.StringValue();
03440   x1=StateIndex(x1t.StringValue());
03441       } else break;
03442 
03443       // 2: the event token
03444       rTr >> evt;
03445       if(evt.IsString()) {
03446   evt.StringValue();
03447   ev=EventIndex(evt.StringValue());
03448       } else break;
03449 
03450       // 3: the x2 evt
03451       rTr >> x2t;
03452       if(x2t.IsInteger()) {
03453   x2=x2t.IntegerValue();
03454       } else if(x2t.IsString()) {
03455   x2t.StringValue();
03456   x2=StateIndex(x2t.StringValue());
03457       } else break;
03458 
03459       // 4: attributes
03460       attrp->Read(rTr,"",this);
03461 
03462       // 5: skip unknown attributes
03463       AttributeVoid::Skip(rTr);
03464 
03465       // check values
03466       if(!ExistsState(x1)){
03467   std::stringstream errstr;
03468   errstr << "invalid state x1 " << x1t.StringValue() << " " << rTr.FileLine();
03469   throw Exception("vGenerator::ReadTransRel", errstr.str(), 85);
03470       } 
03471       if(!ExistsState(x2)){
03472   std::stringstream errstr;
03473   errstr << "invalid state x2 " << x2t.StringValue() << " " << rTr.FileLine();
03474   throw Exception("vGenerator::ReadTransRel", errstr.str(), 85);
03475       } 
03476       if(!ExistsEvent(ev)) {
03477   std::stringstream errstr;
03478   errstr << "invalid event " << evt.StringValue() << " " << rTr.FileLine();
03479   throw Exception("vGenerator::ReadTransRel", errstr.str(), 85);
03480       } 
03481 
03482       // insert transition
03483       Transition trans=Transition(x1,ev,x2);
03484       SetTransition(trans);
03485       TransAttribute(trans,*attrp);
03486 
03487     } // end while
03488     rTr.ReadEnd("TransRel");   
03489   }
03490 
03491   catch (faudes::Exception& oex) {
03492     delete attrp;
03493     std::stringstream errstr;
03494     errstr << "Reading TransRel failed in " << rTr.FileLine() << oex.What();
03495     throw Exception("vGenerator::ReadTransRel", errstr.str(), 50); 
03496   }
03497   FD_DG("vGenerator(" << this << ")::ReadTransRel(\"" << rTr.FileName() << "\"): sone");
03498 
03499   // dispose attribute
03500   delete attrp;
03501 }
03502 
03503 
03504 // XReadTransRel(tr) 
03505 void vGenerator::XReadTransRel(TokenReader& rTr) {
03506   FD_DG("vGenerator(" << this << ")::XReadTransRel()");
03507   AttributeVoid* attrp = mpTransRel->Attribute().New();
03508   FD_DG("vGenerator(" << this << ")::ReadTransRel(..): attribute type " << typeid(*attrp).name());
03509   // Clear my set
03510   mpTransRel->Clear();
03511   mpTransRel->Name("TransRel");
03512   // Read begin
03513   Token btag;
03514   rTr.ReadBegin("TransitionRelation",btag);  
03515   // Scan my section
03516   while(!rTr.Eos("TransitionRelation")) {
03517     Token trtag;
03518     rTr.Get(trtag);
03519     // Ignore other sections
03520     if(!trtag.IsBegin("Transition")) {
03521       if(trtag.IsBegin()) 
03522         rTr.ReadEnd(trtag.StringValue());
03523       continue;
03524     }
03525     // Its a transition
03526     Idx x1=0;
03527     Idx x2=0;
03528     Idx ev=0;
03529     std::string evname;
03530     std::string x1name;
03531     std::string x2name;
03532     if(trtag.ExistsAttributeInteger("x1"))
03533       x1=trtag.AttributeIntegerValue("x1");
03534     if(trtag.ExistsAttributeInteger("x2"))
03535       x2=trtag.AttributeIntegerValue("x2");
03536     if(trtag.ExistsAttributeString("x1"))
03537       x1name=trtag.AttributeStringValue("x1");
03538     if(trtag.ExistsAttributeString("x2"))
03539       x2name=trtag.AttributeStringValue("x2");
03540     if(trtag.ExistsAttributeString("event"))
03541       evname=trtag.AttributeStringValue("event");
03542     // Interpret names
03543     ev=EventIndex(evname);
03544     if(x1==0) x1=StateIndex(x1name);
03545     if(x2==0) x2=StateIndex(x2name);
03546     // Report
03547     FD_DG("vGenerator::XReadTransRel(): got transition " << TStr(Transition(x1,ev,x2)));
03548     // test 1: components specified
03549     if(x1==0 || x2==0 || ev==0) {
03550       delete attrp;
03551       std::stringstream errstr;
03552       errstr << "Invalid transition at token " << trtag.Str() << rTr.FileLine();
03553       throw Exception("vGenerator::XReadTransRel", errstr.str(), 80);
03554     }
03555     // test 2: no doublets
03556     if(ExistsTransition(x1,ev,x2)) {
03557       delete attrp;
03558       std::stringstream errstr;
03559       errstr << "Doublet transition at token " << trtag.Str() << rTr.FileLine();
03560       throw Exception("vGenerator::XReadTransRel", errstr.str(), 80);
03561     }
03562     // test 3: components must exist
03563     if(!ExistsState(x1)){
03564       delete attrp;
03565       std::stringstream errstr;
03566       errstr << "Invalid state x1 " << x1 << " " << rTr.FileLine();
03567       throw Exception("vGenerator::XReadTransRel", errstr.str(), 80);
03568     } 
03569     if(!ExistsState(x2)){
03570       delete attrp;
03571       std::stringstream errstr;
03572       errstr << "Invalid state x2 " << x2 << " " << rTr.FileLine();
03573       throw Exception("vGenerator::XReadTransRel", errstr.str(), 80);
03574     } 
03575     if(!ExistsEvent(ev)){
03576       delete attrp;
03577       std::stringstream errstr;
03578       errstr << "Invalid event  " << evname << " " << rTr.FileLine();
03579       throw Exception("vGenerator::XReadTransRel", errstr.str(), 80);
03580     } 
03581     // record transition
03582     SetTransition(x1,ev,x2);
03583     // test for attribute
03584     Token token;
03585     rTr.Peek(token);
03586     if(!token.IsEnd("Transition")) {
03587       // read attribute
03588       attrp->Read(rTr,"",this);
03589       TransAttribute(Transition(x1,ev,x2),*attrp);
03590     } 
03591     // read end
03592     rTr.ReadEnd("Transition");
03593   }
03594   rTr.ReadEnd("TransitionRelation");
03595   // dispose attribute
03596   delete attrp;
03597   FD_DG("vGenerator(" << this << ")::XReadTransRel(\"" << rTr.FileName() << "\"): done");
03598 }
03599 
03600 // EStr(index)
03601 std::string vGenerator::EStr(Idx index) const {
03602   std::string name = EventName(index);
03603   return name+"#"+faudes::ToStringInteger(index);
03604 }
03605 
03606 // SStr(index)
03607 std::string vGenerator::SStr(Idx index) const {
03608   std::string name = StateName(index);
03609   if(name == "") name=ToStringInteger(index);
03610   return name+"#"+faudes::ToStringInteger(index);
03611 }
03612 
03613 // TStr(index)
03614 std::string vGenerator::TStr(const Transition& trans) const {
03615   return SStr(trans.X1) + "--(" + EStr(trans.Ev) + ")-->" + SStr(trans.X2);
03616 }
03617 
03618 
03619 // GraphWrite(rFileName,rOutFormat)
03620 void vGenerator::GraphWrite(const std::string& rFileName, const std::string& rOutFormat,
03621    const std::string& rDotExec) const {
03622   FD_DG("vGenerator::GraphWrite(...): " << typeid(*this).name());
03623   // generate temp dot ibput file
03624   std::string dotin = CreateTempFile();
03625   if(dotin == "") {
03626     std::stringstream errstr;
03627     errstr << "Exception opening temp file";
03628     throw Exception("vGenerator::GraphWrite", errstr.str(), 2);
03629   }
03630   try{
03631     DotWrite(dotin);
03632   } 
03633   catch (faudes::Exception& exception) {  
03634     RemoveFile(dotin);
03635     std::stringstream errstr;
03636     errstr << "Exception writing dot input file";
03637     throw Exception("vGenerator::GraphWrite", errstr.str(), 2);
03638   }
03639   try{
03640     faudes::ProcessDot(dotin,rFileName,rOutFormat,rDotExec);
03641   } 
03642   catch (faudes::Exception& exception) {  
03643     RemoveFile(dotin);
03644     std::stringstream errstr;
03645     errstr << "Exception processing dot file";
03646     throw Exception("vGenerator::GraphWrite", errstr.str(), 3);
03647   }
03648   RemoveFile(dotin);
03649 }
03650 
03651 // rti wrapper
03652 bool IsAccessible(const vGenerator& rGen) {
03653   return rGen.IsAccessible();
03654 }
03655 
03656 // rti wrapper
03657 bool IsCoaccessible(const vGenerator& rGen) {
03658   return rGen.IsCoaccessible();
03659 }
03660 
03661 // rti wrapper
03662 bool IsTrim(const vGenerator& rGen) {
03663   return rGen.IsTrim();
03664 }
03665 
03666 // rti wrapper
03667 bool IsOmegaTrim(const vGenerator& rGen) {
03668   return rGen.IsOmegaTrim();
03669 }
03670 
03671 // rti wrapper
03672 bool IsComplete(const vGenerator& rGen) {
03673   return rGen.IsComplete();
03674 }
03675 
03676 // rti wrapper
03677 bool IsComplete(const vGenerator& rGen, const StateSet& rStateSet) {
03678   return rGen.IsComplete(rStateSet);
03679 }
03680 
03681 // rti wrapper
03682 bool IsDeterministic(const vGenerator& rGen) {
03683   return rGen.IsDeterministic();
03684 }
03685 
03686 
03687 // rti wrapper
03688 void Accessible(vGenerator& rGen) {
03689   rGen.Accessible();
03690 }
03691 
03692 // rti wrapper
03693 void Accessible(const vGenerator& rGen, vGenerator& rRes) {
03694   rRes=rGen;
03695   rRes.Accessible();
03696 }  
03697 
03698 // rti wrapper
03699 void Coaccessible(vGenerator& rGen) {
03700   rGen.Coaccessible();
03701 }
03702 
03703 // rti wrapper
03704 void Coaccessible(const vGenerator& rGen, vGenerator& rRes) {
03705   rRes=rGen;
03706   rRes.Coaccessible();
03707 }  
03708 
03709 // rti wrapper
03710 void Complete(vGenerator& rGen) {
03711   rGen.Complete();
03712 }
03713 
03714 // rti wrapper
03715 void Complete(const vGenerator& rGen, vGenerator& rRes) {
03716   rRes=rGen;
03717   rRes.Complete();
03718 }  
03719 
03720 // rti wrapper
03721 void Trim(vGenerator& rGen) {
03722   rGen.Trim();
03723 }
03724 
03725 // rti wrapper
03726 void Trim(const vGenerator& rGen, vGenerator& rRes) {
03727   rRes=rGen;
03728   rRes.Trim();
03729 }  
03730 
03731 // rti wrapper
03732 void OmegaTrim(vGenerator& rGen) {
03733   rGen.OmegaTrim();
03734 }
03735 
03736 // rti wrapper
03737 void OmegaTrim(const vGenerator& rGen, vGenerator& rRes) {
03738   rRes=rGen;
03739   rRes.OmegaTrim();
03740 }  
03741 
03742 // rti wrapper
03743 void MarkAllStates(vGenerator& rGen) {
03744   rGen.InjectMarkedStates(rGen.States());
03745 }
03746 
03747 
03748 // rti wrapper
03749 void AlphabetExtract(const vGenerator& rGen, EventSet& rRes) {
03750   // This function is an ideal debugging case for lbp_function.cpp.
03751   // FD_WARN("AlphabetExtract(): gen at " << &rGen << " sig at " << &rRes);
03752   // FD_WARN("AlphabetExtract(): gen id " << typeid(rGen).name() << " sig id " << typeid(rRes).name());
03753   rRes = rGen.Alphabet();
03754   // rRes.Write();
03755 }
03756 
03757 // rti convenience function
03758 void SetIntersection(const GeneratorVector& rGenVec, EventSet& rRes) {
03759   // prepare result
03760   rRes.Clear();
03761   // ignore empty
03762   if(rGenVec.Size()==0) return;
03763   // copy first
03764   rRes.Assign(rGenVec.At(0).Alphabet());
03765   // perform intersecttion 
03766   for(GeneratorVector::Position i=1; i<rGenVec.Size(); i++) 
03767     SetIntersection(rGenVec.At(i).Alphabet(),rRes,rRes);
03768 }
03769 
03770 
03771 // rti convenience function
03772 void SetUnion(const GeneratorVector& rGenVec, EventSet& rRes) {
03773   // prepare result
03774   rRes.Clear();
03775   // ignore empty
03776   if(rGenVec.Size()==0) return;
03777   // copy first
03778   rRes.Assign(rGenVec.At(0).Alphabet());
03779   // perform intersecttion 
03780   for(GeneratorVector::Position i=1; i<rGenVec.Size(); i++) 
03781     SetUnion(rGenVec.At(i).Alphabet(),rRes,rRes);
03782 }
03783 
03784 // rti convenience function
03785 void SetIntersection(const vGenerator& rGenA, const vGenerator& rGenB, EventSet& rRes) {
03786   SetIntersection(rGenA.Alphabet(),rGenB.Alphabet(),rRes);
03787 }
03788 
03789 // rti convenience function
03790 void SetUnion(const vGenerator& rGenA, const vGenerator& rGenB, EventSet& rRes) {
03791   SetUnion(rGenA.Alphabet(),rGenB.Alphabet(),rRes);
03792 }
03793 
03794 // rti convenience function
03795 void SetDifference(const vGenerator& rGenA, const vGenerator& rGenB, EventSet& rRes) {
03796   SetDifference(rGenA.Alphabet(),rGenB.Alphabet(),rRes);
03797 }
03798 
03799 
03800 } // name space
03801 
03802 

libFAUDES 2.20s --- 2011.10.12 --- c++ source docu by doxygen