tp_tgenerator.h

Go to the documentation of this file.
00001 
00003 /* 
00004    Timeplugin for FAU Discrete Event Systems Library (libfaudes)
00005 
00006    Copyright (C) 2007  Thomas Moor
00007    Exclusive copyright is granted to Klaus Schmidt
00008 
00009 */
00010 
00011 
00012 #ifndef FAUDES_TP_TGENERATOR_H
00013 #define FAUDES_TP_TGENERATOR_H
00014 
00015 #include "definitions.h"
00016 #include "corefaudes.h"
00017 #include "tp_attributes.h"
00018 
00019 namespace faudes {
00020 
00021 
00022 
00101 template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
00102 class TtGenerator : public TcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr> {    
00103     public:
00107     TtGenerator(void);
00108 
00114     TtGenerator(const TtGenerator& rOtherGen);
00115 
00121     TtGenerator(const vGenerator& rOtherGen);
00122 
00132     TtGenerator(const std::string& rFileName);
00133 
00140     TtGenerator* NewP(void) const;
00141 
00148     TtGenerator NewTGen(void) const;
00149 
00150 
00151 
00158     virtual void Copy(TtGenerator& rGen) const; 
00159 
00160 
00167     virtual void Copy(vGenerator& rGen) const; 
00168 
00169 
00175     SymbolTable* ClockSymbolTablep(void) const;
00176 
00183     void ClockSymbolTablep(SymbolTable* pClockSymTab);
00184 
00185 
00192      ClockSet NewClockSet(void) const;
00193 
00200      ClockSet* NewClockSetp(void) const;
00201 
00207     Idx ClocksSize(void) const;
00208 
00214     const ClockSet& Clocks(void) const;
00215 
00216 
00222     ClockSet* Clocksp(void);
00223 
00230     void InjectClocks(const ClockSet& newclocks);
00231 
00240     std::string ClockName(Idx index) const;
00241     
00250     Idx ClockIndex(const std::string& rName) const;
00251 
00260     bool InsClock(Idx index);
00261     
00272     Idx InsClock(const std::string& rName);
00273     
00280     void InsClocks(const ClockSet& rClockSet);
00281 
00292     bool DelClock(Idx index);
00293     
00303     bool DelClock(const std::string& rName);
00304     
00311     void DelClocks(const ClockSet& rClocks);
00312     
00322     bool ExistsClock(Idx index) const;
00323 
00333     bool ExistsClock(const std::string& rName) const;
00334 
00344     ClockSet::Iterator FindClock(Idx index) const;
00345 
00355     ClockSet::Iterator FindClock(const std::string& rName) const;
00356 
00364     ClockSet ActiveClocks(void) const;
00365 
00372     ClockSet InactiveClocks(void) const;
00373 
00378     void InsActiveClocks(void);
00379 
00384     void DelInactiveClocks(void);
00385 
00391     ClockSet::Iterator ClocksBegin(void) const;
00392     
00398     ClockSet::Iterator ClocksEnd(void) const;
00399 
00407     void ConsistentTimeConstraint(const TimeConstraint& rTimeConstr) const;
00408 
00416     void ConsistentClocks(const ClockSet& rClocks) const;
00417 
00418 
00427     const TimeConstraint& Invariant(Idx idx) const;
00428 
00437     TimeConstraint* Invariantp(Idx idx);
00438 
00447     const TimeConstraint& Invariant(const std::string& name) const;
00448 
00449 
00458     TimeConstraint* Invariantp(const std::string&  name);
00459 
00468     void Invariant(Idx index, const TimeConstraint& rConstraints);
00469 
00470 
00479     void Invariant(const std::string& name, const TimeConstraint& rConstraints);
00480 
00481 
00490     void InsInvariant(const std::string& name, const TimeConstraint& rConstraints);
00491 
00492 
00501     void InsInvariant(Idx index, const TimeConstraint& rConstraints);
00502 
00503 
00510     void ClrInvariant(Idx idx);
00511 
00518     void ClrInvariant(const std::string& name);
00519 
00524     void ClearInvariants(void);
00525 
00545     bool SetTransition(Idx x1, Idx ev, Idx x2);
00546 
00566     bool SetTransition(const std::string& rX1, const std::string& rEv, 
00567         const std::string& rX2);
00568 
00584     bool SetTransition(const Transition& rTransition, const TransAttr& rAttr);
00585 
00599     bool SetTransition(const Transition& rTrans,
00600       const TimeConstraint& rGuard = TimeConstraint(), const ClockSet& rResets = ClockSet());
00601 
00617     bool SetTransition(Idx x1, Idx ev, Idx x2,
00618               const TimeConstraint& rguard, const ClockSet& rResetClocks = ClockSet());
00619 
00638     bool SetTransition(const std::string& rX1, const std::string& rEv, const std::string& rX2,
00639        const TimeConstraint& rGuard = TimeConstraint(), const ClockSet& rResets = ClockSet());
00640 
00641 
00650     void Guard(const Transition& rTrans, const TimeConstraint& rGuard);
00651 
00660     void InsGuard(const Transition& rTrans, const TimeConstraint& rConstraints);
00661 
00671     const TimeConstraint&  Guard(const Transition& rTrans) const;
00672 
00682     TimeConstraint*  Guardp(const Transition& rTrans);
00683 
00684 
00691     void ClrGuard(const Transition& rTrans);
00692 
00701     void Resets(const Transition& rTrans, const ClockSet& rResets);
00702 
00711     void InsResets(const Transition& rTrans, const ClockSet& rMoreResets);
00712 
00722     const ClockSet&  Resets(const Transition& rTrans) const;
00723 
00733     ClockSet*  Resetsp(const Transition& rTrans);
00734 
00741     void ClrResets(const Transition& rTrans);
00742 
00753     std::string CStr(Idx index) const;
00754 
00761     virtual bool Valid(void);
00762 
00763 
00771     virtual bool UpdateAttributes(void);
00772 
00773 
00774 
00775 }; // end class TtGeneraator
00776 
00777     
00779 typedef TtGenerator<AttributeTimedGlobal, AttributeTimedState, AttributeCFlags,AttributeTimedTrans> 
00780   tGenerator;
00781 
00782 // convenient scope macors  
00783 #define THIS TtGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
00784 #define BASE TcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
00785 #define TEMP template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
00786 
00787 
00788 // TtGenerator(void)
00789 TEMP THIS::TtGenerator(void) : BASE() {
00790   // set basic members (cosmetic)
00791   BASE::mGlobalAttribute.mClocks.Name("Clocks");
00792   BASE::mGlobalAttribute.mpClockSymbolTable=ClockSet::StaticSymbolTablep();
00793   FD_DG("tGenerator(" << this << ")::tGenerator() with csymtab" 
00794      << BASE::mGlobalAttribute.mpClockSymbolTable );
00795 }
00796 
00797 // TtGenerator(rOtherGen)
00798 TEMP THIS::TtGenerator(const TtGenerator& rOtherGen) : BASE(rOtherGen) {
00799   FD_DG("tGenerator(" << this << ")::tGenerator(rOtherGen) with csymtab" 
00800      << BASE::mGlobalAttribute.mpClockSymbolTable );
00801 }
00802 
00803 // TtGenerator(rOtherGen)
00804 TEMP THIS::TtGenerator(const vGenerator& rOtherGen) : BASE(rOtherGen) {
00805   // set basic members (cosmetic)
00806   BASE::mGlobalAttribute.mClocks.Name("Clocks");
00807   BASE::mGlobalAttribute.mpClockSymbolTable=ClockSet::StaticSymbolTablep();
00808   FD_DG("tGenerator(" << this << ")::tGenerator(rOtherGen) with csymtab" 
00809      << BASE::mGlobalAttribute.mpClockSymbolTable );
00810 }
00811 
00812 // TtGenerator(rFilename)
00813 TEMP THIS::TtGenerator(const std::string& rFileName) : BASE(rFileName) {
00814   FD_DG("tGenerator(" << this << ")::tGenerator(" << rFileName << ") with csymtab" 
00815      << BASE::mGlobalAttribute.mpClockSymbolTable );
00816 }
00817 
00818 // Copy(gen)  
00819 TEMP void THIS::Copy(TtGenerator& rGen) const {
00820   FD_DG("tGenerator(" << this << ")::Copy(gen&)");
00821   // copy my data (cosmetic)
00822   rGen.mGlobalAttribute.mpClockSymbolTable = BASE::mGlobalAttribute.mpClockSymbolTable;
00823   // call base method
00824   BASE::Copy(rGen);
00825 } 
00826 
00827 // Copy(gen)  
00828 TEMP void THIS::Copy(vGenerator& rGen) const {
00829   FD_DG("tGenerator(" << this << ")::Copy(vgen&)");
00830   // call base method
00831   BASE::Copy(rGen);
00832 } 
00833 
00834 
00835 
00836 // ClockSymbolTablep()
00837 TEMP SymbolTable* THIS::ClockSymbolTablep(void) const {
00838   return BASE::mGlobalAttribute.mpClockSymbolTable;
00839 }
00840 
00841 // ClockSymbolTablep(pSymTab)
00842 TEMP void THIS::ClockSymbolTablep(SymbolTable* pSymTab) {
00843    BASE::Clear(); // TODO: relax this
00844    BASE::mGlobalAttribute.mpClockSymbolTable=pSymTab;
00845 }
00846 
00847 
00848 // NewP
00849 TEMP THIS* THIS::NewP(void) const {
00850   // allocate
00851   THIS* res = new THIS;
00852   // fix base data
00853   res->EventSymbolTablep(BASE::mpEventSymbolTable);
00854   res->mStateNamesEnabled=BASE::mStateNamesEnabled;
00855   // fix my data
00856   res->ClockSymbolTablep(ClockSymbolTablep());
00857   return res;
00858 }
00859 
00860 // NewTGen
00861 TEMP THIS THIS::NewTGen(void) const {
00862   // call base (fixes by assignment constructor)
00863   THIS res= BASE::NewCGen();
00864   // fix my data
00865   res.ClockSymbolTablep(ClockSymbolTablep());
00866   return res;
00867 }
00868 
00869 // ClockSize() const
00870 TEMP Idx THIS::ClocksSize(void) const {
00871   return BASE::mGlobalAttribute.mClocks.Size();
00872 }
00873 
00874 // Clocks()
00875 TEMP const ClockSet& THIS::Clocks(void) const {
00876   return BASE::mGlobalAttribute.mClocks;
00877 }
00878 
00879 // Clocksp()
00880 TEMP ClockSet* THIS::Clocksp(void) {
00881   return &BASE::mGlobalAttribute.mClocks;
00882 }
00883 
00884 // InjectClocks(set)
00885 TEMP void THIS::InjectClocks(const ClockSet& clockset) {
00886   BASE::mGlobalAttribute.mClocks=clockset;
00887   BASE::mGlobalAttribute.mClocks.Name("Clocks");
00888 }
00889 
00890 // InsClock(index)
00891 TEMP bool THIS::InsClock(Idx clockindex) {
00892   return BASE::mGlobalAttribute.mClocks.Insert(clockindex);
00893 }
00894 
00895 // InsClock(name)
00896 TEMP Idx THIS::InsClock(const std::string& clockname) {
00897   return BASE::mGlobalAttribute.mClocks.Insert(clockname);
00898 }
00899 
00900 // InsClocks(set)
00901 TEMP void THIS::InsClocks(const ClockSet& clockset) {
00902   BASE::mGlobalAttribute.mClocks.InsertSet(clockset);
00903 }
00904 
00905 
00906 // DelClock(index)
00907 TEMP bool THIS::DelClock(Idx clockindex) {
00908   FD_DG("tGenerator(" << this << ")::DelClock(" << clockindex << ")");
00909   TransSet::Iterator tit;
00910   for(tit=BASE::TransRelBegin(); tit!=BASE::TransRelEnd(); tit++) {
00911     if(!BASE::mTransRel.Attribute(*tit).IsDefault()) {
00912       BASE::mTransRel.Attributep(*tit)->mGuard.EraseByClock(clockindex);
00913       BASE::mTransRel.Attributep(*tit)->mResets.Erase(clockindex);
00914     }
00915   }
00916   StateSet::Iterator it;
00917   for(it=BASE::StatesBegin(); it!=BASE::StatesEnd(); it++) { 
00918     if(!BASE::mStates.Attribute(*it).IsDefault()) {
00919       BASE::mStates.Attributep(*it)->mInvariant.EraseByClock(clockindex);
00920     }
00921   }
00922   return BASE::mGlobalAttribute.mClocks.Erase(clockindex);
00923 }
00924 
00925 // DelClock(name)
00926 TEMP bool THIS::DelClock(const std::string& clockname) {
00927   Idx index=BASE::mGlobalAttribute.mClocks.Index(clockname);
00928   return DelClock(index);
00929 }
00930 
00931 // DelClocks(set)
00932 TEMP void THIS::DelClocks(const ClockSet& clockset) {
00933   ClockSet::Iterator it, tmpit;
00934   for(it=ClocksBegin(); it!=ClocksEnd(); ) {
00935     tmpit=it;
00936     it++;
00937     DelClock(*tmpit);
00938   }
00939 }
00940 
00941 // ExistsClock(index)
00942 TEMP bool THIS::ExistsClock(Idx clockindex) const {
00943   return BASE::mGlobalAttribute.mClocks.Exists(clockindex);
00944 }
00945 
00946 // ExistsClock(name)
00947 TEMP bool THIS::ExistsClock(
00948   const std::string& clockname) const {
00949   return BASE::mGlobalAttribute.mClocks.Exists(clockname);
00950 }
00951 
00952 // FindClock(index)
00953 TEMP ClockSet::Iterator THIS::FindClock(Idx clockindex) const {
00954   return BASE::mGlobalAttribute.mClocks.Find(clockindex);
00955 }
00956 
00957 // FindClock(name)
00958 TEMP ClockSet::Iterator THIS::FindClock(const std::string& clockname) const {
00959   return BASE::mGlobalAttribute.mClocks.Find(clockname);
00960 }
00961 
00962 // ClockName(index)
00963 TEMP std::string THIS::ClockName(Idx clockindex) const {
00964   return BASE::mGlobalAttribute.mClocks.SymbolicName(clockindex);
00965 }
00966 
00967 // ClockIndex(name)
00968 TEMP Idx THIS::ClockIndex(const std::string& clockname) const {
00969   return BASE::mGlobalAttribute.mClocks.Index(clockname);
00970 }
00971 
00972 // ActiveClocks() const
00973 TEMP ClockSet THIS::ActiveClocks(void) const {
00974   FD_DG("tGenerator(" << this << ")::ActiveClocks() const");
00975   ClockSet res;
00976   TransSet::Iterator tit;
00977   for(tit=BASE::TransRelBegin(); tit!=BASE::TransRelEnd(); tit++) {
00978     res.InsertSet(Guard(*tit).ActiveClocks());
00979     res.InsertSet(Resets(*tit));
00980   }
00981   StateSet::Iterator it;
00982   for(it=BASE::StatesBegin(); it!=BASE::StatesEnd(); it++) { 
00983     res.InsertSet(Invariant(*it).ActiveClocks());
00984   }
00985   res.Name("AcitiveClocks");
00986   return res;
00987 }
00988 
00989 // InactiveClocks() const
00990 TEMP ClockSet THIS::InactiveClocks(void) const {
00991   FD_DG("TtaGenerator(" << this << ")::InactiveClocks() const");
00992   ClockSet res =  BASE::mClocks - ActiveClocks();
00993   res.Name("InactiveClocks");
00994   return res;
00995 }
00996 
00997 // InsActiveClocks() 
00998 TEMP void THIS::InsActiveClocks(void) {
00999   FD_DG("tGenerator(" << this << ")::InsActiveClocks()");
01000   ClockSet aclocks=ActiveClocks();
01001   InsClocks(aclocks);
01002 }
01003 
01004 // DelInactiveClocks() 
01005 TEMP void THIS::DelInactiveClocks(void) {
01006   FD_DG("tGenerator(" << this << ")::InsActiveClocks()");
01007   ClockSet iaclocks=InactiveClocks();
01008   BASE::mGlobalAttribute.mClocks.Erase(iaclocks);
01009 }
01010 
01011 // iterator ClocksBegin() const
01012 TEMP ClockSet::Iterator THIS::ClocksBegin(void) const {
01013   return BASE::mGlobalAttribute.mClocks.Begin();
01014 }
01015 
01016 // iterator ClocksEnd() const
01017 TEMP ClockSet::Iterator THIS::ClocksEnd(void) const {
01018   return BASE::mGlobalAttribute.mClocks.End();
01019 }
01020 
01021 // ConsistentTimeConstraint(constraint)
01022 TEMP void THIS::ConsistentTimeConstraint(const TimeConstraint& rTimeConstr) const {
01023   FD_DG("tGenerator(" << this << ")::ConsistentTimeConstraint(constr)");
01024   if( rTimeConstr.ClockSymbolTablep() != ClockSymbolTablep()) {
01025     std::stringstream errstr;
01026     errstr << "clocksymboltable mismatch" << std::endl;
01027     throw Exception("tGenerator::ConsistentTimeConstraint)", errstr.str(), 200);
01028   }
01029   if(!( rTimeConstr.ActiveClocks() <= Clocks() )) {
01030     std::stringstream errstr;
01031     errstr << "time constraint refers to clocks not in clockset: " << 
01032       rTimeConstr.ActiveClocks().ToString() << " versus " << Clocks().ToString() << std::endl;
01033     throw Exception("tGenerator::ConsistentTimeConstraint)", errstr.str(), 200);
01034   }
01035   FD_DG("tGenerator(" << this << ")::ConsistentTimeConstraint(constr): ok");
01036 }
01037 
01038 // ConsistentClocks(clocks)
01039 TEMP void THIS::ConsistentClocks(const ClockSet& rClocks) const {
01040   if(!( rClocks <= Clocks() )) {
01041     std::stringstream errstr;
01042     errstr << "clocksset contains clocks not in clockset" << std::endl;
01043     throw Exception("tGenerator::ConsistentClocks)", errstr.str(), 200);
01044   }
01045   if( rClocks.SymbolTablep() != ClockSymbolTablep()) {
01046     std::stringstream errstr;
01047     errstr << "clocksymboltable mismatch" << std::endl;
01048     throw Exception("tGenerator::ConsistentClocks)", errstr.str(), 200);
01049   }
01050 }
01051 
01052 
01053 // Invariant(index)
01054 TEMP const TimeConstraint& THIS::Invariant(Idx stateindex) const {
01055   if(!BASE::ExistsState(stateindex)) {
01056       std::stringstream errstr;
01057       errstr << "state index " << stateindex << " not found in StateSet" << std::endl;
01058       throw Exception("tGenerator::Invariant", errstr.str(), 200);
01059   }
01060   return BASE::mStates.Attribute(stateindex).mInvariant;
01061 }
01062 
01063 // Invariantp(index)
01064 TEMP TimeConstraint* THIS::Invariantp(Idx stateindex) {
01065   if(!BASE::ExistsState(stateindex)) {
01066       std::stringstream errstr;
01067       errstr << "state index " << stateindex << " not found in StateSet" << std::endl;
01068       throw Exception("tGenerator::Invariant", errstr.str(), 200);
01069   }
01070   return &BASE::mStates.Attributep(stateindex)->mInvariant;
01071 }
01072 
01073 // Invariant(name)
01074 TEMP const TimeConstraint& THIS::Invariant(const std::string&  statename) const {
01075   Idx idx=BASE::StateIndex(statename);
01076   return Invariant(idx);
01077 }
01078 
01079 // Invariantp(name)
01080 TEMP TimeConstraint* THIS::Invariantp(const std::string&  statename) {
01081   Idx idx=BASE::StateIndex(statename);
01082   return Invariantp(idx);
01083 }
01084 
01085 // Invariant(index,invariant)
01086 TEMP void THIS::Invariant(Idx stateindex, const TimeConstraint& rInv) {
01087   FD_DG("tGenerator(" << this << ")::Invariant("<<stateindex<<",inv)");
01088 #ifdef FAUDES_CHECKED
01089   ConsistentTimeConstraint(rInv);
01090   if(!BASE::ExistsState(stateindex)) {
01091       std::stringstream errstr;
01092       errstr << "state index " << stateindex << " not found in StateSet" << std::endl;
01093       throw Exception("tGenerator::Invariant", errstr.str(), 200);
01094   }
01095 #endif
01096   BASE::mStates.Attributep(stateindex)->mInvariant=rInv;
01097   BASE::mStates.Attributep(stateindex)->mInvariant.Name("Invariant");
01098 }
01099 
01100 // Invariant(name,invariant)
01101 TEMP void THIS::Invariant(const std::string&  statename, const TimeConstraint& rInv) {
01102   FD_DG("tGenerator(" << this << ")::Invariant("<<statename<<",inv)");
01103   Idx idx=BASE::StateIndex(statename);
01104   Invariant(idx,rInv);
01105 }
01106 
01107 // InsInvariant(index,invariant)
01108 TEMP void THIS::InsInvariant(Idx stateindex, const TimeConstraint& rInv) {
01109   FD_DG("tGenerator(" << this << ")::InsInvariant("<<stateindex<<",inv)");
01110 #ifdef FAUDES_CHECKED
01111   ConsistentTimeConstraint(rInv);
01112   if(!BASE::ExistsState(stateindex)) {
01113       std::stringstream errstr;
01114       errstr << "state index " << stateindex << " not found in StateSet" << std::endl;
01115       throw Exception("tGenerator::InsInvariant", errstr.str(), 200);
01116   }
01117 #endif
01118   if(!rInv.Empty()) {
01119     BASE::mStates.Attributep(stateindex)->mInvariant.Insert(rInv);
01120   }
01121 }
01122 
01123 // InsInvariant(name,invariant)
01124 TEMP void THIS::InsInvariant(const std::string&  statename, const TimeConstraint& rInv) {
01125   FD_DG("tGenerator(" << this << ")::InsInvariant("<<statename<<",inv)");
01126   Idx idx=BASE::StateIndex(statename);
01127   InsInvariant(idx,rInv);
01128 }
01129 
01130 // ClrInvariant(index)
01131 TEMP void THIS::ClrInvariant(Idx stateindex) {
01132   if(!BASE::mStates.Attribute(stateindex).IsDefault()) 
01133      BASE::mStates.Attributep(stateindex)->mInvariant.Clear();
01134 }
01135 
01136 // ClrInvariant(name)
01137 TEMP void THIS::ClrInvariant(const std::string&  statename) {
01138   Idx idx=BASE::StateIndex(statename);
01139   ClrInvariant(idx);
01140 }
01141 
01142 // ClearInvariants()
01143 TEMP void THIS::ClearInvariants(void) {
01144   // FIXME: should iterate, there could be other attributes
01145   BASE::mStates.ClearAttributes(); 
01146 }
01147 
01148 
01149 // SetTransition(rX1, rEv, rX2)
01150 TEMP bool THIS::SetTransition(const std::string& rX1, const std::string& rEv, const std::string& rX2) {
01151   return BASE::SetTransition(rX1,rEv,rX2);
01152 }
01153 
01154 
01155 // SetTransition(x1, ev, x2)
01156 TEMP bool THIS::SetTransition(Idx x1, Idx ev, Idx x2) {
01157   return BASE::SetTransition(Transition(x1,ev,x2));
01158 }
01159 
01160 // SetTransition(rTransition, rAttr)
01161 TEMP bool THIS::SetTransition(const Transition& rTransition, const TransAttr& rAttr) {
01162   return BASE::SetTransition(rTransition,rAttr);
01163 }
01164 
01165 // SetTransition(trans,....)
01166 TEMP bool THIS::SetTransition(const Transition& rTrans,
01167     const TimeConstraint& rGuard, const ClockSet& rResets) {
01168   FD_DG("tGenerator(" << this << ")::SetTransition(" << BASE::TStr(rTrans) <<", " <<
01169     rGuard.ToString() << ", " << rResets.ToString() << ") const");
01170   if(rResets.Empty() && rGuard.Empty()) { 
01171     return BASE::SetTransition(rTrans);
01172   }
01173   TransAttr attr;
01174   attr.mGuard=rGuard;
01175   attr.mResets=rResets;
01176   attr.mGuard.Name("Guard");
01177   attr.mResets.Name("Resets");
01178 #ifdef FAUDES_CHECKED
01179   ConsistentTimeConstraint(rGuard);
01180   ConsistentClocks(rResets);
01181 #endif
01182   return BASE::SetTransition(rTrans,attr);
01183 }
01184 
01185 // SetTransition(x1,ev,x2, ...)
01186 TEMP bool THIS::SetTransition(Idx x1, Idx ev, Idx x2,
01187     const TimeConstraint& rGuard, const ClockSet& rResets) {
01188   return SetTransition(Transition(x1,ev,x2),rGuard,rResets);
01189 }
01190 
01191 // SetTransition(X1,Ev,X2, ...)
01192 TEMP bool THIS::SetTransition(
01193     const std::string& rX1, const std::string& rEv, const std::string& rX2,
01194     const TimeConstraint& rGuard, const ClockSet& rResets) {
01195     FD_DG("tGenerator(" << this << ")::SetTransition(" << rX1 << " " << rEv <<" " << rX2 <<
01196       rGuard.ToString() << ", " << rResets.ToString() << ") const");
01197   bool res=BASE::SetTransition(rX1,rEv,rX2);
01198   if(rResets.Empty() && rGuard.Empty()) { 
01199     return res;
01200   }
01201   TransAttr attr;
01202   attr.mResets=rResets;
01203   attr.mGuard=rGuard;
01204   attr.mGuard.Name("Guard");
01205   attr.mResets.Name("Resets");
01206 #ifdef FAUDES_CHECKED
01207   ConsistentTimeConstraint(rGuard);
01208   ConsistentClocks(rResets);
01209 #endif
01210   BASE::TransAttribute(Transition(rX1,rEv,rX2),attr);
01211   return res;
01212 }
01213 
01214 // Guard(trans)
01215 TEMP const TimeConstraint& THIS::Guard(const Transition& rTrans) const {
01216 #ifdef FAUDES_CHECKED
01217   if(!BASE::ExistsTransition(rTrans)) {
01218       std::stringstream errstr;
01219       errstr << "transition " << BASE::TStr(rTrans) << " not found " << std::endl;
01220       throw Exception("tGenerator::Guard(trans)", errstr.str(), 200);
01221   }
01222 #endif
01223   return BASE::mTransRel.Attribute(rTrans).mGuard;
01224 }
01225 
01226 
01227 // Guardp(trans)
01228 TEMP TimeConstraint* THIS::Guardp(const Transition& rTrans) {
01229 #ifdef FAUDES_CHECKED
01230   if(!BASE::ExistsTransition(rTrans)) {
01231       std::stringstream errstr;
01232       errstr << "transition " << BASE::TStr(rTrans) << " not found " << std::endl;
01233       throw Exception("tGenerator::Guardp(trans)", errstr.str(), 200);
01234   }
01235 #endif
01236   return &BASE::mTransRel.Attributep(rTrans)->mGuard;
01237 }
01238 
01239 
01240 // Guard(trans,guard)
01241 TEMP void THIS::Guard(const Transition& rTrans, const TimeConstraint& rGuard) {
01242 #ifdef FAUDES_CHECKED
01243   ConsistentTimeConstraint(rGuard);
01244   if(!BASE::ExistsTransition(rTrans)) {
01245       std::stringstream errstr;
01246       errstr << "transition " << BASE::TStr(rTrans) << " not found " << std::endl;
01247       throw Exception("tGenerator::Guard(trans,guard)", errstr.str(), 200);
01248   }
01249 #endif
01250   BASE::mTransRel.Attributep(rTrans)->mGuard=rGuard;
01251   BASE::mTransRel.Attributep(rTrans)->mGuard.Name("Guard");
01252 }
01253 
01254 // InsGuard(trans,guard)
01255 TEMP void THIS::InsGuard(const Transition& rTrans, const TimeConstraint& rGuard) {
01256 #ifdef FAUDES_CHECKED
01257   ConsistentTimeConstraint(rGuard);
01258   if(!BASE::ExistsTransition(rTrans)) {
01259       std::stringstream errstr;
01260       errstr << "transition " << BASE::TStr(rTrans) << " not found " << std::endl;
01261       throw Exception("tGenerator::InsGuard(trans,guard)", errstr.str(), 200);
01262   }
01263 #endif
01264   if(!rGuard.Empty()) {
01265     BASE::mTransRel.Attributep(rTrans)->mGuard.Insert(rGuard);
01266   }
01267 }
01268 
01269 // ClrGuard(trans)
01270 TEMP void THIS::ClrGuard(const Transition& rTrans) {
01271 #ifdef FAUDES_CHECKED
01272   if(!BASE::ExistsTransition(rTrans)) {
01273       std::stringstream errstr;
01274       errstr << "transition " << BASE::TStr(rTrans) << " not found " << std::endl;
01275       throw Exception("tGenerator::ClrGuard(trans)", errstr.str(), 200);
01276   }
01277 #endif
01278   if(!BASE::mTransRel.Attribute(rTrans).IsDefault()) 
01279     BASE::mTransRel.Attributep(rTrans)->mGuard.Clear;
01280 }
01281 
01282 
01283 // Resets(trans)
01284 TEMP const ClockSet& THIS::Resets(const Transition& rTrans) const {
01285 #ifdef FAUDES_CHECKED
01286   if(!BASE::ExistsTransition(rTrans)) {
01287       std::stringstream errstr;
01288       errstr << "transition " << BASE::TStr(rTrans) << " not found " << std::endl;
01289       throw Exception("tGenerator::Resets(trans)", errstr.str(), 200);
01290   }
01291 #endif
01292   return BASE::mTransRel.Attribute(rTrans).mResets;
01293 }
01294 
01295 
01296 // Resetsp(trans)
01297 TEMP ClockSet* THIS::Resetsp(const Transition& rTrans) {
01298 #ifdef FAUDES_CHECKED
01299   if(!BASE::ExistsTransition(rTrans)) {
01300       std::stringstream errstr;
01301       errstr << "transition " << BASE::TStr(rTrans) << " not found " << std::endl;
01302       throw Exception("tGenerator::Resetsp(trans)", errstr.str(), 200);
01303   }
01304 #endif
01305   return &BASE::mTransRel.Attributep(rTrans)->mResets;
01306 }
01307 
01308 
01309 // Resets(trans,guard)
01310 TEMP void THIS::Resets(const Transition& rTrans, const ClockSet& rResets) {
01311 #ifdef FAUDES_CHECKED
01312   ConsistentClocks(rResets);
01313   if(!BASE::ExistsTransition(rTrans)) {
01314       std::stringstream errstr;
01315       errstr << "transition " << BASE::TStr(rTrans) << " not found " << std::endl;
01316       throw Exception("tGenerator::Resets(trans,guard)", errstr.str(), 200);
01317   }
01318 #endif
01319   BASE::mTransRel.Attributep(rTrans)->mResets=rResets;
01320   BASE::mTransRel.Attributep(rTrans)->mResets.Name("Resets");
01321 }
01322 
01323 // InsResets(trans,guard)
01324 TEMP void THIS::InsResets(const Transition& rTrans, const ClockSet& rResets) {
01325 #ifdef FAUDES_CHECKED
01326   ConsistentClocks(rResets);
01327   if(!BASE::ExistsTransition(rTrans)) {
01328       std::stringstream errstr;
01329       errstr << "transition " << BASE::TStr(rTrans) << " not found " << std::endl;
01330       throw Exception("tGenerator::InsResets(trans,guard)", errstr.str(), 200);
01331   }
01332 #endif
01333   if(!rResets.Empty()) {
01334     BASE::mTransRel.Attributep(rTrans)->mResets.InsertSet(rResets);
01335   }
01336 }
01337 
01338 
01339 // ClrResets(trans)
01340 TEMP void THIS::ClrResets(const Transition& rTrans) {
01341 #ifdef FAUDES_CHECKED
01342   if(!BASE::ExistsTransition(rTrans)) {
01343       std::stringstream errstr;
01344       errstr << "transition " << BASE::TStr(rTrans) << " not found " << std::endl;
01345       throw Exception("tGenerator::ClrResets(trans)", errstr.str(), 200);
01346   }
01347 #endif
01348   if(!BASE::mTransRel.Attribute(rTrans).IsDefault()) 
01349     BASE::mTransRel.Attributep(rTrans)->mGuard.Clear;
01350 }
01351 
01352 
01353 // Valid()
01354 TEMP bool THIS::Valid(void) {
01355     FD_DV("tGenerator(" << this << ")::Valid()");
01356     //call base
01357     if(!BASE::Valid()) return false;
01358     // check my names
01359     TransSet::Iterator tit;
01360     StateSet::Iterator sit;
01361     for(sit = BASE::StatesBegin(); sit!= BASE::StatesEnd(); ++sit) {
01362       if(Invariant(*sit).Name()!="Invariant") return false;
01363     }
01364     for(tit = BASE::TransRelBegin(); tit!= BASE::TransRelEnd(); ++tit) {
01365       if(Guard(*tit).Name()!="Guard") return false;
01366       if(Resets(*tit).Name()!="Resets") return false;
01367     }
01368     if(Clocks().Name()!="Clocks") return false;
01369     // check my clockset
01370     ClockSet aclocks=ActiveClocks();
01371     if(!(aclocks <= Clocks())) return false;
01372     // check all clocksymboltables
01373     for(sit = BASE::StatesBegin(); sit!= BASE::StatesEnd(); ++sit) {
01374       if(Invariant(*sit).ClockSymbolTablep()!=ClockSymbolTablep()) return false;
01375     }
01376     for(tit = BASE::TransRelBegin(); tit!= BASE::TransRelEnd(); ++tit) {
01377       if(Guard(*tit).ClockSymbolTablep()!=ClockSymbolTablep()) return false;
01378       if(Resets(*tit).SymbolTablep()!=ClockSymbolTablep()) return false;
01379     }
01380     if(Clocks().SymbolTablep()!=ClockSymbolTablep()) return false;
01381 
01382     return true;
01383 }
01384 
01385 
01386 // UpdateAttributes()
01387 TEMP bool THIS::UpdateAttributes(void) {
01388     FD_DG("tGenerator(" << this << ")::UpdateAttributes()");
01389 
01390     // debugging example: flag blocking states
01391     // btw: need efficient methods to set/clr flags by sets
01392     StateSet blockstates=BASE::BlockingSet();
01393     StateSet::Iterator sit;
01394     for(sit=BASE::StatesBegin(); sit!= BASE::StatesEnd(); sit++) {
01395       StateAttr attr=BASE::StateAttribute(*sit);
01396       if(blockstates.Exists(*sit)) {
01397         attr.Set(0x20000000);
01398       } else {
01399         attr.Clr(0x20000000);
01400       }
01401       BASE::StateAttribute(*sit,attr);
01402     };
01403 
01404     return true;
01405 }
01406 
01407 
01408 
01409 // CStr(index)
01410 TEMP std::string THIS::CStr(Idx index) const {
01411   return BASE::mGlobalAttribute.mClocks.Str(index);
01412 }
01413 
01414 
01415 
01416 #undef BASE
01417 #undef THIS
01418 #undef TEMP
01419 
01420 /***********************************************************************
01421  *
01422  *  timed generator pool : manage global data
01423  *  This version is derived from GeneratorPool. You can use it for tGenerators
01424  *  as well as for Generator.
01425  *
01426  */
01427 
01428 
01429 class tGeneratorPool : public GeneratorPool {
01430   public:
01437     template <class AnyGenerator>
01438     AnyGenerator NewGenerator(void) { 
01439       AnyGenerator gen = GeneratorPool::NewGenerator<AnyGenerator>();
01440       gen.ClockSymbolTablep(&mClockSymbolTable);
01441       return gen;
01442     }    
01443 
01450     template <class AnyGenerator>
01451     AnyGenerator* NewGeneratorp(void) { 
01452       AnyGenerator* gen = GeneratorPool::NewGeneratorp<AnyGenerator>();
01453       gen->ClockSymbolTablep(&mClockSymbolTable);
01454       return gen;
01455     }    
01456 
01457  private:
01459     SymbolTable mClockSymbolTable;
01460 };
01461 
01462 
01463 
01464 } // namespace faudes
01465 
01466 
01467 #endif
01468 

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