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()");
174 std::string
SAStr(
Idx dStateIndex)
const;
187 void DotWrite(
const std::string& rFileName)
const;
200 #ifdef FAUDES_COMPATIBILITY
220 #define THIS TdiagGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
221 #define BASE TcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
222 #define TEMP template<class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
227 FD_DG(
"TdiagGenerator(" <<
this <<
")::TdiagGenerator()");
229 BASE::mReindexOnWrite=
false;
234 FD_DG(
"TdiagGenerator(" <<
this <<
")::TdiagGenerator(rOtherGen)");
236 BASE::mReindexOnWrite=
false;
241 FD_DG(
"TdiagGenerator(" <<
this <<
")::TdiagGenerator(rOtherGen)");
243 BASE::mReindexOnWrite=
false;
247 TEMP THIS::TdiagGenerator(
const std::string& rFileName) :
BASE() {
248 FD_DG(
"TDiagGenerator(" <<
this <<
")::TdiagGenerator(rFilename) : done");
250 BASE::mReindexOnWrite=
false;
259 res->EventSymbolTablep(BASE::mpEventSymbolTable);
260 res->mStateNamesEnabled=BASE::mStateNamesEnabled;
261 res->mReindexOnWrite=BASE::mReindexOnWrite;
263 res->mpLabelSymbolTable=mpLabelSymbolTable;
277 TEMP Idx THIS::InsFailureTypeMapping(
const std::string& failureType,
const EventSet& rfailureEvents) {
278 return BASE::pGlobalAttribute->AddFailureTypeMapping(failureType, rfailureEvents);
282 TEMP void THIS::InsFailureTypeMap(
const std::map<std::string,EventSet>& rFailureMap) {
283 BASE::pGlobalAttribute->AddFailureTypeMap(rFailureMap);
289 return BASE::pGlobalAttribute->FailureType(failureEvent);
294 return BASE::pGlobalAttribute->AllFailureEvents();
298 TEMP void THIS::InsStateLabelMapping(
Idx dStateIndex,
Idx gStateIndex,
Idx labelIndex) {
299 BASE::StateAttributep(dStateIndex)->AddStateLabelMapping(gStateIndex, labelIndex);
305 BASE::StateAttributep(dStateIndex)->AddStateLabelMap(gState, labels);
311 BASE::StateAttribute(dStateIndex,newAttr);
315 TEMP std::string THIS::SAStr(
Idx dStateIndex)
const {
316 return BASE::StateAttribute(dStateIndex).Str();
320 TEMP void THIS::DotWrite(
const std::string& rFileName)
const {
321 FD_DG(
"TdiagGenerator(" <<
this <<
")::DotWrite(" << rFileName <<
")");
322 BASE::SetMinStateIndexMap();
323 StateSet::Iterator lit;
324 typename BASE::ATransSet::Iterator tit;
326 std::ofstream stream;
327 stream.exceptions(std::ios::badbit|std::ios::failbit);
328 stream.open(rFileName.c_str());
329 stream <<
"digraph \"" << BASE::Name() <<
"\" {" << std::endl;
330 stream <<
" rankdir=LR" << std::endl;
331 stream <<
" node [shape=box];" << std::endl;
333 stream <<
" // initial states" << std::endl;
335 for (lit = BASE::InitStatesBegin(); lit != BASE::InitStatesEnd(); ++lit) {
337 std::string xname = SAStr(*lit);
339 stream <<
" dot_dummyinit_" << i <<
" [shape=none, label=\"\" ];" << std::endl;
340 stream <<
" dot_dummyinit_" << i <<
" -> \"" << xname <<
"\";" << std::endl;
344 stream <<
" // marked states" << std::endl;
345 for (lit = BASE::MarkedStatesBegin(); lit != BASE::MarkedStatesEnd(); ++lit) {
347 std::string xname = SAStr(*lit);
349 stream <<
" \"" << xname <<
"\" [shape=doubleoctagon];" << std::endl;
352 stream <<
" // rest of stateset" << std::endl;
353 for (lit = BASE::StatesBegin(); lit != BASE::StatesEnd(); ++lit) {
354 if (! (BASE::ExistsInitState(*lit) || BASE::ExistsMarkedState(*lit)) ) {
356 std::string xname = SAStr(*lit);
358 stream <<
" \"" << xname <<
"\";" << std::endl;
363 stream <<
" // transition relation" << std::endl;
364 for (tit = BASE::TransRelBegin(); tit != BASE::TransRelEnd(); ++tit) {
366 std::string x1name = SAStr(tit->X1);
369 std::string x2name = SAStr(tit->X2);
371 stream <<
" \"" << x1name <<
"\" -> \"" << x2name
372 <<
"\" [label=\"" << BASE::EventName(tit->Ev) <<
"\"];" << std::endl;
374 stream <<
"};" << std::endl;
377 catch (std::ios::failure&) {
378 throw Exception(
"TdiagGenerator::DotWrite",
379 "Exception opening/writing dotfile \""+rFileName+
"\"", 2);
381 BASE::ClearMinStateIndexMap();