12 #ifndef FAUDES_TP_TGENERATOR_H
13 #define FAUDES_TP_TGENERATOR_H
100 template <
class GlobalAttr,
class StateAttr,
class EventAttr,
class TransAttr>
178 return dynamic_cast< const TtGenerator*
> (pOther); };
324 bool DelClock(
const std::string& rName);
376 ClockSet::Iterator
FindClock(
const std::string& rName)
const;
419 ClockSet::Iterator
ClocksEnd(
void)
const;
587 bool SetTransition(
const std::string& rX1,
const std::string& rEv,
588 const std::string& rX2);
659 bool SetTransition(
const std::string& rX1,
const std::string& rEv,
const std::string& rX2,
774 std::string
CStr(
Idx index)
const;
782 virtual bool Valid(
void);
800 typedef TtGenerator<AttributeTimedGlobal, AttributeTimedState, AttributeCFlags,AttributeTimedTrans>
804 #ifdef FAUDES_COMPATIBILITY
812 #define THIS TtGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
813 #define BASE TcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
814 #define TEMP template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
820 BASE::pGlobalAttribute->mClocks.Name(
"Clocks");
822 FD_DG(
"TimedGenerator(" <<
this <<
")::TimedGenerator() with csymtab "
823 << (BASE::pGlobalAttribute->mpClockSymbolTable ));
828 FD_DG(
"TimedGenerator(" <<
this <<
")::TimedGenerator(rOtherGen) with csymtab"
829 << (BASE::pGlobalAttribute->mpClockSymbolTable) );
835 BASE::pGlobalAttribute->mClocks.Name(
"Clocks");
837 FD_DG(
"TimedGenerator(" <<
this <<
")::TimedGenerator(rOtherGen) with csymtab"
838 << (BASE::pGlobalAttribute->mpClockSymbolTable) );
842 TEMP THIS::TtGenerator(
const std::string& rFileName) :
BASE(rFileName) {
843 FD_DG(
"TimedGenerator(" <<
this <<
")::TimedGenerator(" << rFileName <<
") with csymtab"
844 << (BASE::pGlobalAttribute->mpClockSymbolTable) );
850 return BASE::pGlobalAttribute->mpClockSymbolTable;
856 BASE::pGlobalAttribute->mpClockSymbolTable=pSymTab;
865 res->EventSymbolTablep(BASE::mpEventSymbolTable);
866 res->mStateNamesEnabled=BASE::mStateNamesEnabled;
867 res->mReindexOnWrite=BASE::mReindexOnWrite;
869 res->ClockSymbolTablep(ClockSymbolTablep());
884 THIS res= BASE::NewCGen();
886 res.ClockSymbolTablep(ClockSymbolTablep());
892 return BASE::pGlobalAttribute->mClocks.Size();
897 return BASE::pGlobalAttribute->mClocks;
902 return &BASE::pGlobalAttribute->mClocks;
907 BASE::pGlobalAttribute->mClocks=clockset;
908 BASE::pGlobalAttribute->mClocks.
Name(
"Clocks");
913 return BASE::pGlobalAttribute->mClocks.Insert(clockindex);
917 TEMP Idx THIS::InsClock(
const std::string& clockname) {
918 return BASE::pGlobalAttribute->mClocks.Insert(clockname);
923 BASE::pGlobalAttribute->mClocks.InsertSet(clockset);
929 FD_DG(
"TimedGenerator(" <<
this <<
")::DelClock(" << clockindex <<
")");
931 for(tit=BASE::TransRelBegin(); tit!=BASE::TransRelEnd(); tit++) {
932 if(!BASE::pTransRel->Attribute(*tit).IsDefault()) {
933 BASE::pTransRel->Attributep(*tit)->mGuard.EraseByClock(clockindex);
934 BASE::pTransRel->Attributep(*tit)->mResets.Erase(clockindex);
937 StateSet::Iterator it;
938 for(it=BASE::StatesBegin(); it!=BASE::StatesEnd(); it++) {
939 if(!BASE::pStates->Attribute(*it).IsDefault()) {
940 BASE::pStates->Attributep(*it)->mInvariant.EraseByClock(clockindex);
943 return BASE::pGlobalAttribute->mClocks.Erase(clockindex);
947 TEMP bool THIS::DelClock(
const std::string& clockname) {
948 Idx index=BASE::pGlobalAttribute->mClocks.Index(clockname);
949 return DelClock(index);
954 ClockSet::Iterator it, tmpit;
955 for(it=ClocksBegin(); it!=ClocksEnd(); ) {
963 TEMP bool THIS::ExistsClock(
Idx clockindex)
const {
964 return BASE::pGlobalAttribute->mClocks.Exists(clockindex);
969 const std::string& clockname)
const {
970 return BASE::pGlobalAttribute->mClocks.Exists(clockname);
974 TEMP ClockSet::Iterator THIS::FindClock(
Idx clockindex)
const {
975 return BASE::pGlobalAttribute->mClocks.Find(clockindex);
979 TEMP ClockSet::Iterator THIS::FindClock(
const std::string& clockname)
const {
980 return BASE::pGlobalAttribute->mClocks.Find(clockname);
984 TEMP std::string THIS::ClockName(
Idx clockindex)
const {
985 return BASE::pGlobalAttribute->mClocks.SymbolicName(clockindex);
989 TEMP Idx THIS::ClockIndex(
const std::string& clockname)
const {
990 return BASE::pGlobalAttribute->mClocks.Index(clockname);
995 FD_DG(
"TimedGenerator(" <<
this <<
")::ActiveClocks() const");
998 for(tit=BASE::TransRelBegin(); tit!=BASE::TransRelEnd(); tit++) {
999 res.
InsertSet(Guard(*tit).ActiveClocks());
1002 StateSet::Iterator it;
1003 for(it=BASE::StatesBegin(); it!=BASE::StatesEnd(); it++) {
1004 res.
InsertSet(Invariant(*it).ActiveClocks());
1006 res.
Name(
"AcitiveClocks");
1012 FD_DG(
"TtaGenerator(" <<
this <<
")::InactiveClocks() const");
1013 ClockSet res = BASE::mClocks - ActiveClocks();
1014 res.
Name(
"InactiveClocks");
1019 TEMP void THIS::InsActiveClocks(
void) {
1020 FD_DG(
"TimedGenerator(" <<
this <<
")::InsActiveClocks()");
1026 TEMP void THIS::DelInactiveClocks(
void) {
1027 FD_DG(
"TimedGenerator(" <<
this <<
")::InsActiveClocks()");
1028 ClockSet iaclocks=InactiveClocks();
1029 BASE::pGlobalAttribute->mClocks.Erase(iaclocks);
1033 TEMP ClockSet::Iterator THIS::ClocksBegin(
void)
const {
1034 return BASE::pGlobalAttribute->mClocks.Begin();
1038 TEMP ClockSet::Iterator THIS::ClocksEnd(
void)
const {
1039 return BASE::pGlobalAttribute->mClocks.End();
1044 FD_DG(
"TimedGenerator(" <<
this <<
")::ConsistentTimeConstraint(constr)");
1046 std::stringstream errstr;
1047 errstr <<
"clocksymboltable mismatch" << std::endl;
1048 throw Exception(
"TimedGenerator::ConsistentTimeConstraint)", errstr.str(), 200);
1051 std::stringstream errstr;
1052 errstr <<
"time constraint refers to clocks not in clockset: " <<
1054 throw Exception(
"TimedGenerator::ConsistentTimeConstraint)", errstr.str(), 200);
1056 FD_DG(
"TimedGenerator(" <<
this <<
")::ConsistentTimeConstraint(constr): ok");
1061 if(!( rClocks <= Clocks() )) {
1062 std::stringstream errstr;
1063 errstr <<
"clocksset contains clocks not in clockset" << std::endl;
1064 throw Exception(
"TimedGenerator::ConsistentClocks)", errstr.str(), 200);
1067 std::stringstream errstr;
1068 errstr <<
"clocksymboltable mismatch" << std::endl;
1069 throw Exception(
"TimedGenerator::ConsistentClocks)", errstr.str(), 200);
1076 if(!BASE::ExistsState(stateindex)) {
1077 std::stringstream errstr;
1078 errstr <<
"state index " << stateindex <<
" not found in StateSet" << std::endl;
1079 throw Exception(
"TimedGenerator::Invariant", errstr.str(), 200);
1081 return BASE::pStates->Attribute(stateindex).mInvariant;
1086 if(!BASE::ExistsState(stateindex)) {
1087 std::stringstream errstr;
1088 errstr <<
"state index " << stateindex <<
" not found in StateSet" << std::endl;
1089 throw Exception(
"TimedGenerator::Invariant", errstr.str(), 200);
1091 return &BASE::pStates->Attributep(stateindex)->mInvariant;
1096 Idx idx=BASE::StateIndex(statename);
1097 return Invariant(idx);
1102 Idx idx=BASE::StateIndex(statename);
1103 return Invariantp(idx);
1108 FD_DG(
"TimedGenerator(" <<
this <<
")::Invariant("<<stateindex<<
",inv)");
1109 #ifdef FAUDES_CHECKED
1110 ConsistentTimeConstraint(rInv);
1111 if(!BASE::ExistsState(stateindex)) {
1112 std::stringstream errstr;
1113 errstr <<
"state index " << stateindex <<
" not found in StateSet" << std::endl;
1114 throw Exception(
"TimedGenerator::Invariant", errstr.str(), 200);
1117 BASE::pStates->Attributep(stateindex)->mInvariant=rInv;
1118 BASE::pStates->Attributep(stateindex)->mInvariant.
Name(
"Invariant");
1123 FD_DG(
"TimedGenerator(" <<
this <<
")::Invariant("<<statename<<
",inv)");
1124 Idx idx=BASE::StateIndex(statename);
1125 Invariant(idx,rInv);
1130 FD_DG(
"TimedGenerator(" <<
this <<
")::InsInvariant("<<stateindex<<
",inv)");
1131 #ifdef FAUDES_CHECKED
1132 ConsistentTimeConstraint(rInv);
1133 if(!BASE::ExistsState(stateindex)) {
1134 std::stringstream errstr;
1135 errstr <<
"state index " << stateindex <<
" not found in StateSet" << std::endl;
1136 throw Exception(
"TimedGenerator::InsInvariant", errstr.str(), 200);
1140 BASE::pStates->Attributep(stateindex)->mInvariant.Insert(rInv);
1146 FD_DG(
"TimedGenerator(" <<
this <<
")::InsInvariant("<<statename<<
",inv)");
1147 Idx idx=BASE::StateIndex(statename);
1148 InsInvariant(idx,rInv);
1153 if(!BASE::pStates->Attribute(stateindex).IsDefault())
1154 BASE::pStates->Attributep(stateindex)->mInvariant.Clear();
1158 TEMP void THIS::ClrInvariant(
const std::string& statename) {
1159 Idx idx=BASE::StateIndex(statename);
1164 TEMP void THIS::ClearInvariants(
void) {
1166 BASE::pStates->ClearAttributes();
1171 TEMP bool THIS::SetTransition(
const std::string& rX1,
const std::string& rEv,
const std::string& rX2) {
1172 return BASE::SetTransition(rX1,rEv,rX2);
1178 return BASE::SetTransition(
Transition(x1,ev,x2));
1182 TEMP bool THIS::SetTransition(
const Transition& rTransition,
const TransAttr& rAttr) {
1183 return BASE::SetTransition(rTransition,rAttr);
1189 FD_DG(
"TimedGenerator(" <<
this <<
")::SetTransition(" << (BASE::TStr(rTrans)) <<
", " <<
1192 return BASE::SetTransition(rTrans);
1196 attr.mResets=rResets;
1197 attr.mGuard.
Name(
"Guard");
1198 attr.mResets.Name(
"Resets");
1199 #ifdef FAUDES_CHECKED
1200 ConsistentTimeConstraint(rGuard);
1201 ConsistentClocks(rResets);
1203 return BASE::SetTransition(rTrans,attr);
1209 return SetTransition(
Transition(x1,ev,x2),rGuard,rResets);
1214 const std::string& rX1,
const std::string& rEv,
const std::string& rX2,
1216 FD_DG(
"TimedGenerator(" <<
this <<
")::SetTransition(" << rX1 <<
" " << rEv <<
" " << rX2 <<
1218 bool res=BASE::SetTransition(rX1,rEv,rX2);
1223 attr.mResets=rResets;
1225 attr.mGuard.
Name(
"Guard");
1226 attr.mResets.Name(
"Resets");
1227 #ifdef FAUDES_CHECKED
1228 ConsistentTimeConstraint(rGuard);
1229 ConsistentClocks(rResets);
1231 BASE::TransAttribute(
Transition(rX1,rEv,rX2),attr);
1237 #ifdef FAUDES_CHECKED
1238 if(!BASE::ExistsTransition(rTrans)) {
1239 std::stringstream errstr;
1240 errstr <<
"transition " << BASE::TStr(rTrans) <<
" not found " << std::endl;
1241 throw Exception(
"TimedGenerator::Guard(trans)", errstr.str(), 200);
1244 return BASE::pTransRel->Attribute(rTrans).mGuard;
1250 #ifdef FAUDES_CHECKED
1251 if(!BASE::ExistsTransition(rTrans)) {
1252 std::stringstream errstr;
1253 errstr <<
"transition " << BASE::TStr(rTrans) <<
" not found " << std::endl;
1254 throw Exception(
"TimedGenerator::Guardp(trans)", errstr.str(), 200);
1257 return &BASE::pTransRel->Attributep(rTrans)->mGuard;
1263 #ifdef FAUDES_CHECKED
1264 ConsistentTimeConstraint(rGuard);
1265 if(!BASE::ExistsTransition(rTrans)) {
1266 std::stringstream errstr;
1267 errstr <<
"transition " << BASE::TStr(rTrans) <<
" not found " << std::endl;
1268 throw Exception(
"TimedGenerator::Guard(trans,guard)", errstr.str(), 200);
1271 BASE::pTransRel->Attributep(rTrans)->mGuard=rGuard;
1272 BASE::pTransRel->Attributep(rTrans)->mGuard.
Name(
"Guard");
1277 #ifdef FAUDES_CHECKED
1278 ConsistentTimeConstraint(rGuard);
1279 if(!BASE::ExistsTransition(rTrans)) {
1280 std::stringstream errstr;
1281 errstr <<
"transition " << BASE::TStr(rTrans) <<
" not found " << std::endl;
1282 throw Exception(
"TimedGenerator::InsGuard(trans,guard)", errstr.str(), 200);
1285 if(!rGuard.
Empty()) {
1286 BASE::pTransRel->Attributep(rTrans)->mGuard.Insert(rGuard);
1292 #ifdef FAUDES_CHECKED
1293 if(!BASE::ExistsTransition(rTrans)) {
1294 std::stringstream errstr;
1295 errstr <<
"transition " << BASE::TStr(rTrans) <<
" not found " << std::endl;
1296 throw Exception(
"TimedGenerator::ClrGuard(trans)", errstr.str(), 200);
1299 if(!BASE::pTransRel->Attribute(rTrans).IsDefault())
1300 BASE::pTransRel->Attributep(rTrans)->mGuard.Clear;
1306 #ifdef FAUDES_CHECKED
1307 if(!BASE::ExistsTransition(rTrans)) {
1308 std::stringstream errstr;
1309 errstr <<
"transition " << BASE::TStr(rTrans) <<
" not found " << std::endl;
1310 throw Exception(
"TimedGenerator::Resets(trans)", errstr.str(), 200);
1313 return BASE::pTransRel->Attribute(rTrans).mResets;
1319 #ifdef FAUDES_CHECKED
1320 if(!BASE::ExistsTransition(rTrans)) {
1321 std::stringstream errstr;
1322 errstr <<
"transition " << BASE::TStr(rTrans) <<
" not found " << std::endl;
1323 throw Exception(
"TimedGenerator::Resetsp(trans)", errstr.str(), 200);
1326 return &BASE::pTransRel->Attributep(rTrans)->mResets;
1332 #ifdef FAUDES_CHECKED
1333 ConsistentClocks(rResets);
1334 if(!BASE::ExistsTransition(rTrans)) {
1335 std::stringstream errstr;
1336 errstr <<
"transition " << BASE::TStr(rTrans) <<
" not found " << std::endl;
1337 throw Exception(
"TimedGenerator::Resets(trans,guard)", errstr.str(), 200);
1340 BASE::pTransRel->Attributep(rTrans)->mResets=rResets;
1346 #ifdef FAUDES_CHECKED
1347 ConsistentClocks(rResets);
1348 if(!BASE::ExistsTransition(rTrans)) {
1349 std::stringstream errstr;
1350 errstr <<
"transition " << BASE::TStr(rTrans) <<
" not found " << std::endl;
1351 throw Exception(
"TimedGenerator::InsResets(trans,guard)", errstr.str(), 200);
1354 if(!rResets.
Empty()) {
1355 BASE::pTransRel->Attributep(rTrans)->mResets.InsertSet(rResets);
1362 #ifdef FAUDES_CHECKED
1363 if(!BASE::ExistsTransition(rTrans)) {
1364 std::stringstream errstr;
1365 errstr <<
"transition " << BASE::TStr(rTrans) <<
" not found " << std::endl;
1366 throw Exception(
"TimedGenerator::ClrResets(trans)", errstr.str(), 200);
1369 if(!BASE::pTransRel->Attribute(rTrans).IsDefault())
1370 BASE::pTransRel->Attributep(rTrans)->mGuard.Clear;
1376 FD_DV(
"TimedGenerator(" <<
this <<
")::Valid()");
1378 if(!BASE::Valid())
return false;
1381 StateSet::Iterator sit;
1382 for(sit = BASE::StatesBegin(); sit!= BASE::StatesEnd(); ++sit) {
1383 if(Invariant(*sit).Name()!=
"Invariant")
return false;
1385 for(tit = BASE::TransRelBegin(); tit!= BASE::TransRelEnd(); ++tit) {
1386 if(Guard(*tit).Name()!=
"Guard")
return false;
1387 if(Resets(*tit).Name()!=
"Resets")
return false;
1389 if(Clocks().Name()!=
"Clocks")
return false;
1392 if(!(aclocks <= Clocks()))
return false;
1394 for(sit = BASE::StatesBegin(); sit!= BASE::StatesEnd(); ++sit) {
1395 if(Invariant(*sit).ClockSymbolTablep()!=ClockSymbolTablep())
return false;
1397 for(tit = BASE::TransRelBegin(); tit!= BASE::TransRelEnd(); ++tit) {
1398 if(Guard(*tit).ClockSymbolTablep()!=ClockSymbolTablep())
return false;
1399 if(Resets(*tit).SymbolTablep()!=ClockSymbolTablep())
return false;
1401 if(Clocks().SymbolTablep()!=ClockSymbolTablep())
return false;
1408 TEMP bool THIS::UpdateAttributes(
void) {
1409 FD_DG(
"TimedGenerator(" <<
this <<
")::UpdateAttributes()");
1413 StateSet blockstates=BASE::BlockingStates();
1414 StateSet::Iterator sit;
1415 for(sit=BASE::StatesBegin(); sit!= BASE::StatesEnd(); sit++) {
1416 StateAttr attr=BASE::StateAttribute(*sit);
1417 if(blockstates.
Exists(*sit)) {
1418 attr.Set(0x20000000);
1420 attr.Clr(0x20000000);
1422 BASE::StateAttribute(*sit,attr);
1432 return BASE::pGlobalAttribute->mClocks.Str(index);