agenerator.h

Go to the documentation of this file.
00001 
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 #ifndef FAUDES_GENERATOR_H
00025 #define FAUDES_GENERATOR_H
00026 
00027 #include "definitions.h"
00028 #include "exception.h"
00029 #include "symboltable.h"
00030 #include "indexset.h"
00031 #include "nameset.h"
00032 #include "transset.h"
00033 #include "token.h"
00034 #include "tokenreader.h"
00035 #include "tokenwriter.h"
00036 #include "vgenerator.h"
00037 #include <map>
00038 #include <set>
00039 #include <sstream>
00040 #include <cstdlib>
00041 #include <assert.h>
00042 
00043 namespace faudes {
00044 
00168 template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
00169 class TaGenerator : public vGenerator {
00170  public:
00171     
00173   typedef TaTransSet<TransAttr> ATransSet;
00174 
00175   /*****************************************
00176    *****************************************
00177    *****************************************
00178    *****************************************/
00179 
00186   TaGenerator(void);
00187 
00193   TaGenerator(const TaGenerator& rOtherGen);
00194 
00200   TaGenerator(const vGenerator& rOtherGen);
00201 
00213   TaGenerator(const std::string& rFileName);
00214 
00225   TaGenerator* NewP(void) const;
00226 
00235   virtual TaGenerator NewAGen(void) const;
00236 
00240   virtual ~TaGenerator(void);
00241 
00244   /*****************************************
00245    *****************************************
00246    *****************************************
00247    *****************************************/
00248 
00259   virtual void Copy(TaGenerator& rGen) const; 
00260 
00267   virtual void Copy(vGenerator& rGen) const; 
00268 
00279   virtual void Move(TaGenerator& rGen); 
00280 
00291   virtual void Move(vGenerator& rGen); 
00292 
00299   virtual TaGenerator& operator = (const TaGenerator& rOtherGen);
00300 
00307   virtual TaGenerator& operator = (const vGenerator& rOtherGen);
00308 
00320   void Version(Idx version, TaGenerator& rResGen);
00321 
00333   void Version(const std::string& rVersion, TaGenerator& rResGen);
00334 
00335 
00338   /*****************************************
00339    *****************************************
00340    *****************************************
00341    *****************************************/
00342 
00349   void WriteAlphabet(void) const;
00350 
00359   std::string AlphabetToString(void) const;
00360 
00370   void WriteAlphabet(TokenWriter& rTw) const;
00371 
00372 
00381   template<class OtherAttr>
00382     void WriteStateSet(const TaStateSet<OtherAttr>& rStateSet) const;
00383 
00392   void WriteStateSet(const StateSet& rStateSet) const;
00393 
00406   template<class OtherAttr>
00407     std::string StateSetToString(const TaStateSet<OtherAttr>& rStateSet) const;
00408 
00421   std::string StateSetToString(const StateSet& rStateSet) const;
00422 
00443   template<class OtherAttr>
00444     void WriteStateSet(TokenWriter& rTw, const TaStateSet<OtherAttr>& rStateSet) const;
00445 
00446 
00460   void WriteStateSet(TokenWriter& rTw, const StateSet& rStateSet) const;
00461 
00462 
00475   template<class OtherAttr>
00476     void DWriteStateSet(TokenWriter& rTw, const TaStateSet<OtherAttr>& rStateSet) const;
00477 
00489   void DWriteStateSet(TokenWriter& rTw, const StateSet& rStateSet) const;
00490 
00491 
00500   std::string StatesToString(void) const;
00501 
00510   std::string MarkedStatesToString(void) const;
00511 
00520   std::string InitStatesToString(void) const;
00521 
00525   void WriteTransRel(void) const;
00526 
00530   std::string TransRelToString(void) const;
00531 
00544   void WriteTransRel(TokenWriter& rTw) const;
00545 
00554   void DWriteTransRel(TokenWriter& rTw) const;
00555 
00556  
00561   void WriteStatistics(void) const;
00562 
00567   std::string StatisticsToString(void) const;
00568 
00578   void WriteStatistics(TokenWriter& rTw) const;
00579 
00580  
00594   void DotWrite(const std::string& rFileName);
00595 
00606   void DDotWrite(const std::string& rFileName) const;
00607 
00619   void XDotWrite(const std::string& rFileName) const;
00620 
00637   void ReadStateSet(TokenReader& rTr, const std::string& rLabel, StateSet& rStateSet) const;
00638 
00639 
00642   /*****************************************
00643    *****************************************
00644    *****************************************
00645    *****************************************/
00646 
00656   bool Valid(void);
00657 
00662   virtual void Clear(void);
00663 
00664 
00668   void ClearStates(void);
00669 
00676   Idx AlphabetSize(void) const;
00677 
00684   Idx Size(void) const;
00685 
00692   Idx TransRelSize(void) const;
00693 
00700   Idx InitStatesSize(void) const;
00701 
00708   Idx MarkedStatesSize(void) const;
00709 
00716   bool Empty(void) const;
00717 
00724   bool AlphabetEmpty(void) const;
00725 
00732   bool TransRelEmpty(void) const;
00733 
00740   bool InitStatesEmpty(void) const;
00741 
00748   bool MarkedStatesEmpty(void) const;
00749 
00755   EventSet UsedEvents(void) const;
00756 
00762   EventSet UnusedEvents(void) const;
00763 
00772   EventSet ActiveEventSet(Idx x1) const;
00773 
00782   TransSet ActiveTransSet(Idx x1) const;
00783 
00789   StateSet TransRelStateSpace(void) const;
00790 
00796   StateSet TransRelStateSpace(Idx x1) const;
00797 
00798 
00806   virtual bool UpdateAttributes(void) {return true;};
00807 
00812   /*****************************************
00813    *****************************************
00814    *****************************************
00815    *****************************************/
00816 
00826   EventSet::Iterator AlphabetBegin(void) const;
00827 
00834   EventSet::Iterator AlphabetEnd(void) const;
00835 
00845   bool ExistsEvent(Idx index) const;
00846 
00856   bool ExistsEvent(const std::string& rName) const;
00857 
00867   EventSet::Iterator FindEvent(Idx index) const;
00868 
00878   EventSet::Iterator FindEvent(const std::string& rName) const;
00879 
00885   const TaEventSet<EventAttr>& Alphabet(void) const;
00886 
00893   StateSet::Iterator StatesBegin(void) const;
00894 
00901   StateSet::Iterator StatesEnd(void) const;
00902 
00912   bool ExistsState(Idx index) const;
00913 
00923   bool ExistsState(const std::string& name) const;
00924 
00934   StateSet::Iterator FindState(Idx index) const;
00935 
00945   StateSet::Iterator FindState(const std::string& rName) const;
00946 
00947 
00954   const TaStateSet<StateAttr>& States(void) const;
00955 
00965   Idx InitState(void) const;
00966 
00973   StateSet::Iterator InitStatesBegin(void) const;
00974 
00981   StateSet::Iterator InitStatesEnd(void) const;
00982 
00992   bool ExistsInitState(Idx index) const;
00993 
01003   StateSet::Iterator FindInitState(Idx index) const;
01004 
01010   const StateSet& InitStates(void) const;
01011 
01018   StateSet::Iterator MarkedStatesBegin(void) const;
01019 
01026   StateSet::Iterator MarkedStatesEnd(void) const;
01027 
01037   bool ExistsMarkedState(Idx index) const;
01038 
01048   StateSet::Iterator FindMarkedState(Idx index) const;
01049 
01055   const StateSet& MarkedStates(void) const;
01056 
01063   typename ATransSet::Iterator TransRelBegin(void) const;
01064 
01071   typename ATransSet::Iterator TransRelEnd(void) const;
01072 
01082   typename ATransSet::Iterator TransRelBegin(Idx x1) const;
01083 
01097   typename ATransSet::Iterator TransRelEnd(Idx x1) const;
01098 
01111   typename ATransSet::Iterator TransRelBegin(Idx x1, Idx ev) const;
01112 
01129   typename ATransSet::Iterator TransRelEnd(Idx x1, Idx ev) const;
01130 
01145   typename ATransSet::Iterator FindTransition(
01146     const std::string& rX1, const std::string& rEv, const std::string& rX2) const;
01147 
01162   typename ATransSet::Iterator FindTransition(Idx x1, Idx ev, Idx x2) const;
01163 
01174   typename ATransSet::Iterator FindTransition(const Transition& rTrans) const;
01175 
01190   bool ExistsTransition(
01191     const std::string& rX1, const std::string& rEv, const std::string& rX2) const;
01192 
01207   bool ExistsTransition(Idx x1, Idx ev, Idx x2) const;
01208 
01219   bool ExistsTransition(const Transition& rTrans) const;
01220 
01226   const ATransSet& TransRel(void) const;
01227 
01235   void TransRel(TransSetX1EvX2& res) const;
01236   void TransRel(TransSetEvX1X2& res) const;
01237   void TransRel(TransSetEvX2X1& res) const;
01238   void TransRel(TransSetX2EvX1& res) const;
01239   void TransRel(TransSetX2X1Ev& res) const;
01240   void TransRel(TransSetX1X2Ev& res) const;
01241 
01246   /*****************************************
01247    *****************************************
01248    *****************************************
01249    *****************************************/
01250 
01263   bool InsEvent(Idx index);
01264 
01275   Idx InsEvent(const std::string& rName);
01276 
01287   bool InsEvent(Idx index, const EventAttr& attr);
01288 
01301   Idx InsEvent(const std::string& rName, const EventAttr& attr);
01302 
01309   void InsEvents(const EventSet& events);
01310 
01321   bool DelEvent(Idx index);
01322 
01333   bool DelEvent(const std::string& rName);
01334 
01342   void DelEvents(const EventSet& rEvents);
01343 
01354   bool DelEventFromAlphabet(Idx index);
01355 
01362   void InjectAlphabet(const EventSet& rNewalphabet);
01363 
01370   void InjectAlphabet(const TaEventSet<EventAttr>& rNewalphabet);
01371 
01378   Idx InsState(void);
01379 
01389   Idx InsState(const StateAttr& attr);
01390 
01397   bool InsState(Idx index);
01398 
01411   Idx InsState(const std::string& rName);
01412 
01426   Idx InsState(const std::string& rName, const StateAttr& attr);
01427 
01440   bool InsState(Idx index, const StateAttr& attr);
01441 
01451   bool DelState(Idx index);
01452 
01465   bool DelState(const std::string& rName);
01466 
01474   void DelStates(const StateSet& rDelStates);
01475 
01476 
01488   bool DelStateFromStates(Idx index);
01489 
01501   StateSet::Iterator DelStateFromStates(StateSet::Iterator pos);
01502 
01510   void InjectState(Idx index);
01511 
01518   void InjectStates(const StateSet& rNewStates);
01519 
01520 
01527   Idx InsInitState(void);
01528 
01538   Idx InsInitState(const std::string& rName);
01539 
01546   Idx InsMarkedState(void);
01547 
01557   Idx InsMarkedState(const std::string& rName);
01558 
01568   void SetInitState(Idx index);
01569 
01580   void SetInitState(const std::string& rName);
01581 
01588   void InjectInitStates(const StateSet& rNewInitStates);
01589 
01601   void ClrInitState(Idx index);
01602 
01613   void ClrInitState(const std::string& rName);
01614 
01621   void ClrInitState(StateSet::Iterator pos);
01622 
01626   void ClearInitStates(void); 
01627 
01638   void SetMarkedState(Idx index);
01639 
01650   void SetMarkedState(const std::string& rName);
01651 
01663   void ClrMarkedState(Idx index);
01664 
01675   void ClrMarkedState(const std::string& rName);
01676 
01683   void ClrMarkedState(StateSet::Iterator pos);
01684 
01688   void ClearMarkedStates(void);
01689 
01696   void InjectMarkedStates(const StateSet& rNewMarkedStates);
01697 
01717   bool SetTransition(Idx x1, Idx ev, Idx x2);
01718 
01738   bool SetTransition(const std::string& rX1, const std::string& rEv, 
01739            const std::string& rX2);
01740 
01754   bool SetTransition(const Transition& rTransition);
01755 
01771   bool SetTransition(const Transition& rTransition, const TransAttr& rAttr);
01772 
01783   void ClrTransition(Idx x1, Idx ev, Idx x2);
01784 
01791   void ClrTransition(const Transition& rTrans);
01792 
01801   typename ATransSet::Iterator ClrTransition(typename ATransSet::Iterator it);
01802 
01806   void ClearTransRel(void);
01807 
01814   void InjectTransition(const Transition& rTrans);
01815 
01822   void InjectTransRel(const TransSet& rNewtransrel);
01823 
01828   /*****************************************
01829    *****************************************
01830    *****************************************
01831    *****************************************/
01832 
01840   void ClearAttributes(void);
01841 
01850   void DetermineAttributes(void) {};
01851 
01855   void ClearEventAttributes(void);
01856 
01863   void ClrEventAttribute(Idx index);
01864 
01876   void EventAttribute(Idx index, const EventAttr& rAttr);
01877 
01886   const EventAttr& EventAttribute(Idx index) const;
01887 
01896   const EventAttr& EventAttribute(const std::string& rName) const;
01897 
01907   EventAttr* EventAttributep(Idx index);
01908 
01918   EventAttr* EventAttributep(const std::string& rName);
01919 
01920 
01924   void ClearStateAttributes(void);
01925 
01932   void ClrStateAttribute(Idx index);
01933 
01945   void StateAttribute(Idx index, const StateAttr& rAttr);
01946 
01954   const StateAttr& StateAttribute(Idx index) const;
01955 
01964   StateAttr* StateAttributep(Idx index);
01965 
01969   void ClearTransAttributes(void);
01970 
01980   void TransAttribute(const Transition& rTrans, const TransAttr& rAttr);
01981 
01988   void ClrTransAttribute(const Transition& rTrans);
01989 
01997   const TransAttr& TransAttribute(const Transition& rTrans) const;
01998 
02007   TransAttr* TransAttributep(const Transition& rTrans);
02008 
02012   void ClearGlobalAttribute(void);
02013 
02020   void GlobalAttribute(const GlobalAttr& rAttr) {mGlobalAttribute=rAttr;};
02021 
02025   const GlobalAttr& GlobalAttribute(void) const {return mGlobalAttribute;};
02026 
02027 
02031   GlobalAttr* GlobalAttributep(void) {return &mGlobalAttribute;};
02032 
02033 
02038   /*****************************************
02039    *****************************************
02040    *****************************************
02041    *****************************************/
02042 
02050   StateSet AccessibleSet(void) const;
02051 
02058   bool Accessible(void);
02059 
02066   bool IsAccessible(void) const;
02067 
02071   StateSet CoaccessibleSet(void) const;
02072 
02079   bool Coaccessible(void);
02080 
02087   bool IsCoaccessible(void) const;
02088 
02092   StateSet TrimSet(void) const;
02093 
02102   bool Trim(void);
02103 
02110   bool IsTrim(void) const;
02111 
02112 
02116   StateSet BlockingSet(void) const;
02117 
02122   /*****************************************
02123    *****************************************
02124    *****************************************
02125    *****************************************/
02126 
02134   void MinimizeAlphabet(void);
02135 
02148   bool IsDeterministic(void) const;
02149 
02157   void SetMinStateIndexMap(void) const;
02158 
02163   void ClearMinStateIndexMap(void) const;
02164 
02173   Idx MinStateIndex(Idx index) const;
02174 
02175 
02182   const std::map<Idx,Idx>& MinStateIndexMap(void) const;
02183 
02184 
02191   SymbolTable* EventSymbolTablep(void) const;
02192 
02201   void EventSymbolTablep(SymbolTable* pSymTab);
02202 
02213   virtual void EventSymbolTablep(const vGenerator& rOtherGen);
02214 
02218  protected:
02220   TaEventSet<EventAttr> mAlphabet;
02221 
02223   TaStateSet<StateAttr> mStates;
02224 
02226   ATransSet mTransRel;
02227 
02229   StateSet mInitStates;
02230 
02232   StateSet mMarkedStates;
02233 
02235   std::map<Idx,Idx> mMinStateIndexMap;
02236 
02238   GlobalAttr mGlobalAttribute;
02239 
02257   virtual void DoRead(TokenReader& rTr,  const std::string& rLabel = "", const Type* pContext=0);
02258  
02276   virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
02277 
02294   virtual void DoDWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const;
02295 
02306   void ReadGeneratorName(const std::string& rFileName);
02307 
02318   void ReadGeneratorName(TokenReader& rTr);
02319 
02330   void ReadAlphabet(const std::string& rFileName);
02331 
02342   void ReadAlphabet(TokenReader& rTr);
02343 
02355   void ReadStates(const std::string& rFileName);
02356 
02368   void ReadStates(TokenReader& rTr);
02369 
02380   void ReadTransRel(const std::string& rFileName);
02381 
02392   void ReadTransRel(TokenReader& rTr);
02393 
02402   void CheckAccessible(StateSet& accessibleset, Idx startState) const;
02403 
02414   void CheckCoaccessible(StateSet& Coaccessibleset, const TransSetX2EvX1& rtrel, Idx startState) const;
02415 
02416 
02417 };
02418 
02419 
02424 typedef TaGenerator<AttributeVoid,AttributeVoid,AttributeVoid,AttributeVoid> Generator; 
02425 
02426 
02427 /* convenience access to relevant scopes */
02428 #define THIS TaGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
02429 #define TEMP template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
02430 #define BASE vGenerator
02431 
02432 // Generator::Generator(void)
02433 TEMP THIS::TaGenerator(void) : 
02434   // init base
02435   vGenerator() 
02436 {  
02437   FD_DG("TaGenerator(" << this << ")::TaGenerator()");
02438   // set basic members
02439   mStates.Name("States");
02440   mInitStates.Name("InitStates");
02441   mMarkedStates.Name("MarkedStates");
02442   mAlphabet.Name("Alphabet");
02443 }
02444 
02445 // Generator::Generator(rOtherGen)
02446 TEMP THIS::TaGenerator(const TaGenerator& rOtherGen) : 
02447   // copy base
02448   vGenerator(rOtherGen)
02449 {
02450   FD_DG("TaGenerator(" << this << ")::TaGenerator(" << &rOtherGen << ")");
02451   // have  a 1:1 copy (incl sym tables)
02452   rOtherGen.Copy(*this);
02453 }
02454 
02455 
02456 // Generator::Generator(rOtherGen)
02457 TEMP THIS::TaGenerator(const vGenerator& rOtherGen) : 
02458   // copy base
02459   vGenerator(rOtherGen)
02460 {
02461   FD_DG("TaGenerator(" << this << ")::TaGenerator([v]" << &rOtherGen << ")");
02462   // have  a 1:1 copy (incl sym tables)
02463   rOtherGen.Copy(*this);
02464 }
02465 
02466 // Generator::Generator(rFileName)
02467 TEMP THIS::TaGenerator(const std::string& rFileName) : 
02468   // init base
02469   vGenerator()
02470 {
02471   FD_DG("TaGenerator(" << this << ")::TaGenerator(" << rFileName << ")");
02472   // set some defaults
02473   mStateNamesEnabled=true;
02474   // do read
02475   Read(rFileName);
02476 }
02477 
02478 // Copy(gen)  
02479 TEMP void THIS::Copy(TaGenerator& rGen) const {
02480   FD_DG("TaGenerator(" << this << ")::Copy(" << &rGen << ")");
02481   // prepare result (call clear for virtual stuff)
02482   rGen.Clear();
02483   // have same event symboltable
02484   rGen.EventSymbolTablep(mpEventSymbolTable);
02485   // copy state symboltable
02486   rGen.StateSymbolTable(mStateSymbolTable);
02487   // set other members
02488   rGen.Name(Name());
02489   rGen.StateNamesEnabled(StateNamesEnabled());
02490   rGen.mStates= mStates;
02491   rGen.mInitStates = mInitStates;
02492   rGen.mMarkedStates = mMarkedStates;
02493   rGen.mAlphabet = mAlphabet;
02494   rGen.mTransRel=mTransRel;
02495   rGen.mStateNamesEnabled=mStateNamesEnabled;
02496   rGen.mGlobalAttribute=mGlobalAttribute;
02497   // copy add on stuff
02498   rGen.mMinStateIndexMap=mMinStateIndexMap;
02499 
02500 #ifdef FAUDES_CHECKED
02501   if(!rGen.Valid()) {
02502     FD_DG("TaGenerator()::Copy(): invalid generator");
02503     rGen.DWrite(); 
02504     abort();
02505   }
02506 #endif
02507 } 
02508 
02509 // Copy(gen)  
02510 TEMP void THIS::Copy(vGenerator& rGen) const {
02511   FD_DG("TaGenerator(" << this << ")::Copy([v]" << &rGen << ")");
02512   // prepare result (call clear for virtual stuff)
02513   rGen.Clear();
02514   // have same event symboltable
02515   rGen.EventSymbolTablep(mpEventSymbolTable);
02516   // copy state symboltable
02517   rGen.StateSymbolTable(mStateSymbolTable);
02518   // set other members
02519   rGen.Name(Name());
02520   rGen.StateNamesEnabled(StateNamesEnabled());
02521   rGen.InjectStates(mStates);
02522   rGen.InjectInitStates(mInitStates);
02523   rGen.InjectMarkedStates(mMarkedStates);
02524   rGen.InjectAlphabet(mAlphabet);
02525   rGen.InjectTransRel(mTransRel);
02526 #ifdef FAUDES_CHECKED
02527   if(!rGen.Valid()) {
02528     FD_DG("TaGenerator()::Copy([v]): invalid generator");
02529     rGen.DWrite(); 
02530     abort();
02531   }
02532 #endif
02533 } 
02534 
02535 
02536 // Move(gen) destructive copy, not implemented
02537 TEMP void THIS::Move(TaGenerator& rGen) {
02538   FD_DG("TaGenerator(" << this << ")::Move(" << &rGen << ")");
02539   Copy(rGen);
02540   Clear();
02541 }
02542 
02543 
02544 // Move(gen) destructive copy, not implemented 
02545 TEMP void THIS::Move(vGenerator& rGen) {
02546   FD_DG("TaGenerator(" << this << ")::Move([v]" << &rGen << ")");
02547   Copy(rGen);
02548   Clear();
02549 }
02550 
02551 // Generator::~Generator
02552 TEMP THIS::~TaGenerator(void) {
02553   FD_DG("TaGenerator(" << this << ")::~TaGenerator()");
02554 }
02555 
02556 // NewP
02557 TEMP THIS* THIS::NewP(void) const {
02558   // allocate
02559   THIS* res = new THIS;
02560   // fix base data
02561   res->EventSymbolTablep(BASE::mpEventSymbolTable);
02562   res->mStateNamesEnabled=BASE::mStateNamesEnabled;
02563   return res;
02564 }
02565 
02566 // NewAGen()
02567 TEMP THIS THIS::NewAGen(void) const {
02568   THIS res;
02569   // fix base data
02570   res.EventSymbolTablep(BASE::mpEventSymbolTable);
02571   res.mStateNamesEnabled=BASE::mStateNamesEnabled;
02572   return res;
02573 }
02574 
02575 
02576 // operator =
02577 TEMP TaGenerator<GlobalAttr,StateAttr,EventAttr,TransAttr>& THIS::operator = (const TaGenerator& rOtherGen) {
02578   FD_DG("TaGenerator(" << this << ")::operator = " << &rOtherGen);
02579   rOtherGen.Copy(*this);
02580   return *this;
02581 }
02582 
02583 // operator =
02584 TEMP TaGenerator<GlobalAttr,StateAttr,EventAttr,TransAttr>& THIS::operator = (const vGenerator& rOtherGen) {
02585   FD_DG("TaGenerator(" << this << ")::operator = [v]" << &rOtherGen);
02586   rOtherGen.Copy(*this);
02587   return *this;
02588 }
02589 
02590 // EventSymbolTablep() 
02591 TEMP SymbolTable* THIS::EventSymbolTablep(void) const {
02592   return BASE::EventSymbolTablep();
02593 }
02594 
02595 // EventSymbolTablep(pSymTab) 
02596 TEMP void THIS::EventSymbolTablep(SymbolTable* pSymTab) {
02597   BASE::EventSymbolTablep(pSymTab);
02598   // todo: reindex rather than clear stuff
02599   Clear();
02600   mAlphabet.SymbolTablep(mpEventSymbolTable);
02601 }
02602 
02603 // EventSymbolTablep(rOtherGen) 
02604 TEMP void THIS::EventSymbolTablep(const vGenerator& rOtherGen) {
02605   BASE::EventSymbolTablep(rOtherGen);
02606 }
02607 
02608 // DoWrite()
02609 TEMP void THIS::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
02610   (void) pContext;
02611   // figure section
02612   std::string label=rLabel;
02613   if(label=="") label="Generator"; 
02614   FD_DG("TaGenerator(" << this << ")::DoWrite(): section " << label);
02615   // reindex for file output
02616   if(rTw.DestMode()==TokenWriter::File) SetMinStateIndexMap();
02617   // write generator
02618   rTw.WriteBegin(label);
02619   rTw << mMyName;
02620   rTw << "\n";
02621   rTw << "\n";
02622   WriteStatistics(rTw);
02623   rTw << "\n";
02624   mAlphabet.Write(rTw);
02625   rTw << "\n";
02626   WriteStateSet(rTw, mStates);
02627   rTw << "\n";
02628   WriteTransRel(rTw);
02629   rTw << "\n";
02630   WriteStateSet(rTw, mInitStates);
02631   rTw << "\n";
02632   WriteStateSet(rTw, mMarkedStates);
02633   rTw << "\n";
02634   mGlobalAttribute.Write(rTw);
02635   rTw << "\n";
02636   rTw.WriteEnd(label);
02637   // end of reindex
02638   ClearMinStateIndexMap();
02639 }
02640 
02641 // DoDWrite()
02642 TEMP void THIS::DoDWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
02643   (void) pContext;
02644   // figure section
02645   std::string label=rLabel;
02646   if(label=="") label="Generator"; 
02647   FD_DG("TaGenerator(" << this << ")::DoDWrite(): section " << label);
02648   // write generator
02649   rTw.WriteBegin(label);
02650   rTw << mMyName;
02651   rTw << "\n";
02652   rTw << "\n";
02653   WriteStatistics(rTw);
02654   rTw << "\n";
02655   mAlphabet.DWrite(rTw);
02656   rTw << "\n";
02657   DWriteStateSet(rTw, mStates);
02658   rTw << "\n";
02659   DWriteTransRel(rTw);
02660   rTw << "\n";
02661   DWriteStateSet(rTw, mInitStates);
02662   rTw << "\n";
02663   DWriteStateSet(rTw, mMarkedStates);
02664   rTw << "\n";
02665   mGlobalAttribute.Write(rTw);
02666   rTw << "\n";
02667   rTw.WriteEnd(label);
02668   rTw << "\n";
02669 }
02670 
02671 // WriteAlphabet() 
02672 TEMP void THIS::WriteAlphabet(void) const {
02673   TokenWriter tw(TokenWriter::Stdout);
02674   WriteAlphabet(tw);
02675 }
02676 
02677 // AlphabetToString()
02678 TEMP std::string THIS::AlphabetToString(void) const {
02679   TokenWriter tw(TokenWriter::String);
02680   WriteAlphabet(tw);
02681   return tw.Str();
02682 }
02683 
02684 // WriteAlphabet(rTw&) 
02685 TEMP void THIS::WriteAlphabet(TokenWriter& rTw) const { 
02686   mAlphabet.Write(rTw);
02687 }
02688 
02689 // WriteStateSet(rStateSet&) 
02690 TEMP template<class OtherAttr>
02691 void THIS::WriteStateSet(const TaStateSet<OtherAttr>&  rStateSet) const {
02692   TokenWriter tw(TokenWriter::Stdout);
02693   WriteStateSet(tw,rStateSet);
02694 }
02695 
02696 // WriteStateSet(rStateSet&) 
02697 TEMP void THIS::WriteStateSet(const StateSet&  rStateSet) const {
02698   TaStateSet<AttributeVoid> vcopy = rStateSet;
02699   WriteStateSet(vcopy);
02700 }
02701 
02702 // StateSetToString()
02703 TEMP template<class OtherAttr>
02704 std::string THIS::StateSetToString(const TaStateSet<OtherAttr>&  rStateSet) const {
02705   TokenWriter tw(TokenWriter::String);
02706   WriteStateSet(tw,rStateSet);
02707   return tw.Str();
02708 }
02709 
02710 // StateSetToString()
02711 TEMP std::string THIS::StateSetToString(const StateSet&  rStateSet) const {
02712   TaStateSet<AttributeVoid> vcopy = rStateSet; 
02713   return StateSetToString(vcopy);
02714 }
02715 
02716 // WriteStateSet(rTw&, rStateSet&) 
02717 TEMP template<class OtherAttr>
02718 void THIS::WriteStateSet(TokenWriter& rTw, const TaStateSet<OtherAttr>&  rStateSet) const {
02719   rTw.WriteBegin(rStateSet.Name());
02720   // build reverse index map of states to write ( fileidx->idx )
02721   // (this ensures named states to be wtritten first; see SetMinStateIndexMap())
02722   std::map<Idx,Idx> reversemap;
02723   std::map<Idx,Idx>::const_iterator minit;
02724   StateSet::Iterator sit;
02725   for (sit = rStateSet.Begin(); sit != rStateSet.End(); ++sit) {
02726     reversemap[MinStateIndex(*sit)] = *sit;
02727   }
02728   // iterate states to write 
02729   for(minit = reversemap.begin(); minit != reversemap.end(); ++minit) {
02730     // identify anonymous block (consecutive state indices)
02731     std::map<Idx,Idx>::const_iterator conit=minit;
02732     Idx start = conit->first;
02733     Idx anoncount = 0;
02734     for(; conit != reversemap.end(); ++conit) {
02735       if(StateName(conit->second) != "") break;
02736       if(!StateAttribute(conit->second).IsDefault()) break;
02737       if(conit->first != start+anoncount) break;
02738       ++anoncount;
02739     }
02740     // write anonymous block
02741     if (anoncount > FD_CONSECUTIVE) {
02742       rTw.WriteBegin("Consecutive");
02743       rTw << start;
02744       rTw << start+anoncount-1;
02745       rTw.WriteEnd("Consecutive");
02746       minit=conit;
02747     } 
02748     // break loop
02749     if(minit == reversemap.end() )
02750       break;
02751     // write non anonymous state name/idx
02752     std::string statename = StateName(minit->second);
02753     if (statename != "") {
02754       rTw << statename;
02755     } else {
02756       rTw << minit->first;
02757     }
02758     // write state attribute
02759     OtherAttr attr=rStateSet.Attribute(minit->second);
02760     attr.Write(rTw);
02761   }
02762   rTw.WriteEnd(rStateSet.Name());
02763 }
02764 
02765 // WriteStateSet(rTw&, rStateSet&) 
02766 TEMP void THIS::WriteStateSet(TokenWriter& rTw, const StateSet&  rStateSet) const {
02767   TaStateSet<AttributeVoid> vcopy=rStateSet;
02768   WriteStateSet(rTw,vcopy);
02769 }
02770 
02771 // DWriteStateSet(rTw&, rStateSet&) 
02772 TEMP template<class OtherAttr>
02773 void THIS::DWriteStateSet(TokenWriter& rTw, const TaStateSet<OtherAttr>& rStateSet) const {
02774   rTw.WriteBegin(rStateSet.Name());
02775   StateSet::Iterator lit;
02776   std::map<Idx,Idx>::const_iterator minit;
02777   for(lit = rStateSet.Begin(); lit != rStateSet.End(); ++lit) {
02778     rTw << SStr(*lit);
02779     OtherAttr attr=rStateSet.Attribute(*lit);
02780     attr.Write(rTw);
02781   }
02782   rTw.WriteEnd(rStateSet.Name());
02783 }
02784 
02785 
02786 // DWriteStateSet(rTw&, rStateSet&) 
02787 TEMP void THIS::DWriteStateSet(TokenWriter& rTw, const StateSet&  rStateSet) const {
02788   TaStateSet<AttributeVoid> vcopy=rStateSet;
02789   DWriteStateSet(rTw,vcopy);
02790 }
02791 
02792 // StatesToString()
02793 TEMP std::string THIS::StatesToString(void) const {
02794   return StateSetToString(mStates);
02795 }
02796 
02797 // MarkedStatesToString()
02798 TEMP std::string THIS::MarkedStatesToString(void) const {
02799   return StateSetToString(mMarkedStates);
02800 }
02801 
02802 // InitStatesToString()
02803 TEMP std::string THIS::InitStatesToString(void) const {
02804   return StateSetToString(mInitStates);
02805 }
02806 
02807 
02808 // WriteTransRel() 
02809 TEMP void THIS::WriteTransRel(void) const {
02810   TokenWriter tw(TokenWriter::Stdout);
02811   WriteTransRel(tw);
02812 }
02813 
02814 // TransRelToString()
02815 TEMP std::string THIS::TransRelToString(void) const {
02816   TokenWriter tw(TokenWriter::String);
02817   WriteTransRel(tw);
02818   return tw.Str();
02819 }
02820 
02821 // WriteTransRel(rTw&)
02822 TEMP void THIS::WriteTransRel(TokenWriter& rTw) const {
02823   typename ATransSet::Iterator tit;
02824   int oldcolumns = rTw.Columns();
02825   rTw.Columns(3);
02826   rTw.WriteBegin("TransRel");
02827   bool smalltransrel = (Size() < FD_SMALLTRANSREL);
02828 
02829   for (tit = mTransRel.Begin(); tit != mTransRel.End(); ++tit) {
02830 
02831     // write x1
02832     Idx x1=MinStateIndex(tit->X1);
02833     if (smalltransrel) {
02834       std::string x1name = StateName(tit->X1);
02835       if (x1name != "") {
02836   rTw << x1name;
02837       } else {
02838   rTw << x1;
02839       }
02840     } else {
02841       rTw << x1;
02842     }
02843 
02844     // write ev
02845     rTw << EventName(tit->Ev);
02846 
02847     // write x2
02848     Idx x2=MinStateIndex(tit->X2);
02849     if (smalltransrel) {
02850       std::string x2name = StateName(tit->X2);
02851       if (x2name != "") {
02852   rTw << x2name;
02853       } else {
02854   rTw << x2;
02855       }
02856     } else {
02857       rTw << x2;
02858     }
02859 
02860     // write attributes
02861     TransAttribute(*tit).Write(rTw);
02862 
02863   }
02864   rTw.WriteEnd("TransRel");
02865   rTw.Columns(oldcolumns);
02866 }
02867 
02868 // DWriteTransRel(rTw&)
02869 TEMP void THIS::DWriteTransRel(TokenWriter& rTw) const {
02870   typename ATransSet::Iterator tit;
02871   int oldcolumns = rTw.Columns();
02872   rTw.Columns(1);
02873   rTw.WriteBegin("TransRel");
02874   for (tit = mTransRel.Begin(); tit != mTransRel.End(); ++tit) {
02875     rTw << TStr(*tit);
02876     TransAttr attr=mTransRel.Attribute(*tit);
02877     attr.Write(rTw);
02878   }
02879   rTw.WriteEnd("TransRel");
02880   rTw.Columns(oldcolumns);
02881 }
02882 
02883 
02884 
02885 // WriteStatistics() 
02886 TEMP
02887 void THIS::WriteStatistics(void) const  
02888 {
02889   TokenWriter tw(TokenWriter::Stdout);
02890   WriteStatistics(tw);
02891 }
02892 
02893 // StatisticsToString()
02894 TEMP std::string THIS::StatisticsToString(void) const {
02895   TokenWriter tw(TokenWriter::String);
02896   WriteStatistics(tw);
02897   return tw.Str();
02898 }
02899 
02900 // WriteStatistics(rTw&)
02901 TEMP void THIS::WriteStatistics(TokenWriter& rTw) const
02902 {
02903   rTw.WriteComment("");
02904   rTw.WriteComment(" Statistics for " + Name());
02905   rTw.WriteComment(" States:        " + ToStringInteger(Size()) );
02906   rTw.WriteComment(" Init/Marked:   " + ToStringInteger(mInitStates.Size()) 
02907         + "/" + ToStringInteger(mMarkedStates.Size()));
02908   rTw.WriteComment(" Events:        " + ToStringInteger(mAlphabet.Size()) );
02909   rTw.WriteComment(" Transitions:   " + ToStringInteger(mTransRel.Size()) );
02910   rTw.WriteComment(" StateSymbols:  " + ToStringInteger(mpStateSymbolTable->Size()) );
02911   rTw.WriteComment(" Attrib. E/S/T: " + ToStringInteger(mAlphabet.AttributesSize()) 
02912         + "/" + ToStringInteger(mStates.AttributesSize())
02913         + "/" + ToStringInteger(mTransRel.AttributesSize()) );
02914   rTw.WriteComment("");
02915 }
02916 
02917 // DotWrite(rFileName)
02918 TEMP void THIS::DotWrite(const std::string& rFileName) {
02919   FD_DG("TaGenerator(" << this << ")::DotWrite(" << rFileName << ")");
02920   SetMinStateIndexMap();
02921   StateSet::Iterator lit;
02922   typename ATransSet::Iterator tit;
02923   try {
02924     std::ofstream stream;
02925     stream.exceptions(std::ios::badbit|std::ios::failbit);
02926     stream.open(rFileName.c_str());
02927     stream << "digraph \"" << Name() << "\" {" << std::endl;
02928     stream << "  rankdir=LR" << std::endl;
02929     stream << "  node [shape=circle];" << std::endl;
02930     stream << std::endl;
02931     stream << "  // istates" << std::endl;
02932     int i = 1;
02933     for (lit = InitStatesBegin(); lit != InitStatesEnd(); ++lit) {
02934       std::string xname= StateName(*lit);
02935       if(xname=="") xname=ToStringInteger(MinStateIndex(*lit));
02936       stream << "  dot_dummyinit_" << i << " [shape=none, label=\"\" ];" << std::endl;
02937       stream << "  dot_dummyinit_" << i << " -> \"" << xname << "\";" << std::endl; 
02938       i++;
02939     }
02940     stream << std::endl;
02941     stream << "  // mstates" << std::endl;
02942     for (lit = MarkedStatesBegin(); lit != MarkedStatesEnd(); ++lit) {
02943       std::string xname= StateName(*lit);
02944       if(xname=="") xname=ToStringInteger(MinStateIndex(*lit));
02945       stream << "  \"" << xname << "\" [shape=doublecircle];" << std::endl;
02946     }
02947     stream << std::endl;
02948     stream << "  // rest of stateset" << std::endl;
02949     for (lit = StatesBegin(); lit != StatesEnd(); ++lit) {
02950       if (! (ExistsInitState(*lit) || ExistsMarkedState(*lit)) ) {
02951   std::string xname= StateName(*lit);
02952   if(xname=="") xname=ToStringInteger(MinStateIndex(*lit));
02953   stream << "  \"" << xname << "\";" << std::endl;
02954       }
02955     }
02956     stream << std::endl;
02957     stream << "  // transition relation" << std::endl;
02958     for (tit = TransRelBegin(); tit != TransRelEnd(); ++tit) {
02959       std::string x1name= StateName(tit->X1);
02960       if(x1name=="") x1name=ToStringInteger(MinStateIndex(tit->X1));
02961       std::string x2name= StateName(tit->X2);
02962       if(x2name=="") x2name=ToStringInteger(MinStateIndex(tit->X2));
02963       stream << "  \"" << x1name  << "\" -> \"" << x2name
02964        << "\" [label=\"" << EventName(tit->Ev) << "\"];" << std::endl;
02965     }
02966     stream << "};" << std::endl;
02967     stream.close();
02968   }
02969   catch (std::ios::failure&) {
02970     throw Exception("TaGenerator::DotWrite", 
02971         "Exception opening/writing dotfile \""+rFileName+"\"", 2);
02972   }
02973   ClearMinStateIndexMap();
02974 }
02975 
02976 // DDotWrite(rFileName)
02977 TEMP void THIS::DDotWrite(const std::string& rFileName) const {
02978   FD_DG("TaGenerator(" << this << ")::DDotWrite(" << rFileName << ")");
02979   StateSet::Iterator lit;
02980   typename ATransSet::Iterator tit;
02981   try {
02982     std::ofstream stream;
02983     stream.exceptions(std::ios::badbit|std::ios::failbit);
02984     stream.open(rFileName.c_str());
02985     stream << "digraph \"" << Name() << "\" {" << std::endl;
02986     stream << "  rankdir=LR" << std::endl;
02987     stream << "  node [shape=circle];" << std::endl;
02988     stream << std::endl;
02989     stream << "  // istates" << std::endl;
02990     int i = 1;
02991     for (lit = InitStatesBegin(); lit != InitStatesEnd(); ++lit) {
02992       stream << "  dot_dummyinit_" << i << " [shape=none, label=\"\" ];" << std::endl;
02993       stream << "  dot_dummyinit_" << i << " -> \"" 
02994        << SStr(*lit)  << "\";" << std::endl; 
02995       i++;
02996     }
02997     stream << std::endl;
02998     stream << "  // mstates" << std::endl;
02999     for (lit = MarkedStatesBegin(); lit != MarkedStatesEnd(); ++lit) {
03000       stream << "  \"" << SStr(*lit) << "\" [shape=doublecircle];" << std::endl;
03001     }
03002     stream << std::endl;
03003     stream << "  // rest of stateset" << std::endl;
03004     for (lit = StatesBegin(); lit != StatesEnd(); ++lit) {
03005       // if not in mInitStates or mMarkedStates
03006       if (! (ExistsInitState(*lit) || ExistsMarkedState(*lit)) ) {
03007   stream << "  \"" << SStr(*lit) << "\";" << std::endl;
03008       }
03009     }
03010     stream << std::endl;
03011     stream << "  // transition relation" << std::endl;
03012     for (tit = TransRelBegin(); tit != TransRelEnd(); ++tit) {
03013       stream << "  \"" << SStr(tit->X1) 
03014        << "\" -> \"" << SStr(tit->X2)
03015        << "\" [label=\"" << EventName(tit->Ev) << "\"];" << std::endl;
03016     }
03017     stream << "};" << std::endl;
03018     stream.close();
03019   }
03020   catch (std::ios::failure&) {
03021     throw Exception("TaGenerator::DotWrite", 
03022         "Exception opening/writing dotfile \""+rFileName+"\"", 2);
03023   }
03024 }
03025 
03026 
03027 // XDotWrite(rFileName)
03028 TEMP void THIS::XDotWrite(const std::string& rFileName) const {
03029   FD_DG("TaGenerator(" << this << ")::XDotWrite(" << rFileName << ")");
03030   StateSet::Iterator lit;
03031   typename ATransSet::Iterator tit;
03032   try {
03033     std::ofstream stream;
03034     stream.exceptions(std::ios::badbit|std::ios::failbit);
03035     stream.open(rFileName.c_str());
03036     stream << "digraph \"___" << Name() << "___\" {" << std::endl;
03037     stream << "  rankdir=LR" << std::endl;
03038     stream << "  node [shape=circle];" << std::endl;
03039     stream << std::endl;
03040     stream << "  // stateset" << std::endl;
03041     for (lit = StatesBegin(); lit != StatesEnd(); ++lit) {
03042       stream << "  \"s" << *lit << "\";" << std::endl;
03043     }
03044     stream << std::endl;
03045     stream << "  // transition relation" << std::endl;
03046     for (tit = TransRelBegin(); tit != TransRelEnd(); ++tit) {
03047       stream << "  \"s" << tit->X1 
03048        << "\" -> \"s" << tit->X2
03049        << "\" [label=\"e" << tit->Ev << "\" " << "polyline" << "];" << std::endl;
03050     }
03051     stream << "};" << std::endl;
03052     stream.close();
03053   }
03054   catch (std::ios::failure&) {
03055     throw Exception("TaGenerator::XDotWrite", 
03056         "Exception opening/writing dotfile \""+rFileName+"\"", 2);
03057   }
03058 }
03059 
03060 // DoRead(tr)
03061 TEMP void THIS::DoRead(TokenReader& rTr,  const std::string& rLabel, const Type* pContext) {
03062   (void) pContext;
03063   std::string label=rLabel;
03064   if(label=="") label="Generator"; 
03065   FD_DG("TaGenerator(" << this << ")::DoRead(): file " << rTr.FileName() << "  section " << label);
03066   // Clear old stuff
03067   Clear();
03068   // find Genertor in any of our current file formats
03069   rTr.SeekBegin(label);
03070   // get the Generator "name" token
03071   ReadGeneratorName(rTr);
03072   // read mAlphabet
03073   ReadAlphabet(rTr);
03074   // read stateset
03075   ReadStates(rTr);
03076   // read transrel
03077   ReadTransRel(rTr);
03078   // read istates
03079   ReadStateSet(rTr, "InitStates", mInitStates);
03080   // read mstates
03081   ReadStateSet(rTr, "MarkedStates", mMarkedStates);
03082   // read attribute
03083   mGlobalAttribute.Read(rTr);
03084   // read end 
03085   rTr.SeekEnd(label);
03086   FD_DG("TaGenerator(" << this << ")::DoRead(): done");
03087 }
03088 
03089 // ReadGeneratorName(rFileName)
03090 TEMP void THIS::ReadGeneratorName(const std::string& rFileName) {
03091   TokenReader tr(rFileName);
03092   tr.SeekBegin("Generator");  // mimique old behaviour .. use "ReadBegin" instead   
03093   ReadGeneratorName(tr);
03094 }
03095 
03096 // ReadGeneratorName(tr)
03097 TEMP void THIS::ReadGeneratorName(TokenReader& rTr) {
03098   FD_DG("TaGenerator(" << this << ")::ReadGeneratorName(\"" 
03099   << rTr.FileName() << "\")");
03100    mMyName=rTr.ReadString();
03101 }
03102 
03103 // ReadAlphabet(rFileName)
03104 TEMP void THIS::ReadAlphabet(const std::string& rFileName) {
03105   FD_DG("TaGenerator(" << this << ")::ReadAlphabet(\"" << rFileName << "\")");
03106   mAlphabet.Read(rFileName,"Alphabet");
03107 }
03108 
03109 // ReadAlphabet(rTr) 
03110 TEMP void THIS::ReadAlphabet(TokenReader& rTr) {
03111   FD_DG("TaGenerator(" << this << ")::ReadAlphabet(\"" 
03112   << rTr.FileName() << "\")");
03113   mAlphabet.Read(rTr,"Alphabet");
03114 }
03115 
03116 // ReadStates(rFileName) 
03117 TEMP void THIS::ReadStates(const std::string& rFileName) {
03118   TokenReader tr(rFileName);
03119   ReadStates(tr);
03120 }
03121 
03122 // ReadStates(tr) 
03123 TEMP void THIS::ReadStates(TokenReader& rTr) {
03124   FD_DG("TaGenerator(" << this << ")::ReadStates(\"" << rTr.FileName() << "\")");
03125   // HELPERS:
03126   Token token;
03127   // ALGORITHM:
03128   mStates.Clear();
03129   mStates.Name("States");
03130   mStateSymbolTable.Clear();
03131   rTr.SeekBegin("States");  
03132   while(rTr.Peek(token)) {
03133     // break end of section
03134     if (token.Type() == Token::End) {
03135       break;
03136     }
03137     // read state by index
03138     if (token.Type() == Token::Integer) {
03139       rTr.Get(token);
03140       Idx index = token.IntegerValue();
03141       FD_DG("TaGenerator(" << this << ")::ReadStates(\"" << rTr.FileName() << "\"): by index " << index);
03142       if(mStates.Exists(index)) {
03143   std::stringstream errstr;
03144   errstr << "Token " << token.IntegerValue() << " appears twice in stateset"
03145          << rTr.FileLine();
03146   throw Exception("TaGenerator::ReadStates", errstr.str(), 80);
03147       }
03148       StateAttr sattr;
03149       sattr.Read(rTr);
03150       InsState(index,sattr);
03151       continue;
03152     } 
03153     // read state by name
03154     if (token.Type() == Token::String) {
03155       rTr.Get(token);
03156       FD_DG("TaGenerator(" << this << ")::ReadStates(\"" << rTr.FileName() << "\"): by name " << token.StringValue());
03157       if(ExistsState(token.StringValue())) {
03158   std::stringstream errstr;
03159   errstr << "Token " << token.StringValue() << " appears twice in stateset"
03160          << rTr.FileLine();
03161   throw Exception("TaGenerator::ReadStates", errstr.str(), 80);
03162       }
03163       StateAttr sattr;
03164       sattr.Read(rTr);
03165       InsState(token.StringValue(),sattr);
03166       continue;
03167     } 
03168     // read consecutive block of anonymous states
03169     if (token.Type() == Token::Begin && token.StringValue() == "Consecutive") {
03170       rTr.ReadBegin("Consecutive");
03171       Token token1,token2;
03172       rTr.Get(token1);
03173       rTr.Get(token2);
03174       FD_DG("TaGenerator(" << this << ")::ReadStates(\"" << rTr.FileName() << "\"): consecutive range");
03175       if ((token1.Type() != Token::Integer) || (token2.Type() != Token::Integer)) {
03176   std::stringstream errstr;
03177   errstr << "Invalid range of consecutive states"  << rTr.FileLine();
03178   throw Exception("TaGenerator::ReadStates", errstr.str(), 80);
03179       }
03180       for(Idx index = (Idx) token1.IntegerValue(); index <= (Idx) token2.IntegerValue(); ++index) {
03181   if(mStates.Exists(index)) {
03182     std::stringstream errstr;
03183     errstr << "Index " << index << " appears twice in stateset"
03184      << rTr.FileLine();
03185     throw Exception("TaGenerator::ReadStates", errstr.str(), 80);
03186   }
03187   InsState(index);
03188       }
03189       rTr.ReadEnd("Consecutive");
03190       continue;
03191     }
03192     // cannot process token
03193     std::stringstream errstr;
03194     errstr << "Invalid token" << rTr.FileLine();
03195     throw Exception("TaGenerator::ReadStates", errstr.str(), 80);
03196   }
03197   rTr.SeekEnd("States");
03198   FD_DG("TaGenerator(" << this << ")::ReadStates(\"" << rTr.FileName() << "\"): done");
03199 }
03200 
03201 
03202 // ReadStateSet(tr, rLabel, rStateSet) 
03203 TEMP void THIS::ReadStateSet(TokenReader& rTr, const std::string& rLabel, StateSet& rStateSet)  const {
03204   FD_DG("TaGenerator(" << this << ")::ReadStateSet(\"" << rLabel<< "\")");
03205   // HELPERS:
03206   Token token;
03207   // ALGORITHM:
03208   rStateSet.Clear();
03209   rTr.SeekBegin(rLabel);  
03210   rStateSet.Name(rLabel);
03211   while(rTr.Peek(token)) {
03212     // break end of section
03213     if (token.Type() == Token::End) {
03214       break;
03215     }
03216     // read state by index
03217     if (token.Type() == Token::Integer) {
03218       rTr.Get(token);
03219       Idx index = token.IntegerValue();
03220       if(!ExistsState(index)) {
03221   std::stringstream errstr;
03222   errstr << "Token " << token.IntegerValue() << " not in stateset"
03223          << rTr.FileLine();
03224   throw Exception("TaGenerator::ReadStateSet", errstr.str(), 80);
03225       }
03226       AttributeVoid vattr;
03227       vattr.Read(rTr);
03228       rStateSet.Insert(index);
03229       continue;
03230     } 
03231     // read state by name
03232     if (token.Type() == Token::String) {
03233       rTr.Get(token);
03234       Idx index =StateIndex(token.StringValue());
03235       if(index==0) {
03236   std::stringstream errstr;
03237   errstr << "Token " << token.StringValue() << " not in stateset"
03238          << rTr.FileLine();
03239   throw Exception("TaGenerator::ReadStateSet", errstr.str(), 80);
03240       }
03241       AttributeVoid vattr;
03242       vattr.Read(rTr);
03243       rStateSet.Insert(index);
03244       continue;
03245     } 
03246     // read consecutve block of anonymous states
03247     if (token.Type() == Token::Begin && token.StringValue() == "Consecutive") {
03248       rTr.ReadBegin("Consecutive");
03249       Token token1,token2;
03250       rTr.Get(token1);
03251       rTr.Get(token2);
03252       if ((token1.Type() != Token::Integer) || (token2.Type() != Token::Integer)) {
03253   std::stringstream errstr;
03254   errstr << "Invalid range of consecutive states"  << rTr.FileLine();
03255   throw Exception("TaGenerator::ReadStateSet", errstr.str(), 80);
03256       }
03257       for(Idx index = (Idx) token1.IntegerValue(); index <= (Idx) token2.IntegerValue(); ++index) {
03258   if(!ExistsState(index)) {
03259     std::stringstream errstr;
03260     errstr << "Token " << token.IntegerValue() << " not in stateset"
03261      << rTr.FileLine();
03262     throw Exception("TaGenerator::ReadStateSet", errstr.str(), 80);
03263   }
03264   rStateSet.Insert(index);
03265       }
03266       rTr.ReadEnd("Consecutive");
03267       continue;
03268     }
03269     // cannot process token
03270     std::stringstream errstr;
03271     errstr << "Invalid token" << rTr.FileLine();
03272     throw Exception("TaGenerator::ReadStateSet", errstr.str(), 50);
03273   }
03274   rTr.SeekEnd(rLabel);
03275 }
03276 
03277 // ReadTransRel(rFileName)
03278 TEMP void THIS::ReadTransRel(const std::string& rFileName) {
03279   TokenReader tr(rFileName);
03280   ReadTransRel(tr);
03281 }
03282 
03283 // ReadTransRel(tr) 
03284 TEMP void THIS::ReadTransRel(TokenReader& rTr) {
03285   FD_DG("TaGenerator(" << this << ")::ReadTransRel(\"" << rTr.FileName() << "\")");
03286   try {
03287     Token token;
03288     Idx x1 = 0, ev = 0, x2 = 0;
03289     rTr.SeekBegin("TransRel");
03290     // Read tokens
03291     while (rTr.Peek(token)) {
03292       // 0: end of transition relation
03293       if ((token.Type() == Token::End)) break;
03294 
03295       // 1: the x1 token
03296       rTr >> token;
03297       if (token.Type() == Token::Integer) {
03298   x1=token.IntegerValue();
03299       } else if (token.Type() == Token::String) {
03300   token.StringValue();
03301   x1=StateIndex(token.StringValue());
03302       } else break;
03303 
03304       // 2: the event token
03305       rTr >> token;
03306       if (token.Type() == Token::Integer) {
03307   ev=token.IntegerValue();
03308       } else if (token.Type() == Token::String) {
03309   token.StringValue();
03310   ev=EventIndex(token.StringValue());
03311       } else break;
03312 
03313       // 3: the x1 token
03314       rTr >> token;
03315       if (token.Type() == Token::Integer) {
03316   x2=token.IntegerValue();
03317       } else if (token.Type() == Token::String) {
03318   token.StringValue();
03319   x2=StateIndex(token.StringValue());
03320       } else break;
03321 
03322       // 4: attributes
03323       TransAttr attr; 
03324       attr.Read(rTr);       
03325 
03326       // check values
03327       if( (!ExistsState(x1)) || (!ExistsState(x2)) ){
03328   std::stringstream errstr;
03329   errstr << "invalid state" << rTr.FileLine();
03330   throw Exception("TaGenerator::ReadTransRel", errstr.str(), 85);
03331       } 
03332       if(!ExistsEvent(ev)) {
03333   std::stringstream errstr;
03334   errstr << "invalid event" << rTr.FileLine();
03335   throw Exception("TaGenerator::ReadTransRel", errstr.str(), 85);
03336       } 
03337 
03338       // insert transition
03339       SetTransition(Transition(x1, ev, x2),attr);
03340 
03341     } // end while
03342     rTr.SeekEnd("TransRel");   
03343   }
03344   catch (faudes::Exception&) {
03345     std::stringstream errstr;
03346     errstr << "Reading TransRel failed in " << rTr.FileLine();
03347     throw Exception("TaGenerator::ReadTransRel", errstr.str(), 50); 
03348   }
03349   FD_DG("TaGenerator(" << this << ")::ReadTransRel(\"" << rTr.FileName() << "\"): sone");
03350 }
03351 
03352 // Valid()
03353 TEMP bool THIS::Valid(void) {
03354   FD_DG("TaGenerator(" << this << ")::Valid()");
03355   typename ATransSet::Iterator tit;
03356   StateSet::Iterator lit;
03357   for (tit = TransRelBegin(); tit != TransRelEnd(); ++tit) {
03358     if (! ExistsState(tit->X1)) return false;
03359     if (! ExistsEvent(tit->Ev)) return false;
03360     if (! ExistsState(tit->X2)) return false;
03361   }
03362   for (lit = InitStatesBegin(); lit != InitStatesEnd(); ++lit) {
03363     if (! ExistsState(static_cast<Idx>(*lit))) return false;
03364   }
03365   for (lit = MarkedStatesBegin(); lit != MarkedStatesEnd(); ++lit) {
03366     if (! ExistsState(static_cast<Idx>(*lit))) return false;
03367   }
03368   if (mAlphabet.Name() != "Alphabet") return false;
03369   if (mStates.Name() != "States") return false;
03370   if (mInitStates.Name() != "InitStates") return false;
03371   if (mMarkedStates.Name() != "MarkedStates") return false;
03372   return true;
03373 }
03374 
03375 // AlphabetSize()
03376 TEMP Idx THIS::AlphabetSize(void) const {
03377   return mAlphabet.Size();
03378 }
03379 
03380 // Size()
03381 TEMP Idx THIS::Size(void) const {
03382   return mStates.Size();
03383 }
03384 
03385 // virtual
03386 // Clear()
03387 TEMP void THIS::Clear(void) {
03388   FD_DG("TaGenerator(" << this << ")::Clear()");
03389   mAlphabet.Clear();
03390   mStates.Clear();
03391   BASE::mpStateSymbolTable->Clear();
03392   mTransRel.Clear();
03393   mInitStates.Clear();
03394   mMarkedStates.Clear();
03395   ClearGlobalAttribute();
03396 }
03397 
03398 // ClearGlobalAttribute()
03399 TEMP void THIS::ClearGlobalAttribute(void) {
03400   mGlobalAttribute = GlobalAttr();
03401 }
03402 
03403 // ClearStateAttributes()
03404 TEMP void THIS::ClearStateAttributes(void) {
03405   mStates.ClearAttributes();
03406 }
03407 
03408 // ClearEventAttributes()
03409 TEMP void THIS::ClearEventAttributes(void) {
03410   mAlphabet.ClearAttributes();
03411 }
03412 
03413 // ClearTransAttributes()
03414 TEMP void THIS::ClearTransAttributes(void) {
03415   mTransRel.ClearAttributes();
03416 }
03417 
03418 // ClearAttributes()
03419 TEMP void THIS::ClearAttributes(void) {
03420   ClearGlobalAttribute();
03421   ClearStateAttributes();
03422   ClearEventAttributes();
03423   ClearTransAttributes();
03424 }
03425 
03426 
03427 // ClearStates()
03428 TEMP void THIS::ClearStates(void) {
03429   mStates.Clear();
03430   mTransRel.Clear();
03431   mInitStates.Clear();
03432   mMarkedStates.Clear();
03433   mpStateSymbolTable->Clear();
03434 }
03435 
03436 // TransRelSize()
03437 TEMP Idx THIS::TransRelSize(void) const {
03438   return mTransRel.Size();
03439 }
03440 
03441 // InitStatesSize()
03442 TEMP Idx THIS::InitStatesSize(void) const {
03443   return mInitStates.Size();
03444 }
03445 
03446 // MarkedStatesSize()
03447 TEMP Idx THIS::MarkedStatesSize(void) const {
03448   return mMarkedStates.Size();
03449 }
03450 
03451 // AlphabetEmpty()
03452 TEMP bool THIS::AlphabetEmpty(void) const {
03453   return mAlphabet.Empty();
03454 }
03455 
03456 // Empty()
03457 TEMP bool THIS::Empty(void) const {
03458   return mStates.Empty();
03459 }
03460 
03461 // TransRelEmpty()
03462 TEMP bool THIS::TransRelEmpty(void) const {
03463   return mTransRel.Empty();
03464 }
03465 
03466 // InitStatesEmpty()
03467 TEMP bool THIS::InitStatesEmpty(void) const {
03468   return mInitStates.Empty();
03469 }
03470 
03471 // MarkedStatesEmpty()
03472 TEMP bool THIS::MarkedStatesEmpty(void) const {
03473   return mMarkedStates.Empty();
03474 }
03475 
03476 // iterator AlphabetBegin() const
03477 TEMP EventSet::Iterator THIS::AlphabetBegin(void) const {
03478   return mAlphabet.Begin();
03479 }
03480 
03481 // iterator AlphabetEnd() const
03482 TEMP EventSet::Iterator THIS::AlphabetEnd(void) const {
03483   return mAlphabet.End();
03484 }
03485 
03486 // iterator StatesBegin() const
03487 TEMP StateSet::Iterator THIS::StatesBegin(void) const {
03488   return mStates.Begin();
03489 }
03490 
03491 // iterator StatesEnd() const
03492 TEMP StateSet::Iterator THIS::StatesEnd(void) const {
03493   return mStates.End();
03494 }
03495 
03496 // iterator TransRelBegin() const
03497 TEMP typename THIS::ATransSet::Iterator 
03498 THIS::TransRelBegin(void) const {
03499   return mTransRel.Begin();
03500 }
03501 
03502 // iterator TransRelEnd() const
03503 TEMP typename THIS::ATransSet::Iterator 
03504 THIS::TransRelEnd(void) const {
03505   return mTransRel.End();
03506 }
03507 
03508 // iterator TransRelBegin(x1) const
03509 TEMP typename THIS::ATransSet::Iterator 
03510 THIS::TransRelBegin(Idx x1) const {
03511   return mTransRel.Begin(x1);
03512 }
03513 
03514 // iterator TransRelEnd(x1) const
03515 TEMP typename THIS::ATransSet::Iterator 
03516 THIS::TransRelEnd(Idx x1) const {
03517   return mTransRel.End(x1);
03518 }
03519 
03520 // iterator TransRelBegin(x1, ev) const
03521 TEMP typename THIS::ATransSet::Iterator 
03522 THIS::TransRelBegin(Idx x1, Idx ev) const {
03523   return mTransRel.Begin(x1, ev);
03524 }
03525 
03526 // iterator TransRelEnd(x1, ev) const
03527 TEMP typename THIS::ATransSet::Iterator 
03528 THIS::TransRelEnd(Idx x1, Idx ev) const {
03529   return mTransRel.End(x1, ev);
03530 }
03531 
03532 // iterator FindTransition(trans)
03533 TEMP typename THIS::ATransSet::Iterator 
03534 THIS::FindTransition(const Transition& rTrans) const {
03535   return mTransRel.Find(rTrans);
03536 }
03537 
03538 // iterator FindTransition(x1, ex x2)
03539 TEMP typename THIS::ATransSet::Iterator 
03540 THIS::FindTransition(Idx x1, Idx ev, Idx x2) const {
03541   return mTransRel.Find(Transition(x1, ev, x2));
03542 }
03543 
03544 // iterator FindTransition(x1, ev, x2)
03545 TEMP typename THIS::ATransSet::Iterator THIS::FindTransition(
03546                 const std::string& rX1, const std::string& rEv, const std::string& rX2) const 
03547 {
03548   return mTransRel.Find(StateIndex(rX1), EventIndex(rEv), StateIndex(rX2));
03549 }
03550 
03551 // iterator ExistsTransition(trans)
03552 TEMP bool THIS::ExistsTransition(const Transition& rTrans) const {
03553   return mTransRel.Exists(rTrans);
03554 }
03555 
03556 // iterator ExistsTransition(x1, ex x2)
03557 TEMP bool THIS::ExistsTransition(Idx x1, Idx ev, Idx x2) const {
03558   return mTransRel.Exists(Transition(x1, ev, x2));
03559 }
03560 
03561 // iterator ExistsTransition(x1, ev, x2)
03562 TEMP bool THIS::ExistsTransition(
03563          const std::string& rX1, const std::string& rEv, const std::string& rX2) const 
03564 {
03565   return mTransRel.Exists(StateIndex(rX1), EventIndex(rEv), StateIndex(rX2));
03566 }
03567 
03568 
03569 // idx InitState() const
03570 TEMP Idx THIS::InitState(void) const {
03571 #ifdef FAUDES_CHECKED
03572   if(mInitStates.Size()!=1) {    
03573     std::stringstream errstr;
03574     errstr << "init state does not exist uniquely" << std::endl;
03575     throw Exception("TaGenerator::InitSTate", errstr.str(), 92);
03576   }
03577 #endif
03578   return *mInitStates.Begin();
03579 }
03580 
03581 // iterator InitStatesBegin() const
03582 TEMP StateSet::Iterator THIS::InitStatesBegin(void) const {
03583   return mInitStates.Begin();
03584 }
03585 
03586 // iterator InitStatesEnd() const
03587 TEMP StateSet::Iterator THIS::InitStatesEnd(void) const {
03588   return mInitStates.End();
03589 }
03590 
03591 // iterator MarkedStatesBegin()
03592 TEMP StateSet::Iterator THIS::MarkedStatesBegin(void) const {
03593   return mMarkedStates.Begin();
03594 }
03595 
03596 // iterator MarkedStatesEnd() const
03597 TEMP StateSet::Iterator THIS::MarkedStatesEnd(void) const {
03598   return mMarkedStates.End(); 
03599 }
03600 
03601 // InjectAlphabet(newalphabet)
03602 TEMP void THIS::InjectAlphabet(const EventSet& newalphabet) {
03603   FD_DG("TaGenerator::InjectAlphabet()  " << newalphabet.ToString());
03604 #ifdef FAUDES_CHECKED
03605   if(newalphabet.SymbolTablep()!=mpEventSymbolTable) {
03606     std::stringstream errstr;
03607     errstr << "symboltable mismatch aka not implemented" << std::endl;
03608     throw Exception("TaGenerator::InjectAlphabet", errstr.str(), 88);
03609   }
03610 #endif
03611   mAlphabet = newalphabet;
03612   mAlphabet.Name("Alphabet");
03613 }
03614 
03615 // InjectAlphabet(newalphabet)
03616 TEMP void THIS::InjectAlphabet(const TaEventSet<EventAttr>& newalphabet) {
03617   FD_DG("TaGenerator::InjectAlphabet(TaEventSet<EventAttr>)  " << newalphabet.ToString());
03618 #ifdef FAUDES_CHECKED
03619   if(newalphabet.SymbolTablep()!=mpEventSymbolTable) {
03620     std::stringstream errstr;
03621     errstr << "symboltable mismatch aka not implemented" << std::endl;
03622     throw Exception("TaGenerator::InjectAlphabet", errstr.str(), 88);
03623   }
03624 #endif
03625   mAlphabet = newalphabet;
03626   mAlphabet.Name("Alphabet");
03627 }
03628 
03629 // InsEvent(index)
03630 TEMP bool THIS::InsEvent(Idx index) {
03631   FD_DG("TaGenerator(" << this << ")::InsEvent(" << index << ")");
03632   return mAlphabet.Insert(index);
03633 }
03634 
03635 // InsEvent(rName)
03636 TEMP Idx THIS::InsEvent(const std::string& rName) {
03637   FD_DG("TaGenerator(" << this << ")::InsEvent(\"" << rName << "\")");
03638   return mAlphabet.Insert(rName);
03639 }
03640 
03641 // InsEvent(index, attr)
03642 TEMP bool THIS::InsEvent(Idx index, const EventAttr& attr) {
03643   FD_DG("TaGenerator(" << this << ")::InsEvent(" << index << " " << attr.ToString() << ")");
03644   return mAlphabet.Insert(index, attr);
03645 }
03646 
03647 // InsEvent(rName)
03648 TEMP Idx THIS::InsEvent(const std::string& rName, const EventAttr& attr) {
03649   FD_DG("TaGenerator(" << this << ")::InsEvent(\"" << rName << attr.ToString() << "\")");
03650   return mAlphabet.Insert(rName, attr);
03651 }
03652 
03653 // InsEvents(events)
03654 TEMP void THIS::InsEvents(const EventSet& events) {
03655   mAlphabet.InsertSet(events);
03656 }
03657 
03658 // DelEvent(index)
03659 TEMP bool THIS::DelEvent(Idx index) {
03660   FD_DG("TaGenerator(" << this << ")::DelEvent(" << index << ")");
03661   mTransRel.EraseByEv(index);
03662   return mAlphabet.Erase(index);
03663 }
03664 
03665 // DelEvent(rName)
03666 TEMP bool THIS::DelEvent(const std::string& rName) {
03667   FD_DG("TaGenerator(" << this << ")::DelEvent(\"" << rName << "\")");
03668   Idx index = mAlphabet.Index(rName);
03669   mTransRel.EraseByEv(index);
03670   return mAlphabet.Erase(index);
03671 }
03672 
03673 // DelEvents(events)
03674 TEMP void THIS::DelEvents(const EventSet& rEvents) {
03675   FD_DG("TaGenerator(" << this << ")::DelEvents(\"" 
03676   << rEvents.ToString() << "\")");
03677   EventSet::Iterator it;
03678   for (it = rEvents.Begin(); it != rEvents.End(); ++it) {
03679     DelEvent(*it);
03680   }
03681 }
03682 
03683 // DelEventFromAlphabet(index)
03684 TEMP bool THIS::DelEventFromAlphabet(Idx index) {
03685   FD_DG("TaGenerator(" << this << ")::DelEventFromAlphabet(" 
03686   << index << ")");
03687   return mAlphabet.Erase(index);
03688 }
03689 
03690 // InsState()
03691 TEMP Idx THIS::InsState(void) {
03692   FD_DG("TaGenerator(" << this << ")::InsState()");
03693   return mStates.Insert();
03694 }
03695 
03696 // InsState(index)
03697 TEMP bool THIS::InsState(Idx index) {
03698   FD_DG("TaGenerator(" << this << ")::InsState(" << index << ")");
03699   return mStates.Insert(index);
03700 }
03701 
03702 // InsState(index, attr)
03703 TEMP bool THIS::InsState(Idx index, const StateAttr& attr) {
03704   FD_DG("TaGenerator(" << this << ")::InsState(" << index << ",attr)");
03705   return mStates.Insert(index,attr);
03706 }
03707 
03708 // InsState(rName)
03709 TEMP Idx THIS::InsState(const std::string& rName) {
03710   FD_DG("TaGenerator(" << this << ")::InsState(\"" << rName << "\")");
03711   Idx index=mStates.Insert();
03712   StateName(index,rName);
03713   return index;
03714 }
03715 
03716 // InsState(rName, attr)
03717 TEMP Idx THIS::InsState(const std::string& rName, const StateAttr& attr) {
03718   FD_DG("TaGenerator(" << this << ")::InsState(\"" << rName << "\", attr)");
03719   Idx index=mStates.Insert();
03720   StateName(index,rName);
03721   StateAttribute(index,attr);
03722   return index;
03723 }
03724 
03725 
03726 // InjectState(index)
03727 TEMP void THIS::InjectState(Idx index) {
03728   FD_DG("TaGenerator(" << this << ")::InjectState(\"" 
03729   << SStr(index) << "\")");
03730   mStates.Insert(index);
03731 }
03732 
03733 // InjectStates(rNewStates)
03734 TEMP void THIS::InjectStates(const StateSet& rNewStates) {
03735   FD_DG("TaGenerator(" << this << ")::InjectStates(" 
03736   << rNewStates.ToString() << ")");
03737   mStates = rNewStates;
03738   mStates.Name("States");
03739 }
03740 
03741 // InsInitState()
03742 TEMP Idx THIS::InsInitState(void) {
03743   FD_DG("TaGenerator(" << this << ")::InsInitState()");
03744   Idx index;
03745   index = InsState();
03746   mInitStates.Insert(index);
03747   return index;
03748 }
03749 
03750 // InsInitState(name)
03751 TEMP Idx THIS::InsInitState(const std::string& rName) {
03752   FD_DG("TaGenerator(" << this << ")::InsInitState(\"" << rName << "\")");
03753   Idx index;
03754   index = InsState(rName);
03755   mInitStates.Insert(index);
03756   return index;
03757 }
03758 
03759 // InsMarkedState()
03760 TEMP Idx THIS::InsMarkedState(void) {
03761   FD_DG("TaGenerator(" << this << ")::InsMarkedState()");
03762   Idx index;
03763   index = InsState();
03764   mMarkedStates.Insert(index);
03765   return index;
03766 }
03767 
03768 // InsMarkedState(rName)
03769 TEMP Idx THIS::InsMarkedState(const std::string& rName) {
03770   FD_DG("TaGenerator(" << this << ")::InsMarkedState(\"" << rName << "\")");
03771   Idx index;
03772   index = InsState(rName);
03773   mMarkedStates.Insert(index);
03774   return index;
03775 }
03776 
03777 // DelState(index)
03778 TEMP bool THIS::DelState(Idx index) {
03779   FD_DG("TaGenerator(" << this << ")::DelState(" << index << ")");
03780   // mInitStates
03781   mInitStates.Erase(index);
03782   // mstates
03783   mMarkedStates.Erase(index);
03784   // transrel 
03785   mTransRel.EraseByX1OrX2(index);
03786   // mStates + global
03787   mStateSymbolTable.ClrEntry(index);
03788   return mStates.Erase(index);
03789 }
03790 
03791 // DelState(rName)
03792 TEMP bool THIS::DelState(const std::string& rName) {
03793   FD_DG("TaGenerator(" << this << ")::DelState(\"" << rName << "\")");
03794   Idx index;
03795   index = StateIndex(rName);
03796 #ifdef FAUDES_CHECKED
03797   if (index == 0) {
03798     std::stringstream errstr;
03799     errstr << "state name \"" << rName << "\" not found in generator \""
03800      << Name() << "\"";
03801     throw Exception("TaGenerator::DelState(name)", errstr.str(), 90);
03802   }
03803 #endif
03804   return DelState(index);
03805 }
03806 
03807 // DelStates(rDelStates)
03808 TEMP void THIS::DelStates(const StateSet& rDelStates) {
03809   FD_DG("TaGenerator(" << this << ")::DelStates(" 
03810   << rDelStates.ToString() << ")");
03811   StateSet::Iterator cit;
03812   StateSet::Iterator cit_end;
03813   // symbolic state names
03814   if (StateNamesEnabled()) {
03815     for (cit = rDelStates.Begin(); cit != rDelStates.End(); ++cit) {
03816       mpStateSymbolTable->ClrEntry(*cit);
03817     }
03818   }
03819   // statesets
03820   mStates.EraseSet(rDelStates);
03821   mInitStates.EraseSet(rDelStates);
03822   mMarkedStates.EraseSet(rDelStates);
03823   // mTransRel:
03824   // should reimplement: iterate over transition rather than states
03825   for (cit = rDelStates.Begin(); cit != rDelStates.End(); ++cit) {
03826     mTransRel.EraseByX1OrX2(*cit);
03827   }
03828 }
03829 
03830 // DelStateFromStates(index)
03831 TEMP bool THIS::DelStateFromStates(Idx index) {
03832   FD_DG("TaGenerator(" << this << ")::DelStateFromStates(" << index << ")");
03833   // mStates + global
03834   return mStates.Erase(index);
03835 }
03836 
03837 // DelStateFromStates(pos)
03838 TEMP StateSet::Iterator THIS::DelStateFromStates(StateSet::Iterator pos) {
03839   FD_DG("TaGenerator(" << this << ")::DelState(" << *pos << ")");
03840   return mStates.Erase(pos);
03841 }
03842 
03843 // SetInitState(index)
03844 TEMP void THIS::SetInitState(Idx index) {
03845   FD_DG("TaGenerator(" << this << ")::SetInitState(" << index << ")");
03846 #ifdef FAUDES_CHECKED
03847   if (! mStates.Exists(index)) {
03848     std::stringstream errstr;
03849     errstr << "TaGenerator::SetMarkedState: index " << index 
03850      << " not in stateset";
03851     throw Exception("TaGenerator::SetInitState(..)", errstr.str(), 91);
03852   }
03853 #endif
03854   mInitStates.Insert(index);
03855 }
03856 
03857 // SetInitState(rName)
03858 TEMP void THIS::SetInitState(const std::string& rName) {
03859   FD_DG("TaGenerator(" << this << ")::SetInitState(\"" << rName << "\")");
03860   Idx index = StateIndex(rName);
03861 #ifdef FAUDES_CHECKED
03862   if (index == 0) {
03863     std::stringstream errstr;
03864     errstr << "State name \"" << rName << "\" not known in Generator";
03865     throw Exception("TaGenerator::SetInitState(..)", errstr.str(), 90);
03866   }
03867 #endif
03868   SetInitState(index);
03869 }
03870 
03871 // InjectInitStates(rNewInitStates)
03872 TEMP void THIS::InjectInitStates(const StateSet& rNewInitStates) {
03873   FD_DG("TaGenerator(" << this << ")::InjectInitStates(" 
03874   << rNewInitStates.ToString() << ")");
03875   mInitStates = rNewInitStates;
03876   mInitStates.Name("InitStates");
03877 }
03878 
03879 // ClrInitState(index)
03880 TEMP void THIS::ClrInitState(Idx index) {
03881   FD_DG("TaGenerator(" << this << ")::ClrInitState(" << index << ")");
03882 #ifdef FAUDES_CHECKED
03883   if (! mStates.Exists(index)) {
03884     std::stringstream errstr;
03885     errstr << "TaGenerator::SetMarkedState: index " << index 
03886      << " not in stateset";
03887     throw Exception("TaGenerator::ClrInitState(..)", errstr.str(), 91);
03888   }
03889 #endif
03890   mInitStates.Erase(index);
03891 }
03892 
03893 // ClrInitState(rName)
03894 TEMP void THIS::ClrInitState(const std::string& rName) {
03895   FD_DG("TaGenerator(" << this << ")::ClrInitState(\"" << rName << "\")");
03896   Idx index = StateIndex(rName);
03897 #ifdef FAUDES_CHECKED
03898   if (index == 0) {
03899     std::stringstream errstr;
03900     errstr << "State name \"" << rName << "\" not known in Generator";
03901     throw Exception("TaGenerator::ClrInitState(..)", errstr.str(), 90);
03902   }
03903 #endif
03904   ClrInitState(index);
03905 }
03906 
03907 // ClrInitState(pos)
03908 TEMP void THIS::ClrInitState(StateSet::Iterator pos) {
03909   FD_DG("TaGenerator(" << this << ")::ClrInitState(" << *pos << ")");
03910   mInitStates.Erase(pos);
03911 }
03912 
03913 // ClearInitStates()
03914 TEMP void THIS::ClearInitStates(void) {
03915   mInitStates.Clear();
03916 }
03917 
03918 // SetMarkedState(index)
03919 TEMP void THIS::SetMarkedState(Idx index) {
03920   FD_DG("TaGenerator(" << this << ")::SetMarkedState(" << index << ")");
03921 #ifdef FAUDES_CHECKED
03922   if (! mStates.Exists(index)) {
03923     std::stringstream errstr;
03924     errstr << "TaGenerator::SetMarkedState: index " << index 
03925      << " not in stateset";
03926     throw Exception("TaGenerator::SetMarkedState(..)", errstr.str(), 91);
03927   }
03928 #endif
03929   mMarkedStates.Insert(index);
03930 }
03931 
03932 // SetMarkedState(rName)
03933 TEMP void THIS::SetMarkedState(const std::string& rName) {
03934   FD_DG("TaGenerator(" << this << ")::SetMarkedState(\"" << rName << "\")");
03935   Idx index = StateIndex(rName);
03936 #ifdef FAUDES_CHECKED
03937   if (index == 0) {
03938     std::stringstream errstr;
03939     errstr << "State name \"" << rName << "\" not known in Generator";
03940     throw Exception("TaGenerator::SetMarkedState(..)", errstr.str(), 90);
03941   }
03942 #endif
03943   SetMarkedState(index);
03944 }
03945 
03946 // InjectMarkedStates(rNewMarkedStates)
03947 TEMP void THIS::InjectMarkedStates(const StateSet& rNewMarkedStates) {
03948   FD_DG("TaGenerator(" << this << ")::InjectMarkedStates(" 
03949   << rNewMarkedStates.ToString() << ")");
03950   mMarkedStates = rNewMarkedStates;
03951   mMarkedStates.Name("MarkedStates");
03952 }
03953 
03954 // ClrMarkedState(index)
03955 TEMP void THIS::ClrMarkedState(Idx index) {
03956   FD_DG("TaGenerator(" << this << ")::ClrMarkedState(" << index << ")");
03957 #ifdef FAUDES_CHECKED
03958   if (! mStates.Exists(index)) {
03959     std::stringstream errstr;
03960     errstr << "TaGenerator::ClrMarkedState: index " << index 
03961      << " not in stateset";
03962     throw Exception("TaGenerator::ClrMarkedState(..)", errstr.str(), 91);
03963   }
03964 #endif
03965   mMarkedStates.Erase(index);
03966 }
03967 
03968 // ClrMarkedState(rName)
03969 TEMP void THIS::ClrMarkedState(const std::string& rName) {
03970   FD_DG("TaGenerator(" << this << ")::ClrMarkedState(\"" << rName << "\")");
03971   Idx index = StateIndex(rName);
03972 #ifdef FAUDES_CHECKED
03973   if (index == 0) {
03974     std::stringstream errstr;
03975     errstr << "State name \"" << rName << "\" not known in Generator";
03976     throw Exception("TaGenerator::ClrMarkedState(..)", errstr.str(), 90);
03977   }
03978 #endif
03979   ClrMarkedState(index);
03980 }
03981 
03982 // ClrMarkedState(pos)
03983 TEMP void THIS::ClrMarkedState(StateSet::Iterator pos) {
03984   FD_DG("TaGenerator(" << this << ")::ClrMarkedState(" << *pos << ")");
03985   mMarkedStates.Erase(pos);
03986 }
03987 
03988 // ClearMarkedStates()
03989 TEMP void THIS::ClearMarkedStates(void) {
03990   mMarkedStates.Clear();
03991 }
03992 
03993 // InjectTransition(newtrans)
03994 TEMP void THIS::InjectTransition(const Transition& rTrans) {
03995   FD_DG("TaGenerator::InjectTransition(" << TStr(rTrans) << ")");
03996   mTransRel.Insert(rTrans);
03997 }
03998 
03999 // InjectTransRel(newtransrel)
04000 TEMP void THIS::InjectTransRel(const TransSet& newtransrel) {
04001   FD_DG("TaGenerator::InjectTransRel(...)");
04002   mTransRel=newtransrel;
04003 }
04004 
04005 // SetTransition(rX1, rEv, rX2)
04006 TEMP bool THIS::SetTransition(const std::string& rX1, const std::string& rEv, const std::string& rX2) {
04007   FD_DG("TaGenerator(" << this << ")::SetTransition(\""
04008   << rX1 << "\", \"" << rEv << "\", \"" << rX2 << "\")");
04009   Idx x1 = StateIndex(rX1);
04010   Idx x2 = StateIndex(rX2);
04011 #ifdef FAUDES_CHECKED
04012   if (x1 == 0) {
04013     FD_ERR("TaGenerator::SetTransition: state " << rX1 
04014      << " not in stateset");
04015     std::stringstream errstr;
04016     errstr << "State name " << rX1 << " not found in Generator";
04017     throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 90);
04018   }
04019   if (! mAlphabet.Exists(rEv)) {
04020     FD_ERR("TaGenerator::SetTransition: event " << rEv << " not in alphabet");
04021     std::stringstream errstr;
04022     errstr << "Event name " << rEv << " not found in event domain of Generator";
04023     throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
04024   }
04025   if (x2 == 0) {
04026     FD_ERR("TaGenerator::SetTransition: state " << rX2 << " not in stateset");
04027     std::stringstream errstr;
04028     errstr << "State name " << rX2 << " not found in Generator";
04029     throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 90);
04030   }
04031 #endif
04032   return SetTransition(Transition(x1, EventIndex(rEv), x2));
04033 }
04034 
04035 
04036 // SetTransition(x1, ev, x2)
04037 TEMP bool THIS::SetTransition(Idx x1, Idx ev, Idx x2) {
04038   return SetTransition(Transition(x1,ev,x2));
04039 }
04040 
04041 // SetTransition(rTransition)
04042 TEMP bool THIS::SetTransition(const Transition& rTransition) {
04043   FD_DG("TaGenerator(" << this << ")::SetTransition(" << rTransition.X1 << "," 
04044   << rTransition.Ev << "," << rTransition.X2 << ")");
04045 #ifdef FAUDES_CHECKED
04046   if (! mStates.Exists(rTransition.X1)) {
04047     std::stringstream errstr;
04048     errstr << "TaGenerator::SetTransition: state " << rTransition.X1 
04049      << " not in stateset";
04050     throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
04051   }
04052   if (! mAlphabet.Exists(rTransition.Ev)) {
04053     std::stringstream errstr;
04054     errstr << "TaGenerator::SetTransition: event " << rTransition.Ev 
04055      << " not in alphabet ";
04056     throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
04057   }
04058   if (! mStates.Exists(rTransition.X2)) {
04059     std::stringstream errstr;
04060     errstr << "TaGenerator::SetTransition: state " << rTransition.X2 
04061      << " not in stateset";
04062     throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
04063   }
04064 #endif
04065   return mTransRel.Insert(rTransition);
04066 }
04067 
04068 // SetTransition(rTransition, rAttr)
04069 TEMP bool THIS::SetTransition(const Transition& rTransition, const TransAttr& rAttr) {
04070   FD_DG("TaGenerator(" << this << ")::SetTransition(" << rTransition.X1 << "," 
04071   << rTransition.Ev << "," << rTransition.X2 << ", [attr:]" << rAttr.ToString() << ")");
04072 #ifdef FAUDES_CHECKED
04073   if (! mStates.Exists(rTransition.X1)) {
04074     std::stringstream errstr;
04075     errstr << "TaGenerator::SetTransition: state " << rTransition.X1 
04076      << " not in stateset";
04077     throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
04078   }
04079   if (! mAlphabet.Exists(rTransition.Ev)) {
04080     std::stringstream errstr;
04081     errstr << "TaGenerator::SetTransition: event " << rTransition.Ev 
04082      << " not in alphabet ";
04083     throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
04084   }
04085   if (! mStates.Exists(rTransition.X2)) {
04086     std::stringstream errstr;
04087     errstr << "TaGenerator::SetTransition: state " << rTransition.X2 
04088      << " not in stateset";
04089     throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
04090   }
04091 #endif
04092   return mTransRel.Insert(rTransition,rAttr);
04093 }
04094 
04095 // ClrTransition.X1, ev, x2)
04096 TEMP void THIS::ClrTransition(Idx x1, Idx ev, Idx x2) {
04097   FD_DG("TaGenerator(" << this << ")::ClrTransition(" 
04098   << x1 << "," << ev << "," << x2 << ")");
04099   mTransRel.Erase(x1, ev, x2);
04100 }
04101 
04102 // ClrTransition(rTransition)
04103 TEMP void THIS::ClrTransition(const Transition& rTransition) {
04104   FD_DG("TaGenerator(" << this << ")::ClrTransition(" << TStr(rTransition) << ")");
04105   mTransRel.Erase(rTransition);
04106 }
04107 
04108 // ClrTransition(it)
04109 TEMP typename THIS::ATransSet::Iterator THIS::ClrTransition(typename ATransSet::Iterator it) {
04110   FD_DG("TaGenerator(" << this << ")::ClrTransition(" << TStr(*it)<< ")" );
04111   return mTransRel.Erase(it);
04112 }
04113 
04114 
04115 // TransAttribute(trans, attr)
04116 TEMP void THIS::TransAttribute(const Transition& rTrans, const TransAttr& rAttr)  {
04117   FD_DG("TaGenerator(" << this << ")::TransAttribute(" 
04118   << TStr(rTrans) << ",\"" << rAttr.ToString() << "\")");
04119   mTransRel.Attribute(rTrans, rAttr);
04120 }
04121 
04122 // TransAttributep(trans)
04123 TEMP TransAttr* THIS::TransAttributep(const Transition& rTrans)  {
04124   return mTransRel.Attributep(rTrans);
04125 }
04126 
04127 
04128 // TransAttribute(trans)
04129 TEMP const TransAttr& THIS::TransAttribute(const Transition& rTrans) const {
04130   return mTransRel.Attribute(rTrans);
04131 }
04132 
04133 // ClrTransAttribute(trans)
04134 TEMP void THIS::ClrTransAttribute(const Transition& rTrans)  {
04135   mTransRel.ClrAttribute(rTrans);
04136 }
04137 
04138 
04139 // ClearTransRel()
04140 TEMP void THIS::ClearTransRel(void) {
04141   mTransRel.Clear();
04142 }
04143 
04144 // EventAttribute(index, attr)
04145 TEMP void THIS::EventAttribute(Idx index, const EventAttr& rAttr) {
04146   FD_DG("TaGenerator(" << this << ")::EventAttribute(" 
04147   << EStr(index) << ",\"" << rAttr.ToString() << "\")");
04148   mAlphabet.Attribute(index, rAttr);
04149 }
04150 
04151 // ClrEventAttribute(index)
04152 TEMP void THIS::ClrEventAttribute(Idx index) {
04153   FD_DG("TaGenerator(" << this << ")::ClrEventAttribute(\"" << EStr(index) << "\")");
04154   mAlphabet.ClrAttribute(index);
04155 }
04156 
04157 // StateAttribute(index, attr)
04158 TEMP void THIS::StateAttribute(Idx index, const StateAttr& rAttr) {
04159   FD_DG("TaGenerator(" << this << ")::StateAttribute(" 
04160   << index << ",\"" << rAttr.ToString() << "\")");
04161   mStates.Attribute(index, rAttr);
04162 }
04163 
04164 // ClrStateAttribute(index)
04165 TEMP void THIS::ClrStateAttribute(Idx index) {
04166   FD_DG("TaGenerator(" << this << ")::ClrStateAttribute(\"" << index << "\")");
04167   mStates.ClrAttribute(index);
04168 }
04169 
04170 // ExistsEvent(index)
04171 TEMP bool THIS::ExistsEvent(Idx index) const {
04172   return mAlphabet.Exists(index);
04173 }
04174 
04175 // ExistsEvent(rName)
04176 TEMP bool THIS::ExistsEvent(const std::string& rName) const {
04177   return mAlphabet.Exists(rName);
04178 }
04179 
04180 // FindEvent(index) const
04181 TEMP EventSet::Iterator THIS::FindEvent(Idx index) const {
04182   return mAlphabet.Find(index);
04183 }
04184 
04185 // FindEvent(rName)
04186 TEMP EventSet::Iterator THIS::FindEvent(const std::string& rName) const {
04187   return mAlphabet.Find(rName);
04188 }
04189 
04190 // ExistsState(index)
04191 TEMP bool THIS::ExistsState(Idx index) const {
04192   return mStates.Exists(index);
04193 }
04194 
04195 // ExistsName(name)
04196 TEMP bool THIS::ExistsState(const std::string& rName) const {
04197   return ExistsState(StateIndex(rName));
04198 }
04199 
04200 // FindState(rName) const
04201 TEMP StateSet::Iterator THIS::FindState(const std::string& rName) const {
04202   return mStates.Find(mpStateSymbolTable->Index(rName));
04203 }
04204 
04205 // FindState(index) const
04206 TEMP StateSet::Iterator THIS::FindState(Idx index) const {
04207   return mStates.Find(index);
04208 }
04209 
04210 // ExistsInitState(index)
04211 TEMP bool THIS::ExistsInitState(Idx index) const {
04212   return mInitStates.Exists(index);
04213 }
04214 
04215 // FindInitState(index)
04216 TEMP StateSet::Iterator THIS::FindInitState(Idx index) const {
04217   return mInitStates.Find(index);
04218 }
04219 
04220 // ExistsMarkedState(index)
04221 TEMP bool THIS::ExistsMarkedState(Idx index) const {
04222   return mMarkedStates.Exists(index);
04223 }
04224 
04225 // FindMarkedState(index)
04226 TEMP StateSet::Iterator THIS::FindMarkedState(Idx index) const {
04227   return mMarkedStates.Find(index);
04228 }
04229 
04230 // EventAttribute(index)
04231 TEMP const EventAttr&  THIS::EventAttribute(Idx index) const {
04232   return mAlphabet.Attribute(index);
04233 }
04234 
04235 // EventAttributep(index)
04236 TEMP EventAttr* THIS::EventAttributep(Idx index) {
04237   return mAlphabet.Attributep(index);
04238 }
04239 
04240 // EventAttribute(rName)
04241 TEMP const EventAttr&  THIS::EventAttribute(const std::string& rName) const {
04242   return EventAttribute(EventIndex(rName));
04243 }
04244 
04245 // EventAttributep(rName)
04246 TEMP EventAttr* THIS::EventAttributep(const std::string& rName) {
04247   return EventAttributep(EventIndex(rName));
04248 }
04249 // StateAttribute(index)
04250 TEMP const StateAttr&  THIS::StateAttribute(Idx index) const {
04251   return mStates.Attribute(index);
04252 }
04253 
04254 // StateAttributep(index)
04255 TEMP StateAttr*  THIS::StateAttributep(Idx index) {
04256   return mStates.Attributep(index);
04257 }
04258 
04259 // Alphabet()
04260 TEMP const TaEventSet<EventAttr>& THIS::Alphabet(void) const {
04261   return mAlphabet;
04262 }
04263 
04264 // States()
04265 TEMP const TaStateSet<StateAttr>& THIS::States(void) const {
04266   return mStates;
04267 }
04268 
04269 // TransRel()
04270 TEMP const typename THIS::ATransSet& THIS::TransRel(void) const {
04271   return mTransRel;
04272 }
04273 
04274 
04275 // TransRel(res)
04276 TEMP void THIS::TransRel(TransSetX1EvX2& res) const { mTransRel.ReSort(res); }
04277 TEMP void THIS::TransRel(TransSetEvX1X2& res) const { mTransRel.ReSort(res); }
04278 TEMP void THIS::TransRel(TransSetEvX2X1& res) const { mTransRel.ReSort(res); }
04279 TEMP void THIS::TransRel(TransSetX2EvX1& res) const { mTransRel.ReSort(res); }
04280 TEMP void THIS::TransRel(TransSetX2X1Ev& res) const { mTransRel.ReSort(res); }
04281 TEMP void THIS::TransRel(TransSetX1X2Ev& res) const { mTransRel.ReSort(res); }
04282 
04283 
04284 // InitStates()
04285 TEMP const StateSet& THIS::InitStates(void) const {
04286   return mInitStates;
04287 }
04288 
04289 // MarkedStates()
04290 TEMP const StateSet& THIS::MarkedStates(void) const {
04291   return mMarkedStates;
04292 }
04293 
04294 // MinimizeAlphabet()
04295 TEMP void THIS::MinimizeAlphabet(void) {
04296   mAlphabet.NameSet::EraseSet(UnusedEvents());
04297 }
04298 
04299 // UsedEvents()
04300 TEMP EventSet THIS::UsedEvents(void) const {
04301   EventSet resultset = NewEventSet();
04302   typename ATransSet::Iterator it;
04303   for (it = mTransRel.Begin(); it != mTransRel.End(); ++it) {
04304     resultset.Insert(it->Ev);
04305   }
04306   return resultset;
04307 }
04308 
04309 // UnusedEvents()
04310 TEMP EventSet THIS::UnusedEvents(void) const {
04311   return mAlphabet - UsedEvents();
04312 }
04313 
04314 // ActiveEventSet(x1)
04315 TEMP EventSet THIS::ActiveEventSet(Idx x1) const {
04316   EventSet result = NewEventSet();
04317   typename ATransSet::Iterator it;
04318   for (it = TransRelBegin(x1); it != TransRelEnd(x1); ++it) {
04319     result.Insert(it->Ev);
04320   }
04321   return result;
04322 }
04323 
04324 // ActiveTransSet(x1)
04325 TEMP TransSet THIS::ActiveTransSet(Idx x1) const {
04326   TransSet result;
04327   typename ATransSet::Iterator it;
04328   for (it = TransRelBegin(x1); it != TransRelEnd(x1); ++it) {
04329     result.Insert(*it);
04330   }
04331   return result;
04332 }
04333 
04334 // TransRelStateSpace()
04335 TEMP StateSet THIS::TransRelStateSpace(void) const {
04336   StateSet states = StateSet();
04337   typename ATransSet::Iterator it;
04338   for (it=mTransRel.Begin(); it != mTransRel.End(); ++it) {
04339     states.Insert(it->X1);
04340     states.Insert(it->X2);
04341   }
04342   return states;
04343 }
04344 
04345 // TransRelStateSpace(x1)
04346 TEMP StateSet THIS::TransRelStateSpace(Idx x1) const {
04347   StateSet states = StateSet();
04348   typename ATransSet::Iterator it = mTransRel.Begin(x1);
04349   typename ATransSet::Iterator it_end = mTransRel.End(x1);
04350   for (; it != it_end; ++it) {
04351     states.Insert(it->X2);
04352   }
04353   return states;
04354 }
04355 
04356 // Version(idx)
04357 TEMP void THIS::Version(Idx version, TaGenerator& rResGen) {
04358   FD_DG("TaGenerator(" << this << ")::Version(" << version << ")");
04359   std::ostringstream o;
04360   o << version;
04361   Version(o.str(),rResGen);
04362 }
04363 
04364 // Version(string)
04365 TEMP void THIS::Version(const std::string& rVersion, TaGenerator& rResGen) {
04366   FD_DG("TaGenerator(" << this << ")::Version(" << rVersion << ")");
04367   // second arg must not be us if(this==&rResGen) {exception ..}
04368   if (this==&rResGen) {
04369     FD_ERR("TaGenerator::Version(): rResGen must not be this generator");
04370     abort();
04371   }
04372   // prepare Empty generator
04373   rResGen.Clear();
04374   rResGen.mGlobalAttribute=mGlobalAttribute;
04375   EventSet::Iterator eit;
04376   StateSet::Iterator lit;
04377   typename ATransSet::Iterator tit;
04378   std::map<Idx,Idx> eventoldnewmap;
04379   rResGen.Name(Name()+"_"+rVersion);
04380   // create versioned mAlphabet
04381   for (eit = AlphabetBegin(); eit != AlphabetEnd(); ++eit) {
04382     eventoldnewmap[*eit] = rResGen.InsEvent(EventName(*eit)+"_"+rVersion, EventAttribute(*eit)); 
04383   }
04384   // create new stateset
04385   rResGen.mStates=mStates;
04386   for (lit = StatesBegin(); lit != StatesEnd(); ++lit) {
04387     if (StateName(*lit) != "") {
04388       rResGen.StateName(*lit,StateName(*lit));
04389     }
04390   }
04391   // created versioned transrel
04392   for (tit = TransRelBegin(); tit != TransRelEnd(); ++tit) {
04393     rResGen.SetTransition(Transition(tit->X1, eventoldnewmap[tit->Ev], tit->X2), TransAttribute(*tit));
04394   }
04395   // set i/m states
04396   rResGen.mInitStates=mInitStates;
04397   rResGen.mMarkedStates=mMarkedStates;
04398 
04399   rResGen.mStateNamesEnabled = mStateNamesEnabled;
04400 }
04401 
04402 // AccessibleSet()
04403 TEMP StateSet THIS::AccessibleSet(void) const {
04404   StateSet accessibleset = StateSet();
04405   StateSet::Iterator it;
04406   for (it = InitStatesBegin(); it != InitStatesEnd(); ++it) {
04407     CheckAccessible(accessibleset, *it);
04408   }
04409   accessibleset.Name("accessibleset");
04410   return accessibleset;
04411 }
04412 
04413 // Accessible()
04414 TEMP bool THIS::Accessible(void) {
04415   StateSet accessibleset = AccessibleSet();
04416   StateSet not_accessible = mStates - accessibleset;
04417   StateSet::Iterator it;
04418   for(it = not_accessible.Begin(); it != not_accessible.End(); ++it){
04419     mTransRel.EraseByX1OrX2(*it);
04420   }
04421   // mStates
04422   mStates = accessibleset;
04423   mStates.Name("States");
04424   // mInitStates
04425   mInitStates = mInitStates * accessibleset;
04426   mInitStates.Name("InitStates");
04427   // mMarkedStates
04428   mMarkedStates = mMarkedStates * accessibleset;
04429   mMarkedStates.Name("MarkedStates");
04430   // symbolic state name handling
04431   if (StateNamesEnabled()) {
04432     for (it = not_accessible.Begin(); it != not_accessible.End(); ++it) {
04433       mpStateSymbolTable->ClrEntry(*it);
04434     }
04435   }
04436   // return true if there is an initial state
04437   if (! mInitStates.Empty()) {
04438     FD_DF("TaGenerator::accessible: generator is accessible");
04439     return true;
04440   }
04441   else {
04442     FD_DF("TaGenerator::accessible: generator is accessible");
04443     return false;
04444   }
04445 
04446 }
04447 
04448 // IsAccessible()
04449 TEMP bool THIS::IsAccessible(void) const {
04450   if ((AccessibleSet() == mStates) && (! mInitStates.Empty())) {
04451     FD_DF("TaGenerator::accessible: generator is accessible");
04452     return true;
04453   }
04454   else {
04455     FD_DF("TaGenerator::accessible: generator is not accessible");
04456     return false;
04457   }
04458 }
04459 
04460 // CoaccessibleSet()
04461 TEMP StateSet THIS::CoaccessibleSet(void) const {
04462   StateSet coaccessibleset = StateSet();
04463   StateSet::Iterator it;
04464   // build reverse transition relation
04465   TransSetX2EvX1 rtrel;
04466   TransRel(rtrel);
04467   for (it = MarkedStatesBegin(); it != MarkedStatesEnd(); ++it) {
04468     CheckCoaccessible(coaccessibleset, rtrel, *it);
04469   }
04470   coaccessibleset.Name("coaccessibleset");
04471   return coaccessibleset;
04472 }
04473 
04474 // Coaccessible()
04475 TEMP bool THIS::Coaccessible(void) {
04476   StateSet coaccessibleset = CoaccessibleSet();
04477   StateSet not_coaccessible = mStates - coaccessibleset;
04478   StateSet::Iterator it;
04479   // mTransRel
04480   for(it = not_coaccessible.Begin(); it != not_coaccessible.End(); ++it){
04481     mTransRel.EraseByX1OrX2(*it);
04482   }
04483   // mStates
04484   mStates = coaccessibleset;
04485   mStates.Name("States");
04486   // mInitStates
04487   mInitStates = mInitStates * coaccessibleset;
04488   mInitStates.Name("InitStates");
04489   // mMarkedStates
04490   mMarkedStates = mMarkedStates * coaccessibleset;
04491   mMarkedStates.Name("MarkedStates");
04492   // symbolic state name handling
04493   if (StateNamesEnabled()) {
04494     for (it = not_coaccessible.Begin(); it != not_coaccessible.End(); ++it) {
04495       mpStateSymbolTable->ClrEntry(*it);
04496     }
04497   }
04498   // return true if there is a marked state
04499   if (! mMarkedStates.Empty()) {
04500     FD_DF("TaGenerator::coaccessible: generator is coaccessible");
04501     return true;
04502   }
04503   else {
04504     FD_DF("TaGenerator::coaccessible: generator is not coaccessible");
04505     return false;
04506   }
04507 }
04508 
04509 // IsCoaccessible()
04510 TEMP bool THIS::IsCoaccessible(void) const {
04511   if ((CoaccessibleSet() == mStates) && (! mMarkedStates.Empty())) {
04512     FD_DF("TaGenerator::coaccessible: generator is coaccessible");
04513     return true;
04514   }
04515   else {
04516     FD_DF("TaGenerator::coaccessible: generator is not coaccessible");
04517     return false;
04518   }
04519 }
04520 
04521 // TrimSet()
04522 TEMP StateSet THIS::TrimSet(void) const {
04523   FD_DF("TaGenerator::trimset: trim states: " 
04524   << StateSet(AccessibleSet() * CoaccessibleSet()).ToString());
04525   return AccessibleSet() * CoaccessibleSet();
04526 }
04527 
04528 // Trim()
04529 TEMP bool THIS::Trim(void) {
04530   FD_DF("TaGenerator::trim: generator states: " << mStates.ToString());
04531   bool accessiblebool = Accessible();
04532   bool coaccessiblebool = Coaccessible();
04533   FD_DF("TaGenerator::trim: trim states: " << mStates.ToString());
04534   if (accessiblebool && coaccessiblebool) {
04535     FD_DF("TaGenerator::trim: generator is trim");
04536     return true;
04537   }
04538   else {
04539     FD_DF("TaGenerator::trim: generator is not trim");
04540     return false;
04541   }
04542 }
04543 
04544 // IsTrim()
04545 TEMP bool THIS::IsTrim(void) const {
04546   if (IsAccessible() && IsCoaccessible()) {
04547     FD_DF("TaGenerator::trim: generator is trim");
04548     return true;
04549   }
04550   else {
04551     FD_DF("TaGenerator::trim: generator is not trim");
04552     return false;
04553   }
04554 }
04555 
04556 // BlockingSet()
04557 TEMP StateSet THIS::BlockingSet(void) const {
04558   FD_DF("TaGenerator::BlockingSet: blocking states: " 
04559   << StateSet(AccessibleSet() - CoaccessibleSet()).ToString());
04560   return AccessibleSet() - CoaccessibleSet();
04561 }
04562 
04563 // CheckAccessible(accessibleset, startState)
04564 TEMP void THIS::CheckAccessible(StateSet& accessibleset, Idx startState) const {
04565   if (! accessibleset.Exists(startState)) {
04566     accessibleset.Insert(startState);
04567     typename ATransSet::Iterator it = TransRelBegin(startState);
04568     typename ATransSet::Iterator it_end = TransRelEnd(startState);
04569     for (; it != it_end; ++it) {
04570       CheckAccessible(accessibleset, it->X2);
04571     }
04572   }
04573 }
04574 
04575 // CheckCoaccessible(coaccessibleset, rtransrel, startState)
04576 TEMP void THIS::CheckCoaccessible(StateSet& coaccessibleset, 
04577           const TransSetX2EvX1& rtrel, Idx startState) const {
04578   if (! coaccessibleset.Exists(startState)) {
04579     coaccessibleset.Insert(startState);
04580     typename TransSetX2EvX1::Iterator it = rtrel.BeginByX2(startState);
04581     typename TransSetX2EvX1::Iterator it_end = rtrel.EndByX2(startState);
04582     for (; it != it_end; ++it) {
04583       CheckCoaccessible(coaccessibleset, rtrel, it->X1);
04584     }
04585   }
04586 }
04587 
04588 // IsDeterministic()
04589 TEMP bool THIS::IsDeterministic(void) const {
04590   // if there is more than one initial state ... nondet
04591   if (InitStatesSize() != 1) {
04592     FD_DG("TaGenerator::IsDeterministic: number of initial states not 1");
04593     return false;
04594   }
04595   // if there is a state/event pair with non-unique successor ... nondet
04596   if (TransRelSize() < 2) return true;
04597   typename ATransSet::Iterator it1;
04598   typename ATransSet::Iterator it2;
04599   for (it1 = TransRelBegin(), it2 = it1++; it1 != TransRelEnd(); it2 = it1++) {
04600     if ((it1->X1 == it2->X1) && (it1->Ev == it2->Ev)) {
04601       FD_WP("IsDeterministic: nondeterministic generator. at least one state "
04602       << "contains more than on transition with same event: " 
04603       << SStr(it1->X1) << ", event " << EStr(it1->Ev));
04604       return false;
04605     }
04606   }
04607   // in all other cases generator is deterministic
04608   return true;
04609 }
04610 
04611 // ClearMinStateIndexMap()
04612 TEMP void THIS::ClearMinStateIndexMap(void) const {
04613   FD_DG("TaGenerator::ClearMinStateIndexMap()");
04614   // fake const
04615   THIS* fakeconst = const_cast<THIS*>(this);
04616   fakeconst->mMinStateIndexMap.clear();
04617 }
04618 
04619 // MinStateIndex(index)
04620 TEMP Idx THIS::MinStateIndex(Idx index) const {
04621   std::map<Idx,Idx>::const_iterator minit;
04622   minit = mMinStateIndexMap.find(index);
04623   Idx fidx;
04624   if(minit != mMinStateIndexMap.end()) {
04625     fidx= minit->second;
04626   } else {
04627     fidx=index;
04628   }
04629   return fidx;
04630 }
04631 
04632 // MinStateIndex()
04633 TEMP const std::map<Idx,Idx>& THIS::MinStateIndexMap(void) const {
04634   return mMinStateIndexMap;
04635 }
04636 
04637 
04638 
04639 // SetMinStateIndexMap()
04640 TEMP void THIS::SetMinStateIndexMap(void) const {
04641   FD_DG("TaGenerator::SetMinStateIndexMap()");
04642   // fake const
04643   THIS* fakeconst = const_cast<THIS*>(this);
04644   // clear map
04645   fakeconst->ClearMinStateIndexMap();
04646   StateSet::Iterator it;
04647   Idx minindex = 0;
04648   // if generator states get names
04649   if(StateNamesEnabled()) {
04650     // named initial states first
04651     for(it = InitStatesBegin(); it != InitStatesEnd(); ++it) {
04652       if(StateName(static_cast<Idx>(*it)) != "") {
04653   fakeconst->mMinStateIndexMap[*it] = ++minindex;
04654       }
04655     }
04656     // then all other named states
04657     for(it = StatesBegin(); it != StatesEnd(); ++it) {
04658       if(mMinStateIndexMap.count(*it) == 0) {
04659   if(StateName(static_cast<Idx>(*it)) != "") {
04660     fakeconst->mMinStateIndexMap[*it] = ++minindex;
04661   }
04662       }
04663     }
04664     // at last all anonymous states
04665     for(it = StatesBegin(); it != StatesEnd(); ++it) {
04666       if(mMinStateIndexMap.count(*it) == 0) {
04667   fakeconst->mMinStateIndexMap[*it] = ++minindex;
04668       }
04669     }
04670   }
04671   // if generator states are all anonymous
04672   else {
04673     // all initial states first
04674     for(it = InitStatesBegin(); it != InitStatesEnd(); ++it) {
04675       fakeconst->mMinStateIndexMap[*it] = ++minindex;
04676     }
04677     // then the rest
04678     for(it = StatesBegin(); it != StatesEnd(); ++it) {
04679       if(mMinStateIndexMap.count(*it) == 0) {
04680   fakeconst->mMinStateIndexMap[*it] = ++minindex;
04681       }
04682     }
04683   }
04684 #ifdef FAUDES_DEBUG_CONTAINER
04685   std::map<Idx,Idx>::const_iterator _it;
04686   for(_it = mMinStateIndexMap.begin(); _it != mMinStateIndexMap.end(); ++_it) {
04687     FD_DC("TaGenerator::MinStateIndexMap: " << _it->first
04688     << " <-- " << SStr(_it->second));
04689   }
04690 #endif
04691 }
04692 
04693 #undef THIS
04694 #undef TEMP
04695 #undef BASE
04696 
04697 
04706 class GeneratorPool {
04707  public:
04709   GeneratorPool(void) {
04710     mEventSymbolTablep=SymbolTable::GlobalEventSymbolTablep();
04711   }
04712 
04720   template <class AnyGenerator>
04721     AnyGenerator NewGenerator(void) { 
04722     AnyGenerator gen;
04723     gen.EventSymbolTablep(mEventSymbolTablep);
04724     return gen;
04725   }    
04726 
04734   template <class AnyGenerator>
04735     AnyGenerator* NewGeneratorp(void) { 
04736     AnyGenerator* gen = new AnyGenerator;
04737     gen->EventSymbolTablep(mEventSymbolTablep);
04738     return gen;
04739   }    
04740 
04747   template <class AnyEventSet>
04748     AnyEventSet NewAlphabet(void) { 
04749     AnyEventSet eset;
04750     eset.SymbolTablep(mEventSymbolTablep);
04751     return eset;
04752   }    
04753 
04754  private:
04756   SymbolTable mEventSymbolTable;
04757   SymbolTable* mEventSymbolTablep;
04758 };
04759 
04760 
04761 } // namespace faudes
04762 
04763 #endif
04764 

Generated on Mon Nov 10 08:13:14 2008 for libFAUDES 2.11v by  doxygen 1.4.4