12 #ifndef FAUDES_TP_TGENERATOR_H
13 #define FAUDES_TP_TGENERATOR_H
99 template <
class GlobalAttr,
class StateAttr,
class EventAttr,
class TransAttr>
169 return dynamic_cast< const TtGenerator*
> (pOther); };
203 Idx ClocksSize(
void)
const;
226 void InjectClocks(
const ClockSet& newclocks);
236 std::string ClockName(
Idx index)
const;
246 Idx ClockIndex(
const std::string& rName)
const;
256 bool InsClock(
Idx index);
268 Idx InsClock(
const std::string& rName);
276 void InsClocks(
const ClockSet& rClockSet);
288 bool DelClock(
Idx index);
299 bool DelClock(
const std::string& rName);
307 void DelClocks(
const ClockSet& rClocks);
318 bool ExistsClock(
Idx index)
const;
329 bool ExistsClock(
const std::string& rName)
const;
340 ClockSet::Iterator FindClock(
Idx index)
const;
351 ClockSet::Iterator FindClock(
const std::string& rName)
const;
368 ClockSet InactiveClocks(
void)
const;
374 void InsActiveClocks(
void);
380 void DelInactiveClocks(
void);
387 ClockSet::Iterator ClocksBegin(
void)
const;
394 ClockSet::Iterator ClocksEnd(
void)
const;
403 void ConsistentTimeConstraint(
const TimeConstraint& rTimeConstr)
const;
412 void ConsistentClocks(
const ClockSet& rClocks)
const;
475 void Invariant(
const std::string& name,
const TimeConstraint& rConstraints);
486 void InsInvariant(
const std::string& name,
const TimeConstraint& rConstraints);
506 void ClrInvariant(
Idx idx);
514 void ClrInvariant(
const std::string& name);
520 void ClearInvariants(
void);
541 bool SetTransition(
Idx x1,
Idx ev,
Idx x2);
562 bool SetTransition(
const std::string& rX1,
const std::string& rEv,
563 const std::string& rX2);
580 bool SetTransition(
const Transition& rTransition,
const TransAttr& rAttr);
613 bool SetTransition(
Idx x1,
Idx ev,
Idx x2,
634 bool SetTransition(
const std::string& rX1,
const std::string& rEv,
const std::string& rX2,
749 std::string CStr(
Idx index)
const;
757 virtual bool Valid(
void)
const;
767 virtual bool UpdateAttributes(
void);
775 typedef TtGenerator<AttributeTimedGlobal, AttributeTimedState, AttributeCFlags,AttributeTimedTrans>
779 #ifdef FAUDES_COMPATIBILITY
787 #define THIS TtGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
788 #define BASE TcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
789 #define TEMP template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
795 BASE::pGlobalAttribute->mClocks.Name(
"Clocks");
797 FD_DG(
"TimedGenerator(" <<
this <<
")::TimedGenerator() with csymtab "
798 << (BASE::pGlobalAttribute->mpClockSymbolTable ));
803 FD_DG(
"TimedGenerator(" <<
this <<
")::TimedGenerator(rOtherGen) with csymtab"
804 << (BASE::pGlobalAttribute->mpClockSymbolTable) );
810 BASE::pGlobalAttribute->mClocks.Name(
"Clocks");
812 FD_DG(
"TimedGenerator(" <<
this <<
")::TimedGenerator(rOtherGen) with csymtab"
813 << (BASE::pGlobalAttribute->mpClockSymbolTable) );
817 TEMP THIS::TtGenerator(
const std::string& rFileName) :
BASE(rFileName) {
818 FD_DG(
"TimedGenerator(" <<
this <<
")::TimedGenerator(" << rFileName <<
") with csymtab"
819 << (BASE::pGlobalAttribute->mpClockSymbolTable) );
825 return BASE::pGlobalAttribute->mpClockSymbolTable;
831 BASE::pGlobalAttribute->mpClockSymbolTable=pSymTab;
840 res->EventSymbolTablep(BASE::mpEventSymbolTable);
841 res->mStateNamesEnabled=BASE::mStateNamesEnabled;
842 res->mReindexOnWrite=BASE::mReindexOnWrite;
844 res->ClockSymbolTablep(ClockSymbolTablep());
859 THIS res= BASE::NewCGen();
861 res.ClockSymbolTablep(ClockSymbolTablep());
867 return BASE::pGlobalAttribute->mClocks.Size();
872 return BASE::pGlobalAttribute->mClocks;
877 return &BASE::pGlobalAttribute->mClocks;
882 BASE::pGlobalAttribute->mClocks=clockset;
883 BASE::pGlobalAttribute->mClocks.
Name(
"Clocks");
888 return BASE::pGlobalAttribute->mClocks.Insert(clockindex);
892 TEMP Idx THIS::InsClock(
const std::string& clockname) {
893 return BASE::pGlobalAttribute->mClocks.Insert(clockname);
898 BASE::pGlobalAttribute->mClocks.InsertSet(clockset);
904 FD_DG(
"TimedGenerator(" <<
this <<
")::DelClock(" << clockindex <<
")");
906 for(tit=BASE::TransRelBegin(); tit!=BASE::TransRelEnd(); tit++) {
907 if(!BASE::pTransRel->Attribute(*tit).IsDefault()) {
908 BASE::pTransRel->Attributep(*tit)->mGuard.EraseByClock(clockindex);
909 BASE::pTransRel->Attributep(*tit)->mResets.Erase(clockindex);
912 StateSet::Iterator it;
913 for(it=BASE::StatesBegin(); it!=BASE::StatesEnd(); it++) {
914 if(!BASE::pStates->Attribute(*it).IsDefault()) {
915 BASE::pStates->Attributep(*it)->mInvariant.EraseByClock(clockindex);
918 return BASE::pGlobalAttribute->mClocks.Erase(clockindex);
922 TEMP bool THIS::DelClock(
const std::string& clockname) {
923 Idx index=BASE::pGlobalAttribute->mClocks.Index(clockname);
924 return DelClock(index);
929 ClockSet::Iterator it, tmpit;
930 for(it=clockset.
Begin(); it!=clockset.
End(); ) {
938 TEMP bool THIS::ExistsClock(
Idx clockindex)
const {
939 return BASE::pGlobalAttribute->mClocks.Exists(clockindex);
944 const std::string& clockname)
const {
945 return BASE::pGlobalAttribute->mClocks.Exists(clockname);
949 TEMP ClockSet::Iterator THIS::FindClock(
Idx clockindex)
const {
950 return BASE::pGlobalAttribute->mClocks.Find(clockindex);
954 TEMP ClockSet::Iterator THIS::FindClock(
const std::string& clockname)
const {
955 return BASE::pGlobalAttribute->mClocks.Find(clockname);
959 TEMP std::string THIS::ClockName(
Idx clockindex)
const {
960 return BASE::pGlobalAttribute->mClocks.SymbolicName(clockindex);
964 TEMP Idx THIS::ClockIndex(
const std::string& clockname)
const {
965 return BASE::pGlobalAttribute->mClocks.Index(clockname);
970 FD_DG(
"TimedGenerator(" <<
this <<
")::ActiveClocks() const");
973 for(tit=BASE::TransRelBegin(); tit!=BASE::TransRelEnd(); tit++) {
974 res.
InsertSet(Guard(*tit).ActiveClocks());
977 StateSet::Iterator it;
978 for(it=BASE::StatesBegin(); it!=BASE::StatesEnd(); it++) {
979 res.
InsertSet(Invariant(*it).ActiveClocks());
981 res.
Name(
"AcitiveClocks");
987 FD_DG(
"TtaGenerator(" <<
this <<
")::InactiveClocks() const");
988 ClockSet res = BASE::pGlobalAttribute->mClocks;
990 res.
Name(
"InactiveClocks");
995 TEMP void THIS::InsActiveClocks(
void) {
996 FD_DG(
"TimedGenerator(" <<
this <<
")::InsActiveClocks()");
1002 TEMP void THIS::DelInactiveClocks(
void) {
1003 FD_DG(
"TimedGenerator(" <<
this <<
")::InsActiveClocks()");
1004 ClockSet iaclocks=InactiveClocks();
1005 BASE::pGlobalAttribute->mClocks.EraseSet(iaclocks);
1009 TEMP ClockSet::Iterator THIS::ClocksBegin(
void)
const {
1010 return BASE::pGlobalAttribute->mClocks.Begin();
1014 TEMP ClockSet::Iterator THIS::ClocksEnd(
void)
const {
1015 return BASE::pGlobalAttribute->mClocks.End();
1020 FD_DG(
"TimedGenerator(" <<
this <<
")::ConsistentTimeConstraint(constr)");
1022 std::stringstream errstr;
1023 errstr <<
"clocksymboltable mismatch" << std::endl;
1024 throw Exception(
"TimedGenerator::ConsistentTimeConstraint)", errstr.str(), 200);
1027 std::stringstream errstr;
1028 errstr <<
"time constraint refers to clocks not in clockset: " <<
1030 throw Exception(
"TimedGenerator::ConsistentTimeConstraint)", errstr.str(), 200);
1032 FD_DG(
"TimedGenerator(" <<
this <<
")::ConsistentTimeConstraint(constr): ok");
1037 if(!( rClocks <= Clocks() )) {
1038 std::stringstream errstr;
1039 errstr <<
"clocksset contains clocks not in clockset" << std::endl;
1040 throw Exception(
"TimedGenerator::ConsistentClocks)", errstr.str(), 200);
1043 std::stringstream errstr;
1044 errstr <<
"clocksymboltable mismatch" << std::endl;
1045 throw Exception(
"TimedGenerator::ConsistentClocks)", errstr.str(), 200);
1052 if(!BASE::ExistsState(stateindex)) {
1053 std::stringstream errstr;
1054 errstr <<
"state index " << stateindex <<
" not found in StateSet" << std::endl;
1055 throw Exception(
"TimedGenerator::Invariant", errstr.str(), 200);
1057 return BASE::pStates->Attribute(stateindex).mInvariant;
1062 if(!BASE::ExistsState(stateindex)) {
1063 std::stringstream errstr;
1064 errstr <<
"state index " << stateindex <<
" not found in StateSet" << std::endl;
1065 throw Exception(
"TimedGenerator::Invariant", errstr.str(), 200);
1067 return &BASE::pStates->Attributep(stateindex)->mInvariant;
1072 Idx idx=BASE::StateIndex(statename);
1073 return Invariant(idx);
1078 Idx idx=BASE::StateIndex(statename);
1079 return Invariantp(idx);
1084 FD_DG(
"TimedGenerator(" <<
this <<
")::Invariant("<<stateindex<<
",inv)");
1085 #ifdef FAUDES_CHECKED
1086 ConsistentTimeConstraint(rInv);
1087 if(!BASE::ExistsState(stateindex)) {
1088 std::stringstream errstr;
1089 errstr <<
"state index " << stateindex <<
" not found in StateSet" << std::endl;
1090 throw Exception(
"TimedGenerator::Invariant", errstr.str(), 200);
1093 BASE::pStates->Attributep(stateindex)->mInvariant=rInv;
1094 BASE::pStates->Attributep(stateindex)->mInvariant.
Name(
"Invariant");
1099 FD_DG(
"TimedGenerator(" <<
this <<
")::Invariant("<<statename<<
",inv)");
1100 Idx idx=BASE::StateIndex(statename);
1101 Invariant(idx,rInv);
1106 FD_DG(
"TimedGenerator(" <<
this <<
")::InsInvariant("<<stateindex<<
",inv)");
1107 #ifdef FAUDES_CHECKED
1108 ConsistentTimeConstraint(rInv);
1109 if(!BASE::ExistsState(stateindex)) {
1110 std::stringstream errstr;
1111 errstr <<
"state index " << stateindex <<
" not found in StateSet" << std::endl;
1112 throw Exception(
"TimedGenerator::InsInvariant", errstr.str(), 200);
1116 BASE::pStates->Attributep(stateindex)->mInvariant.Insert(rInv);
1122 FD_DG(
"TimedGenerator(" <<
this <<
")::InsInvariant("<<statename<<
",inv)");
1123 Idx idx=BASE::StateIndex(statename);
1124 InsInvariant(idx,rInv);
1129 if(!BASE::pStates->Attribute(stateindex).IsDefault())
1130 BASE::pStates->Attributep(stateindex)->mInvariant.Clear();
1134 TEMP void THIS::ClrInvariant(
const std::string& statename) {
1135 Idx idx=BASE::StateIndex(statename);
1140 TEMP void THIS::ClearInvariants(
void) {
1142 BASE::pStates->ClearAttributes();
1147 TEMP bool THIS::SetTransition(
const std::string& rX1,
const std::string& rEv,
const std::string& rX2) {
1148 return BASE::SetTransition(rX1,rEv,rX2);
1154 return BASE::SetTransition(
Transition(x1,ev,x2));
1158 TEMP bool THIS::SetTransition(
const Transition& rTransition,
const TransAttr& rAttr) {
1159 return BASE::SetTransition(rTransition,rAttr);
1165 FD_DG(
"TimedGenerator(" <<
this <<
")::SetTransition(" << (BASE::TStr(rTrans)) <<
", " <<
1168 return BASE::SetTransition(rTrans);
1172 attr.mResets=rResets;
1173 attr.mGuard.
Name(
"Guard");
1174 attr.mResets.Name(
"Resets");
1175 #ifdef FAUDES_CHECKED
1176 ConsistentTimeConstraint(rGuard);
1177 ConsistentClocks(rResets);
1179 return BASE::SetTransition(rTrans,attr);
1185 return SetTransition(
Transition(x1,ev,x2),rGuard,rResets);
1190 const std::string& rX1,
const std::string& rEv,
const std::string& rX2,
1192 FD_DG(
"TimedGenerator(" <<
this <<
")::SetTransition(" << rX1 <<
" " << rEv <<
" " << rX2 <<
1194 Idx x1=this->StateIndex(rX1);
1195 Idx ev=this->EventIndex(rEv);
1196 Idx x2=this->StateIndex(rX2);
1197 bool res=BASE::SetTransition(x1,ev,x2);
1202 attr.mResets=rResets;
1204 attr.mGuard.
Name(
"Guard");
1205 attr.mResets.Name(
"Resets");
1206 #ifdef FAUDES_CHECKED
1207 ConsistentTimeConstraint(rGuard);
1208 ConsistentClocks(rResets);
1210 BASE::TransAttribute(
Transition(x1,ev,x2),attr);
1216 #ifdef FAUDES_CHECKED
1217 if(!BASE::ExistsTransition(rTrans)) {
1218 std::stringstream errstr;
1219 errstr <<
"transition " << BASE::TStr(rTrans) <<
" not found " << std::endl;
1220 throw Exception(
"TimedGenerator::Guard(trans)", errstr.str(), 200);
1223 return BASE::pTransRel->Attribute(rTrans).mGuard;
1229 #ifdef FAUDES_CHECKED
1230 if(!BASE::ExistsTransition(rTrans)) {
1231 std::stringstream errstr;
1232 errstr <<
"transition " << BASE::TStr(rTrans) <<
" not found " << std::endl;
1233 throw Exception(
"TimedGenerator::Guardp(trans)", errstr.str(), 200);
1236 return &BASE::pTransRel->Attributep(rTrans)->mGuard;
1242 #ifdef FAUDES_CHECKED
1243 ConsistentTimeConstraint(rGuard);
1244 if(!BASE::ExistsTransition(rTrans)) {
1245 std::stringstream errstr;
1246 errstr <<
"transition " << BASE::TStr(rTrans) <<
" not found " << std::endl;
1247 throw Exception(
"TimedGenerator::Guard(trans,guard)", errstr.str(), 200);
1250 BASE::pTransRel->Attributep(rTrans)->mGuard=rGuard;
1251 BASE::pTransRel->Attributep(rTrans)->mGuard.
Name(
"Guard");
1256 #ifdef FAUDES_CHECKED
1257 ConsistentTimeConstraint(rGuard);
1258 if(!BASE::ExistsTransition(rTrans)) {
1259 std::stringstream errstr;
1260 errstr <<
"transition " << BASE::TStr(rTrans) <<
" not found " << std::endl;
1261 throw Exception(
"TimedGenerator::InsGuard(trans,guard)", errstr.str(), 200);
1264 if(!rGuard.
Empty()) {
1265 BASE::pTransRel->Attributep(rTrans)->mGuard.Insert(rGuard);
1271 #ifdef FAUDES_CHECKED
1272 if(!BASE::ExistsTransition(rTrans)) {
1273 std::stringstream errstr;
1274 errstr <<
"transition " << BASE::TStr(rTrans) <<
" not found " << std::endl;
1275 throw Exception(
"TimedGenerator::ClrGuard(trans)", errstr.str(), 200);
1278 if(!BASE::pTransRel->Attribute(rTrans).IsDefault())
1279 BASE::pTransRel->Attributep(rTrans)->mGuard.Clear();
1285 #ifdef FAUDES_CHECKED
1286 if(!BASE::ExistsTransition(rTrans)) {
1287 std::stringstream errstr;
1288 errstr <<
"transition " << BASE::TStr(rTrans) <<
" not found " << std::endl;
1289 throw Exception(
"TimedGenerator::Resets(trans)", errstr.str(), 200);
1292 return BASE::pTransRel->Attribute(rTrans).mResets;
1298 #ifdef FAUDES_CHECKED
1299 if(!BASE::ExistsTransition(rTrans)) {
1300 std::stringstream errstr;
1301 errstr <<
"transition " << BASE::TStr(rTrans) <<
" not found " << std::endl;
1302 throw Exception(
"TimedGenerator::Resetsp(trans)", errstr.str(), 200);
1305 return &BASE::pTransRel->Attributep(rTrans)->mResets;
1311 #ifdef FAUDES_CHECKED
1312 ConsistentClocks(rResets);
1313 if(!BASE::ExistsTransition(rTrans)) {
1314 std::stringstream errstr;
1315 errstr <<
"transition " << BASE::TStr(rTrans) <<
" not found " << std::endl;
1316 throw Exception(
"TimedGenerator::Resets(trans,guard)", errstr.str(), 200);
1319 BASE::pTransRel->Attributep(rTrans)->mResets=rResets;
1325 #ifdef FAUDES_CHECKED
1326 ConsistentClocks(rResets);
1327 if(!BASE::ExistsTransition(rTrans)) {
1328 std::stringstream errstr;
1329 errstr <<
"transition " << BASE::TStr(rTrans) <<
" not found " << std::endl;
1330 throw Exception(
"TimedGenerator::InsResets(trans,guard)", errstr.str(), 200);
1333 if(!rResets.
Empty()) {
1334 BASE::pTransRel->Attributep(rTrans)->mResets.InsertSet(rResets);
1341 #ifdef FAUDES_CHECKED
1342 if(!BASE::ExistsTransition(rTrans)) {
1343 std::stringstream errstr;
1344 errstr <<
"transition " << BASE::TStr(rTrans) <<
" not found " << std::endl;
1345 throw Exception(
"TimedGenerator::ClrResets(trans)", errstr.str(), 200);
1348 if(!BASE::pTransRel->Attribute(rTrans).IsDefault())
1349 BASE::pTransRel->Attributep(rTrans)->mGuard.Clear();
1354 TEMP bool THIS::Valid(
void)
const {
1355 FD_DV(
"TimedGenerator(" <<
this <<
")::Valid()");
1357 if(!BASE::Valid())
return false;
1360 StateSet::Iterator sit;
1361 for(sit = BASE::StatesBegin(); sit!= BASE::StatesEnd(); ++sit) {
1362 if(Invariant(*sit).Name()!=
"Invariant")
return false;
1364 for(tit = BASE::TransRelBegin(); tit!= BASE::TransRelEnd(); ++tit) {
1365 if(Guard(*tit).Name()!=
"Guard")
return false;
1366 if(Resets(*tit).Name()!=
"Resets")
return false;
1368 if(Clocks().Name()!=
"Clocks")
return false;
1371 if(!(aclocks <= Clocks()))
return false;
1373 for(sit = BASE::StatesBegin(); sit!= BASE::StatesEnd(); ++sit) {
1374 if(Invariant(*sit).ClockSymbolTablep()!=ClockSymbolTablep())
return false;
1376 for(tit = BASE::TransRelBegin(); tit!= BASE::TransRelEnd(); ++tit) {
1377 if(Guard(*tit).ClockSymbolTablep()!=ClockSymbolTablep())
return false;
1378 if(Resets(*tit).SymbolTablep()!=ClockSymbolTablep())
return false;
1380 if(Clocks().SymbolTablep()!=ClockSymbolTablep())
return false;
1387 TEMP bool THIS::UpdateAttributes(
void) {
1388 FD_DG(
"TimedGenerator(" <<
this <<
")::UpdateAttributes()");
1392 StateSet blockstates=BASE::BlockingStates();
1393 StateSet::Iterator sit;
1394 for(sit=BASE::StatesBegin(); sit!= BASE::StatesEnd(); sit++) {
1395 StateAttr attr=BASE::StateAttribute(*sit);
1396 if(blockstates.
Exists(*sit)) {
1397 attr.Set(0x20000000);
1399 attr.Clr(0x20000000);
1401 BASE::StateAttribute(*sit,attr);
1411 return BASE::pGlobalAttribute->mClocks.Str(index);
#define FD_DG(message)
Debug: optional report on generator operations.
#define FD_DV(message)
Debug: optional low-level report on iterations and token IO.
Container class to model a set of clocks.
static SymbolTable * GlobalClockSymbolTablep(void)
Get pointer to static clock SymbolTable (init on first use pattern)
virtual void InsertSet(const NameSet &rOtherSet)
Inserts all elements of rOtherSet.
SymbolTable * SymbolTablep(void) const
Get Pointer mpSymbolTable.
void EraseSet(const NameSet &rOtherSet)
Erase elements specified by rOtherSet.
A SymbolTable associates sybolic names with indices.
TBaseSet< Transition, TransSort::X1EvX2 >::Iterator Iterator
Iterator on transition.
Generator with controllability attributes.
A TimeConstraint is a set of elementary clock constraints.
std::string ToString(void) const
Write to a std::string.
bool Empty(void) const
Checks if TimeConstraint containts no ElemConstraints.
std::string Name(void) const
Return name of Constraint.
ClockSet ActiveClocks(void) const
Returns a Clockset containing all clocks used by the TimeConstraint.
SymbolTable * ClockSymbolTablep(void) const
Get Pointer to mpClockSymbolTable.
Triple (X1,Ev,X2) to represent current state, event and next state.
Generator with timing extensions.
virtual const Type * Cast(const Type *pOther) const
Type test.
Base class of all libFAUDES objects that participate in the run-time interface.
virtual void Name(const std::string &rName)
Set the objects's name.
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
Write configuration data to a string.
Base class of all FAUDES generators.
Includes all libFAUDES headers, no plugins.
bool Empty(void) const
Test whether if the TBaseSet is Empty.
bool Exists(const T &rElem) const
Test existence of element.
Iterator End(void) const
Iterator to the end of set.
virtual AttributeVoid * Attributep(const T &rElem)
Attribute access.
Iterator Begin(void) const
Iterator to the begin of set.
const std::string & Name(void) const
Return name of TBaseSet.
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)
TtGenerator< AttributeTimedGlobal, AttributeTimedState, AttributeCFlags, AttributeTimedTrans > TimedGenerator
Convenience typedef for std TimedGenerator.
TtGenerator< AttributeTimedGlobal, AttributeTimedState, AttributeCFlags, AttributeTimedTrans > tGenerator
Compatibility: pre 2.20b used tGenerator as C++ class name.
Attributes for timed automata.