6 #ifndef DIAG_GENERATOR_H
7 #define DIAG_GENERATOR_H
25 template <
class GlobalAttr,
class StateAttr,
class EventAttr,
class TransAttr>
85 FD_DG(
"TdiagGenerator(" <<
this <<
")::~TdiagGenerator()");
181 std::string
SAStr(
Idx dStateIndex)
const;
194 void DotWrite(
const std::string& rFileName)
const;
207 #ifdef FAUDES_COMPATIBILITY
227 #define THIS TdiagGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
228 #define BASE TcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
229 #define TEMP template<class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
234 FD_DG(
"TdiagGenerator(" <<
this <<
")::TdiagGenerator()");
236 BASE::mReindexOnWrite=
false;
241 FD_DG(
"TdiagGenerator(" <<
this <<
")::TdiagGenerator(rOtherGen)");
243 BASE::mReindexOnWrite=
false;
248 FD_DG(
"TdiagGenerator(" <<
this <<
")::TdiagGenerator(rOtherGen)");
250 BASE::mReindexOnWrite=
false;
254 TEMP THIS::TdiagGenerator(
const std::string& rFileName) :
BASE() {
255 FD_DG(
"TDiagGenerator(" <<
this <<
")::TdiagGenerator(rFilename) : done");
257 BASE::mReindexOnWrite=
false;
266 res->EventSymbolTablep(BASE::mpEventSymbolTable);
267 res->mStateNamesEnabled=BASE::mStateNamesEnabled;
268 res->mReindexOnWrite=BASE::mReindexOnWrite;
270 res->mpLabelSymbolTable=mpLabelSymbolTable;
284 TEMP Idx THIS::InsFailureTypeMapping(
const std::string& failureType,
const EventSet& rfailureEvents) {
285 return BASE::pGlobalAttribute->AddFailureTypeMapping(failureType, rfailureEvents);
289 TEMP void THIS::InsFailureTypeMap(
const std::map<std::string,EventSet>& rFailureMap) {
290 BASE::pGlobalAttribute->AddFailureTypeMap(rFailureMap);
296 return BASE::pGlobalAttribute->FailureType(failureEvent);
301 return BASE::pGlobalAttribute->AllFailureEvents();
305 TEMP void THIS::InsStateLabelMapping(
Idx dStateIndex,
Idx gStateIndex,
Idx labelIndex) {
306 BASE::StateAttributep(dStateIndex)->AddStateLabelMapping(gStateIndex, labelIndex);
312 BASE::StateAttributep(dStateIndex)->AddStateLabelMap(gState, labels);
318 BASE::StateAttribute(dStateIndex,newAttr);
322 TEMP std::string THIS::SAStr(
Idx dStateIndex)
const {
323 return BASE::StateAttribute(dStateIndex).Str();
327 TEMP void THIS::DotWrite(
const std::string& rFileName)
const {
328 FD_DG(
"TdiagGenerator(" <<
this <<
")::DotWrite(" << rFileName <<
")");
329 BASE::SetMinStateIndexMap();
330 StateSet::Iterator lit;
331 typename BASE::ATransSet::Iterator tit;
333 std::ofstream stream;
334 stream.exceptions(std::ios::badbit|std::ios::failbit);
335 stream.open(rFileName.c_str());
336 stream <<
"digraph \"" << BASE::Name() <<
"\" {" << std::endl;
337 stream <<
" rankdir=LR" << std::endl;
338 stream <<
" node [shape=box];" << std::endl;
340 stream <<
" // initial states" << std::endl;
342 for (lit = BASE::InitStatesBegin(); lit != BASE::InitStatesEnd(); ++lit) {
344 std::string xname = SAStr(*lit);
346 stream <<
" dot_dummyinit_" << i <<
" [shape=none, label=\"\" ];" << std::endl;
347 stream <<
" dot_dummyinit_" << i <<
" -> \"" << xname <<
"\";" << std::endl;
351 stream <<
" // marked states" << std::endl;
352 for (lit = BASE::MarkedStatesBegin(); lit != BASE::MarkedStatesEnd(); ++lit) {
354 std::string xname = SAStr(*lit);
356 stream <<
" \"" << xname <<
"\" [shape=doubleoctagon];" << std::endl;
359 stream <<
" // rest of stateset" << std::endl;
360 for (lit = BASE::StatesBegin(); lit != BASE::StatesEnd(); ++lit) {
361 if (! (BASE::ExistsInitState(*lit) || BASE::ExistsMarkedState(*lit)) ) {
363 std::string xname = SAStr(*lit);
365 stream <<
" \"" << xname <<
"\";" << std::endl;
370 stream <<
" // transition relation" << std::endl;
371 for (tit = BASE::TransRelBegin(); tit != BASE::TransRelEnd(); ++tit) {
373 std::string x1name = SAStr(tit->X1);
376 std::string x2name = SAStr(tit->X2);
378 stream <<
" \"" << x1name <<
"\" -> \"" << x2name
379 <<
"\" [label=\"" << BASE::EventName(tit->Ev) <<
"\"];" << std::endl;
381 stream <<
"};" << std::endl;
384 catch (std::ios::failure&) {
385 throw Exception(
"TdiagGenerator::DotWrite",
386 "Exception opening/writing dotfile \""+rFileName+
"\"", 2);
388 BASE::ClearMinStateIndexMap();