24 #ifndef FAUDES_AGENERATOR_H
25 #define FAUDES_AGENERATOR_H
69 template <
class GlobalAttr,
class StateAttr,
class EventAttr,
class TransAttr>
158 virtual const Type* Cast(
const Type* pOther)
const;
233 bool Valid(
void)
const;
241 virtual void Clear(
void);
263 const TaEventSet<EventAttr>&
Alphabet(
void)
const;
316 bool InsEvent(
Idx index);
328 Idx InsEvent(
const std::string& rName);
341 bool InsEvent(
Idx index,
const EventAttr& rAttr);
357 Idx InsEvent(
const std::string& rName,
const EventAttr& rAttr);
366 void InjectAlphabet(
const EventSet& rNewalphabet);
374 void InjectAlphabet(
const TaEventSet<EventAttr>& rNewalphabet);
393 Idx InsState(
const StateAttr& attr);
401 bool InsState(
Idx index);
415 Idx InsState(
const std::string& rName);
430 Idx InsState(
const std::string& rName,
const StateAttr& attr);
444 bool InsState(
Idx index,
const StateAttr& attr);
453 void InjectStates(
const StateSet& rNewStates);
484 bool SetTransition(
Idx x1,
Idx ev,
Idx x2);
505 bool SetTransition(
const std::string& rX1,
const std::string& rEv,
506 const std::string& rX2);
521 bool SetTransition(
const Transition& rTransition);
538 bool SetTransition(
const Transition& rTransition,
const TransAttr& rAttr);
547 void InjectTransRel(
const TransSet& rNewtransrel);
555 void InjectTransRel(
const ATransSet& rNewtransrel);
581 void EventAttribute(
Idx index,
const EventAttr& rAttr);
598 void EventAttribute(
Idx index,
const Type& rAttr);
608 const EventAttr& EventAttribute(
Idx index)
const;
618 const EventAttr& EventAttribute(
const std::string& rName)
const;
629 EventAttr* EventAttributep(
Idx index);
640 EventAttr* EventAttributep(
const std::string& rName);
654 void StateAttribute(
Idx index,
const StateAttr& rAttr);
671 void StateAttribute(
Idx index,
const Type& rAttr);
680 const StateAttr& StateAttribute(
Idx index)
const;
690 StateAttr* StateAttributep(
Idx index);
701 void TransAttribute(
const Transition& rTrans,
const TransAttr& rAttr);
728 const TransAttr& TransAttribute(
const Transition& rTrans)
const;
738 TransAttr* TransAttributep(
const Transition& rTrans);
747 void GlobalAttribute(
const Type& rAttr) {
const GlobalAttr* ap=
dynamic_cast<const GlobalAttr*
>(&rAttr);
if(ap) *pGlobalAttribute=*ap;};
787 static const ATransSet& TransRelTaGen(
void);
790 static const GlobalAttr& GlobalTaGen(
void);
793 virtual void NewCore(
void);
796 virtual void UpdateCore(
void);
807 #define THIS TaGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
808 #define TEMP template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
809 #define BASE vGenerator
824 TEMP const GlobalAttr& THIS::GlobalTaGen(
void) {
825 static GlobalAttr fls;;
835 FD_DG(
"TaGenerator(" <<
this <<
")::TaGenerator()");
839 FD_DG(
"TaGenerator(" <<
this <<
")::TaGenerator(): done");
847 FD_DG(
"TaGenerator(" <<
this <<
")::TaGenerator(" << &rOtherGen <<
")");
861 FD_DG(
"TaGenerator(" <<
this <<
")::TaGenerator([v]" << &rOtherGen <<
")");
867 FD_DG(
"TaGenerator(" <<
this <<
")::TaGenerator([v]" << &rOtherGen <<
"): ok");
871 TEMP THIS::TaGenerator(
const std::string& rFileName) :
875 FD_DG(
"TaGenerator(" <<
this <<
")::TaGenerator(" << rFileName <<
")");
888 TEMP void THIS::NewCore(
void) {
889 FD_DG(
"TaGenerator(" <<
this <<
")::NewCore()");
897 mpAlphabet= AlphabetTaGen().New();
898 mpStates=StatesTaGen().New();
899 mpTransRel=TransRelTaGen().New();
900 mpGlobalAttribute=GlobalTaGen().New();
906 TEMP void THIS::UpdateCore(
void) {
910 pGlobalAttribute =
dynamic_cast< GlobalAttr*
>(mpGlobalAttribute);
913 pTransRel =
dynamic_cast< ATransSet*
>(mpTransRel);
916 if(pGlobalAttribute==0 && mpGlobalAttribute!=0) tmm=
true;
917 if(pAlphabet==0 && mpAlphabet!=0) tmm=
true;
918 if(pStates==0 && mpStates!=0) tmm=
true;
919 if(pTransRel==0 && mpTransRel!=0) tmm=
true;
921 std::stringstream errstr;
922 errstr <<
"cannot cast attributes for generator type " <<
typeid(*this).name();
923 errstr <<
" ptrs " << pGlobalAttribute <<
"-" << pAlphabet <<
"-" << pStates <<
"-" << pTransRel;
924 throw Exception(
"Generator::UpdateCore", errstr.str(), 63);
931 FD_DG(
"TaGenerator(" <<
this <<
")::DoAssign(" << &rGen <<
")");
932 FD_DG(
"TaGenerator(" <<
this <<
")::DoAssign(..): types " <<
typeid(*this).name() <<
" <= " <<
typeid(rGen).name());
951 #ifdef FAUDES_DEBUG_CODE
953 FD_DG(
"TaGenerator()::DoAssign(): invalid generator");
958 FD_DG(
"TaGenerator(" <<
this <<
")::DoAssign(" << &rGen <<
"): done");
963 FD_DG(
"TaGenerator(" <<
this <<
")::Assign([type] " << &rSrc <<
")");
964 FD_DG(
"TaGenerator(" <<
this <<
")::Assign(..): types \n" <<
typeid(*this).name() <<
" <= \n" <<
typeid(rSrc).name());
965 FD_DG(
"TaGenerator(" <<
this <<
")::Assign(..): match str " << (
typeid(*this).name() ==
typeid(rSrc).name()));
966 FD_DG(
"TaGenerator(" <<
this <<
")::Assign(..): match id " << (
typeid(*
this) ==
typeid(rSrc)));
969 FD_DG(
"TaGenerator(" <<
this <<
")::Assign(..): agen " << agen);
971 if(
this==agen)
return *
this;
974 FD_DG(
"TaGenerator(" <<
this <<
")::Assign([type] " << &rSrc <<
"):: call aGenerator DoAssign");
978 FD_DG(
"TaGenerator(" <<
this <<
")::Assign([type] " << &rSrc <<
"):: call vGenerator base");
987 FD_DG(
"TaGenerator(" <<
this <<
")::Move(" << &rGen <<
")");
995 FD_DG(
"TaGenerator(" <<
this <<
")::Move([v]" << &rGen <<
")");
1002 FD_DG(
"TaGenerator(" <<
this <<
")::~TaGenerator()");
1010 res->EventSymbolTablep(BASE::mpEventSymbolTable);
1011 res->mStateNamesEnabled=BASE::mStateNamesEnabled;
1012 res->mReindexOnWrite=BASE::mReindexOnWrite;
1028 res.EventSymbolTablep(BASE::mpEventSymbolTable);
1031 res.StateNamesEnabled(BASE::mStateNamesEnabled);
1032 res.ReindexOnWrite(BASE::mReindexOnWrite);
1039 return dynamic_cast< const THIS*
> (pOther);
1045 FD_DG(
"TaGenerator(" <<
this <<
")::operator = [v]" << &rOtherGen);
1046 return Assign(rOtherGen);
1050 TEMP bool THIS::Valid(
void)
const {
1051 FD_DG(
"TaGenerator(" <<
this <<
")::Valid()");
1052 if(!BASE::Valid())
return false;
1055 if(
typeid(
Alphabet().AttributeType())!=
typeid(
const EventAttr*)) tmm=
true;
1056 if(
typeid(States().AttributeType())!=
typeid(
const StateAttr*)) tmm=
true;
1057 if(
typeid(TransRel().AttributeType())!=
typeid(
const TransAttr*)) tmm=
true;
1058 if(
typeid(GlobalAttribute())!=
typeid(
const GlobalAttr&)) tmm=
true;
1070 FD_DG(
"TaGenerator(" <<
this <<
")::Clear()");
1077 FD_DG(
"TaGenerator::InjectAlphabet() " << rNewAlphabet.
ToString());
1078 BASE::InjectAlphabet(rNewAlphabet);
1082 TEMP void THIS::InjectAlphabet(
const TaEventSet<EventAttr>& rNewAlphabet) {
1083 FD_DG(
"TaGenerator::InjectAlphabet(TaEventSet<EventAttr>) " << rNewAlphabet.ToString());
1084 #ifdef FAUDES_CHECKED
1085 if(rNewAlphabet.SymbolTablep()!=mpEventSymbolTable) {
1086 std::stringstream errstr;
1087 errstr <<
"symboltable mismatch aka not implemented" << std::endl;
1088 throw Exception(
"TaGenerator::InjectAlphabet", errstr.str(), 88);
1091 *pAlphabet=rNewAlphabet;
1092 mpAlphabet->Name(
"Alphabet");
1097 FD_DG(
"TaGenerator(" <<
this <<
")::InsEvent(" << index <<
")");
1098 return pAlphabet->Insert(index);
1102 TEMP Idx THIS::InsEvent(
const std::string& rName) {
1103 FD_DG(
"TaGenerator(" <<
this <<
")::InsEvent(\"" << rName <<
"\")");
1104 return pAlphabet->Insert(rName);
1108 TEMP bool THIS::InsEvent(
Idx index,
const EventAttr& attr) {
1109 FD_DG(
"TaGenerator(" <<
this <<
")::InsEvent(" << index <<
" " << attr.ToString() <<
")");
1110 return pAlphabet->Insert(index, attr);
1114 TEMP Idx THIS::InsEvent(
const std::string& rName,
const EventAttr& attr) {
1115 FD_DG(
"TaGenerator(" <<
this <<
")::InsEvent(\"" << rName << attr.ToString() <<
"\")");
1116 return pAlphabet->Insert(rName, attr);
1121 FD_DG(
"TaGenerator(" <<
this <<
")::InsState()");
1122 return pStates->Insert();
1127 FD_DG(
"TaGenerator(" <<
this <<
")::InsState(attr)");
1128 return pStates->Insert(attr);
1133 FD_DG(
"TaGenerator(" <<
this <<
")::InsState(" << index <<
")");
1134 return pStates->Insert(index);
1138 TEMP bool THIS::InsState(
Idx index,
const StateAttr& rAttr) {
1139 FD_DG(
"TaGenerator(" <<
this <<
")::InsState(" << index <<
",rAttr)");
1140 return pStates->Insert(index,rAttr);
1144 TEMP Idx THIS::InsState(
const std::string& rName) {
1145 FD_DG(
"TaGenerator(" <<
this <<
")::InsState(\"" << rName <<
"\")");
1146 Idx index=pStates->Insert();
1147 StateName(index,rName);
1152 TEMP Idx THIS::InsState(
const std::string& rName,
const StateAttr& attr) {
1153 FD_DG(
"TaGenerator(" <<
this <<
")::InsState(\"" << rName <<
"\", attr)");
1154 Idx index=pStates->Insert();
1155 StateName(index,rName);
1156 StateAttribute(index,attr);
1163 FD_DG(
"TaGenerator(" <<
this <<
")::InjectStates("
1165 BASE::InjectStates(rNewStates);
1170 FD_DG(
"TaGenerator(" <<
this <<
")::InjectStates("
1172 *pStates=rNewStates;
1173 pStates->
Name(
"States");
1174 mpStateSymbolTable->RestrictDomain(*mpStates);
1181 FD_DG(
"TaGenerator::InjectTransRel(...)");
1182 *pTransRel=rNewTransRel;
1187 FD_DG(
"TaGenerator::InjectTransRel(...)");
1188 *pTransRel=rNewTransRel;
1193 TEMP bool THIS::SetTransition(
const std::string& rX1,
const std::string& rEv,
const std::string& rX2) {
1194 return BASE::SetTransition(rX1,rEv,rX2);
1205 FD_DG(
"TaGenerator(" <<
this <<
")::SetTransition(" << rTransition.
X1 <<
","
1206 << rTransition.
Ev <<
"," << rTransition.
X2 <<
")");
1207 #ifdef FAUDES_CHECKED
1208 if (! mpStates->Exists(rTransition.
X1)) {
1209 std::stringstream errstr;
1210 errstr <<
"TaGenerator::SetTransition: state " << rTransition.
X1
1211 <<
" not in stateset";
1212 throw Exception(
"TaGenerator::SetTransition(..)", errstr.str(), 95);
1214 if (! mpAlphabet->Exists(rTransition.
Ev)) {
1215 std::stringstream errstr;
1216 errstr <<
"TaGenerator::SetTransition: event " << rTransition.
Ev
1217 <<
" not in alphabet ";
1218 throw Exception(
"TaGenerator::SetTransition(..)", errstr.str(), 95);
1220 if (! mpStates->Exists(rTransition.
X2)) {
1221 std::stringstream errstr;
1222 errstr <<
"TaGenerator::SetTransition: state " << rTransition.
X2
1223 <<
" not in stateset";
1224 throw Exception(
"TaGenerator::SetTransition(..)", errstr.str(), 95);
1227 return pTransRel->Insert(rTransition);
1231 TEMP bool THIS::SetTransition(
const Transition& rTransition,
const TransAttr& rAttr) {
1232 FD_DG(
"TaGenerator(" <<
this <<
")::SetTransition(" << rTransition.
X1 <<
","
1233 << rTransition.
Ev <<
"," << rTransition.
X2 <<
", [attr:]" << rAttr.ToString() <<
")");
1234 #ifdef FAUDES_CHECKED
1235 if (! mpStates->Exists(rTransition.
X1)) {
1236 std::stringstream errstr;
1237 errstr <<
"TaGenerator::SetTransition: state " << rTransition.
X1
1238 <<
" not in stateset";
1239 throw Exception(
"TaGenerator::SetTransition(..)", errstr.str(), 95);
1241 if (! mpAlphabet->Exists(rTransition.
Ev)) {
1242 std::stringstream errstr;
1243 errstr <<
"TaGenerator::SetTransition: event " << rTransition.
Ev
1244 <<
" not in alphabet ";
1245 throw Exception(
"TaGenerator::SetTransition(..)", errstr.str(), 95);
1247 if (! mpStates->Exists(rTransition.
X2)) {
1248 std::stringstream errstr;
1249 errstr <<
"TaGenerator::SetTransition: state " << rTransition.
X2
1250 <<
" not in stateset";
1251 throw Exception(
"TaGenerator::SetTransition(..)", errstr.str(), 95);
1254 return pTransRel->Insert(rTransition,rAttr);
1259 FD_DG(
"TaGenerator(" <<
this <<
")::TransAttribute("
1260 << TStr(rTrans) <<
",\"" << rAttr.ToString() <<
"\")");
1261 pTransRel->Attribute(rTrans, rAttr);
1266 FD_DG(
"TaGenerator(" <<
this <<
")::TransAttribute("
1267 << TStr(rTrans) <<
",\"" << rAttr.
ToString() <<
"\")");
1268 const TransAttr* attrp =
dynamic_cast<const TransAttr*
>(&rAttr);
1270 std::stringstream errstr;
1271 errstr <<
"cannot cast event attribute " << rAttr.
ToString() <<
" for generator " << Name();
1272 throw Exception(
"TaGenerator::TransAttribute", errstr.str(), 63);
1274 pTransRel->Attribute(rTrans, *attrp);
1279 return pTransRel->Attributep(rTrans);
1285 return pTransRel->Attribute(rTrans);
1289 TEMP void THIS::EventAttribute(
Idx index,
const EventAttr& rAttr) {
1290 FD_DG(
"TaGenerator(" <<
this <<
")::EventAttribute("
1291 << EStr(index) <<
",\"" << rAttr.ToString() <<
"\")");
1292 pAlphabet->Attribute(index, rAttr);
1297 FD_DG(
"TaGenerator(" <<
this <<
")::EventAttribute("
1298 << EStr(index) <<
",\"" << rAttr.
ToString() <<
"\")");
1299 const EventAttr* attrp =
dynamic_cast<const EventAttr*
>(&rAttr);
1301 std::stringstream errstr;
1302 errstr <<
"cannot cast event attribute " << rAttr.
ToString() <<
" for generator " << Name();
1303 throw Exception(
"TaGenerator::EventAttribute", errstr.str(), 63);
1305 pAlphabet->Attribute(index, *attrp);
1309 TEMP const EventAttr& THIS::EventAttribute(
Idx index)
const {
1310 return pAlphabet->Attribute(index);
1314 TEMP EventAttr* THIS::EventAttributep(
Idx index) {
1315 return pAlphabet->Attributep(index);
1319 TEMP const EventAttr& THIS::EventAttribute(
const std::string& rName)
const {
1320 return EventAttribute(EventIndex(rName));
1324 TEMP EventAttr* THIS::EventAttributep(
const std::string& rName) {
1325 return EventAttributep(EventIndex(rName));
1329 TEMP void THIS::StateAttribute(
Idx index,
const StateAttr& rAttr) {
1330 FD_DG(
"TaGenerator(" <<
this <<
")::StateAttribute("
1331 << index <<
",\"" << rAttr.ToString() <<
"\")");
1332 pStates->Attribute(index, rAttr);
1337 FD_DG(
"TaGenerator(" <<
this <<
")::StateAttribute("
1338 << SStr(index) <<
",\"" << rAttr.
ToString() <<
"\")");
1339 const StateAttr* attrp =
dynamic_cast<const StateAttr*
>(&rAttr);
1341 std::stringstream errstr;
1342 errstr <<
"cannot cast event attribute " << rAttr.
ToString() <<
" for generator " << Name();
1343 throw Exception(
"TaGenerator::StateAttribute", errstr.str(), 63);
1345 pStates->Attribute(index, *attrp);
1350 TEMP const StateAttr& THIS::StateAttribute(
Idx index)
const {
1351 return pStates->Attribute(index);
1355 TEMP StateAttr* THIS::StateAttributep(
Idx index) {
1356 return pStates->Attributep(index);
1370 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 indices with attributes.
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.
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)