00001
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef GENERATOR_H
00025
00026 #include "definitions.h"
00027 #include "exception.h"
00028 #include "symboltable.h"
00029 #include "indexset.h"
00030 #include "nameset.h"
00031 #include "transset.h"
00032 #include "token.h"
00033 #include "tokenreader.h"
00034 #include "tokenwriter.h"
00035 #include "vgenerator.h"
00036 #include <map>
00037 #include <set>
00038 #include <sstream>
00039 #include <cstdlib>
00040 #include <assert.h>
00041
00042 namespace faudes {
00043
00166 template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
00167 class TaGenerator : public vGenerator {
00168 public:
00169
00171 typedef TaTransSet<TransAttr> ATransSet;
00172
00173
00174
00175
00176
00177
00184 TaGenerator(void);
00185
00191 TaGenerator(const TaGenerator& rOtherGen);
00192
00198 TaGenerator(const vGenerator& rOtherGen);
00199
00211 TaGenerator(const char* pFileName);
00212
00223 TaGenerator* NewP(void) const;
00224
00233 virtual TaGenerator NewAGen(void) const;
00234
00238 virtual ~TaGenerator(void);
00239
00242
00243
00244
00245
00246
00257 virtual void Copy(TaGenerator& rGen) const;
00258
00265 virtual void Copy(vGenerator& rGen) const;
00266
00277 virtual void Move(TaGenerator& rGen);
00278
00289 virtual void Move(vGenerator& rGen);
00290
00297 virtual TaGenerator& operator = (const TaGenerator& rOtherGen);
00298
00305 virtual TaGenerator& operator = (const vGenerator& rOtherGen);
00306
00318 void Version(Idx version, TaGenerator& rResGen);
00319
00331 void Version(const std::string& rVersion, TaGenerator& rResGen);
00332
00333
00336
00337
00338
00339
00340
00348 void Write(void) const;
00349
00358 std::string ToString(void) const;
00359
00375 void Write(const char* pFileName,
00376 std::ios::openmode openmode = std::ios::out|std::ios::trunc);
00377
00396 void Write(TokenWriter& rTw) const;
00397
00398
00402 void DWrite(void) const;
00403
00404
00408 void WriteAlphabet(void) const;
00409
00418 std::string AlphabetToString(void) const;
00419
00429 void WriteAlphabet(TokenWriter& rTw) const;
00430
00431
00440 template<class OtherAttr>
00441 void WriteStateSet(const TaStateSet<OtherAttr>& rStateSet) const;
00442
00451 void WriteStateSet(const StateSet& rStateSet) const;
00452
00465 template<class OtherAttr>
00466 std::string StateSetToString(const TaStateSet<OtherAttr>& rStateSet) const;
00467
00480 std::string StateSetToString(const StateSet& rStateSet) const;
00481
00502 template<class OtherAttr>
00503 void WriteStateSet(TokenWriter& rTw, const TaStateSet<OtherAttr>& rStateSet) const;
00504
00505
00519 void WriteStateSet(TokenWriter& rTw, const StateSet& rStateSet) const;
00520
00521
00534 template<class OtherAttr>
00535 void DWriteStateSet(TokenWriter& rTw, const TaStateSet<OtherAttr>& rStateSet) const;
00536
00548 void DWriteStateSet(TokenWriter& rTw, const StateSet& rStateSet) const;
00549
00550
00559 std::string StatesToString(void) const;
00560
00569 std::string MarkedStatesToString(void) const;
00570
00579 std::string InitStatesToString(void) const;
00580
00584 void WriteTransRel(void) const;
00585
00589 std::string TransRelToString(void) const;
00590
00603 void WriteTransRel(TokenWriter& rTw) const;
00604
00613 void DWriteTransRel(TokenWriter& rTw) const;
00614
00615
00620 void WriteStatistics(void) const;
00621
00626 std::string StatisticsToString(void) const;
00627
00637 void WriteStatistics(TokenWriter& rTw) const;
00638
00639
00653 void DotWrite(const std::string& rFileName);
00654
00665 void DDotWrite(const std::string& rFileName) const;
00666
00678 void XDotWrite(const std::string& rFileName) const;
00679
00690 void Read(const char* pFileName);
00691
00702 void Read(TokenReader& rTr);
00703
00720 void ReadStateSet(TokenReader& rTr, const std::string& rLabel, StateSet& rStateSet) const;
00721
00722
00725
00726
00727
00728
00729
00739 bool Valid(void);
00740
00745 virtual void Clear(void);
00746
00747
00751 void ClearStates(void);
00752
00759 Idx AlphabetSize(void) const;
00760
00767 Idx Size(void) const;
00768
00775 Idx TransRelSize(void) const;
00776
00783 Idx InitStatesSize(void) const;
00784
00791 Idx MarkedStatesSize(void) const;
00792
00799 bool Empty(void) const;
00800
00807 bool AlphabetEmpty(void) const;
00808
00815 bool TransRelEmpty(void) const;
00816
00823 bool InitStatesEmpty(void) const;
00824
00831 bool MarkedStatesEmpty(void) const;
00832
00838 EventSet UsedEvents(void) const;
00839
00845 EventSet UnusedEvents(void) const;
00846
00855 EventSet ActiveEventSet(Idx x1) const;
00856
00862 StateSet TransRelStateSpace(void) const;
00863
00869 StateSet TransRelStateSpace(Idx x1) const;
00870
00871
00879 virtual bool UpdateAttributes(void) {return true;};
00880
00885
00886
00887
00888
00889
00899 EventSet::Iterator AlphabetBegin(void) const;
00900
00907 EventSet::Iterator AlphabetEnd(void) const;
00908
00918 bool ExistsEvent(Idx index) const;
00919
00929 bool ExistsEvent(const std::string& rName) const;
00930
00940 EventSet::Iterator FindEvent(Idx index) const;
00941
00951 EventSet::Iterator FindEvent(const std::string& rName) const;
00952
00958 const TaEventSet<EventAttr>& Alphabet(void) const;
00959
00966 StateSet::Iterator StatesBegin(void) const;
00967
00974 StateSet::Iterator StatesEnd(void) const;
00975
00985 bool ExistsState(Idx index) const;
00986
00996 bool ExistsState(const std::string& name) const;
00997
01007 StateSet::Iterator FindState(Idx index) const;
01008
01018 StateSet::Iterator FindState(const std::string& rName) const;
01019
01020
01027 const TaStateSet<StateAttr>& States(void) const;
01028
01038 Idx InitState(void) const;
01039
01046 StateSet::Iterator InitStatesBegin(void) const;
01047
01054 StateSet::Iterator InitStatesEnd(void) const;
01055
01065 bool ExistsInitState(Idx index) const;
01066
01076 StateSet::Iterator FindInitState(Idx index) const;
01077
01083 const StateSet& InitStates(void) const;
01084
01091 StateSet::Iterator MarkedStatesBegin(void) const;
01092
01099 StateSet::Iterator MarkedStatesEnd(void) const;
01100
01110 bool ExistsMarkedState(Idx index) const;
01111
01121 StateSet::Iterator FindMarkedState(Idx index) const;
01122
01128 const StateSet& MarkedStates(void) const;
01129
01136 typename ATransSet::Iterator TransRelBegin(void) const;
01137
01144 typename ATransSet::Iterator TransRelEnd(void) const;
01145
01155 typename ATransSet::Iterator TransRelBegin(Idx x1) const;
01156
01170 typename ATransSet::Iterator TransRelEnd(Idx x1) const;
01171
01184 typename ATransSet::Iterator TransRelBegin(Idx x1, Idx ev) const;
01185
01202 typename ATransSet::Iterator TransRelEnd(Idx x1, Idx ev) const;
01203
01218 typename ATransSet::Iterator FindTransition(
01219 const std::string& rX1, const std::string& rEv, const std::string& rX2) const;
01220
01235 typename ATransSet::Iterator FindTransition(Idx x1, Idx ev, Idx x2) const;
01236
01247 typename ATransSet::Iterator FindTransition(const Transition& rTrans) const;
01248
01263 bool ExistsTransition(
01264 const std::string& rX1, const std::string& rEv, const std::string& rX2) const;
01265
01280 bool ExistsTransition(Idx x1, Idx ev, Idx x2) const;
01281
01292 bool ExistsTransition(const Transition& rTrans) const;
01293
01299 const ATransSet& TransRel(void) const;
01300
01308 void TransRel(TransSetX1EvX2& res) const;
01309 void TransRel(TransSetEvX1X2& res) const;
01310 void TransRel(TransSetEvX2X1& res) const;
01311 void TransRel(TransSetX2EvX1& res) const;
01312 void TransRel(TransSetX2X1Ev& res) const;
01313 void TransRel(TransSetX1X2Ev& res) const;
01314
01319
01320
01321
01322
01323
01336 bool InsEvent(Idx index);
01337
01348 Idx InsEvent(const std::string& rName);
01349
01360 bool InsEvent(Idx index, const EventAttr& attr);
01361
01374 Idx InsEvent(const std::string& rName, const EventAttr& attr);
01375
01382 void InsEvents(const EventSet& events);
01383
01394 bool DelEvent(Idx index);
01395
01406 bool DelEvent(const std::string& rName);
01407
01415 void DelEvents(const EventSet& rEvents);
01416
01427 bool DelEventFromAlphabet(Idx index);
01428
01435 void InjectAlphabet(const EventSet& rNewalphabet);
01436
01443 void InjectAlphabet(const TaEventSet<EventAttr>& rNewalphabet);
01444
01451 Idx InsState(void);
01452
01462 Idx InsState(const StateAttr& attr);
01463
01470 bool InsState(Idx index);
01471
01484 Idx InsState(const std::string& rName);
01485
01499 Idx InsState(const std::string& rName, const StateAttr& attr);
01500
01513 bool InsState(Idx index, const StateAttr& attr);
01514
01524 bool DelState(Idx index);
01525
01538 bool DelState(const std::string& rName);
01539
01547 void DelStates(const StateSet& rDelStates);
01548
01549
01561 bool DelStateFromStates(Idx index);
01562
01574 StateSet::Iterator DelStateFromStates(StateSet::Iterator pos);
01575
01583 void InjectState(Idx index);
01584
01591 void InjectStates(const StateSet& rNewStates);
01592
01593
01600 Idx InsInitState(void);
01601
01611 Idx InsInitState(const std::string& rName);
01612
01619 Idx InsMarkedState(void);
01620
01630 Idx InsMarkedState(const std::string& rName);
01631
01641 void SetInitState(Idx index);
01642
01653 void SetInitState(const std::string& rName);
01654
01661 void InjectInitStates(const StateSet& rNewInitStates);
01662
01674 void ClrInitState(Idx index);
01675
01686 void ClrInitState(const std::string& rName);
01687
01694 void ClrInitState(StateSet::Iterator pos);
01695
01699 void ClearInitStates(void);
01700
01711 void SetMarkedState(Idx index);
01712
01723 void SetMarkedState(const std::string& rName);
01724
01736 void ClrMarkedState(Idx index);
01737
01748 void ClrMarkedState(const std::string& rName);
01749
01756 void ClrMarkedState(StateSet::Iterator pos);
01757
01761 void ClearMarkedStates(void);
01762
01769 void InjectMarkedStates(const StateSet& rNewMarkedStates);
01770
01790 bool SetTransition(Idx x1, Idx ev, Idx x2);
01791
01811 bool SetTransition(const std::string& rX1, const std::string& rEv,
01812 const std::string& rX2);
01813
01827 bool SetTransition(const Transition& rTransition);
01828
01844 bool SetTransition(const Transition& rTransition, const TransAttr& rAttr);
01845
01856 void ClrTransition(Idx x1, Idx ev, Idx x2);
01857
01864 void ClrTransition(const Transition& rTrans);
01865
01874 typename ATransSet::Iterator ClrTransition(typename ATransSet::Iterator it);
01875
01879 void ClearTransRel(void);
01880
01887 void InjectTransition(const Transition& rTrans);
01888
01895 void InjectTransRel(const TransSet& rNewtransrel);
01896
01901
01902
01903
01904
01905
01913 void ClearAttributes(void);
01914
01923 void DetermineAttributes(void) {};
01924
01928 void ClearEventAttributes(void);
01929
01936 void ClrEventAttribute(Idx index);
01937
01950 void EventAttribute(Idx index, const EventAttr& rAttr);
01951
01960 const EventAttr& EventAttribute(Idx index) const;
01961
01970 const EventAttr& EventAttribute(const std::string& rName) const;
01971
01981 EventAttr* EventAttributep(Idx index);
01982
01992 EventAttr* EventAttributep(const std::string& rName);
01993
01994
01998 void ClearStateAttributes(void);
01999
02006 void ClrStateAttribute(Idx index);
02007
02019 void StateAttribute(Idx index, const StateAttr& rAttr);
02020
02028 const StateAttr& StateAttribute(Idx index) const;
02029
02038 StateAttr* StateAttributep(Idx index);
02039
02043 void ClearTransAttributes(void);
02044
02054 void TransAttribute(const Transition& rTrans, const TransAttr& rAttr);
02055
02062 void ClrTransAttribute(const Transition& rTrans);
02063
02071 const TransAttr& TransAttribute(const Transition& rTrans) const;
02072
02081 TransAttr* TransAttributep(const Transition& rTrans);
02082
02086 void ClearGlobalAttribute(void);
02087
02094 void GlobalAttribute(const GlobalAttr& rAttr) {mGlobalAttribute=rAttr;};
02095
02099 const GlobalAttr& GlobalAttribute(void) const {return mGlobalAttribute;};
02100
02101
02105 GlobalAttr* GlobalAttributep(void) {return &mGlobalAttribute;};
02106
02107
02112
02113
02114
02115
02116
02124 StateSet AccessibleSet(void) const;
02125
02132 bool Accessible(void);
02133
02140 bool IsAccessible(void) const;
02141
02145 StateSet CoaccessibleSet(void) const;
02146
02153 bool Coaccessible(void);
02154
02161 bool IsCoaccessible(void) const;
02162
02166 StateSet TrimSet(void) const;
02167
02176 bool Trim(void);
02177
02184 bool IsTrim(void) const;
02185
02186
02191
02192
02193
02194
02195
02203 void MinimizeAlphabet(void);
02204
02217 bool IsDeterministic(void) const;
02218
02223 void SetMinStateIndexMap(void);
02224
02229 void ClearMinStateIndexMap(void) ;
02230
02239 Idx MinStateIndex(Idx index) const;
02240
02241
02248 SymbolTable* EventSymbolTablep(void) const;
02249
02258 void EventSymbolTablep(SymbolTable* pSymTab);
02259
02270 virtual void EventSymbolTablep(const vGenerator& rOtherGen);
02271
02275 protected:
02277 TaEventSet<EventAttr> mAlphabet;
02278
02280 TaStateSet<StateAttr> mStates;
02281
02283 ATransSet mTransRel;
02284
02286 StateSet mInitStates;
02287
02289 StateSet mMarkedStates;
02290
02292 std::map<Idx,Idx> mMinStateIndexMap;
02293
02295 GlobalAttr mGlobalAttribute;
02296
02307 void ReadGeneratorName(const char* pFileName);
02308
02319 void ReadGeneratorName(TokenReader& rTr);
02320
02331 void ReadAlphabet(const char* pFileName);
02332
02343 void ReadAlphabet(TokenReader& rTr);
02344
02356 void ReadStates(const char* pFileName);
02357
02369 void ReadStates(TokenReader& rTr);
02370
02381 void ReadTransRel(const char* pFileName);
02382
02393 void ReadTransRel(TokenReader& rTr);
02394
02403 void CheckAccessible(StateSet& accessibleset, Idx startState) const;
02404
02415 void CheckCoaccessible(StateSet& Coaccessibleset, const TransSetX2EvX1& rtrel, Idx startState) const;
02416
02417
02418 };
02419
02420
02425 typedef TaGenerator<AttributeVoid,AttributeVoid,AttributeVoid,AttributeVoid> Generator;
02426
02427
02428
02429 #define THIS TaGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
02430 #define TEMP template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
02431 #define BASE vGenerator
02432
02433
02434 TEMP THIS::TaGenerator(void) :
02435
02436 vGenerator()
02437 {
02438 FD_DG("TaGenerator(" << this << ")::TaGenerator()");
02439
02440 mStates.Name("States");
02441 mInitStates.Name("InitStates");
02442 mMarkedStates.Name("MarkedStates");
02443 mAlphabet.Name("Alphabet");
02444 }
02445
02446
02447 TEMP THIS::TaGenerator(const TaGenerator& rOtherGen) :
02448
02449 vGenerator(rOtherGen)
02450 {
02451 FD_DG("TaGenerator(" << this << ")::TaGenerator(" << &rOtherGen << ")");
02452
02453 rOtherGen.Copy(*this);
02454 }
02455
02456
02457
02458 TEMP THIS::TaGenerator(const vGenerator& rOtherGen) :
02459
02460 vGenerator(rOtherGen)
02461 {
02462 FD_DG("TaGenerator(" << this << ")::TaGenerator([v]" << &rOtherGen << ")");
02463
02464 rOtherGen.Copy(*this);
02465 }
02466
02467
02468 TEMP THIS::TaGenerator(const char* pFileName) :
02469
02470 vGenerator()
02471 {
02472 FD_DG("TaGenerator(" << this << ")::TaGenerator(" << pFileName << ")");
02473
02474 mStateNamesEnabled=true;
02475
02476 Read(pFileName);
02477 }
02478
02479
02480 TEMP void THIS::Copy(TaGenerator& rGen) const {
02481 FD_DG("TaGenerator(" << this << ")::Copy(" << &rGen << ")");
02482
02483 rGen.Clear();
02484
02485 rGen.EventSymbolTablep(mpEventSymbolTable);
02486
02487 rGen.StateSymbolTable(mStateSymbolTable);
02488
02489 rGen.Name(Name());
02490 rGen.StateNamesEnabled(StateNamesEnabled());
02491 rGen.mStates= mStates;
02492 rGen.mInitStates = mInitStates;
02493 rGen.mMarkedStates = mMarkedStates;
02494 rGen.mAlphabet = mAlphabet;
02495 rGen.mTransRel=mTransRel;
02496 rGen.mStateNamesEnabled=mStateNamesEnabled;
02497 rGen.mGlobalAttribute=mGlobalAttribute;
02498
02499 rGen.mMinStateIndexMap=mMinStateIndexMap;
02500
02501 #ifdef FAUDES_CHECKED
02502 if(!rGen.Valid()) {
02503 FD_DG("TaGenerator()::Copy(): invalid generator");
02504 rGen.DWrite();
02505 abort();
02506 }
02507 #endif
02508 }
02509
02510
02511 TEMP void THIS::Copy(vGenerator& rGen) const {
02512 FD_DG("TaGenerator(" << this << ")::Copy([v]" << &rGen << ")");
02513
02514 rGen.Clear();
02515
02516 rGen.EventSymbolTablep(mpEventSymbolTable);
02517
02518 rGen.StateSymbolTable(mStateSymbolTable);
02519
02520 rGen.Name(Name());
02521 rGen.StateNamesEnabled(StateNamesEnabled());
02522 rGen.InjectStates(mStates);
02523 rGen.InjectInitStates(mInitStates);
02524 rGen.InjectMarkedStates(mMarkedStates);
02525 rGen.InjectAlphabet(mAlphabet);
02526 rGen.InjectTransRel(mTransRel);
02527 #ifdef FAUDES_CHECKED
02528 if(!rGen.Valid()) {
02529 FD_DG("TaGenerator()::Copy([v]): invalid generator");
02530 rGen.DWrite();
02531 abort();
02532 }
02533 #endif
02534 }
02535
02536
02537
02538 TEMP void THIS::Move(TaGenerator& rGen) {
02539 FD_DG("TaGenerator(" << this << ")::Move(" << &rGen << ")");
02540 Copy(rGen);
02541 Clear();
02542 }
02543
02544
02545
02546 TEMP void THIS::Move(vGenerator& rGen) {
02547 FD_DG("TaGenerator(" << this << ")::Move([v]" << &rGen << ")");
02548 Copy(rGen);
02549 Clear();
02550 }
02551
02552
02553 TEMP THIS::~TaGenerator(void) {
02554 FD_DG("TaGenerator(" << this << ")::~TaGenerator()");
02555 }
02556
02557
02558 TEMP THIS* THIS::NewP(void) const {
02559
02560 THIS* res = new THIS;
02561
02562 res->EventSymbolTablep(BASE::mpEventSymbolTable);
02563 res->mStateNamesEnabled=BASE::mStateNamesEnabled;
02564 return res;
02565 }
02566
02567
02568 TEMP THIS THIS::NewAGen(void) const {
02569 THIS res;
02570
02571 res.EventSymbolTablep(BASE::mpEventSymbolTable);
02572 res.mStateNamesEnabled=BASE::mStateNamesEnabled;
02573 return res;
02574 }
02575
02576
02577
02578 TEMP TaGenerator<GlobalAttr,StateAttr,EventAttr,TransAttr>& THIS::operator = (const TaGenerator& rOtherGen) {
02579 FD_DG("TaGenerator(" << this << ")::operator = " << &rOtherGen);
02580 rOtherGen.Copy(*this);
02581 return *this;
02582 }
02583
02584
02585 TEMP TaGenerator<GlobalAttr,StateAttr,EventAttr,TransAttr>& THIS::operator = (const vGenerator& rOtherGen) {
02586 FD_DG("TaGenerator(" << this << ")::operator = [v]" << &rOtherGen);
02587 rOtherGen.Copy(*this);
02588 return *this;
02589 }
02590
02591
02592 TEMP SymbolTable* THIS::EventSymbolTablep(void) const {
02593 return BASE::EventSymbolTablep();
02594 }
02595
02596
02597 TEMP void THIS::EventSymbolTablep(SymbolTable* pSymTab) {
02598 BASE::EventSymbolTablep(pSymTab);
02599
02600 Clear();
02601 mAlphabet.SymbolTablep(mpEventSymbolTable);
02602 }
02603
02604
02605 TEMP void THIS::EventSymbolTablep(const vGenerator& rOtherGen) {
02606 BASE::EventSymbolTablep(rOtherGen);
02607 }
02608
02609
02610 TEMP void THIS::Write(void) const {
02611 TokenWriter tw(TokenWriter::Stdout);
02612 Write(tw);
02613 }
02614
02615
02616 TEMP void THIS::Write(const char* pFileName, std::ios::openmode openmode) {
02617 FD_DG("TaGenerator(" << this << ")::Write(" << pFileName << ")");
02618 SetMinStateIndexMap();
02619 TokenWriter tw(pFileName, openmode);
02620 Write(tw);
02621 ClearMinStateIndexMap();
02622 }
02623
02624
02625 TEMP std::string THIS::ToString(void) const {
02626 TokenWriter tw(TokenWriter::String);
02627 Write(tw);
02628 return tw.Str();
02629 }
02630
02631
02632 TEMP void THIS::Write(TokenWriter& rTw) const {
02633 FD_DG("TaGenerator(" << this << ")::Write(tw)");
02634
02635 rTw.WriteBegin("Generator");
02636 rTw << mMyName;
02637 rTw << "\n";
02638 rTw << "\n";
02639 WriteStatistics(rTw);
02640 rTw << "\n";
02641 mAlphabet.Write(rTw);
02642 rTw << "\n";
02643 WriteStateSet(rTw, mStates);
02644 rTw << "\n";
02645 WriteTransRel(rTw);
02646 rTw << "\n";
02647 WriteStateSet(rTw, mInitStates);
02648 rTw << "\n";
02649 WriteStateSet(rTw, mMarkedStates);
02650 rTw << "\n";
02651 mGlobalAttribute.Write(rTw);
02652 rTw << "\n";
02653 rTw.WriteEnd("Generator");
02654 }
02655
02656
02657 TEMP void THIS::DWrite(void) const {
02658 TokenWriter tw(TokenWriter::Stdout);
02659 tw.WriteBegin("Generator");
02660 tw << mMyName;
02661 tw << "\n";
02662 tw << "\n";
02663 WriteStatistics(tw);
02664 tw << "\n";
02665 mAlphabet.DWrite(tw);
02666 tw << "\n";
02667 DWriteStateSet(tw, mStates);
02668 tw << "\n";
02669 DWriteTransRel(tw);
02670 tw << "\n";
02671 DWriteStateSet(tw, mInitStates);
02672 tw << "\n";
02673 DWriteStateSet(tw, mMarkedStates);
02674 tw << "\n";
02675 mGlobalAttribute.Write(tw);
02676 tw << "\n";
02677 tw.WriteEnd("Generator");
02678 tw << "\n";
02679 }
02680
02681
02682 TEMP void THIS::WriteAlphabet(void) const {
02683 TokenWriter tw(TokenWriter::Stdout);
02684 WriteAlphabet(tw);
02685 }
02686
02687
02688 TEMP std::string THIS::AlphabetToString(void) const {
02689 TokenWriter tw(TokenWriter::String);
02690 WriteAlphabet(tw);
02691 return tw.Str();
02692 }
02693
02694
02695 TEMP void THIS::WriteAlphabet(TokenWriter& rTw) const {
02696 mAlphabet.Write(rTw);
02697 }
02698
02699
02700 TEMP template<class OtherAttr>
02701 void THIS::WriteStateSet(const TaStateSet<OtherAttr>& rStateSet) const {
02702 TokenWriter tw(TokenWriter::Stdout);
02703 WriteStateSet(tw,rStateSet);
02704 }
02705
02706
02707 TEMP void THIS::WriteStateSet(const StateSet& rStateSet) const {
02708 TaStateSet<AttributeVoid> vcopy = rStateSet;
02709 WriteStateSet(vcopy);
02710 }
02711
02712
02713 TEMP template<class OtherAttr>
02714 std::string THIS::StateSetToString(const TaStateSet<OtherAttr>& rStateSet) const {
02715 TokenWriter tw(TokenWriter::String);
02716 WriteStateSet(tw,rStateSet);
02717 return tw.Str();
02718 }
02719
02720
02721 TEMP std::string THIS::StateSetToString(const StateSet& rStateSet) const {
02722 TaStateSet<AttributeVoid> vcopy = rStateSet;
02723 return StateSetToString(vcopy);
02724 }
02725
02726
02727 TEMP template<class OtherAttr>
02728 void THIS::WriteStateSet(TokenWriter& rTw, const TaStateSet<OtherAttr>& rStateSet) const {
02729 rTw.WriteBegin(rStateSet.Name());
02730
02731
02732 std::map<Idx,Idx> reversemap;
02733 std::map<Idx,Idx>::const_iterator minit;
02734 StateSet::Iterator sit;
02735 for (sit = rStateSet.Begin(); sit != rStateSet.End(); ++sit) {
02736 reversemap[MinStateIndex(*sit)] = *sit;
02737 }
02738
02739 for(minit = reversemap.begin(); minit != reversemap.end(); ++minit) {
02740
02741 std::map<Idx,Idx>::const_iterator conit=minit;
02742 Idx start = conit->first;
02743 Idx anoncount = 0;
02744 for(; conit != reversemap.end(); ++conit) {
02745 if(StateName(conit->second) != "") break;
02746 if(!StateAttribute(conit->second).IsDefault()) break;
02747 if(conit->first != start+anoncount) break;
02748 ++anoncount;
02749 }
02750
02751 if (anoncount > FD_CONSECUTIVE) {
02752 rTw.WriteBegin("Consecutive");
02753 rTw << start;
02754 rTw << start+anoncount-1;
02755 rTw.WriteEnd("Consecutive");
02756 minit=conit;
02757 }
02758
02759 if(minit == reversemap.end() )
02760 break;
02761
02762 std::string statename = StateName(minit->second);
02763 if (statename != "") {
02764 rTw << statename;
02765 } else {
02766 rTw << minit->first;
02767 }
02768
02769 OtherAttr attr=rStateSet.Attribute(minit->second);
02770 attr.Write(rTw);
02771 }
02772 rTw.WriteEnd(rStateSet.Name());
02773 }
02774
02775
02776 TEMP void THIS::WriteStateSet(TokenWriter& rTw, const StateSet& rStateSet) const {
02777 TaStateSet<AttributeVoid> vcopy=rStateSet;
02778 WriteStateSet(rTw,vcopy);
02779 }
02780
02781
02782 TEMP template<class OtherAttr>
02783 void THIS::DWriteStateSet(TokenWriter& rTw, const TaStateSet<OtherAttr>& rStateSet) const {
02784 rTw.WriteBegin(rStateSet.Name());
02785 StateSet::Iterator lit;
02786 std::map<Idx,Idx>::const_iterator minit;
02787 for(lit = rStateSet.Begin(); lit != rStateSet.End(); ++lit) {
02788 rTw << SStr(*lit);
02789 OtherAttr attr=rStateSet.Attribute(*lit);
02790 attr.Write(rTw);
02791 }
02792 rTw.WriteEnd(rStateSet.Name());
02793 }
02794
02795
02796
02797 TEMP void THIS::DWriteStateSet(TokenWriter& rTw, const StateSet& rStateSet) const {
02798 TaStateSet<AttributeVoid> vcopy=rStateSet;
02799 DWriteStateSet(rTw,vcopy);
02800 }
02801
02802
02803 TEMP std::string THIS::StatesToString(void) const {
02804 return StateSetToString(mStates);
02805 }
02806
02807
02808 TEMP std::string THIS::MarkedStatesToString(void) const {
02809 return StateSetToString(mMarkedStates);
02810 }
02811
02812
02813 TEMP std::string THIS::InitStatesToString(void) const {
02814 return StateSetToString(mInitStates);
02815 }
02816
02817
02818
02819 TEMP void THIS::WriteTransRel(void) const {
02820 TokenWriter tw(TokenWriter::Stdout);
02821 WriteTransRel(tw);
02822 }
02823
02824
02825 TEMP std::string THIS::TransRelToString(void) const {
02826 TokenWriter tw(TokenWriter::String);
02827 WriteTransRel(tw);
02828 return tw.Str();
02829 }
02830
02831
02832 TEMP void THIS::WriteTransRel(TokenWriter& rTw) const {
02833 typename ATransSet::Iterator tit;
02834 int oldcolumns = rTw.Columns();
02835 rTw.Columns(3);
02836 rTw.WriteBegin("TransRel");
02837 bool smalltransrel = (Size() < FD_SMALLTRANSREL);
02838
02839 for (tit = mTransRel.Begin(); tit != mTransRel.End(); ++tit) {
02840
02841
02842 Idx x1=MinStateIndex(tit->X1);
02843 if (smalltransrel) {
02844 std::string x1name = StateName(tit->X1);
02845 if (x1name != "") {
02846 rTw << x1name;
02847 } else {
02848 rTw << x1;
02849 }
02850 } else {
02851 rTw << x1;
02852 }
02853
02854
02855 rTw << EventName(tit->Ev);
02856
02857
02858 Idx x2=MinStateIndex(tit->X2);
02859 if (smalltransrel) {
02860 std::string x2name = StateName(tit->X2);
02861 if (x2name != "") {
02862 rTw << x2name;
02863 } else {
02864 rTw << x2;
02865 }
02866 } else {
02867 rTw << x2;
02868 }
02869
02870
02871 TransAttribute(*tit).Write(rTw);
02872
02873 }
02874 rTw.WriteEnd("TransRel");
02875 rTw.Columns(oldcolumns);
02876 }
02877
02878
02879 TEMP void THIS::DWriteTransRel(TokenWriter& rTw) const {
02880 typename ATransSet::Iterator tit;
02881 int oldcolumns = rTw.Columns();
02882 rTw.Columns(1);
02883 rTw.WriteBegin("TransRel");
02884 for (tit = mTransRel.Begin(); tit != mTransRel.End(); ++tit) {
02885 rTw << TStr(*tit);
02886 TransAttr attr=mTransRel.Attribute(*tit);
02887 attr.Write(rTw);
02888 }
02889 rTw.WriteEnd("TransRel");
02890 rTw.Columns(oldcolumns);
02891 }
02892
02893
02894
02895
02896 TEMP
02897 void THIS::WriteStatistics(void) const
02898 {
02899 TokenWriter tw(TokenWriter::Stdout);
02900 WriteStatistics(tw);
02901 }
02902
02903
02904 TEMP std::string THIS::StatisticsToString(void) const {
02905 TokenWriter tw(TokenWriter::String);
02906 WriteStatistics(tw);
02907 return tw.Str();
02908 }
02909
02910
02911 TEMP void THIS::WriteStatistics(TokenWriter& rTw) const
02912 {
02913 rTw.Comment("");
02914 rTw.Comment(" Statistics for " + Name());
02915 rTw.Comment(" States: " + ToStringInteger(Size()) );
02916 rTw.Comment(" Init/Marked: " + ToStringInteger(mInitStates.Size())
02917 + "/" + ToStringInteger(mMarkedStates.Size()));
02918 rTw.Comment(" Events: " + ToStringInteger(mAlphabet.Size()) );
02919 rTw.Comment(" Transitions: " + ToStringInteger(mTransRel.Size()) );
02920 rTw.Comment(" StateSymbols: " + ToStringInteger(mpStateSymbolTable->Size()) );
02921 rTw.Comment(" Attrib. E/S/T: " + ToStringInteger(mAlphabet.AttributesSize())
02922 + "/" + ToStringInteger(mStates.AttributesSize())
02923 + "/" + ToStringInteger(mTransRel.AttributesSize()) );
02924 rTw.Comment("");
02925 }
02926
02927
02928 TEMP void THIS::DotWrite(const std::string& rFileName) {
02929 FD_DG("TaGenerator(" << this << ")::DotWrite(" << rFileName << ")");
02930 SetMinStateIndexMap();
02931 StateSet::Iterator lit;
02932 typename ATransSet::Iterator tit;
02933 try {
02934 std::ofstream stream;
02935 stream.exceptions(std::ios::badbit|std::ios::failbit);
02936 stream.open(rFileName.c_str());
02937 stream << "digraph \"" << Name() << "\" {" << std::endl;
02938 stream << " rankdir=LR" << std::endl;
02939 stream << " node [shape=circle];" << std::endl;
02940 stream << std::endl;
02941 stream << " // istates" << std::endl;
02942 int i = 1;
02943 for (lit = InitStatesBegin(); lit != InitStatesEnd(); ++lit) {
02944 std::string xname= StateName(*lit);
02945 if(xname=="") xname=ToStringInteger(MinStateIndex(*lit));
02946 stream << " dot_dummyinit_" << i << " [shape=none, label=\"\" ];" << std::endl;
02947 stream << " dot_dummyinit_" << i << " -> \"" << xname << "\";" << std::endl;
02948 i++;
02949 }
02950 stream << std::endl;
02951 stream << " // mstates" << std::endl;
02952 for (lit = MarkedStatesBegin(); lit != MarkedStatesEnd(); ++lit) {
02953 std::string xname= StateName(*lit);
02954 if(xname=="") xname=ToStringInteger(MinStateIndex(*lit));
02955 stream << " \"" << xname << "\" [shape=doublecircle];" << std::endl;
02956 }
02957 stream << std::endl;
02958 stream << " // rest of stateset" << std::endl;
02959 for (lit = StatesBegin(); lit != StatesEnd(); ++lit) {
02960 if (! (ExistsInitState(*lit) || ExistsMarkedState(*lit)) ) {
02961 std::string xname= StateName(*lit);
02962 if(xname=="") xname=ToStringInteger(MinStateIndex(*lit));
02963 stream << " \"" << xname << "\";" << std::endl;
02964 }
02965 }
02966 stream << std::endl;
02967 stream << " // transition relation" << std::endl;
02968 for (tit = TransRelBegin(); tit != TransRelEnd(); ++tit) {
02969 std::string x1name= StateName(tit->X1);
02970 if(x1name=="") x1name=ToStringInteger(MinStateIndex(tit->X1));
02971 std::string x2name= StateName(tit->X2);
02972 if(x2name=="") x2name=ToStringInteger(MinStateIndex(tit->X2));
02973 stream << " \"" << x1name << "\" -> \"" << x2name
02974 << "\" [label=\"" << EventName(tit->Ev) << "\"];" << std::endl;
02975 }
02976 stream << "};" << std::endl;
02977 stream.close();
02978 }
02979 catch (std::ios::failure&) {
02980 throw Exception("TaGenerator::DotWrite",
02981 "Exception opening/writing dotfile \""+rFileName+"\"", 2);
02982 }
02983 ClearMinStateIndexMap();
02984 }
02985
02986
02987 TEMP void THIS::DDotWrite(const std::string& rFileName) const {
02988 FD_DG("TaGenerator(" << this << ")::DDotWrite(" << rFileName << ")");
02989 StateSet::Iterator lit;
02990 typename ATransSet::Iterator tit;
02991 try {
02992 std::ofstream stream;
02993 stream.exceptions(std::ios::badbit|std::ios::failbit);
02994 stream.open(rFileName.c_str());
02995 stream << "digraph \"" << Name() << "\" {" << std::endl;
02996 stream << " rankdir=LR" << std::endl;
02997 stream << " node [shape=circle];" << std::endl;
02998 stream << std::endl;
02999 stream << " // istates" << std::endl;
03000 int i = 1;
03001 for (lit = InitStatesBegin(); lit != InitStatesEnd(); ++lit) {
03002 stream << " dot_dummyinit_" << i << " [shape=none, label=\"\" ];" << std::endl;
03003 stream << " dot_dummyinit_" << i << " -> \""
03004 << SStr(*lit) << "\";" << std::endl;
03005 i++;
03006 }
03007 stream << std::endl;
03008 stream << " // mstates" << std::endl;
03009 for (lit = MarkedStatesBegin(); lit != MarkedStatesEnd(); ++lit) {
03010 stream << " \"" << SStr(*lit) << "\" [shape=doublecircle];" << std::endl;
03011 }
03012 stream << std::endl;
03013 stream << " // rest of stateset" << std::endl;
03014 for (lit = StatesBegin(); lit != StatesEnd(); ++lit) {
03015
03016 if (! (ExistsInitState(*lit) || ExistsMarkedState(*lit)) ) {
03017 stream << " \"" << SStr(*lit) << "\";" << std::endl;
03018 }
03019 }
03020 stream << std::endl;
03021 stream << " // transition relation" << std::endl;
03022 for (tit = TransRelBegin(); tit != TransRelEnd(); ++tit) {
03023 stream << " \"" << SStr(tit->X1)
03024 << "\" -> \"" << SStr(tit->X2)
03025 << "\" [label=\"" << EventName(tit->Ev) << "\"];" << std::endl;
03026 }
03027 stream << "};" << std::endl;
03028 stream.close();
03029 }
03030 catch (std::ios::failure&) {
03031 throw Exception("TaGenerator::DotWrite",
03032 "Exception opening/writing dotfile \""+rFileName+"\"", 2);
03033 }
03034 }
03035
03036
03037
03038 TEMP void THIS::XDotWrite(const std::string& rFileName) const {
03039 FD_DG("TaGenerator(" << this << ")::XDotWrite(" << rFileName << ")");
03040 StateSet::Iterator lit;
03041 typename ATransSet::Iterator tit;
03042 try {
03043 std::ofstream stream;
03044 stream.exceptions(std::ios::badbit|std::ios::failbit);
03045 stream.open(rFileName.c_str());
03046 stream << "digraph \"___" << Name() << "___\" {" << std::endl;
03047 stream << " rankdir=LR" << std::endl;
03048 stream << " node [shape=circle];" << std::endl;
03049 stream << std::endl;
03050 stream << " // stateset" << std::endl;
03051 for (lit = StatesBegin(); lit != StatesEnd(); ++lit) {
03052 stream << " \"s" << *lit << "\";" << std::endl;
03053 }
03054 stream << std::endl;
03055 stream << " // transition relation" << std::endl;
03056 for (tit = TransRelBegin(); tit != TransRelEnd(); ++tit) {
03057 stream << " \"s" << tit->X1
03058 << "\" -> \"s" << tit->X2
03059 << "\" [label=\"e" << tit->Ev << "\" " << "polyline" << "];" << std::endl;
03060 }
03061 stream << "};" << std::endl;
03062 stream.close();
03063 }
03064 catch (std::ios::failure&) {
03065 throw Exception("TaGenerator::XDotWrite",
03066 "Exception opening/writing dotfile \""+rFileName+"\"", 2);
03067 }
03068 }
03069
03070
03071 TEMP void THIS::Read(const char* pFileName) {
03072 TokenReader tr(pFileName);
03073 Read(tr);
03074 }
03075
03076
03077 TEMP void THIS::Read(TokenReader& rTr) {
03078 FD_DG("TaGenerator(" << this << ")::Read(" << rTr.FileName() << ")");
03079
03080 Clear();
03081
03082 rTr.SeekBegin("Generator");
03083
03084 ReadGeneratorName(rTr);
03085
03086 ReadAlphabet(rTr);
03087
03088 ReadStates(rTr);
03089
03090 ReadTransRel(rTr);
03091
03092 ReadStateSet(rTr, "InitStates", mInitStates);
03093
03094 ReadStateSet(rTr, "MarkedStates", mMarkedStates);
03095
03096 mGlobalAttribute.Read(rTr);
03097
03098 rTr.SeekEnd("Generator");
03099 }
03100
03101
03102 TEMP void THIS::ReadGeneratorName(const char* pFileName) {
03103 TokenReader tr(pFileName);
03104 tr.SeekBegin("Generator");
03105 ReadGeneratorName(tr);
03106 }
03107
03108
03109 TEMP void THIS::ReadGeneratorName(TokenReader& rTr) {
03110 FD_DG("TaGenerator(" << this << ")::ReadGeneratorName(\""
03111 << rTr.FileName() << "\")");
03112 mMyName=rTr.ReadString();
03113 }
03114
03115
03116 TEMP void THIS::ReadAlphabet(const char* pFileName) {
03117 FD_DG("TaGenerator(" << this << ")::ReadAlphabet(\"" << pFileName << "\")");
03118 mAlphabet.Read(pFileName,"Alphabet");
03119 }
03120
03121
03122 TEMP void THIS::ReadAlphabet(TokenReader& rTr) {
03123 FD_DG("TaGenerator(" << this << ")::ReadAlphabet(\""
03124 << rTr.FileName() << "\")");
03125 mAlphabet.Read(rTr,"Alphabet");
03126 }
03127
03128
03129 TEMP void THIS::ReadStates(const char* pFileName) {
03130 TokenReader tr(pFileName);
03131 ReadStates(tr);
03132 }
03133
03134
03135 TEMP void THIS::ReadStates(TokenReader& rTr) {
03136 FD_DG("TaGenerator(" << this << ")::ReadStates(\"" << rTr.FileName() << "\")");
03137
03138 Token token;
03139
03140 mStates.Clear();
03141 mStates.Name("States");
03142 mStateSymbolTable.Clear();
03143 rTr.SeekBegin("States");
03144 while(rTr.Peek(token)) {
03145
03146 if (token.Type() == Token::End) {
03147 break;
03148 }
03149
03150 if (token.Type() == Token::Integer) {
03151 rTr.Get(token);
03152 Idx index = token.IntegerValue();
03153 FD_DG("TaGenerator(" << this << ")::ReadStates(\"" << rTr.FileName() << "\"): by index " << index);
03154 if(mStates.Exists(index)) {
03155 std::stringstream errstr;
03156 errstr << "Token " << token.IntegerValue() << " appears twice in stateset"
03157 << rTr.FileLine();
03158 throw Exception("TaGenerator::ReadStates", errstr.str(), 80);
03159 }
03160 StateAttr sattr;
03161 sattr.Read(rTr);
03162 AttributeVoid vattr;
03163 vattr.Read(rTr);
03164 InsState(index,sattr);
03165 continue;
03166 }
03167
03168 if (token.Type() == Token::String) {
03169 rTr.Get(token);
03170 FD_DG("TaGenerator(" << this << ")::ReadStates(\"" << rTr.FileName() << "\"): by name " << token.StringValue());
03171 if(ExistsState(token.StringValue())) {
03172 std::stringstream errstr;
03173 errstr << "Token " << token.StringValue() << " appears twice in stateset"
03174 << rTr.FileLine();
03175 throw Exception("TaGenerator::ReadStates", errstr.str(), 80);
03176 }
03177 StateAttr sattr;
03178 sattr.Read(rTr);
03179 AttributeVoid vattr;
03180 vattr.Read(rTr);
03181 InsState(token.StringValue(),sattr);
03182 continue;
03183 }
03184
03185 if (token.Type() == Token::Begin && token.StringValue() == "Consecutive") {
03186 rTr.ReadBegin("Consecutive");
03187 Token token1,token2;
03188 rTr.Get(token1);
03189 rTr.Get(token2);
03190 FD_DG("TaGenerator(" << this << ")::ReadStates(\"" << rTr.FileName() << "\"): consecutive range");
03191 if ((token1.Type() != Token::Integer) || (token2.Type() != Token::Integer)) {
03192 std::stringstream errstr;
03193 errstr << "Invalid range of consecutive states" << rTr.FileLine();
03194 throw Exception("TaGenerator::ReadStates", errstr.str(), 80);
03195 }
03196 for(Idx index = (Idx) token1.IntegerValue(); index <= (Idx) token2.IntegerValue(); ++index) {
03197 if(mStates.Exists(index)) {
03198 std::stringstream errstr;
03199 errstr << "Index " << index << " appears twice in stateset"
03200 << rTr.FileLine();
03201 throw Exception("TaGenerator::ReadStates", errstr.str(), 80);
03202 }
03203 InsState(index);
03204 }
03205 rTr.ReadEnd("Consecutive");
03206 continue;
03207 }
03208
03209 std::stringstream errstr;
03210 errstr << "Invalid token" << rTr.FileLine();
03211 throw Exception("TaGenerator::ReadStates", errstr.str(), 80);
03212 }
03213 rTr.SeekEnd("States");
03214 }
03215
03216
03217
03218 TEMP void THIS::ReadStateSet(TokenReader& rTr, const std::string& rLabel, StateSet& rStateSet) const {
03219 FD_DG("TaGenerator(" << this << ")::ReadStateSet(\"" << rLabel<< "\")");
03220
03221 Token token;
03222
03223 rStateSet.Clear();
03224 rTr.SeekBegin(rLabel);
03225 rStateSet.Name(rLabel);
03226 while(rTr.Peek(token)) {
03227
03228 if (token.Type() == Token::End) {
03229 break;
03230 }
03231
03232 if (token.Type() == Token::Integer) {
03233 rTr.Get(token);
03234 Idx index = token.IntegerValue();
03235 if(!ExistsState(index)) {
03236 std::stringstream errstr;
03237 errstr << "Token " << token.IntegerValue() << " 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
03247 if (token.Type() == Token::String) {
03248 rTr.Get(token);
03249 Idx index =StateIndex(token.StringValue());
03250 if(index==0) {
03251 std::stringstream errstr;
03252 errstr << "Token " << token.StringValue() << " not in stateset"
03253 << rTr.FileLine();
03254 throw Exception("TaGenerator::ReadStateSet", errstr.str(), 80);
03255 }
03256 AttributeVoid vattr;
03257 vattr.Read(rTr);
03258 rStateSet.Insert(index);
03259 continue;
03260 }
03261
03262 if (token.Type() == Token::Begin && token.StringValue() == "Consecutive") {
03263 rTr.ReadBegin("Consecutive");
03264 Token token1,token2;
03265 rTr.Get(token1);
03266 rTr.Get(token2);
03267 if ((token1.Type() != Token::Integer) || (token2.Type() != Token::Integer)) {
03268 std::stringstream errstr;
03269 errstr << "Invalid range of consecutive states" << rTr.FileLine();
03270 throw Exception("TaGenerator::ReadStateSet", errstr.str(), 80);
03271 }
03272 for(Idx index = (Idx) token1.IntegerValue(); index <= (Idx) token2.IntegerValue(); ++index) {
03273 if(!ExistsState(index)) {
03274 std::stringstream errstr;
03275 errstr << "Token " << token.IntegerValue() << " not in stateset"
03276 << rTr.FileLine();
03277 throw Exception("TaGenerator::ReadStateSet", errstr.str(), 80);
03278 }
03279 rStateSet.Insert(index);
03280 }
03281 rTr.ReadEnd("Consecutive");
03282 continue;
03283 }
03284
03285 std::stringstream errstr;
03286 errstr << "Invalid token" << rTr.FileLine();
03287 throw Exception("TaGenerator::ReadStateSet", errstr.str(), 50);
03288 }
03289 rTr.SeekEnd(rLabel);
03290 }
03291
03292
03293 TEMP void THIS::ReadTransRel(const char* pFileName) {
03294 TokenReader tr(pFileName);
03295 ReadTransRel(tr);
03296 }
03297
03298
03299 TEMP void THIS::ReadTransRel(TokenReader& rTr) {
03300 FD_DG("TaGenerator(" << this << ")::ReadTransRel(\"" << rTr.FileName() << "\")");
03301 try {
03302 Token token;
03303 Idx x1 = 0, ev = 0, x2 = 0;
03304 rTr.SeekBegin("TransRel");
03305
03306 while (rTr.Peek(token)) {
03307
03308 if ((token.Type() == Token::End)) break;
03309
03310
03311 rTr >> token;
03312 if (token.Type() == Token::Integer) {
03313 x1=token.IntegerValue();
03314 } else if (token.Type() == Token::String) {
03315 token.StringValue();
03316 x1=StateIndex(token.StringValue());
03317 } else break;
03318
03319
03320 rTr >> token;
03321 if (token.Type() == Token::Integer) {
03322 ev=token.IntegerValue();
03323 } else if (token.Type() == Token::String) {
03324 token.StringValue();
03325 ev=EventIndex(token.StringValue());
03326 } else break;
03327
03328
03329 rTr >> token;
03330 if (token.Type() == Token::Integer) {
03331 x2=token.IntegerValue();
03332 } else if (token.Type() == Token::String) {
03333 token.StringValue();
03334 x2=StateIndex(token.StringValue());
03335 } else break;
03336
03337
03338 TransAttr attr;
03339 attr.Read(rTr);
03340 AttributeVoid vattr;
03341 vattr.Read(rTr);
03342
03343
03344 if( (!ExistsState(x1)) || (!ExistsState(x2)) ){
03345 std::stringstream errstr;
03346 errstr << "invalid state" << rTr.FileLine();
03347 throw Exception("TaGenerator::ReadTransRel", errstr.str(), 85);
03348 }
03349 if(!ExistsEvent(ev)) {
03350 std::stringstream errstr;
03351 errstr << "invalid event" << rTr.FileLine();
03352 throw Exception("TaGenerator::ReadTransRel", errstr.str(), 85);
03353 }
03354
03355
03356 SetTransition(Transition(x1, ev, x2),attr);
03357
03358 }
03359 rTr.SeekEnd("TransRel");
03360 }
03361 catch (faudes::Exception&) {
03362 std::stringstream errstr;
03363 errstr << "Reading TransRel failed in " << rTr.FileLine();
03364 throw Exception("TaGenerator::ReadTransRel", errstr.str(), 50);
03365 }
03366 }
03367
03368
03369 TEMP bool THIS::Valid(void) {
03370 FD_DG("TaGenerator(" << this << ")::Valid()");
03371 typename ATransSet::Iterator tit;
03372 StateSet::Iterator lit;
03373 for (tit = TransRelBegin(); tit != TransRelEnd(); ++tit) {
03374 if (! ExistsState(tit->X1)) return false;
03375 if (! ExistsEvent(tit->Ev)) return false;
03376 if (! ExistsState(tit->X2)) return false;
03377 }
03378 for (lit = InitStatesBegin(); lit != InitStatesEnd(); ++lit) {
03379 if (! ExistsState(static_cast<Idx>(*lit))) return false;
03380 }
03381 for (lit = MarkedStatesBegin(); lit != MarkedStatesEnd(); ++lit) {
03382 if (! ExistsState(static_cast<Idx>(*lit))) return false;
03383 }
03384 if (mAlphabet.Name() != "Alphabet") return false;
03385 if (mStates.Name() != "States") return false;
03386 if (mInitStates.Name() != "InitStates") return false;
03387 if (mMarkedStates.Name() != "MarkedStates") return false;
03388 return true;
03389 }
03390
03391
03392 TEMP Idx THIS::AlphabetSize(void) const {
03393 return mAlphabet.Size();
03394 }
03395
03396
03397 TEMP Idx THIS::Size(void) const {
03398 return mStates.Size();
03399 }
03400
03401
03402
03403 TEMP void THIS::Clear(void) {
03404 FD_DG("TaGenerator(" << this << ")::Clear()");
03405 mAlphabet.Clear();
03406 mStates.Clear();
03407 BASE::mpStateSymbolTable->Clear();
03408 mTransRel.Clear();
03409 mInitStates.Clear();
03410 mMarkedStates.Clear();
03411 ClearGlobalAttribute();
03412 }
03413
03414
03415 TEMP void THIS::ClearGlobalAttribute(void) {
03416 mGlobalAttribute = GlobalAttr();
03417 }
03418
03419
03420 TEMP void THIS::ClearStateAttributes(void) {
03421 mStates.ClearAttributes();
03422 }
03423
03424
03425 TEMP void THIS::ClearEventAttributes(void) {
03426 mAlphabet.ClearAttributes();
03427 }
03428
03429
03430 TEMP void THIS::ClearTransAttributes(void) {
03431 mTransRel.ClearAttributes();
03432 }
03433
03434
03435 TEMP void THIS::ClearAttributes(void) {
03436 ClearGlobalAttribute();
03437 ClearStateAttributes();
03438 ClearEventAttributes();
03439 ClearTransAttributes();
03440 }
03441
03442
03443
03444 TEMP void THIS::ClearStates(void) {
03445 mStates.Clear();
03446 mTransRel.Clear();
03447 mInitStates.Clear();
03448 mMarkedStates.Clear();
03449 mpStateSymbolTable->Clear();
03450 }
03451
03452
03453 TEMP Idx THIS::TransRelSize(void) const {
03454 return mTransRel.Size();
03455 }
03456
03457
03458 TEMP Idx THIS::InitStatesSize(void) const {
03459 return mInitStates.Size();
03460 }
03461
03462
03463 TEMP Idx THIS::MarkedStatesSize(void) const {
03464 return mMarkedStates.Size();
03465 }
03466
03467
03468 TEMP bool THIS::AlphabetEmpty(void) const {
03469 return mAlphabet.Empty();
03470 }
03471
03472
03473 TEMP bool THIS::Empty(void) const {
03474 return mStates.Empty();
03475 }
03476
03477
03478 TEMP bool THIS::TransRelEmpty(void) const {
03479 return mTransRel.Empty();
03480 }
03481
03482
03483 TEMP bool THIS::InitStatesEmpty(void) const {
03484 return mInitStates.Empty();
03485 }
03486
03487
03488 TEMP bool THIS::MarkedStatesEmpty(void) const {
03489 return mMarkedStates.Empty();
03490 }
03491
03492
03493 TEMP EventSet::Iterator THIS::AlphabetBegin(void) const {
03494 return mAlphabet.Begin();
03495 }
03496
03497
03498 TEMP EventSet::Iterator THIS::AlphabetEnd(void) const {
03499 return mAlphabet.End();
03500 }
03501
03502
03503 TEMP StateSet::Iterator THIS::StatesBegin(void) const {
03504 return mStates.Begin();
03505 }
03506
03507
03508 TEMP StateSet::Iterator THIS::StatesEnd(void) const {
03509 return mStates.End();
03510 }
03511
03512
03513 TEMP typename THIS::ATransSet::Iterator
03514 THIS::TransRelBegin(void) const {
03515 return mTransRel.Begin();
03516 }
03517
03518
03519 TEMP typename THIS::ATransSet::Iterator
03520 THIS::TransRelEnd(void) const {
03521 return mTransRel.End();
03522 }
03523
03524
03525 TEMP typename THIS::ATransSet::Iterator
03526 THIS::TransRelBegin(Idx x1) const {
03527 return mTransRel.Begin(x1);
03528 }
03529
03530
03531 TEMP typename THIS::ATransSet::Iterator
03532 THIS::TransRelEnd(Idx x1) const {
03533 return mTransRel.End(x1);
03534 }
03535
03536
03537 TEMP typename THIS::ATransSet::Iterator
03538 THIS::TransRelBegin(Idx x1, Idx ev) const {
03539 return mTransRel.Begin(x1, ev);
03540 }
03541
03542
03543 TEMP typename THIS::ATransSet::Iterator
03544 THIS::TransRelEnd(Idx x1, Idx ev) const {
03545 return mTransRel.End(x1, ev);
03546 }
03547
03548
03549 TEMP typename THIS::ATransSet::Iterator
03550 THIS::FindTransition(const Transition& rTrans) const {
03551 return mTransRel.Find(rTrans);
03552 }
03553
03554
03555 TEMP typename THIS::ATransSet::Iterator
03556 THIS::FindTransition(Idx x1, Idx ev, Idx x2) const {
03557 return mTransRel.Find(Transition(x1, ev, x2));
03558 }
03559
03560
03561 TEMP typename THIS::ATransSet::Iterator THIS::FindTransition(
03562 const std::string& rX1, const std::string& rEv, const std::string& rX2) const
03563 {
03564 return mTransRel.Find(StateIndex(rX1), EventIndex(rEv), StateIndex(rX2));
03565 }
03566
03567
03568 TEMP bool THIS::ExistsTransition(const Transition& rTrans) const {
03569 return mTransRel.Exists(rTrans);
03570 }
03571
03572
03573 TEMP bool THIS::ExistsTransition(Idx x1, Idx ev, Idx x2) const {
03574 return mTransRel.Exists(Transition(x1, ev, x2));
03575 }
03576
03577
03578 TEMP bool THIS::ExistsTransition(
03579 const std::string& rX1, const std::string& rEv, const std::string& rX2) const
03580 {
03581 return mTransRel.Exists(StateIndex(rX1), EventIndex(rEv), StateIndex(rX2));
03582 }
03583
03584
03585
03586 TEMP Idx THIS::InitState(void) const {
03587 #ifdef FAUDES_CHECKED
03588 if(mInitStates.Size()!=1) {
03589 std::stringstream errstr;
03590 errstr << "init state does not exist uniquely" << std::endl;
03591 throw Exception("TaGenerator::InitSTate", errstr.str(), 92);
03592 }
03593 #endif
03594 return *mInitStates.Begin();
03595 }
03596
03597
03598 TEMP StateSet::Iterator THIS::InitStatesBegin(void) const {
03599 return mInitStates.Begin();
03600 }
03601
03602
03603 TEMP StateSet::Iterator THIS::InitStatesEnd(void) const {
03604 return mInitStates.End();
03605 }
03606
03607
03608 TEMP StateSet::Iterator THIS::MarkedStatesBegin(void) const {
03609 return mMarkedStates.Begin();
03610 }
03611
03612
03613 TEMP StateSet::Iterator THIS::MarkedStatesEnd(void) const {
03614 return mMarkedStates.End();
03615 }
03616
03617
03618 TEMP void THIS::InjectAlphabet(const EventSet& newalphabet) {
03619 FD_DG("TaGenerator::InjectAlphabet() " << newalphabet.ToString());
03620 #ifdef FAUDES_CHECKED
03621 if(newalphabet.SymbolTablep()!=mpEventSymbolTable) {
03622 std::stringstream errstr;
03623 errstr << "symboltable mismatch aka not implemented" << std::endl;
03624 throw Exception("TaGenerator::InjectAlphabet", errstr.str(), 88);
03625 }
03626 #endif
03627 mAlphabet = newalphabet;
03628 mAlphabet.Name("Alphabet");
03629 }
03630
03631
03632 TEMP void THIS::InjectAlphabet(const TaEventSet<EventAttr>& newalphabet) {
03633 FD_DG("TaGenerator::InjectAlphabet(TaEventSet<EventAttr>) " << newalphabet.ToString());
03634 #ifdef FAUDES_CHECKED
03635 if(newalphabet.SymbolTablep()!=mpEventSymbolTable) {
03636 std::stringstream errstr;
03637 errstr << "symboltable mismatch aka not implemented" << std::endl;
03638 throw Exception("TaGenerator::InjectAlphabet", errstr.str(), 88);
03639 }
03640 #endif
03641 mAlphabet = newalphabet;
03642 mAlphabet.Name("Alphabet");
03643 }
03644
03645
03646 TEMP bool THIS::InsEvent(Idx index) {
03647 FD_DG("TaGenerator(" << this << ")::InsEvent(" << index << ")");
03648 return mAlphabet.Insert(index);
03649 }
03650
03651
03652 TEMP Idx THIS::InsEvent(const std::string& rName) {
03653 FD_DG("TaGenerator(" << this << ")::InsEvent(\"" << rName << "\")");
03654 return mAlphabet.Insert(rName);
03655 }
03656
03657
03658 TEMP bool THIS::InsEvent(Idx index, const EventAttr& attr) {
03659 FD_DG("TaGenerator(" << this << ")::InsEvent(" << index << " " << attr.ToString() << ")");
03660 return mAlphabet.Insert(index, attr);
03661 }
03662
03663
03664 TEMP Idx THIS::InsEvent(const std::string& rName, const EventAttr& attr) {
03665 FD_DG("TaGenerator(" << this << ")::InsEvent(\"" << rName << attr.ToString() << "\")");
03666 return mAlphabet.Insert(rName, attr);
03667 }
03668
03669
03670 TEMP void THIS::InsEvents(const EventSet& events) {
03671 mAlphabet.InsertSet(events);
03672 }
03673
03674
03675 TEMP bool THIS::DelEvent(Idx index) {
03676 FD_DG("TaGenerator(" << this << ")::DelEvent(" << index << ")");
03677 mTransRel.EraseByEv(index);
03678 return mAlphabet.Erase(index);
03679 }
03680
03681
03682 TEMP bool THIS::DelEvent(const std::string& rName) {
03683 FD_DG("TaGenerator(" << this << ")::DelEvent(\"" << rName << "\")");
03684 Idx index = mAlphabet.Index(rName);
03685 mTransRel.EraseByEv(index);
03686 return mAlphabet.Erase(index);
03687 }
03688
03689
03690 TEMP void THIS::DelEvents(const EventSet& rEvents) {
03691 FD_DG("TaGenerator(" << this << ")::DelEvents(\""
03692 << rEvents.ToString() << "\")");
03693 EventSet::Iterator it;
03694 for (it = rEvents.Begin(); it != rEvents.End(); ++it) {
03695 DelEvent(*it);
03696 }
03697 }
03698
03699
03700 TEMP bool THIS::DelEventFromAlphabet(Idx index) {
03701 FD_DG("TaGenerator(" << this << ")::DelEventFromAlphabet("
03702 << index << ")");
03703 return mAlphabet.Erase(index);
03704 }
03705
03706
03707 TEMP Idx THIS::InsState(void) {
03708 FD_DG("TaGenerator(" << this << ")::InsState()");
03709 return mStates.Insert();
03710 }
03711
03712
03713 TEMP bool THIS::InsState(Idx index) {
03714 FD_DG("TaGenerator(" << this << ")::InsState(" << index << ")");
03715 return mStates.Insert(index);
03716 }
03717
03718
03719 TEMP bool THIS::InsState(Idx index, const StateAttr& attr) {
03720 FD_DG("TaGenerator(" << this << ")::InsState(" << index << ",attr)");
03721 return mStates.Insert(index,attr);
03722 }
03723
03724
03725 TEMP Idx THIS::InsState(const std::string& rName) {
03726 FD_DG("TaGenerator(" << this << ")::InsState(\"" << rName << "\")");
03727 Idx index=mStates.Insert();
03728 StateName(index,rName);
03729 return index;
03730 }
03731
03732
03733 TEMP Idx THIS::InsState(const std::string& rName, const StateAttr& attr) {
03734 FD_DG("TaGenerator(" << this << ")::InsState(\"" << rName << "\")");
03735 Idx index=mStates.Insert();
03736 StateName(index,rName);
03737 StateAttribute(index,attr);
03738 return index;
03739 }
03740
03741
03742
03743 TEMP void THIS::InjectState(Idx index) {
03744 FD_DG("TaGenerator(" << this << ")::InjectState(\""
03745 << SStr(index) << "\")");
03746 mStates.Insert(index);
03747 }
03748
03749
03750 TEMP void THIS::InjectStates(const StateSet& rNewStates) {
03751 FD_DG("TaGenerator(" << this << ")::InjectStates("
03752 << rNewStates.ToString() << ")");
03753 mStates = rNewStates;
03754 mStates.Name("States");
03755 }
03756
03757
03758 TEMP Idx THIS::InsInitState(void) {
03759 FD_DG("TaGenerator(" << this << ")::InsInitState()");
03760 Idx index;
03761 index = InsState();
03762 mInitStates.Insert(index);
03763 return index;
03764 }
03765
03766
03767 TEMP Idx THIS::InsInitState(const std::string& rName) {
03768 FD_DG("TaGenerator(" << this << ")::InsInitState(\"" << rName << "\")");
03769 Idx index;
03770 index = InsState(rName);
03771 mInitStates.Insert(index);
03772 return index;
03773 }
03774
03775
03776 TEMP Idx THIS::InsMarkedState(void) {
03777 FD_DG("TaGenerator(" << this << ")::InsMarkedState()");
03778 Idx index;
03779 index = InsState();
03780 mMarkedStates.Insert(index);
03781 return index;
03782 }
03783
03784
03785 TEMP Idx THIS::InsMarkedState(const std::string& rName) {
03786 FD_DG("TaGenerator(" << this << ")::InsMarkedState(\"" << rName << "\")");
03787 Idx index;
03788 index = InsState(rName);
03789 mMarkedStates.Insert(index);
03790 return index;
03791 }
03792
03793
03794 TEMP bool THIS::DelState(Idx index) {
03795 FD_DG("TaGenerator(" << this << ")::DelState(" << index << ")");
03796
03797 mInitStates.Erase(index);
03798
03799 mMarkedStates.Erase(index);
03800
03801 mTransRel.EraseByX1OrX2(index);
03802
03803 mStateSymbolTable.ClrEntry(index);
03804 return mStates.Erase(index);
03805 }
03806
03807
03808 TEMP bool THIS::DelState(const std::string& rName) {
03809 FD_DG("TaGenerator(" << this << ")::DelState(\"" << rName << "\")");
03810 Idx index;
03811 index = StateIndex(rName);
03812 #ifdef FAUDES_CHECKED
03813 if (index == 0) {
03814 std::stringstream errstr;
03815 errstr << "state name \"" << rName << "\" not found in generator \""
03816 << Name() << "\"";
03817 throw Exception("TaGenerator::DelState(name)", errstr.str(), 90);
03818 }
03819 #endif
03820 return DelState(index);
03821 }
03822
03823
03824 TEMP void THIS::DelStates(const StateSet& rDelStates) {
03825 FD_DG("TaGenerator(" << this << ")::DelStates("
03826 << rDelStates.ToString() << ")");
03827 StateSet::Iterator cit;
03828 StateSet::Iterator cit_end;
03829
03830 if (StateNamesEnabled()) {
03831 for (cit = rDelStates.Begin(); cit != rDelStates.End(); ++cit) {
03832 mpStateSymbolTable->ClrEntry(*cit);
03833 }
03834 }
03835
03836 mStates.EraseSet(rDelStates);
03837 mInitStates.EraseSet(rDelStates);
03838 mMarkedStates.EraseSet(rDelStates);
03839
03840
03841 for (cit = rDelStates.Begin(); cit != rDelStates.End(); ++cit) {
03842 mTransRel.EraseByX1OrX2(*cit);
03843 }
03844 }
03845
03846
03847 TEMP bool THIS::DelStateFromStates(Idx index) {
03848 FD_DG("TaGenerator(" << this << ")::DelStateFromStates(" << index << ")");
03849
03850 return mStates.Erase(index);
03851 }
03852
03853
03854 TEMP StateSet::Iterator THIS::DelStateFromStates(StateSet::Iterator pos) {
03855 FD_DG("TaGenerator(" << this << ")::DelState(" << *pos << ")");
03856 return mStates.Erase(pos);
03857 }
03858
03859
03860 TEMP void THIS::SetInitState(Idx index) {
03861 FD_DG("TaGenerator(" << this << ")::SetInitState(" << index << ")");
03862 #ifdef FAUDES_CHECKED
03863 if (! mStates.Exists(index)) {
03864 std::stringstream errstr;
03865 errstr << "TaGenerator::SetMarkedState: index " << index
03866 << " not in stateset";
03867 throw Exception("TaGenerator::SetInitState(..)", errstr.str(), 91);
03868 }
03869 #endif
03870 mInitStates.Insert(index);
03871 }
03872
03873
03874 TEMP void THIS::SetInitState(const std::string& rName) {
03875 FD_DG("TaGenerator(" << this << ")::SetInitState(\"" << rName << "\")");
03876 Idx index = StateIndex(rName);
03877 #ifdef FAUDES_CHECKED
03878 if (index == 0) {
03879 std::stringstream errstr;
03880 errstr << "State name \"" << rName << "\" not known in Generator";
03881 throw Exception("TaGenerator::SetInitState(..)", errstr.str(), 90);
03882 }
03883 #endif
03884 SetInitState(index);
03885 }
03886
03887
03888 TEMP void THIS::InjectInitStates(const StateSet& rNewInitStates) {
03889 FD_DG("TaGenerator(" << this << ")::InjectInitStates("
03890 << rNewInitStates.ToString() << ")");
03891 mInitStates = rNewInitStates;
03892 mInitStates.Name("InitStates");
03893 }
03894
03895
03896 TEMP void THIS::ClrInitState(Idx index) {
03897 FD_DG("TaGenerator(" << this << ")::ClrInitState(" << index << ")");
03898 #ifdef FAUDES_CHECKED
03899 if (! mStates.Exists(index)) {
03900 std::stringstream errstr;
03901 errstr << "TaGenerator::SetMarkedState: index " << index
03902 << " not in stateset";
03903 throw Exception("TaGenerator::ClrInitState(..)", errstr.str(), 91);
03904 }
03905 #endif
03906 mInitStates.Erase(index);
03907 }
03908
03909
03910 TEMP void THIS::ClrInitState(const std::string& rName) {
03911 FD_DG("TaGenerator(" << this << ")::ClrInitState(\"" << rName << "\")");
03912 Idx index = StateIndex(rName);
03913 #ifdef FAUDES_CHECKED
03914 if (index == 0) {
03915 std::stringstream errstr;
03916 errstr << "State name \"" << rName << "\" not known in Generator";
03917 throw Exception("TaGenerator::ClrInitState(..)", errstr.str(), 90);
03918 }
03919 #endif
03920 ClrInitState(index);
03921 }
03922
03923
03924 TEMP void THIS::ClrInitState(StateSet::Iterator pos) {
03925 FD_DG("TaGenerator(" << this << ")::ClrInitState(" << *pos << ")");
03926 mInitStates.Erase(pos);
03927 }
03928
03929
03930 TEMP void THIS::ClearInitStates(void) {
03931 mInitStates.Clear();
03932 }
03933
03934
03935 TEMP void THIS::SetMarkedState(Idx index) {
03936 FD_DG("TaGenerator(" << this << ")::SetMarkedState(" << index << ")");
03937 #ifdef FAUDES_CHECKED
03938 if (! mStates.Exists(index)) {
03939 std::stringstream errstr;
03940 errstr << "TaGenerator::SetMarkedState: index " << index
03941 << " not in stateset";
03942 throw Exception("TaGenerator::SetMarkedState(..)", errstr.str(), 91);
03943 }
03944 #endif
03945 mMarkedStates.Insert(index);
03946 }
03947
03948
03949 TEMP void THIS::SetMarkedState(const std::string& rName) {
03950 FD_DG("TaGenerator(" << this << ")::SetMarkedState(\"" << rName << "\")");
03951 Idx index = StateIndex(rName);
03952 #ifdef FAUDES_CHECKED
03953 if (index == 0) {
03954 std::stringstream errstr;
03955 errstr << "State name \"" << rName << "\" not known in Generator";
03956 throw Exception("TaGenerator::SetMarkedState(..)", errstr.str(), 90);
03957 }
03958 #endif
03959 SetMarkedState(index);
03960 }
03961
03962
03963 TEMP void THIS::InjectMarkedStates(const StateSet& rNewMarkedStates) {
03964 FD_DG("TaGenerator(" << this << ")::InjectMarkedStates("
03965 << rNewMarkedStates.ToString() << ")");
03966 mMarkedStates = rNewMarkedStates;
03967 mMarkedStates.Name("MarkedStates");
03968 }
03969
03970
03971 TEMP void THIS::ClrMarkedState(Idx index) {
03972 FD_DG("TaGenerator(" << this << ")::ClrMarkedState(" << index << ")");
03973 #ifdef FAUDES_CHECKED
03974 if (! mStates.Exists(index)) {
03975 std::stringstream errstr;
03976 errstr << "TaGenerator::ClrMarkedState: index " << index
03977 << " not in stateset";
03978 throw Exception("TaGenerator::ClrMarkedState(..)", errstr.str(), 91);
03979 }
03980 #endif
03981 mMarkedStates.Erase(index);
03982 }
03983
03984
03985 TEMP void THIS::ClrMarkedState(const std::string& rName) {
03986 FD_DG("TaGenerator(" << this << ")::ClrMarkedState(\"" << rName << "\")");
03987 Idx index = StateIndex(rName);
03988 #ifdef FAUDES_CHECKED
03989 if (index == 0) {
03990 std::stringstream errstr;
03991 errstr << "State name \"" << rName << "\" not known in Generator";
03992 throw Exception("TaGenerator::ClrMarkedState(..)", errstr.str(), 90);
03993 }
03994 #endif
03995 ClrMarkedState(index);
03996 }
03997
03998
03999 TEMP void THIS::ClrMarkedState(StateSet::Iterator pos) {
04000 FD_DG("TaGenerator(" << this << ")::ClrMarkedState(" << *pos << ")");
04001 mMarkedStates.Erase(pos);
04002 }
04003
04004
04005 TEMP void THIS::ClearMarkedStates(void) {
04006 mMarkedStates.Clear();
04007 }
04008
04009
04010 TEMP void THIS::InjectTransition(const Transition& rTrans) {
04011 FD_DG("TaGenerator::InjectTransition(" << TStr(rTrans) << ")");
04012 mTransRel.Insert(rTrans);
04013 }
04014
04015
04016 TEMP void THIS::InjectTransRel(const TransSet& newtransrel) {
04017 FD_DG("TaGenerator::InjectTransRel(...)");
04018 mTransRel=newtransrel;
04019 }
04020
04021
04022 TEMP bool THIS::SetTransition(const std::string& rX1, const std::string& rEv, const std::string& rX2) {
04023 FD_DG("TaGenerator(" << this << ")::SetTransition(\""
04024 << rX1 << "\", \"" << rEv << "\", \"" << rX2 << "\")");
04025 Idx x1 = StateIndex(rX1);
04026 Idx x2 = StateIndex(rX2);
04027 #ifdef FAUDES_CHECKED
04028 if (x1 == 0) {
04029 FD_ERR("TaGenerator::SetTransition: state " << rX1
04030 << " not in stateset");
04031 std::stringstream errstr;
04032 errstr << "State name " << rX1 << " not found in Generator";
04033 throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 90);
04034 }
04035 if (! mAlphabet.Exists(rEv)) {
04036 FD_ERR("TaGenerator::SetTransition: event " << rEv << " not in alphabet");
04037 std::stringstream errstr;
04038 errstr << "Event name " << rEv << " not found in event domain of Generator";
04039 throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
04040 }
04041 if (x2 == 0) {
04042 FD_ERR("TaGenerator::SetTransition: state " << rX2 << " not in stateset");
04043 std::stringstream errstr;
04044 errstr << "State name " << rX2 << " not found in Generator";
04045 throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 90);
04046 }
04047 #endif
04048 return SetTransition(Transition(x1, EventIndex(rEv), x2));
04049 }
04050
04051
04052
04053 TEMP bool THIS::SetTransition(Idx x1, Idx ev, Idx x2) {
04054 return SetTransition(Transition(x1,ev,x2));
04055 }
04056
04057
04058 TEMP bool THIS::SetTransition(const Transition& rTransition) {
04059 FD_DG("TaGenerator(" << this << ")::SetTransition(" << rTransition.X1 << ","
04060 << rTransition.Ev << "," << rTransition.X2 << ")");
04061 #ifdef FAUDES_CHECKED
04062 if (! mStates.Exists(rTransition.X1)) {
04063 std::stringstream errstr;
04064 errstr << "TaGenerator::SetTransition: state " << rTransition.X1
04065 << " not in stateset";
04066 throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
04067 }
04068 if (! mAlphabet.Exists(rTransition.Ev)) {
04069 std::stringstream errstr;
04070 errstr << "TaGenerator::SetTransition: event " << rTransition.Ev
04071 << " not in alphabet ";
04072 throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
04073 }
04074 if (! mStates.Exists(rTransition.X2)) {
04075 std::stringstream errstr;
04076 errstr << "TaGenerator::SetTransition: state " << rTransition.X2
04077 << " not in stateset";
04078 throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
04079 }
04080 #endif
04081 return mTransRel.Insert(rTransition);
04082 }
04083
04084
04085 TEMP bool THIS::SetTransition(const Transition& rTransition, const TransAttr& rAttr) {
04086 FD_DG("TaGenerator(" << this << ")::SetTransition(" << rTransition.X1 << ","
04087 << rTransition.Ev << "," << rTransition.X2 << ", [attr:]" << rAttr.ToString() << ")");
04088 #ifdef FAUDES_CHECKED
04089 if (! mStates.Exists(rTransition.X1)) {
04090 std::stringstream errstr;
04091 errstr << "TaGenerator::SetTransition: state " << rTransition.X1
04092 << " not in stateset";
04093 throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
04094 }
04095 if (! mAlphabet.Exists(rTransition.Ev)) {
04096 std::stringstream errstr;
04097 errstr << "TaGenerator::SetTransition: event " << rTransition.Ev
04098 << " not in alphabet ";
04099 throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
04100 }
04101 if (! mStates.Exists(rTransition.X2)) {
04102 std::stringstream errstr;
04103 errstr << "TaGenerator::SetTransition: state " << rTransition.X2
04104 << " not in stateset";
04105 throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
04106 }
04107 #endif
04108 return mTransRel.Insert(rTransition,rAttr);
04109 }
04110
04111
04112 TEMP void THIS::ClrTransition(Idx x1, Idx ev, Idx x2) {
04113 FD_DG("TaGenerator(" << this << ")::ClrTransition("
04114 << x1 << "," << ev << "," << x2 << ")");
04115 mTransRel.Erase(x1, ev, x2);
04116 }
04117
04118
04119 TEMP void THIS::ClrTransition(const Transition& rTransition) {
04120 FD_DG("TaGenerator(" << this << ")::ClrTransition(" << TStr(rTransition) << ")");
04121 mTransRel.Erase(rTransition);
04122 }
04123
04124
04125 TEMP typename THIS::ATransSet::Iterator THIS::ClrTransition(typename ATransSet::Iterator it) {
04126 FD_DG("TaGenerator(" << this << ")::ClrTransition(" << TStr(*it)<< ")" );
04127 return mTransRel.Erase(it);
04128 }
04129
04130
04131
04132 TEMP void THIS::TransAttribute(const Transition& rTrans, const TransAttr& rAttr) {
04133 FD_DG("TaGenerator(" << this << ")::TransAttribute("
04134 << TStr(rTrans) << ",\"" << rAttr.ToString() << "\")");
04135 mTransRel.Attribute(rTrans, rAttr);
04136 }
04137
04138
04139 TEMP TransAttr* THIS::TransAttributep(const Transition& rTrans) {
04140 return mTransRel.Attributep(rTrans);
04141 }
04142
04143
04144
04145 TEMP const TransAttr& THIS::TransAttribute(const Transition& rTrans) const {
04146 return mTransRel.Attribute(rTrans);
04147 }
04148
04149
04150 TEMP void THIS::ClrTransAttribute(const Transition& rTrans) {
04151 mTransRel.ClrAttribute(rTrans);
04152 }
04153
04154
04155
04156 TEMP void THIS::ClearTransRel(void) {
04157 mTransRel.Clear();
04158 }
04159
04160
04161 TEMP void THIS::EventAttribute(Idx index, const EventAttr& rAttr) {
04162 FD_DG("TaGenerator(" << this << ")::EventAttribute("
04163 << EStr(index) << ",\"" << rAttr.ToString() << "\")");
04164 mAlphabet.Attribute(index, rAttr);
04165 }
04166
04167
04168 TEMP void THIS::ClrEventAttribute(Idx index) {
04169 FD_DG("TaGenerator(" << this << ")::ClrEventAttribute(\"" << EStr(index) << "\")");
04170 mAlphabet.ClrAttribute(index);
04171 }
04172
04173
04174 TEMP void THIS::StateAttribute(Idx index, const StateAttr& rAttr) {
04175 FD_DG("TaGenerator(" << this << ")::StateAttribute("
04176 << index << ",\"" << rAttr.ToString() << "\")");
04177 mStates.Attribute(index, rAttr);
04178 }
04179
04180
04181 TEMP void THIS::ClrStateAttribute(Idx index) {
04182 FD_DG("TaGenerator(" << this << ")::ClrStateAttribute(\"" << index << "\")");
04183 mStates.ClrAttribute(index);
04184 }
04185
04186
04187 TEMP bool THIS::ExistsEvent(Idx index) const {
04188 return mAlphabet.Exists(index);
04189 }
04190
04191
04192 TEMP bool THIS::ExistsEvent(const std::string& rName) const {
04193 return mAlphabet.Exists(rName);
04194 }
04195
04196
04197 TEMP EventSet::Iterator THIS::FindEvent(Idx index) const {
04198 return mAlphabet.Find(index);
04199 }
04200
04201
04202 TEMP EventSet::Iterator THIS::FindEvent(const std::string& rName) const {
04203 return mAlphabet.Find(rName);
04204 }
04205
04206
04207 TEMP bool THIS::ExistsState(Idx index) const {
04208 return mStates.Exists(index);
04209 }
04210
04211
04212 TEMP bool THIS::ExistsState(const std::string& rName) const {
04213 return mpStateSymbolTable->Exists(rName);
04214 }
04215
04216
04217 TEMP StateSet::Iterator THIS::FindState(const std::string& rName) const {
04218 return mStates.Find(mpStateSymbolTable->Index(rName));
04219 }
04220
04221
04222 TEMP StateSet::Iterator THIS::FindState(Idx index) const {
04223 return mStates.Find(index);
04224 }
04225
04226
04227 TEMP bool THIS::ExistsInitState(Idx index) const {
04228 return mInitStates.Exists(index);
04229 }
04230
04231
04232 TEMP StateSet::Iterator THIS::FindInitState(Idx index) const {
04233 return mInitStates.Find(index);
04234 }
04235
04236
04237 TEMP bool THIS::ExistsMarkedState(Idx index) const {
04238 return mMarkedStates.Exists(index);
04239 }
04240
04241
04242 TEMP StateSet::Iterator THIS::FindMarkedState(Idx index) const {
04243 return mMarkedStates.Find(index);
04244 }
04245
04246
04247 TEMP const EventAttr& THIS::EventAttribute(Idx index) const {
04248 return mAlphabet.Attribute(index);
04249 }
04250
04251
04252 TEMP EventAttr* THIS::EventAttributep(Idx index) {
04253 return mAlphabet.Attributep(index);
04254 }
04255
04256
04257 TEMP const EventAttr& THIS::EventAttribute(const std::string& rName) const {
04258 return EventAttribute(EventIndex(rName));
04259 }
04260
04261
04262 TEMP EventAttr* THIS::EventAttributep(const std::string& rName) {
04263 return EventAttributep(EventIndex(rName));
04264 }
04265
04266 TEMP const StateAttr& THIS::StateAttribute(Idx index) const {
04267 return mStates.Attribute(index);
04268 }
04269
04270
04271 TEMP StateAttr* THIS::StateAttributep(Idx index) {
04272 return mStates.Attributep(index);
04273 }
04274
04275
04276 TEMP const TaEventSet<EventAttr>& THIS::Alphabet(void) const {
04277 return mAlphabet;
04278 }
04279
04280
04281 TEMP const TaStateSet<StateAttr>& THIS::States(void) const {
04282 return mStates;
04283 }
04284
04285
04286 TEMP const typename THIS::ATransSet& THIS::TransRel(void) const {
04287 return mTransRel;
04288 }
04289
04290
04291
04292 TEMP void THIS::TransRel(TransSetX1EvX2& res) const { mTransRel.ReSort(res); }
04293 TEMP void THIS::TransRel(TransSetEvX1X2& res) const { mTransRel.ReSort(res); }
04294 TEMP void THIS::TransRel(TransSetEvX2X1& res) const { mTransRel.ReSort(res); }
04295 TEMP void THIS::TransRel(TransSetX2EvX1& res) const { mTransRel.ReSort(res); }
04296 TEMP void THIS::TransRel(TransSetX2X1Ev& res) const { mTransRel.ReSort(res); }
04297 TEMP void THIS::TransRel(TransSetX1X2Ev& res) const { mTransRel.ReSort(res); }
04298
04299
04300
04301 TEMP const StateSet& THIS::InitStates(void) const {
04302 return mInitStates;
04303 }
04304
04305
04306 TEMP const StateSet& THIS::MarkedStates(void) const {
04307 return mMarkedStates;
04308 }
04309
04310
04311 TEMP void THIS::MinimizeAlphabet(void) {
04312 mAlphabet.NameSet::EraseSet(UnusedEvents());
04313 }
04314
04315
04316 TEMP EventSet THIS::UsedEvents(void) const {
04317 EventSet resultset = NewEventSet();
04318 typename ATransSet::Iterator it;
04319 for (it = mTransRel.Begin(); it != mTransRel.End(); ++it) {
04320 resultset.Insert(it->Ev);
04321 }
04322 return resultset;
04323 }
04324
04325
04326 TEMP EventSet THIS::UnusedEvents(void) const {
04327 return mAlphabet - UsedEvents();
04328 }
04329
04330
04331 TEMP EventSet THIS::ActiveEventSet(Idx x1) const {
04332 EventSet result = NewEventSet();
04333 typename ATransSet::Iterator it;
04334 for (it = TransRelBegin(x1); it != TransRelEnd(x1); ++it) {
04335 result.Insert(it->Ev);
04336 }
04337 return result;
04338 }
04339
04340
04341 TEMP StateSet THIS::TransRelStateSpace(void) const {
04342 StateSet states = StateSet();
04343 typename ATransSet::Iterator it;
04344 for (it=mTransRel.Begin(); it != mTransRel.End(); ++it) {
04345 states.Insert(it->X1);
04346 states.Insert(it->X2);
04347 }
04348 return states;
04349 }
04350
04351
04352 TEMP StateSet THIS::TransRelStateSpace(Idx x1) const {
04353 StateSet states = StateSet();
04354 typename ATransSet::Iterator it = mTransRel.Begin(x1);
04355 typename ATransSet::Iterator it_end = mTransRel.End(x1);
04356 for (; it != it_end; ++it) {
04357 states.Insert(it->X2);
04358 }
04359 return states;
04360 }
04361
04362
04363 TEMP void THIS::Version(Idx version, TaGenerator& rResGen) {
04364 FD_DG("TaGenerator(" << this << ")::Version(" << version << ")");
04365 std::ostringstream o;
04366 o << version;
04367 Version(o.str(),rResGen);
04368 }
04369
04370
04371 TEMP void THIS::Version(const std::string& rVersion, TaGenerator& rResGen) {
04372 FD_DG("TaGenerator(" << this << ")::Version(" << rVersion << ")");
04373
04374 if (this==&rResGen) {
04375 FD_ERR("TaGenerator::Version(): rResGen must not be this generator");
04376 abort();
04377 }
04378
04379 rResGen.Clear();
04380 rResGen.mGlobalAttribute=mGlobalAttribute;
04381 EventSet::Iterator eit;
04382 StateSet::Iterator lit;
04383 typename ATransSet::Iterator tit;
04384 std::map<Idx,Idx> eventoldnewmap;
04385 rResGen.Name(Name()+"_"+rVersion);
04386
04387 for (eit = AlphabetBegin(); eit != AlphabetEnd(); ++eit) {
04388 eventoldnewmap[*eit] = rResGen.InsEvent(EventName(*eit)+"_"+rVersion, EventAttribute(*eit));
04389 }
04390
04391 rResGen.mStates=mStates;
04392 for (lit = StatesBegin(); lit != StatesEnd(); ++lit) {
04393 if (StateName(*lit) != "") {
04394 rResGen.StateName(*lit,StateName(*lit));
04395 }
04396 }
04397
04398 for (tit = TransRelBegin(); tit != TransRelEnd(); ++tit) {
04399 rResGen.SetTransition(Transition(tit->X1, eventoldnewmap[tit->Ev], tit->X2), TransAttribute(*tit));
04400 }
04401
04402 rResGen.mInitStates=mInitStates;
04403 rResGen.mMarkedStates=mMarkedStates;
04404
04405 rResGen.mStateNamesEnabled = mStateNamesEnabled;
04406 }
04407
04408
04409 TEMP StateSet THIS::AccessibleSet(void) const {
04410 StateSet accessibleset = StateSet();
04411 StateSet::Iterator it;
04412 for (it = InitStatesBegin(); it != InitStatesEnd(); ++it) {
04413 CheckAccessible(accessibleset, *it);
04414 }
04415 accessibleset.Name("accessibleset");
04416 return accessibleset;
04417 }
04418
04419
04420 TEMP bool THIS::Accessible(void) {
04421 StateSet accessibleset = AccessibleSet();
04422 StateSet not_accessible = mStates - accessibleset;
04423 StateSet::Iterator it;
04424 for(it = not_accessible.Begin(); it != not_accessible.End(); ++it){
04425 mTransRel.EraseByX1OrX2(*it);
04426 }
04427
04428 mStates = accessibleset;
04429 mStates.Name("States");
04430
04431 mInitStates = mInitStates * accessibleset;
04432 mInitStates.Name("InitStates");
04433
04434 mMarkedStates = mMarkedStates * accessibleset;
04435 mMarkedStates.Name("MarkedStates");
04436
04437 if (StateNamesEnabled()) {
04438 for (it = not_accessible.Begin(); it != not_accessible.End(); ++it) {
04439 mpStateSymbolTable->ClrEntry(*it);
04440 }
04441 }
04442
04443 if (! mInitStates.Empty()) {
04444 FD_DF("TaGenerator::accessible: generator is accessible");
04445 return true;
04446 }
04447 else {
04448 FD_DF("TaGenerator::accessible: generator is accessible");
04449 return false;
04450 }
04451
04452 }
04453
04454
04455 TEMP bool THIS::IsAccessible(void) const {
04456 if ((AccessibleSet() == mStates) && (! mInitStates.Empty())) {
04457 FD_DF("TaGenerator::accessible: generator is accessible");
04458 return true;
04459 }
04460 else {
04461 FD_DF("TaGenerator::accessible: generator is not accessible");
04462 return false;
04463 }
04464 }
04465
04466
04467 TEMP StateSet THIS::CoaccessibleSet(void) const {
04468 StateSet coaccessibleset = StateSet();
04469 StateSet::Iterator it;
04470
04471 TransSetX2EvX1 rtrel;
04472 TransRel(rtrel);
04473 for (it = MarkedStatesBegin(); it != MarkedStatesEnd(); ++it) {
04474 CheckCoaccessible(coaccessibleset, rtrel, *it);
04475 }
04476 coaccessibleset.Name("coaccessibleset");
04477 return coaccessibleset;
04478 }
04479
04480
04481 TEMP bool THIS::Coaccessible(void) {
04482 StateSet coaccessibleset = CoaccessibleSet();
04483 StateSet not_coaccessible = mStates - coaccessibleset;
04484 StateSet::Iterator it;
04485
04486 for(it = not_coaccessible.Begin(); it != not_coaccessible.End(); ++it){
04487 mTransRel.EraseByX1OrX2(*it);
04488 }
04489
04490 mStates = coaccessibleset;
04491 mStates.Name("States");
04492
04493 mInitStates = mInitStates * coaccessibleset;
04494 mInitStates.Name("InitStates");
04495
04496 mMarkedStates = mMarkedStates * coaccessibleset;
04497 mMarkedStates.Name("MarkedStates");
04498
04499 if (StateNamesEnabled()) {
04500 for (it = not_coaccessible.Begin(); it != not_coaccessible.End(); ++it) {
04501 mpStateSymbolTable->ClrEntry(*it);
04502 }
04503 }
04504
04505 if (! mMarkedStates.Empty()) {
04506 FD_DF("TaGenerator::coaccessible: generator is coaccessible");
04507 return true;
04508 }
04509 else {
04510 FD_DF("TaGenerator::coaccessible: generator is not coaccessible");
04511 return false;
04512 }
04513 }
04514
04515
04516 TEMP bool THIS::IsCoaccessible(void) const {
04517 if ((CoaccessibleSet() == mStates) && (! mMarkedStates.Empty())) {
04518 FD_DF("TaGenerator::coaccessible: generator is coaccessible");
04519 return true;
04520 }
04521 else {
04522 FD_DF("TaGenerator::coaccessible: generator is not coaccessible");
04523 return false;
04524 }
04525 }
04526
04527
04528 TEMP StateSet THIS::TrimSet(void) const {
04529 FD_DF("TaGenerator::trimset: trim states: "
04530 << StateSet(AccessibleSet() * CoaccessibleSet()).ToString());
04531 return AccessibleSet() * CoaccessibleSet();
04532 }
04533
04534
04535 TEMP bool THIS::Trim(void) {
04536 FD_DF("TaGenerator::trim: generator states: " << mStates.ToString());
04537 bool accessiblebool = Accessible();
04538 bool coaccessiblebool = Coaccessible();
04539 FD_DF("TaGenerator::trim: trim states: " << mStates.ToString());
04540 if (accessiblebool && coaccessiblebool) {
04541 FD_DF("TaGenerator::trim: generator is trim");
04542 return true;
04543 }
04544 else {
04545 FD_DF("TaGenerator::trim: generator is not trim");
04546 return false;
04547 }
04548 }
04549
04550
04551 TEMP bool THIS::IsTrim(void) const {
04552 if (IsAccessible() && IsCoaccessible()) {
04553 FD_DF("TaGenerator::trim: generator is trim");
04554 return true;
04555 }
04556 else {
04557 FD_DF("TaGenerator::trim: generator is not trim");
04558 return false;
04559 }
04560 }
04561
04562
04563 TEMP void THIS::CheckAccessible(StateSet& accessibleset, Idx startState) const {
04564 if (! accessibleset.Exists(startState)) {
04565 accessibleset.Insert(startState);
04566 typename ATransSet::Iterator it = TransRelBegin(startState);
04567 typename ATransSet::Iterator it_end = TransRelEnd(startState);
04568 for (; it != it_end; ++it) {
04569 CheckAccessible(accessibleset, it->X2);
04570 }
04571 }
04572 }
04573
04574
04575 TEMP void THIS::CheckCoaccessible(StateSet& coaccessibleset,
04576 const TransSetX2EvX1& rtrel, Idx startState) const {
04577 if (! coaccessibleset.Exists(startState)) {
04578 coaccessibleset.Insert(startState);
04579 typename TransSetX2EvX1::Iterator it = rtrel.BeginByX2(startState);
04580 typename TransSetX2EvX1::Iterator it_end = rtrel.EndByX2(startState);
04581 for (; it != it_end; ++it) {
04582 CheckCoaccessible(coaccessibleset, rtrel, it->X1);
04583 }
04584 }
04585 }
04586
04587
04588 TEMP bool THIS::IsDeterministic(void) const {
04589
04590 if (InitStatesSize() != 1) {
04591 FD_DG("TaGenerator::IsDeterministic: number of initial states not 1");
04592 return false;
04593 }
04594
04595 if (TransRelSize() < 2) return true;
04596 typename ATransSet::Iterator it1;
04597 typename ATransSet::Iterator it2;
04598 for (it1 = TransRelBegin(), it2 = it1++; it1 != TransRelEnd(); it2 = it1++) {
04599 if ((it1->X1 == it2->X1) && (it1->Ev == it2->Ev)) {
04600 FD_WP("IsDeterministic: nondeterministic generator. at least one state "
04601 << "contains more than on transition with same event: "
04602 << SStr(it1->X1) << ", event " << EStr(it1->Ev));
04603 return false;
04604 }
04605 }
04606
04607 return true;
04608 }
04609
04610
04611 TEMP void THIS::ClearMinStateIndexMap(void) {
04612 FD_DG("TaGenerator::ClearMinStateIndexMap()");
04613 mMinStateIndexMap.clear();
04614 }
04615
04616
04617 TEMP Idx THIS::MinStateIndex(Idx index) const {
04618 std::map<Idx,Idx>::const_iterator minit;
04619 minit = mMinStateIndexMap.find(index);
04620 Idx fidx;
04621 if(minit != mMinStateIndexMap.end()) {
04622 fidx= minit->second;
04623 } else {
04624 fidx=index;
04625 }
04626 return fidx;
04627 }
04628
04629
04630
04631 TEMP void THIS::SetMinStateIndexMap(void) {
04632
04633 ClearMinStateIndexMap();
04634 FD_DG("TaGenerator::SetMinStateIndexMap()");
04635 StateSet::Iterator it;
04636 Idx minindex = 0;
04637
04638 if (StateNamesEnabled()) {
04639
04640 for (it = InitStatesBegin(); it != InitStatesEnd(); ++it) {
04641 if (StateName(static_cast<Idx>(*it)) != "") {
04642 mMinStateIndexMap[*it] = ++minindex;
04643 }
04644 }
04645
04646 for (it = StatesBegin(); it != StatesEnd(); ++it) {
04647 if (mMinStateIndexMap.count(*it) == 0) {
04648 if (StateName(static_cast<Idx>(*it)) != "") {
04649 mMinStateIndexMap[*it] = ++minindex;
04650 }
04651 }
04652 }
04653
04654 for (it = StatesBegin(); it != StatesEnd(); ++it) {
04655 if (mMinStateIndexMap.count(*it) == 0) {
04656 mMinStateIndexMap[*it] = ++minindex;
04657 }
04658 }
04659 }
04660
04661 else {
04662
04663 for (it = InitStatesBegin(); it != InitStatesEnd(); ++it) {
04664 mMinStateIndexMap[*it] = ++minindex;
04665 }
04666
04667 for (it = StatesBegin(); it != StatesEnd(); ++it) {
04668 if (mMinStateIndexMap.count(*it) == 0) {
04669 mMinStateIndexMap[*it] = ++minindex;
04670 }
04671 }
04672 }
04673 #ifdef FAUDES_DEBUG_CONTAINER
04674 std::map<Idx,Idx>::const_iterator _it;
04675 for (_it = mMinStateIndexMap.begin(); _it != mMinStateIndexMap.end(); ++_it) {
04676 FD_DC("TaGenerator::MinStateIndexMap: " << _it->first
04677 << " <-- " << SStr(_it->second));
04678 }
04679 #endif
04680 }
04681
04682 #undef THIS
04683 #undef TEMP
04684 #undef BASE
04685
04686
04695 class GeneratorPool {
04696 public:
04698 GeneratorPool(void) {
04699 mEventSymbolTablep=SymbolTable::GlobalEventSymbolTablep();
04700 }
04701
04709 template <class AnyGenerator>
04710 AnyGenerator NewGenerator(void) {
04711 AnyGenerator gen;
04712 gen.EventSymbolTablep(mEventSymbolTablep);
04713 return gen;
04714 }
04715
04723 template <class AnyGenerator>
04724 AnyGenerator* NewGeneratorp(void) {
04725 AnyGenerator* gen = new AnyGenerator;
04726 gen->EventSymbolTablep(mEventSymbolTablep);
04727 return gen;
04728 }
04729
04736 template <class AnyEventSet>
04737 AnyEventSet NewAlphabet(void) {
04738 AnyEventSet eset;
04739 eset.SymbolTablep(mEventSymbolTablep);
04740 return eset;
04741 }
04742
04743 private:
04745 SymbolTable mEventSymbolTable;
04746 SymbolTable* mEventSymbolTablep;
04747 };
04748
04749
04750 }
04751
04752 #define GENERATOR_H
04753 #endif
04754