24 #ifndef FAUDES_AGENERATOR_H
25 #define FAUDES_AGENERATOR_H
69 template <
class GlobalAttr,
class StateAttr,
class EventAttr,
class TransAttr>
157 virtual const Type* Cast(
const Type* pOther)
const;
231 bool Valid(
void)
const;
239 virtual void Clear(
void);
261 const TaEventSet<EventAttr>&
Alphabet(
void)
const;
269 const TaStateSet<StateAttr>& States(
void)
const;
314 bool InsEvent(
Idx index);
326 Idx InsEvent(
const std::string& rName);
339 bool InsEvent(
Idx index,
const EventAttr& rAttr);
355 Idx InsEvent(
const std::string& rName,
const EventAttr& rAttr);
364 void InjectAlphabet(
const EventSet& rNewalphabet);
372 void InjectAlphabet(
const TaEventSet<EventAttr>& rNewalphabet);
391 Idx InsState(
const StateAttr& attr);
399 bool InsState(
Idx index);
413 Idx InsState(
const std::string& rName);
428 Idx InsState(
const std::string& rName,
const StateAttr& attr);
442 bool InsState(
Idx index,
const StateAttr& attr);
451 void InjectStates(
const StateSet& rNewStates);
460 void InjectStates(
const TaStateSet<StateAttr>& rNewStates);
482 bool SetTransition(
Idx x1,
Idx ev,
Idx x2);
503 bool SetTransition(
const std::string& rX1,
const std::string& rEv,
504 const std::string& rX2);
519 bool SetTransition(
const Transition& rTransition);
536 bool SetTransition(
const Transition& rTransition,
const TransAttr& rAttr);
545 void InjectTransRel(
const TransSet& rNewtransrel);
553 void InjectTransRel(
const ATransSet& rNewtransrel);
579 void EventAttribute(
Idx index,
const EventAttr& rAttr);
596 void EventAttribute(
Idx index,
const Type& rAttr);
606 const EventAttr& EventAttribute(
Idx index)
const;
616 const EventAttr& EventAttribute(
const std::string& rName)
const;
627 EventAttr* EventAttributep(
Idx index);
638 EventAttr* EventAttributep(
const std::string& rName);
652 void StateAttribute(
Idx index,
const StateAttr& rAttr);
669 void StateAttribute(
Idx index,
const Type& rAttr);
678 const StateAttr& StateAttribute(
Idx index)
const;
688 StateAttr* StateAttributep(
Idx index);
699 void TransAttribute(
const Transition& rTrans,
const TransAttr& rAttr);
726 const TransAttr& TransAttribute(
const Transition& rTrans)
const;
736 TransAttr* TransAttributep(
const Transition& rTrans);
745 void GlobalAttribute(
const Type& rAttr) {
const GlobalAttr* ap=
dynamic_cast<const GlobalAttr*
>(&rAttr);
if(ap) *pGlobalAttribute=*ap;};
785 static const ATransSet& TransRelTaGen(
void);
788 static const GlobalAttr& GlobalTaGen(
void);
791 virtual void NewCore(
void);
794 virtual void UpdateCore(
void);
805 #define THIS TaGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
806 #define TEMP template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
807 #define BASE vGenerator
822 TEMP const GlobalAttr& THIS::GlobalTaGen(
void) {
823 static GlobalAttr fls;;
833 FD_DG(
"TaGenerator(" <<
this <<
")::TaGenerator()");
837 FD_DG(
"TaGenerator(" <<
this <<
")::TaGenerator(): done");
845 FD_DG(
"TaGenerator(" <<
this <<
")::TaGenerator(" << &rOtherGen <<
")");
859 FD_DG(
"TaGenerator(" <<
this <<
")::TaGenerator([v]" << &rOtherGen <<
")");
865 FD_DG(
"TaGenerator(" <<
this <<
")::TaGenerator([v]" << &rOtherGen <<
"): ok");
869 TEMP THIS::TaGenerator(
const std::string& rFileName) :
873 FD_DG(
"TaGenerator(" <<
this <<
")::TaGenerator(" << rFileName <<
")");
886 TEMP void THIS::NewCore(
void) {
887 FD_DG(
"TaGenerator(" <<
this <<
")::NewCore()");
895 mpAlphabet= AlphabetTaGen().New();
896 mpStates=StatesTaGen().New();
897 mpTransRel=TransRelTaGen().New();
898 mpGlobalAttribute=GlobalTaGen().New();
904 TEMP void THIS::UpdateCore(
void) {
908 pGlobalAttribute =
dynamic_cast< GlobalAttr*
>(mpGlobalAttribute);
911 pTransRel =
dynamic_cast< ATransSet*
>(mpTransRel);
914 if(pGlobalAttribute==0 && mpGlobalAttribute!=0) tmm=
true;
915 if(pAlphabet==0 && mpAlphabet!=0) tmm=
true;
916 if(pStates==0 && mpStates!=0) tmm=
true;
917 if(pTransRel==0 && mpTransRel!=0) tmm=
true;
919 std::stringstream errstr;
920 errstr <<
"cannot cast attributes for generator type " <<
typeid(*this).name();
921 errstr <<
" ptrs " << pGlobalAttribute <<
"-" << pAlphabet <<
"-" << pStates <<
"-" << pTransRel;
922 throw Exception(
"Generator::UpdateCore", errstr.str(), 63);
929 FD_DG(
"TaGenerator(" <<
this <<
")::DoAssign(" << &rGen <<
")");
930 FD_DG(
"TaGenerator(" <<
this <<
")::DoAssign(..): types " <<
typeid(*this).name() <<
" <= " <<
typeid(rGen).name());
949 #ifdef FAUDES_DEBUG_CODE
951 FD_DG(
"TaGenerator()::DoAssign(): invalid generator");
956 FD_DG(
"TaGenerator(" <<
this <<
")::DoAssign(" << &rGen <<
"): done");
961 FD_DG(
"TaGenerator(" <<
this <<
")::Assign([type] " << &rSrc <<
")");
962 FD_DG(
"TaGenerator(" <<
this <<
")::Assign(..): types \n" <<
typeid(*this).name() <<
" <= \n" <<
typeid(rSrc).name());
963 FD_DG(
"TaGenerator(" <<
this <<
")::Assign(..): match str " << (
typeid(*this).name() ==
typeid(rSrc).name()));
964 FD_DG(
"TaGenerator(" <<
this <<
")::Assign(..): match id " << (
typeid(*
this) ==
typeid(rSrc)));
967 FD_DG(
"TaGenerator(" <<
this <<
")::Assign(..): agen " << agen);
969 if(
this==agen)
return *
this;
972 FD_DG(
"TaGenerator(" <<
this <<
")::Assign([type] " << &rSrc <<
"):: call aGenerator DoAssign");
976 FD_DG(
"TaGenerator(" <<
this <<
")::Assign([type] " << &rSrc <<
"):: call vGenerator base");
985 FD_DG(
"TaGenerator(" <<
this <<
")::Move(" << &rGen <<
")");
993 FD_DG(
"TaGenerator(" <<
this <<
")::Move([v]" << &rGen <<
")");
999 TEMP THIS::~TaGenerator(
void) {
1000 FD_DG(
"TaGenerator(" <<
this <<
")::~TaGenerator()");
1008 res->EventSymbolTablep(BASE::mpEventSymbolTable);
1009 res->mStateNamesEnabled=BASE::mStateNamesEnabled;
1010 res->mReindexOnWrite=BASE::mReindexOnWrite;
1026 res.EventSymbolTablep(BASE::mpEventSymbolTable);
1029 res.StateNamesEnabled(BASE::mStateNamesEnabled);
1030 res.ReindexOnWrite(BASE::mReindexOnWrite);
1037 return dynamic_cast< const THIS*
> (pOther);
1043 FD_DG(
"TaGenerator(" <<
this <<
")::operator = [v]" << &rOtherGen);
1044 return Assign(rOtherGen);
1048 TEMP bool THIS::Valid(
void)
const {
1049 FD_DG(
"TaGenerator(" <<
this <<
")::Valid()");
1050 if(!BASE::Valid())
return false;
1053 if(
typeid(
Alphabet().AttributeType())!=
typeid(
const EventAttr*)) tmm=
true;
1054 if(
typeid(States().AttributeType())!=
typeid(
const StateAttr*)) tmm=
true;
1055 if(
typeid(TransRel().AttributeType())!=
typeid(
const TransAttr*)) tmm=
true;
1056 if(
typeid(GlobalAttribute())!=
typeid(
const GlobalAttr&)) tmm=
true;
1068 FD_DG(
"TaGenerator(" <<
this <<
")::Clear()");
1075 FD_DG(
"TaGenerator::InjectAlphabet() " << rNewAlphabet.
ToString());
1076 BASE::InjectAlphabet(rNewAlphabet);
1080 TEMP void THIS::InjectAlphabet(
const TaEventSet<EventAttr>& rNewAlphabet) {
1081 FD_DG(
"TaGenerator::InjectAlphabet(TaEventSet<EventAttr>) " << rNewAlphabet.ToString());
1082 #ifdef FAUDES_CHECKED
1083 if(rNewAlphabet.SymbolTablep()!=mpEventSymbolTable) {
1084 std::stringstream errstr;
1085 errstr <<
"symboltable mismatch aka not implemented" << std::endl;
1086 throw Exception(
"TaGenerator::InjectAlphabet", errstr.str(), 88);
1089 *pAlphabet=rNewAlphabet;
1090 mpAlphabet->Name(
"Alphabet");
1095 FD_DG(
"TaGenerator(" <<
this <<
")::InsEvent(" << index <<
")");
1096 return pAlphabet->Insert(index);
1100 TEMP Idx THIS::InsEvent(
const std::string& rName) {
1101 FD_DG(
"TaGenerator(" <<
this <<
")::InsEvent(\"" << rName <<
"\")");
1102 return pAlphabet->Insert(rName);
1106 TEMP bool THIS::InsEvent(
Idx index,
const EventAttr& attr) {
1107 FD_DG(
"TaGenerator(" <<
this <<
")::InsEvent(" << index <<
" " << attr.ToString() <<
")");
1108 return pAlphabet->Insert(index, attr);
1112 TEMP Idx THIS::InsEvent(
const std::string& rName,
const EventAttr& attr) {
1113 FD_DG(
"TaGenerator(" <<
this <<
")::InsEvent(\"" << rName << attr.ToString() <<
"\")");
1114 return pAlphabet->Insert(rName, attr);
1119 FD_DG(
"TaGenerator(" <<
this <<
")::InsState()");
1120 return pStates->Insert();
1125 FD_DG(
"TaGenerator(" <<
this <<
")::InsState(attr)");
1126 return pStates->Insert(attr);
1131 FD_DG(
"TaGenerator(" <<
this <<
")::InsState(" << index <<
")");
1132 return pStates->Insert(index);
1136 TEMP bool THIS::InsState(
Idx index,
const StateAttr& rAttr) {
1137 FD_DG(
"TaGenerator(" <<
this <<
")::InsState(" << index <<
",rAttr)");
1138 return pStates->Insert(index,rAttr);
1142 TEMP Idx THIS::InsState(
const std::string& rName) {
1143 FD_DG(
"TaGenerator(" <<
this <<
")::InsState(\"" << rName <<
"\")");
1144 Idx index=pStates->Insert();
1145 StateName(index,rName);
1150 TEMP Idx THIS::InsState(
const std::string& rName,
const StateAttr& attr) {
1151 FD_DG(
"TaGenerator(" <<
this <<
")::InsState(\"" << rName <<
"\", attr)");
1152 Idx index=pStates->Insert();
1153 StateName(index,rName);
1154 StateAttribute(index,attr);
1161 FD_DG(
"TaGenerator(" <<
this <<
")::InjectStates("
1163 BASE::InjectStates(rNewStates);
1167 TEMP void THIS::InjectStates(
const TaStateSet<StateAttr>& rNewStates) {
1168 FD_DG(
"TaGenerator(" <<
this <<
")::InjectStates("
1169 << rNewStates.ToString() <<
")");
1170 *pStates=rNewStates;
1171 pStates->Name(
"States");
1172 mpStateSymbolTable->RestrictDomain(*mpStates);
1179 FD_DG(
"TaGenerator::InjectTransRel(...)");
1180 *pTransRel=rNewTransRel;
1185 FD_DG(
"TaGenerator::InjectTransRel(...)");
1186 *pTransRel=rNewTransRel;
1191 TEMP bool THIS::SetTransition(
const std::string& rX1,
const std::string& rEv,
const std::string& rX2) {
1192 return BASE::SetTransition(rX1,rEv,rX2);
1203 FD_DG(
"TaGenerator(" <<
this <<
")::SetTransition(" << rTransition.
X1 <<
","
1204 << rTransition.
Ev <<
"," << rTransition.
X2 <<
")");
1205 #ifdef FAUDES_CHECKED
1206 if (! mpStates->Exists(rTransition.
X1)) {
1207 std::stringstream errstr;
1208 errstr <<
"TaGenerator::SetTransition: state " << rTransition.
X1
1209 <<
" not in stateset";
1210 throw Exception(
"TaGenerator::SetTransition(..)", errstr.str(), 95);
1212 if (! mpAlphabet->Exists(rTransition.
Ev)) {
1213 std::stringstream errstr;
1214 errstr <<
"TaGenerator::SetTransition: event " << rTransition.
Ev
1215 <<
" not in alphabet ";
1216 throw Exception(
"TaGenerator::SetTransition(..)", errstr.str(), 95);
1218 if (! mpStates->Exists(rTransition.
X2)) {
1219 std::stringstream errstr;
1220 errstr <<
"TaGenerator::SetTransition: state " << rTransition.
X2
1221 <<
" not in stateset";
1222 throw Exception(
"TaGenerator::SetTransition(..)", errstr.str(), 95);
1225 return pTransRel->Insert(rTransition);
1229 TEMP bool THIS::SetTransition(
const Transition& rTransition,
const TransAttr& rAttr) {
1230 FD_DG(
"TaGenerator(" <<
this <<
")::SetTransition(" << rTransition.
X1 <<
","
1231 << rTransition.
Ev <<
"," << rTransition.
X2 <<
", [attr:]" << rAttr.ToString() <<
")");
1232 #ifdef FAUDES_CHECKED
1233 if (! mpStates->Exists(rTransition.
X1)) {
1234 std::stringstream errstr;
1235 errstr <<
"TaGenerator::SetTransition: state " << rTransition.
X1
1236 <<
" not in stateset";
1237 throw Exception(
"TaGenerator::SetTransition(..)", errstr.str(), 95);
1239 if (! mpAlphabet->Exists(rTransition.
Ev)) {
1240 std::stringstream errstr;
1241 errstr <<
"TaGenerator::SetTransition: event " << rTransition.
Ev
1242 <<
" not in alphabet ";
1243 throw Exception(
"TaGenerator::SetTransition(..)", errstr.str(), 95);
1245 if (! mpStates->Exists(rTransition.
X2)) {
1246 std::stringstream errstr;
1247 errstr <<
"TaGenerator::SetTransition: state " << rTransition.
X2
1248 <<
" not in stateset";
1249 throw Exception(
"TaGenerator::SetTransition(..)", errstr.str(), 95);
1252 return pTransRel->Insert(rTransition,rAttr);
1257 FD_DG(
"TaGenerator(" <<
this <<
")::TransAttribute("
1258 << TStr(rTrans) <<
",\"" << rAttr.ToString() <<
"\")");
1259 pTransRel->Attribute(rTrans, rAttr);
1264 FD_DG(
"TaGenerator(" <<
this <<
")::TransAttribute("
1265 << TStr(rTrans) <<
",\"" << rAttr.
ToString() <<
"\")");
1266 const TransAttr* attrp =
dynamic_cast<const TransAttr*
>(&rAttr);
1268 std::stringstream errstr;
1269 errstr <<
"cannot cast event attribute " << rAttr.
ToString() <<
" for generator " << Name();
1270 throw Exception(
"TaGenerator::TransAttribute", errstr.str(), 63);
1272 pTransRel->Attribute(rTrans, *attrp);
1277 return pTransRel->Attributep(rTrans);
1283 return pTransRel->Attribute(rTrans);
1287 TEMP void THIS::EventAttribute(
Idx index,
const EventAttr& rAttr) {
1288 FD_DG(
"TaGenerator(" <<
this <<
")::EventAttribute("
1289 << EStr(index) <<
",\"" << rAttr.ToString() <<
"\")");
1290 pAlphabet->Attribute(index, rAttr);
1295 FD_DG(
"TaGenerator(" <<
this <<
")::EventAttribute("
1296 << EStr(index) <<
",\"" << rAttr.
ToString() <<
"\")");
1297 const EventAttr* attrp =
dynamic_cast<const EventAttr*
>(&rAttr);
1299 std::stringstream errstr;
1300 errstr <<
"cannot cast event attribute " << rAttr.
ToString() <<
" for generator " << Name();
1301 throw Exception(
"TaGenerator::EventAttribute", errstr.str(), 63);
1303 pAlphabet->Attribute(index, *attrp);
1307 TEMP const EventAttr& THIS::EventAttribute(
Idx index)
const {
1308 return pAlphabet->Attribute(index);
1312 TEMP EventAttr* THIS::EventAttributep(
Idx index) {
1313 return pAlphabet->Attributep(index);
1317 TEMP const EventAttr& THIS::EventAttribute(
const std::string& rName)
const {
1318 return EventAttribute(EventIndex(rName));
1322 TEMP EventAttr* THIS::EventAttributep(
const std::string& rName) {
1323 return EventAttributep(EventIndex(rName));
1327 TEMP void THIS::StateAttribute(
Idx index,
const StateAttr& rAttr) {
1328 FD_DG(
"TaGenerator(" <<
this <<
")::StateAttribute("
1329 << index <<
",\"" << rAttr.ToString() <<
"\")");
1330 pStates->Attribute(index, rAttr);
1335 FD_DG(
"TaGenerator(" <<
this <<
")::StateAttribute("
1336 << SStr(index) <<
",\"" << rAttr.
ToString() <<
"\")");
1337 const StateAttr* attrp =
dynamic_cast<const StateAttr*
>(&rAttr);
1339 std::stringstream errstr;
1340 errstr <<
"cannot cast event attribute " << rAttr.
ToString() <<
" for generator " << Name();
1341 throw Exception(
"TaGenerator::StateAttribute", errstr.str(), 63);
1343 pStates->Attribute(index, *attrp);
1348 TEMP const StateAttr& THIS::StateAttribute(
Idx index)
const {
1349 return pStates->Attribute(index);
1353 TEMP StateAttr* THIS::StateAttributep(
Idx index) {
1354 return pStates->Attributep(index);
1363 TEMP const TaStateSet<StateAttr>& THIS::States(
void)
const {
1368 TEMP const typename THIS::ATransSet& THIS::TransRel(
void)
const {
#define FD_DG(message)
Debug: optional report on generator operations.
Classes IndexSet, TaIndexSet.
Classes NameSet, TaNameSet.
Classes Transition, TTransSet and TaTransSet.
Set of indices with symbolic names.
Generator with specified attribute types.
TaNameSet< EventAttr > * pAlphabet
Alphabet, pointer with actual attribute type.
TaIndexSet< StateAttr > * pStates
State set, pointer with actual attribute type.
void TransRel(TransSetX2X1Ev &res) const
GlobalAttr * GlobalAttributep(void)
Get global attribute pointer.
void TransRel(TransSetEvX2X1 &res) const
TaTransSet< TransAttr > ATransSet
Convenience typdef for member transiton set.
void TransRel(TransSetX2EvX1 &res) const
const GlobalAttr & GlobalAttribute(void) const
Get global attribute ref.
void GlobalAttribute(const Type &rAttr)
Set global attribute.
virtual TaGenerator & Assign(const Type &rSrc)
Copy from other faudes Type (try to cast to agenerator or pass to base)
static const TaIndexSet< StateAttr > & StatesTaGen(void)
Static default state set prototype (incl.
virtual void NewCore(void)
Allocate my heap members (attribute dependent types)
ATransSet * pTransRel
Transition relation, pointer with actual attribute type.
GlobalAttr * pGlobalAttribute
Global attribute, pointer with actual attribute type.
void GlobalAttribute(const GlobalAttr &rAttr)
Set global attribute.
static const TaNameSet< EventAttr > & AlphabetTaGen(void)
Static default alphabet prototype (incl.
static const GlobalAttr & GlobalTaGen(void)
Static default global attribute prototype (configures global attribute type)
void TransRel(TransSetX1X2Ev &res) const
static const ATransSet & TransRelTaGen(void)
Static default transition relation prototype (incl.
void DoAssign(const TaGenerator &rGen)
Assignment.
Set of Transitions with attributes.
Triple (X1,Ev,X2) to represent current state, event and next state.
Base class of all libFAUDES objects that participate in the run-time interface.
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
Read configuration data from file with label specified.
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
Write configuration data to a string.
Base class of all FAUDES generators.
bool mReindexOnWrite
Reindex states on file-i/o.
StateSet mMarkedStates
Marked states.
SymbolTable mStateSymbolTable
State symbol table (local per Generator)
SymbolTable * mpEventSymbolTable
Pointer to Event symbol table.
bool mStateNamesEnabled
Automatic state names.
void ConfigureAttributeTypes(const AttributeVoid *pNewGlobalPrototype, const StateSet *pNewStatesPrototype, const EventSet *pNewAlphabetPrototype, const TransSet *pNewTransRelPrototype)
Configure attribute types.
static bool msStateNamesEnabledDefault
Default for automatic statenames.
void Name(const std::string &rName)
Set the generator's name.
std::map< Idx, Idx > mMinStateIndexMap
Map State indices to consecutive indices.
StateSet mInitStates
Initial states.
TaNameSet< AttributeCFlags > Alphabet
Convenience typedef for event sets with controllability attributes.
TTransSet< TransSort::X2EvX1 > TransSetX2EvX1
Type definition for x2, ev, x1 sorted TTransSet.
TTransSet< TransSort::X1X2Ev > TransSetX1X2Ev
Type definition for x1, x2, ev sorted TTransSet.
TTransSet< TransSort::X2X1Ev > TransSetX2X1Ev
Type definition for x2, x1, ev sorted TTransSet.
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)