|
libFAUDES
Sections
Index
|
cfl_generator.cppGo to the documentation of this file.00001 /** @file cfl_generator.cpp Class vGenerator */ 00002 00003 /* FAU Discrete Event Systems Library (libfaudes) 00004 00005 Copyright (C) 2006 Bernd Opitz 00006 Copyright (C) 2007 Thomas Moor 00007 Exclusive copyright is granted to Klaus Schmidt 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNES FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 00022 00023 00024 #include "cfl_generator.h" 00025 00026 00027 namespace faudes { 00028 00029 // msObjectCount (static) 00030 Idx vGenerator::msObjectCount = 0; 00031 00032 // msObjectCount (static) 00033 bool vGenerator::msStateNamesEnabledDefault = true; 00034 00035 // static default prototypes (construct on first use design pattern) 00036 const EventSet& vGenerator::AlphabetVoid(void) { 00037 static EventSet* pstatic = new EventSet(); 00038 return *pstatic; 00039 } 00040 const StateSet& vGenerator::StatesVoid(void) { 00041 static StateSet* pstatic = new StateSet(); 00042 return *pstatic; 00043 } 00044 const TransSet& vGenerator::TransRelVoid(void) { 00045 static TransSet* pstatic = new TransSet(); 00046 return *pstatic; 00047 } 00048 const AttributeVoid& vGenerator::GlobalVoid(void) { 00049 static AttributeVoid* pstatic = new AttributeVoid(); 00050 return *pstatic; 00051 } 00052 00053 00054 00055 // constructor 00056 vGenerator::vGenerator(void) : 00057 // base 00058 Type(), 00059 // my name 00060 mMyName("Generator"), 00061 // have std symboltables 00062 mpStateSymbolTable(&mStateSymbolTable), 00063 mpEventSymbolTable(GlobalEventSymbolTablep()), 00064 // other members 00065 mStateNamesEnabled(msStateNamesEnabledDefault), 00066 // initialise heap members 00067 mpAlphabet(0), 00068 mpStates(0), 00069 mpTransRel(0), 00070 mpGlobalAttribute(0), 00071 // initialise prototypes 00072 pAlphabetPrototype(&AlphabetVoid()), 00073 pStatesPrototype(&StatesVoid()), 00074 pTransRelPrototype(&TransRelVoid()), 00075 pGlobalPrototype(&GlobalVoid()) 00076 { 00077 FAUDES_OBJCOUNT_INC("Generator"); 00078 FD_DG("vGenerator(" << this << ")::vGenerator()"); 00079 // track generator objects 00080 msObjectCount++; 00081 mId = msObjectCount; 00082 // allocate core members 00083 NewCore(); 00084 // fix std names 00085 mInitStates.Name("InitStates"); 00086 mMarkedStates.Name("MarkedStates"); 00087 } 00088 00089 // copy constructor 00090 vGenerator::vGenerator(const vGenerator& rOtherGen) : 00091 // my name 00092 mMyName("Generator"), 00093 // have std symboltables 00094 mpStateSymbolTable(&mStateSymbolTable), 00095 mpEventSymbolTable(GlobalEventSymbolTablep()), 00096 // other members 00097 mStateNamesEnabled(msStateNamesEnabledDefault), 00098 // initialise heap members 00099 mpAlphabet(0), 00100 mpStates(0), 00101 mpTransRel(0), 00102 mpGlobalAttribute(0), 00103 // initialise prototypes 00104 pAlphabetPrototype(&AlphabetVoid()), 00105 pStatesPrototype(&StatesVoid()), 00106 pTransRelPrototype(&TransRelVoid()), 00107 pGlobalPrototype(&GlobalVoid()) 00108 { 00109 FAUDES_OBJCOUNT_INC("Generator"); 00110 FD_DG("vGenerator(" << this << ")::vGenerator(" << &rOtherGen << ")"); 00111 // track generator objects 00112 msObjectCount++; 00113 mId = msObjectCount; 00114 // allocate core members 00115 NewCore(); 00116 // perform copy 00117 Assign(rOtherGen); 00118 } 00119 00120 // construct from file 00121 vGenerator::vGenerator(const std::string& rFileName) : 00122 // my name 00123 mMyName("Generator"), 00124 // have std symboltables 00125 mpStateSymbolTable(&mStateSymbolTable), 00126 mpEventSymbolTable(GlobalEventSymbolTablep()), 00127 // other members 00128 mStateNamesEnabled(msStateNamesEnabledDefault), 00129 // initialise heap members 00130 mpAlphabet(0), 00131 mpStates(0), 00132 mpTransRel(0), 00133 mpGlobalAttribute(0), 00134 // initialise prototypes 00135 pAlphabetPrototype(&AlphabetVoid()), 00136 pStatesPrototype(&StatesVoid()), 00137 pTransRelPrototype(&TransRelVoid()), 00138 pGlobalPrototype(&GlobalVoid()) 00139 { 00140 FAUDES_OBJCOUNT_INC("Generator"); 00141 FD_DG("vGenerator(" << this << ")::vGenerator(" << rFileName << ")"); 00142 // track generator objects 00143 msObjectCount++; 00144 mId = msObjectCount; 00145 // allocate core members 00146 NewCore(); 00147 // fix std names 00148 mInitStates.Name("InitStates"); 00149 mMarkedStates.Name("MarkedStates"); 00150 // set defaults for file io 00151 mStateNamesEnabled=true; 00152 // do read 00153 Read(rFileName,"Generator"); 00154 // restore defaults 00155 mStateNamesEnabled=msStateNamesEnabledDefault; 00156 } 00157 00158 // construct on heap 00159 vGenerator* vGenerator::New(void) const { 00160 FD_DG("vGenerator(" << this << ")::New()"); 00161 // allocate 00162 vGenerator* res = new vGenerator(); 00163 // fix configuration 00164 res->EventSymbolTablep(mpEventSymbolTable); 00165 res->mStateNamesEnabled=mStateNamesEnabled; 00166 return res; 00167 } 00168 00169 // construct on heap 00170 vGenerator* vGenerator::Copy(void) const { 00171 FD_DG("vGenerator(" << this << ")::Copy()"); 00172 // copy construct 00173 vGenerator* res = new vGenerator(*this); 00174 return res; 00175 } 00176 00177 // destruct 00178 vGenerator::~vGenerator(void) { 00179 FAUDES_OBJCOUNT_DEC("Generator"); 00180 // free my members 00181 DeleteCore(); 00182 } 00183 00184 // configure attribute types 00185 void vGenerator::ConfigureAttributeTypes(const AttributeVoid* pNewGlobalPrototype, 00186 const StateSet* pNewStatesPrototype, const EventSet* pNewAlphabetPrototype, 00187 const TransSet* pNewTransRelPrototype) { 00188 FD_DG("vGenerator(" << this << ")::ConfigureAtributes(..)"); 00189 pGlobalPrototype= pNewGlobalPrototype; 00190 pStatesPrototype= pNewStatesPrototype; 00191 pAlphabetPrototype= pNewAlphabetPrototype; 00192 pTransRelPrototype= pNewTransRelPrototype; 00193 FD_DG("vGenerator(" << this << ")::ConfigureAtributes(): done"); 00194 } 00195 00196 // indicate new core 00197 void vGenerator::UpdateCore(void) { 00198 // fix std names 00199 if(mpAlphabet) mpAlphabet->Name("Alphabet"); 00200 if(mpStates) mpStates->Name("States"); 00201 if(mpTransRel) mpTransRel->Name("TransRel"); 00202 // fix symbol table 00203 if(mpAlphabet) EventSymbolTablep(mpEventSymbolTable); 00204 } 00205 00206 // protected helper: allocate core on heap 00207 void vGenerator::NewCore(void) { 00208 DeleteCore(); 00209 // allocate (use prototypes, fallback to void attributes) 00210 if(pAlphabetPrototype) mpAlphabet= pAlphabetPrototype->New(); 00211 else mpAlphabet = new EventSet(); 00212 if(pStatesPrototype) mpStates=pStatesPrototype->New(); 00213 else mpStates = new StateSet(); 00214 if(pTransRelPrototype) mpTransRel= pTransRelPrototype->New(); 00215 else mpTransRel = new TransSet(); 00216 if(pGlobalPrototype) mpGlobalAttribute=pGlobalPrototype->New(); 00217 else mpGlobalAttribute = new AttributeVoid(); 00218 // update callback 00219 UpdateCore(); 00220 } 00221 00222 // protected helper: free core from heap 00223 void vGenerator::DeleteCore(void) { 00224 if(mpAlphabet) delete mpAlphabet; 00225 if(mpStates) delete mpStates; 00226 if(mpTransRel) delete mpTransRel; 00227 if(mpGlobalAttribute) delete mpGlobalAttribute; 00228 mpAlphabet=0; 00229 mpStates=0; 00230 mpTransRel=0; 00231 mpGlobalAttribute=0; 00232 // update callback 00233 UpdateCore(); 00234 } 00235 00236 00237 00238 // copy from other vGenerator (try to convert attributes) 00239 vGenerator& vGenerator::Assign(const vGenerator& rGen) { 00240 FD_DG("vGenerator(" << this << ")::Assign(" << &rGen << ")"); 00241 // prepare result (call clear for virtual stuff) 00242 Clear(); 00243 // have same event symboltable 00244 EventSymbolTablep(rGen.mpEventSymbolTable); 00245 // copy state symboltable 00246 StateSymbolTable(rGen.mStateSymbolTable); 00247 // set other members 00248 Name(rGen.Name()); 00249 StateNamesEnabled(rGen.StateNamesEnabled()); 00250 InjectInitStates(rGen.mInitStates); 00251 InjectMarkedStates(rGen.mMarkedStates); 00252 // core members, try attributes 00253 InjectStates(*rGen.mpStates); 00254 InjectAlphabet(*rGen.mpAlphabet); 00255 InjectTransRel(*rGen.mpTransRel); 00256 GlobalAttributeTry(*rGen.mpGlobalAttribute); 00257 #ifdef FAUDES_DEBUG_CODE 00258 if(!Valid()) { 00259 FD_DG("vGenerator()::Copy(): invalid generator"); 00260 DWrite(); 00261 abort(); 00262 } 00263 #endif 00264 return *this; 00265 } 00266 00267 // copy from other vGenerator (try to convert attributes) 00268 vGenerator& vGenerator::Assign(const Type& rSrc) { 00269 FD_DG("vGenerator(" << this << ")::Assign([type] " << &rSrc << ")"); 00270 Clear(); 00271 const vGenerator* vgen=dynamic_cast<const vGenerator*>(&rSrc); 00272 if(vgen) Assign(*vgen); 00273 return *this; 00274 } 00275 00276 // copy from other vGenerator (clear attributes) 00277 vGenerator& vGenerator::AssignWithoutAttributes(const vGenerator& rGen) { 00278 FD_DG("vGenerator(" << this << ")::Assign(" << &rGen << ")"); 00279 // prepare result (call clear for virtual stuff) 00280 Clear(); 00281 // have same event symboltable 00282 EventSymbolTablep(rGen.mpEventSymbolTable); 00283 // copy state symboltable 00284 StateSymbolTable(rGen.mStateSymbolTable); 00285 // set other members 00286 Name(rGen.Name()); 00287 StateNamesEnabled(rGen.StateNamesEnabled()); 00288 InjectInitStates(rGen.mInitStates); 00289 InjectMarkedStates(rGen.mMarkedStates); 00290 // core members, ignore attributes 00291 mpStates->AssignWithoutAttributes(rGen.States()); 00292 mpAlphabet->AssignWithoutAttributes(rGen.Alphabet()); 00293 mpTransRel->AssignWithoutAttributes(rGen.TransRel()); 00294 #ifdef FAUDES_DEBUG_CODE 00295 if(!Valid()) { 00296 FD_DG("vGenerator()::Copy(): invalid generator"); 00297 DWrite(); 00298 abort(); 00299 } 00300 #endif 00301 return *this; 00302 } 00303 00304 00305 // Move(gen) destructive copy 00306 void vGenerator::Move(vGenerator& rGen) { 00307 FD_DG("vGenerator(" << this << ")::Move(" << &rGen << ")"); 00308 // test types 00309 bool tmm=false; 00310 if(typeid(rGen.Alphabet())!=typeid(Alphabet())) tmm=true; 00311 if(typeid(rGen.States())!=typeid(States())) tmm=true; 00312 if(typeid(rGen.TransRel())!=typeid(TransRel())) tmm=true; 00313 if(typeid(rGen.GlobalAttribute())!=typeid(GlobalAttribute())) tmm=true; 00314 if(tmm) { 00315 FD_DG("vGenerator(" << this << ")::Move(" << &rGen << "): using std copy"); 00316 rGen.Assign(*this); 00317 Clear(); 00318 return; 00319 } 00320 // prepare result (call clear for virtual stuff) 00321 rGen.Clear(); 00322 // have same event symboltable 00323 rGen.EventSymbolTablep(mpEventSymbolTable); 00324 // copy state symboltable (todo: make this pointer based?) 00325 rGen.StateSymbolTable(mStateSymbolTable); 00326 // copy members 00327 rGen.Name(Name()); 00328 rGen.StateNamesEnabled(StateNamesEnabled()); 00329 rGen.InjectInitStates(InitStates()); 00330 rGen.InjectMarkedStates(MarkedStates()); 00331 // delete destination core 00332 if(rGen.mpStates) delete rGen.mpStates; 00333 if(rGen.mpAlphabet) delete rGen.mpAlphabet; 00334 if(rGen.mpTransRel) delete rGen.mpTransRel; 00335 if(rGen.mpGlobalAttribute) delete rGen.mpGlobalAttribute; 00336 // move and invalidate core members 00337 rGen.mpStates=mpStates; 00338 rGen.mpAlphabet=mpAlphabet; 00339 rGen.mpTransRel=mpTransRel; 00340 rGen.mpGlobalAttribute=mpGlobalAttribute; 00341 mpStates=0; 00342 mpAlphabet=0; 00343 mpTransRel=0; 00344 mpGlobalAttribute=0; 00345 // register core update 00346 rGen.UpdateCore(); 00347 // install new empty core members 00348 NewCore(); 00349 // clear myself (incl derived classes members) 00350 Clear(); 00351 } 00352 00353 // operator = 00354 vGenerator& vGenerator::operator = (const vGenerator& rOtherGen) { 00355 FD_DG("vGenerator(" << this << ")::operator = " << &rOtherGen); 00356 return Assign(rOtherGen); 00357 } 00358 00359 // Version(idx) 00360 void vGenerator::Version(Idx version, vGenerator& rResGen) const { 00361 FD_DG("vGenerator(" << this << ")::Version(" << version << ")"); 00362 std::ostringstream o; 00363 o << version; 00364 Version(o.str(),rResGen); 00365 } 00366 00367 // Version(string) 00368 void vGenerator::Version(const std::string& rVersion, vGenerator& rResGen) const { 00369 FD_DG("vGenerator(" << this << ")::Version(" << rVersion << ")"); 00370 // second arg must not be us 00371 if(this==&rResGen) { 00372 std::stringstream errstr; 00373 errstr << "Destination must not match source."; 00374 throw Exception("vGenerator::Version(string)", errstr.str(), 96); 00375 } 00376 // prepare Empty generator 00377 rResGen.Clear(); 00378 rResGen.GlobalAttribute(GlobalAttribute()); 00379 EventSet::Iterator eit; 00380 StateSet::Iterator lit; 00381 TransSet::Iterator tit; 00382 std::map<Idx,Idx> eventoldnewmap; 00383 rResGen.Name(Name()+"_"+rVersion); 00384 // create versioned mAlphabet 00385 for (eit = AlphabetBegin(); eit != AlphabetEnd(); ++eit) { 00386 Idx newevent= rResGen.InsEvent(EventName(*eit)+"_"+rVersion); 00387 eventoldnewmap[*eit] = newevent; 00388 rResGen.EventAttribute(newevent,EventAttribute(*eit)); 00389 } 00390 // create new stateset 00391 for (lit = StatesBegin(); lit != StatesEnd(); ++lit) { 00392 rResGen.InsState(*lit); 00393 rResGen.StateAttribute(*lit,StateAttribute(*lit)); //would be faster if directly copied ? 00394 if (StateName(*lit) != "") rResGen.StateName(*lit,StateName(*lit)); 00395 } 00396 // created versioned transrel 00397 for (tit = TransRelBegin(); tit != TransRelEnd(); ++tit) { 00398 Transition trans=Transition(tit->X1, eventoldnewmap[tit->Ev], tit->X2); 00399 rResGen.SetTransition(trans); 00400 rResGen.TransAttribute(trans, TransAttribute(*tit)); 00401 } 00402 // set i/m states 00403 rResGen.mInitStates=mInitStates; 00404 rResGen.mMarkedStates=mMarkedStates; 00405 // behavioural flags 00406 rResGen.mStateNamesEnabled = mStateNamesEnabled; 00407 } 00408 00409 00410 // Version(string,string) 00411 void vGenerator::Version(const std::string& rPattern, const std::string& rReplacement, vGenerator& rResGen) const { 00412 FD_DG("vGenerator(" << this << ")::Version(" << rPattern << ", " << rReplacement << ", ...)"); 00413 // second arg must not be us 00414 if(this==&rResGen) { 00415 std::stringstream errstr; 00416 errstr << "Destination must not match source."; 00417 throw Exception("vGenerator::Version(string,string)", errstr.str(), 96); 00418 } 00419 // ignore invalid pattern 00420 if(rPattern.empty()) { 00421 rResGen.Assign(*this); 00422 return; 00423 } 00424 // trivial case 00425 if (rPattern==rReplacement) { 00426 rResGen.Assign(*this); 00427 return; 00428 } 00429 // prepare Empty generator 00430 rResGen.Clear(); 00431 rResGen.GlobalAttribute(GlobalAttribute()); 00432 rResGen.Name(Name()+"_"+rReplacement); 00433 EventSet::Iterator eit; 00434 StateSet::Iterator lit; 00435 TransSet::Iterator tit; 00436 std::map<Idx,Idx> eventoldnewmap; 00437 // create versioned mAlphabet 00438 std::string newstring; 00439 std::string::size_type pos = 0; 00440 int patternlength=rPattern.size(); 00441 int replacementlength=rReplacement.size(); 00442 for (eit = AlphabetBegin(); eit != AlphabetEnd(); ++eit) { 00443 // search for all pattern occurences in event name and replace 00444 newstring=EventName(*eit); 00445 while ( (pos = newstring.find(rPattern, pos)) != std::string::npos ) { 00446 newstring.replace(pos, patternlength, rReplacement); 00447 //pos++; 00448 pos=pos+replacementlength; 00449 } 00450 Idx newevent= rResGen.InsEvent(newstring); 00451 eventoldnewmap[*eit] = newevent; 00452 rResGen.EventAttribute(newevent,EventAttribute(*eit)); 00453 } 00454 // create new stateset 00455 for (lit = StatesBegin(); lit != StatesEnd(); ++lit) { 00456 rResGen.InsState(*lit); 00457 rResGen.StateAttribute(*lit,StateAttribute(*lit)); //would be faster if directly copied ? 00458 if (StateName(*lit) != "") rResGen.StateName(*lit,StateName(*lit)); 00459 } 00460 // created versioned transrel 00461 for (tit = TransRelBegin(); tit != TransRelEnd(); ++tit) { 00462 Transition trans=Transition(tit->X1, eventoldnewmap[tit->Ev], tit->X2); 00463 rResGen.SetTransition(trans); 00464 rResGen.TransAttribute(trans, TransAttribute(*tit)); 00465 } 00466 // set i/m states 00467 rResGen.mInitStates=mInitStates; 00468 rResGen.mMarkedStates=mMarkedStates; 00469 // behavioural flags 00470 rResGen.mStateNamesEnabled = mStateNamesEnabled; 00471 } 00472 00473 00474 // Name(rName) 00475 void vGenerator::Name(const std::string& rName) { 00476 FD_DV("vGenerator(" << this << ")::Name(\"" << rName << "\")"); 00477 mMyName = rName; 00478 } 00479 00480 // Name() 00481 const std::string& vGenerator::Name(void) const { 00482 return mMyName; 00483 } 00484 00485 // Valid() 00486 bool vGenerator::Valid(void) { 00487 FD_DG("vGenerator(" << this << ")::Valid()"); 00488 // core members on heap 00489 if(mpAlphabet==0) return false; 00490 if(mpStates==0) return false; 00491 if(mpTransRel==0) return false; 00492 if(mpGlobalAttribute==0) return false; 00493 // transitions to be known 00494 TransSet::Iterator tit; 00495 StateSet::Iterator lit; 00496 for(tit = TransRelBegin(); tit != TransRelEnd(); ++tit) { 00497 if(! ExistsState(tit->X1)) return false; 00498 if(! ExistsEvent(tit->Ev)) return false; 00499 if(! ExistsState(tit->X2)) return false; 00500 } 00501 // init states to be known 00502 for(lit = InitStatesBegin(); lit != InitStatesEnd(); ++lit) 00503 if(! ExistsState(static_cast<Idx>(*lit))) return false; 00504 for(lit = MarkedStatesBegin(); lit != MarkedStatesEnd(); ++lit) 00505 if(! ExistsState(static_cast<Idx>(*lit))) return false; 00506 // sets to have proper names 00507 if(mpAlphabet->Name() != "Alphabet") return false; 00508 if(mpStates->Name() != "States") return false; 00509 if(mInitStates.Name() != "InitStates") return false; 00510 if(mMarkedStates.Name() != "MarkedStates") return false; 00511 // event symbol table 00512 NameSet::Iterator eit; 00513 for(eit = AlphabetBegin(); eit != AlphabetEnd(); eit ++) { 00514 if(EventName(*eit)=="") return false; 00515 } 00516 // done 00517 return true; 00518 } 00519 00520 // AlphabetSize() 00521 Idx vGenerator::AlphabetSize(void) const { 00522 return mpAlphabet->Size(); 00523 } 00524 00525 // Size() 00526 Idx vGenerator::Size(void) const { 00527 return mpStates->Size(); 00528 } 00529 00530 // Clear() 00531 void vGenerator::Clear(void) { 00532 FD_DG("vGenerator(" << this << ")::Clear()"); 00533 mpAlphabet->Clear(); 00534 mpStates->Clear(); 00535 mpStateSymbolTable->Clear(); 00536 mpTransRel->Clear(); 00537 mInitStates.Clear(); 00538 mMarkedStates.Clear(); 00539 ClearGlobalAttribute(); 00540 } 00541 00542 // ClearGlobalAttribute() 00543 void vGenerator::ClearGlobalAttribute(void) { 00544 mpGlobalAttribute->Clear(); 00545 } 00546 00547 // ClearStateAttributes() 00548 void vGenerator::ClearStateAttributes(void) { 00549 mpStates->ClearAttributes(); 00550 } 00551 00552 // ClearEventAttributes() 00553 void vGenerator::ClearEventAttributes(void) { 00554 mpAlphabet->ClearAttributes(); 00555 } 00556 00557 // ClearTransAttributes() 00558 void vGenerator::ClearTransAttributes(void) { 00559 mpTransRel->ClearAttributes(); 00560 } 00561 00562 // ClearAttributes() 00563 void vGenerator::ClearAttributes(void) { 00564 ClearGlobalAttribute(); 00565 ClearStateAttributes(); 00566 ClearEventAttributes(); 00567 ClearTransAttributes(); 00568 } 00569 00570 00571 // ClearStates() 00572 void vGenerator::ClearStates(void) { 00573 mpStates->Clear(); 00574 mpTransRel->Clear(); 00575 mInitStates.Clear(); 00576 mMarkedStates.Clear(); 00577 mpStateSymbolTable->Clear(); 00578 } 00579 00580 // TransRelSize() 00581 Idx vGenerator::TransRelSize(void) const { 00582 return mpTransRel->Size(); 00583 } 00584 00585 // InitStatesSize() 00586 Idx vGenerator::InitStatesSize(void) const { 00587 return mInitStates.Size(); 00588 } 00589 00590 // MarkedStatesSize() 00591 Idx vGenerator::MarkedStatesSize(void) const { 00592 return mMarkedStates.Size(); 00593 } 00594 00595 // AlphabetEmpty() 00596 bool vGenerator::AlphabetEmpty(void) const { 00597 return mpAlphabet->Empty(); 00598 } 00599 00600 // Empty() 00601 bool vGenerator::Empty(void) const { 00602 return mpStates->Empty(); 00603 } 00604 00605 // TransRelEmpty() 00606 bool vGenerator::TransRelEmpty(void) const { 00607 return mpTransRel->Empty(); 00608 } 00609 00610 // InitStatesEmpty() 00611 bool vGenerator::InitStatesEmpty(void) const { 00612 return mInitStates.Empty(); 00613 } 00614 00615 // MarkedStatesEmpty() 00616 bool vGenerator::MarkedStatesEmpty(void) const { 00617 return mMarkedStates.Empty(); 00618 } 00619 00620 00621 // ClearMinStateIndexMap() 00622 void vGenerator::ClearMinStateIndexMap(void) const { 00623 FD_DG("vGenerator::ClearMinStateIndexMap()"); 00624 // fake const 00625 vGenerator* fakeconst = const_cast<vGenerator*>(this); 00626 fakeconst->mMinStateIndexMap.clear(); 00627 } 00628 00629 // MinStateIndex(index) 00630 Idx vGenerator::MinStateIndex(Idx index) const { 00631 std::map<Idx,Idx>::const_iterator minit; 00632 minit = mMinStateIndexMap.find(index); 00633 Idx fidx; 00634 if(minit != mMinStateIndexMap.end()) { 00635 fidx= minit->second; 00636 } else { 00637 fidx=index; 00638 } 00639 return fidx; 00640 } 00641 00642 // MinStateIndex() 00643 const std::map<Idx,Idx>& vGenerator::MinStateIndexMap(void) const { 00644 return mMinStateIndexMap; 00645 } 00646 00647 00648 // SetMinStateIndexMap() 00649 void vGenerator::SetMinStateIndexMap(void) const { 00650 FD_DG("vGenerator::SetMinStateIndexMap()"); 00651 // fake const 00652 vGenerator* fakeconst = const_cast<vGenerator*>(this); 00653 // clear map 00654 fakeconst->ClearMinStateIndexMap(); 00655 StateSet::Iterator it; 00656 Idx minindex = 0; 00657 // if generator states get names 00658 if(StateNamesEnabled()) { 00659 // named initial states first 00660 for(it = InitStatesBegin(); it != InitStatesEnd(); ++it) { 00661 if(StateName(static_cast<Idx>(*it)) != "") { 00662 fakeconst->mMinStateIndexMap[*it] = ++minindex; 00663 } 00664 } 00665 // then all other named states 00666 for(it = StatesBegin(); it != StatesEnd(); ++it) { 00667 if(mMinStateIndexMap.count(*it) == 0) { 00668 if(StateName(static_cast<Idx>(*it)) != "") { 00669 fakeconst->mMinStateIndexMap[*it] = ++minindex; 00670 } 00671 } 00672 } 00673 // at last all anonymous states 00674 for(it = StatesBegin(); it != StatesEnd(); ++it) { 00675 if(mMinStateIndexMap.count(*it) == 0) { 00676 fakeconst->mMinStateIndexMap[*it] = ++minindex; 00677 } 00678 } 00679 } 00680 // if generator states are all anonymous 00681 else { 00682 // all initial states first 00683 for(it = InitStatesBegin(); it != InitStatesEnd(); ++it) { 00684 fakeconst->mMinStateIndexMap[*it] = ++minindex; 00685 } 00686 // then the rest 00687 for(it = StatesBegin(); it != StatesEnd(); ++it) { 00688 if(mMinStateIndexMap.count(*it) == 0) { 00689 fakeconst->mMinStateIndexMap[*it] = ++minindex; 00690 } 00691 } 00692 } 00693 #ifdef FAUDES_DEBUG_CONTAINER 00694 std::map<Idx,Idx>::const_iterator _it; 00695 for(_it = mMinStateIndexMap.begin(); _it != mMinStateIndexMap.end(); ++_it) { 00696 FD_DC("vGenerator::MinStateIndexMap: " << _it->first 00697 << " <-- " << SStr(_it->second)); 00698 } 00699 #endif 00700 } 00701 00702 // EventSymbolTablep() const 00703 SymbolTable* vGenerator::EventSymbolTablep(void) const { 00704 return mpEventSymbolTable; 00705 } 00706 00707 // GlobalEventSymbolTablep() const 00708 SymbolTable* vGenerator::GlobalEventSymbolTablep(void) { 00709 return SymbolTable::GlobalEventSymbolTablep(); 00710 } 00711 00712 // EventSymbolTablep(pSymTab) 00713 void vGenerator::EventSymbolTablep(SymbolTable* pSymTab) { 00714 mpEventSymbolTable=pSymTab; 00715 // todo: set symboltable in mpAlphabet 00716 } 00717 00718 // EventSymbolTablep(rOtherGen) 00719 void vGenerator::EventSymbolTablep(const vGenerator& rOtherGen) { 00720 EventSymbolTablep(rOtherGen.EventSymbolTablep()); 00721 } 00722 00723 // EventIndex(rName) 00724 Idx vGenerator::EventIndex(const std::string& rName) const { 00725 return mpEventSymbolTable->Index(rName); 00726 } 00727 00728 // EventName(index) 00729 std::string vGenerator::EventName(Idx index) const { 00730 return mpEventSymbolTable->Symbol(index); 00731 } 00732 00733 // EventName(index, name) 00734 void vGenerator::EventName(Idx index, const std::string& rName) { 00735 FD_DG("vGenerator(" << this << ")::EventName(" 00736 << index << ",\"" << rName << "\")"); 00737 #ifdef FAUDES_CHECKED 00738 if (! ExistsEvent(index)) { 00739 std::stringstream errstr; 00740 errstr << "event \"" << index << "\" not found in generator \"" 00741 << Name() << "\""; 00742 throw Exception("vGenerator::EventName(name)", errstr.str(), 89); 00743 } 00744 #endif 00745 mpEventSymbolTable->SetEntry(index, rName); 00746 } 00747 00748 // UniqueEventName(rName) 00749 std::string vGenerator::UniqueEventName(const std::string& rName) const { 00750 std::string name=rName; 00751 if(name=="") name="ev"; 00752 return mpEventSymbolTable->UniqueSymbol(name) ; 00753 } 00754 00755 00756 // EventRename 00757 bool vGenerator::EventRename(Idx event, const std::string& rNewName) { 00758 // consistency 00759 FD_DG("vGenerator(" << this << ")::EventRename(" << EStr(event) << ", " << rNewName << ")"); 00760 #ifdef FAUDES_CHECKED 00761 if (! ExistsEvent(event)) { 00762 std::stringstream errstr; 00763 errstr << "event \"" << event << "\" not found in generator \"" 00764 << Name() << "\""; 00765 throw Exception("vGenerator::EventReame(name)", errstr.str(), 89); 00766 } 00767 #endif 00768 // prepare formal result 00769 bool res=ExistsEvent(rNewName); 00770 // insert new event 00771 Idx newidx=InsEvent(rNewName); 00772 // bail out if events are the same 00773 if(newidx==event) return true; 00774 // copy event attribute 00775 if(!res) EventAttribute(newidx,EventAttribute(event)); 00776 // store new transitions (with their attributes) 00777 TransSet* newtrans= TransRel().New(); 00778 // iterate over transitions 00779 TransSet::Iterator tit; 00780 for (tit = TransRelBegin(); tit != TransRelEnd(); ++tit) { 00781 if(tit->Ev!=event) continue; 00782 Transition trans= Transition(tit->X1, newidx, tit->X2); 00783 newtrans->Insert(trans); 00784 newtrans->Attribute(trans,TransAttribute(*tit)); 00785 tit=ClrTransition(tit); 00786 } 00787 // merge transitions 00788 for(tit=newtrans->Begin(); tit!=newtrans->End(); tit++) { 00789 SetTransition(*tit); 00790 TransAttribute(*tit,newtrans->Attribute(*tit)); 00791 } 00792 // free temp 00793 delete newtrans; 00794 // remore original event 00795 DelEvent(event); 00796 // done 00797 return res; 00798 } 00799 00800 00801 00802 // NewEventSet() 00803 EventSet vGenerator::NewEventSet(void) const { 00804 EventSet res; 00805 res.SymbolTablep(mpEventSymbolTable); 00806 return res; 00807 } 00808 00809 // NewEventSetp() 00810 EventSet* vGenerator::NewEventSetp(void) const { 00811 EventSet* res = new EventSet(); 00812 res->SymbolTablep(mpEventSymbolTable); 00813 return res; 00814 } 00815 00816 00817 // StateSymbolTable() const 00818 const SymbolTable& vGenerator::StateSymbolTable(void) const { 00819 return mStateSymbolTable; 00820 } 00821 00822 // StateSymbolTable(rSymTab) 00823 void vGenerator::StateSymbolTable(const SymbolTable& rSymTab) { 00824 mStateSymbolTable=rSymTab; 00825 mpStateSymbolTable=&mStateSymbolTable; 00826 } 00827 00828 // StateIndex(rName) 00829 Idx vGenerator::StateIndex(const std::string& rName) const { 00830 return mpStateSymbolTable->Index(rName); 00831 } 00832 00833 // StateName(index) 00834 std::string vGenerator::StateName(Idx index) const { 00835 return mpStateSymbolTable->Symbol(index); 00836 } 00837 00838 // StateName(index, name) 00839 void vGenerator::StateName(Idx index, const std::string& rName) { 00840 FD_DG("vGenerator(" << this << ")::StateName(" 00841 << index << ",\"" << rName << "\")"); 00842 #ifdef FAUDES_CHECKED 00843 if (! ExistsState(index)) { 00844 std::stringstream errstr; 00845 errstr << "state name \"" << rName << "\" not found in generator \"" 00846 << Name() << "\""; 00847 throw Exception("vGenerator::StateName(name)", errstr.str(), 90); 00848 } 00849 #endif 00850 mpStateSymbolTable->SetEntry(index, rName); 00851 } 00852 00853 00854 // ClearStateNames() 00855 void vGenerator::ClearStateNames(void) { 00856 FD_DG("vGenerator(" << this << ")::ClearStateNames()"); 00857 mpStateSymbolTable->Clear(); 00858 mStateNamesEnabled = false; 00859 } 00860 00861 00862 // ClrStateName(index) 00863 void vGenerator::ClrStateName(Idx index) { 00864 FD_DG("Generator(" << this << ")::ClrStateName(\"" << index << "\")"); 00865 #ifdef FAUDES_CHECKED 00866 if (! ExistsState(index)) { 00867 std::stringstream errstr; 00868 errstr << "state \"" << index << "\" not found in generator \"" 00869 << Name() << "\""; 00870 throw Exception("vGenerator::ClrStateName(name)", errstr.str(), 90); 00871 } 00872 #endif 00873 mpStateSymbolTable->ClrEntry(index); 00874 } 00875 00876 // ClrStateName(rName) 00877 void vGenerator::ClrStateName(const std::string& rName) { 00878 FD_DG("vGenerator(" << this << ")::ClrStateName(\"" << rName << "\")"); 00879 Idx index = StateIndex(rName); 00880 ClrStateName(index); 00881 } 00882 00883 00884 // StateNamesEnabled() 00885 bool vGenerator::StateNamesEnabled(void) const { 00886 return mStateNamesEnabled; 00887 } 00888 00889 // StateNamesEnabled(flag) 00890 void vGenerator::StateNamesEnabled(bool flag) { 00891 mStateNamesEnabled = flag; 00892 } 00893 00894 // StateNamesEnabled(flag) 00895 void vGenerator::StateNamesEnabledDefault(bool flag) { 00896 msStateNamesEnabledDefault = flag; 00897 } 00898 00899 // SetDefaultStateNames() 00900 void vGenerator::SetDefaultStateNames(void) { 00901 FD_DG("vGenerator(" << this << ")::SetDefaultStateNames()"); 00902 StateSet::Iterator it; 00903 for (it = StatesBegin(); it != StatesEnd(); ++it) { 00904 mpStateSymbolTable->SetDefaultSymbol(*it); 00905 } 00906 } 00907 00908 // EnforceStateNames(rTemplate) 00909 void vGenerator::EnforceStateNames(const std::string& rTemplate) { 00910 FD_DG("vGenerator(" << this << ")::EnforceStateNames(temp)"); 00911 StateSet::Iterator it; 00912 for (it = StatesBegin(); it != StatesEnd(); ++it) { 00913 if(StateName(*it)=="") { 00914 std::string name=UniqueStateName(rTemplate + "_1"); 00915 StateName(*it,name); 00916 } 00917 } 00918 } 00919 00920 // UniqueStateName(rName) 00921 std::string vGenerator::UniqueStateName(const std::string& rName) const { 00922 std::string name=rName; 00923 if(name=="") name="st"; 00924 return mpStateSymbolTable->UniqueSymbol(name) ; 00925 } 00926 00927 00928 // iterator AlphabetBegin() const 00929 EventSet::Iterator vGenerator::AlphabetBegin(void) const { 00930 return mpAlphabet->Begin(); 00931 } 00932 00933 // iterator AlphabetEnd() const 00934 EventSet::Iterator vGenerator::AlphabetEnd(void) const { 00935 return mpAlphabet->End(); 00936 } 00937 00938 // iterator StatesBegin() const 00939 StateSet::Iterator vGenerator::StatesBegin(void) const { 00940 return mpStates->Begin(); 00941 } 00942 00943 // iterator StatesEnd() const 00944 StateSet::Iterator vGenerator::StatesEnd(void) const { 00945 return mpStates->End(); 00946 } 00947 00948 // iterator TransRelBegin() const 00949 TransSet::Iterator vGenerator::TransRelBegin(void) const { 00950 return mpTransRel->Begin(); 00951 } 00952 00953 // iterator TransRelEnd() const 00954 TransSet::Iterator vGenerator::TransRelEnd(void) const { 00955 return mpTransRel->End(); 00956 } 00957 00958 // iterator TransRelBegin(x1) const 00959 TransSet::Iterator vGenerator::TransRelBegin(Idx x1) const { 00960 return mpTransRel->Begin(x1); 00961 } 00962 00963 // iterator TransRelEnd(x1) const 00964 TransSet::Iterator vGenerator::TransRelEnd(Idx x1) const { 00965 return mpTransRel->End(x1); 00966 } 00967 00968 // iterator TransRelBegin(x1, ev) const 00969 TransSet::Iterator vGenerator::TransRelBegin(Idx x1, Idx ev) const { 00970 return mpTransRel->Begin(x1, ev); 00971 } 00972 00973 // iterator TransRelEnd(x1, ev) const 00974 TransSet::Iterator vGenerator::TransRelEnd(Idx x1, Idx ev) const { 00975 return mpTransRel->End(x1, ev); 00976 } 00977 00978 // iterator FindTransition(trans) 00979 TransSet::Iterator vGenerator::FindTransition(const Transition& rTrans) const { 00980 return mpTransRel->Find(rTrans); 00981 } 00982 00983 // iterator FindTransition(x1, ex x2) 00984 TransSet::Iterator vGenerator::FindTransition(Idx x1, Idx ev, Idx x2) const { 00985 return mpTransRel->Find(Transition(x1, ev, x2)); 00986 } 00987 00988 // iterator FindTransition(x1, ev, x2) 00989 TransSet::Iterator vGenerator::FindTransition( 00990 const std::string& rX1, const std::string& rEv, const std::string& rX2) const 00991 { 00992 return mpTransRel->Find(StateIndex(rX1), EventIndex(rEv), StateIndex(rX2)); 00993 } 00994 00995 // iterator ExistsTransition(trans) 00996 bool vGenerator::ExistsTransition(const Transition& rTrans) const { 00997 return mpTransRel->Exists(rTrans); 00998 } 00999 01000 // iterator ExistsTransition(x1, ex x2) 01001 bool vGenerator::ExistsTransition(Idx x1, Idx ev, Idx x2) const { 01002 return mpTransRel->Exists(Transition(x1, ev, x2)); 01003 } 01004 01005 // iterator ExistsTransition(x1, ev, x2) 01006 bool vGenerator::ExistsTransition( 01007 const std::string& rX1, const std::string& rEv, const std::string& rX2) const 01008 { 01009 return mpTransRel->Exists(StateIndex(rX1), EventIndex(rEv), StateIndex(rX2)); 01010 } 01011 01012 01013 // idx InitState() const 01014 Idx vGenerator::InitState(void) const { 01015 #ifdef FAUDES_CHECKED 01016 if(mInitStates.Size()!=1) { 01017 std::stringstream errstr; 01018 errstr << "init state does not exist uniquely" << std::endl; 01019 throw Exception("vGenerator::InitSTate", errstr.str(), 92); 01020 } 01021 #endif 01022 return *mInitStates.Begin(); 01023 } 01024 01025 // iterator InitStatesBegin() const 01026 StateSet::Iterator vGenerator::InitStatesBegin(void) const { 01027 return mInitStates.Begin(); 01028 } 01029 01030 // iterator InitStatesEnd() const 01031 StateSet::Iterator vGenerator::InitStatesEnd(void) const { 01032 return mInitStates.End(); 01033 } 01034 01035 // iterator MarkedStatesBegin() 01036 StateSet::Iterator vGenerator::MarkedStatesBegin(void) const { 01037 return mMarkedStates.Begin(); 01038 } 01039 01040 // iterator MarkedStatesEnd() const 01041 StateSet::Iterator vGenerator::MarkedStatesEnd(void) const { 01042 return mMarkedStates.End(); 01043 } 01044 01045 // InjectAlphabet(newalphabet) 01046 void vGenerator::InjectAlphabet(const EventSet& rNewAlphabet) { 01047 FD_DG("vGenerator::InjectAlphabet() " << rNewAlphabet.ToString()); 01048 #ifdef FAUDES_CHECKED 01049 if(rNewAlphabet.SymbolTablep()!=mpEventSymbolTable) { 01050 std::stringstream errstr; 01051 errstr << "symboltable mismatch aka not implemented" << std::endl; 01052 throw Exception("vGenerator::InjectAlphabet", errstr.str(), 88); 01053 } 01054 #endif 01055 *mpAlphabet = rNewAlphabet; 01056 mpAlphabet->Name("Alphabet"); 01057 } 01058 01059 // RestrictAlphabet(newalphabet) 01060 void vGenerator::RestrictAlphabet(const EventSet& rNewAlphabet) { 01061 FD_DG("vGenerator::RestrictAlphabet() " << rNewAlphabet.ToString()); 01062 #ifdef FAUDES_CHECKED 01063 if(rNewAlphabet.SymbolTablep()!=mpEventSymbolTable) { 01064 std::stringstream errstr; 01065 errstr << "symboltable mismatch aka not implemented" << std::endl; 01066 throw Exception("vGenerator::RestrictAlphabet", errstr.str(), 88); 01067 } 01068 #endif 01069 mpAlphabet->RestrictSet(rNewAlphabet); 01070 } 01071 01072 // InsEvent(index) 01073 bool vGenerator::InsEvent(Idx index) { 01074 FD_DG("vGenerator(" << this << ")::InsEvent(" << index << ")"); 01075 return mpAlphabet->Insert(index); 01076 } 01077 01078 // InsEvent(rName) 01079 Idx vGenerator::InsEvent(const std::string& rName) { 01080 FD_DG("vGenerator(" << this << ")::InsEvent(\"" << rName << "\")"); 01081 return mpAlphabet->Insert(rName); 01082 } 01083 01084 // InsEvents(events) 01085 void vGenerator::InsEvents(const EventSet& events) { 01086 mpAlphabet->InsertSet(events); 01087 } 01088 01089 // DelEvent(index) 01090 bool vGenerator::DelEvent(Idx index) { 01091 FD_DG("vGenerator(" << this << ")::DelEvent(" << index << ")"); 01092 mpTransRel->EraseByEv(index); 01093 return mpAlphabet->Erase(index); 01094 } 01095 01096 // DelEvent(rName) 01097 bool vGenerator::DelEvent(const std::string& rName) { 01098 FD_DG("vGenerator(" << this << ")::DelEvent(\"" << rName << "\")"); 01099 Idx index = mpAlphabet->Index(rName); 01100 mpTransRel->EraseByEv(index); 01101 return mpAlphabet->Erase(index); 01102 } 01103 01104 // DelEvents(events) 01105 void vGenerator::DelEvents(const EventSet& rEvents) { 01106 FD_DG("vGenerator(" << this << ")::DelEvents(\"" 01107 << rEvents.ToString() << "\")"); 01108 EventSet::Iterator it; 01109 for (it = rEvents.Begin(); it != rEvents.End(); ++it) { 01110 DelEvent(*it); 01111 } 01112 } 01113 01114 // DelEventFromAlphabet(index) 01115 bool vGenerator::DelEventFromAlphabet(Idx index) { 01116 FD_DG("vGenerator(" << this << ")::DelEventFromAlphabet(" 01117 << index << ")"); 01118 return mpAlphabet->Erase(index); 01119 } 01120 01121 // InsState() 01122 Idx vGenerator::InsState(void) { 01123 FD_DG("vGenerator(" << this << ")::InsState()"); 01124 return mpStates->Insert(); 01125 } 01126 01127 // InsState(index) 01128 bool vGenerator::InsState(Idx index) { 01129 FD_DG("vGenerator(" << this << ")::InsState(" << index << ")"); 01130 return mpStates->Insert(index); 01131 } 01132 01133 // InsState(rName) 01134 Idx vGenerator::InsState(const std::string& rName) { 01135 FD_DG("vGenerator(" << this << ")::InsState(\"" << rName << "\")"); 01136 Idx index=mpStates->Insert(); 01137 StateName(index,rName); 01138 return index; 01139 } 01140 01141 // InjectState(index) 01142 void vGenerator::InjectState(Idx index) { 01143 FD_DG("vGenerator(" << this << ")::InjectState(\"" << SStr(index) << "\")"); 01144 mpStates->Insert(index); 01145 } 01146 01147 // InjectStates(rNewStates) 01148 void vGenerator::InjectStates(const StateSet& rNewStates) { 01149 FD_DG("vGenerator(" << this << ")::InjectStates(" << rNewStates.ToString() << ")"); 01150 *mpStates=rNewStates; 01151 mpStates->Name("States"); 01152 mpStateSymbolTable->RestrictDomain(*mpStates); 01153 FD_DG("vGenerator(" << this << ")::InjectStates(): report " << mpStates->ToString()); 01154 } 01155 01156 // InsInitState() 01157 Idx vGenerator::InsInitState(void) { 01158 FD_DG("vGenerator(" << this << ")::InsInitState()"); 01159 Idx index; 01160 index = InsState(); 01161 mInitStates.Insert(index); 01162 return index; 01163 } 01164 01165 // InsInitState(name) 01166 Idx vGenerator::InsInitState(const std::string& rName) { 01167 FD_DG("vGenerator(" << this << ")::InsInitState(\"" << rName << "\")"); 01168 Idx index; 01169 index = InsState(rName); 01170 mInitStates.Insert(index); 01171 return index; 01172 } 01173 01174 // InsInitState(name) 01175 bool vGenerator::InsInitState(Idx index) { 01176 bool res=InsState(index); 01177 mInitStates.Insert(index); 01178 return res; 01179 } 01180 01181 // InsMarkedState() 01182 Idx vGenerator::InsMarkedState(void) { 01183 FD_DG("vGenerator(" << this << ")::InsMarkedState()"); 01184 Idx index; 01185 index = InsState(); 01186 mMarkedStates.Insert(index); 01187 return index; 01188 } 01189 01190 // InsInitState(name) 01191 bool vGenerator::InsMarkedState(Idx index) { 01192 bool res=InsState(index); 01193 mMarkedStates.Insert(index); 01194 return res; 01195 } 01196 01197 // InsMarkedState(rName) 01198 Idx vGenerator::InsMarkedState(const std::string& rName) { 01199 FD_DG("vGenerator(" << this << ")::InsMarkedState(\"" << rName << "\")"); 01200 Idx index; 01201 index = InsState(rName); 01202 mMarkedStates.Insert(index); 01203 return index; 01204 } 01205 01206 // DelState(index) 01207 bool vGenerator::DelState(Idx index) { 01208 FD_DG("vGenerator(" << this << ")::DelState(" << index << ")"); 01209 // mInitStates 01210 mInitStates.Erase(index); 01211 // mstates 01212 mMarkedStates.Erase(index); 01213 // transrel 01214 mpTransRel->EraseByX1OrX2(index); 01215 // symbolic name 01216 mpStateSymbolTable->ClrEntry(index); 01217 // finally ... remove the state 01218 return mpStates->Erase(index); 01219 } 01220 01221 // DelState(rName) 01222 bool vGenerator::DelState(const std::string& rName) { 01223 FD_DG("vGenerator(" << this << ")::DelState(\"" << rName << "\")"); 01224 Idx index; 01225 index = StateIndex(rName); 01226 #ifdef FAUDES_CHECKED 01227 if (index == 0) { 01228 std::stringstream errstr; 01229 errstr << "state name \"" << rName << "\" not found in generator \"" 01230 << Name() << "\""; 01231 throw Exception("vGenerator::DelState(name)", errstr.str(), 90); 01232 } 01233 #endif 01234 return DelState(index); 01235 } 01236 01237 // DelStates(rDelStates) 01238 void vGenerator::DelStates(const StateSet& rDelStates) { 01239 FD_DG("vGenerator(" << this << ")::DelStates(" 01240 << rDelStates.ToString() << ")"); 01241 StateSet::Iterator cit; 01242 StateSet::Iterator cit_end; 01243 // symbolic state names 01244 if (StateNamesEnabled()) { 01245 for (cit = rDelStates.Begin(); cit != rDelStates.End(); ++cit) { 01246 mpStateSymbolTable->ClrEntry(*cit); 01247 } 01248 } 01249 // statesets 01250 mpStates->EraseSet(rDelStates); 01251 mInitStates.EraseSet(rDelStates); 01252 mMarkedStates.EraseSet(rDelStates); 01253 // mpTransRel: 01254 mpTransRel->EraseByX1OrX2(rDelStates); 01255 // original (slow) 01256 //for (cit = rDelStates.Begin(); cit != rDelStates.End(); ++cit) { 01257 // mpTransRel->EraseByX1OrX2(*cit); 01258 //} 01259 } 01260 01261 // DelStateFromStates(index) 01262 bool vGenerator::DelStateFromStates(Idx index) { 01263 FD_DG("vGenerator(" << this << ")::DelStateFromStates(" << index << ")"); 01264 // mStates + global 01265 return mpStates->Erase(index); 01266 } 01267 01268 // DelStateFromStates(pos) 01269 StateSet::Iterator vGenerator::DelStateFromStates(StateSet::Iterator pos) { 01270 FD_DG("vGenerator(" << this << ")::DelState(" << *pos << ")"); 01271 return mpStates->Erase(pos); 01272 } 01273 01274 // SetInitState(index) 01275 void vGenerator::SetInitState(Idx index) { 01276 FD_DG("vGenerator(" << this << ")::SetInitState(" << index << ")"); 01277 #ifdef FAUDES_CHECKED 01278 if (! mpStates->Exists(index)) { 01279 std::stringstream errstr; 01280 errstr << "vGenerator::SetMarkedState: index " << index 01281 << " not in stateset"; 01282 throw Exception("vGenerator::SetInitState(..)", errstr.str(), 91); 01283 } 01284 #endif 01285 mInitStates.Insert(index); 01286 } 01287 01288 // SetInitState(rName) 01289 void vGenerator::SetInitState(const std::string& rName) { 01290 FD_DG("vGenerator(" << this << ")::SetInitState(\"" << rName << "\")"); 01291 Idx index = StateIndex(rName); 01292 #ifdef FAUDES_CHECKED 01293 if (index == 0) { 01294 std::stringstream errstr; 01295 errstr << "State name \"" << rName << "\" not known in Generator"; 01296 throw Exception("vGenerator::SetInitState(..)", errstr.str(), 90); 01297 } 01298 #endif 01299 SetInitState(index); 01300 } 01301 01302 // InjectInitStates(rNewInitStates) 01303 void vGenerator::InjectInitStates(const StateSet& rNewInitStates) { 01304 FD_DG("vGenerator(" << this << ")::InjectInitStates(" 01305 << rNewInitStates.ToString() << ")"); 01306 mInitStates = rNewInitStates; 01307 mInitStates.Name("InitStates"); 01308 } 01309 01310 // ClrInitState(index) 01311 void vGenerator::ClrInitState(Idx index) { 01312 FD_DG("vGenerator(" << this << ")::ClrInitState(" << index << ")"); 01313 #ifdef FAUDES_CHECKED 01314 if (! mpStates->Exists(index)) { 01315 std::stringstream errstr; 01316 errstr << "vGenerator::SetMarkedState: index " << index 01317 << " not in stateset"; 01318 throw Exception("vGenerator::ClrInitState(..)", errstr.str(), 91); 01319 } 01320 #endif 01321 mInitStates.Erase(index); 01322 } 01323 01324 // ClrInitState(rName) 01325 void vGenerator::ClrInitState(const std::string& rName) { 01326 FD_DG("vGenerator(" << this << ")::ClrInitState(\"" << rName << "\")"); 01327 Idx index = StateIndex(rName); 01328 #ifdef FAUDES_CHECKED 01329 if (index == 0) { 01330 std::stringstream errstr; 01331 errstr << "State name \"" << rName << "\" not known in Generator"; 01332 throw Exception("vGenerator::ClrInitState(..)", errstr.str(), 90); 01333 } 01334 #endif 01335 ClrInitState(index); 01336 } 01337 01338 // ClrInitState(pos) 01339 StateSet::Iterator vGenerator::ClrInitState(StateSet::Iterator pos) { 01340 FD_DG("vGenerator(" << this << ")::ClrInitState(" << *pos << ")"); 01341 return mInitStates.Erase(pos); 01342 } 01343 01344 // ClearInitStates() 01345 void vGenerator::ClearInitStates(void) { 01346 mInitStates.Clear(); 01347 } 01348 01349 // SetMarkedState(index) 01350 void vGenerator::SetMarkedState(Idx index) { 01351 FD_DG("vGenerator(" << this << ")::SetMarkedState(" << index << ")"); 01352 #ifdef FAUDES_CHECKED 01353 if (! mpStates->Exists(index)) { 01354 std::stringstream errstr; 01355 errstr << "vGenerator::SetMarkedState: index " << index 01356 << " not in stateset"; 01357 throw Exception("vGenerator::SetMarkedState(..)", errstr.str(), 91); 01358 } 01359 #endif 01360 mMarkedStates.Insert(index); 01361 } 01362 01363 // SetMarkedState(rName) 01364 void vGenerator::SetMarkedState(const std::string& rName) { 01365 FD_DG("vGenerator(" << this << ")::SetMarkedState(\"" << rName << "\")"); 01366 Idx index = StateIndex(rName); 01367 #ifdef FAUDES_CHECKED 01368 if (index == 0) { 01369 std::stringstream errstr; 01370 errstr << "State name \"" << rName << "\" not known in Generator"; 01371 throw Exception("vGenerator::SetMarkedState(..)", errstr.str(), 90); 01372 } 01373 #endif 01374 SetMarkedState(index); 01375 } 01376 01377 // InjectMarkedStates(rNewMarkedStates) 01378 void vGenerator::InjectMarkedStates(const StateSet& rNewMarkedStates) { 01379 FD_DG("vGenerator(" << this << ")::InjectMarkedStates(" 01380 << rNewMarkedStates.ToString() << ")"); 01381 mMarkedStates = rNewMarkedStates; 01382 mMarkedStates.Name("MarkedStates"); 01383 } 01384 01385 // ClrMarkedState(index) 01386 void vGenerator::ClrMarkedState(Idx index) { 01387 FD_DG("vGenerator(" << this << ")::ClrMarkedState(" << index << ")"); 01388 #ifdef FAUDES_CHECKED 01389 if (! mpStates->Exists(index)) { 01390 std::stringstream errstr; 01391 errstr << "vGenerator::ClrMarkedState: index " << index 01392 << " not in stateset"; 01393 throw Exception("vGenerator::ClrMarkedState(..)", errstr.str(), 91); 01394 } 01395 #endif 01396 mMarkedStates.Erase(index); 01397 } 01398 01399 // ClrMarkedState(rName) 01400 void vGenerator::ClrMarkedState(const std::string& rName) { 01401 FD_DG("vGenerator(" << this << ")::ClrMarkedState(\"" << rName << "\")"); 01402 Idx index = StateIndex(rName); 01403 #ifdef FAUDES_CHECKED 01404 if (index == 0) { 01405 std::stringstream errstr; 01406 errstr << "State name \"" << rName << "\" not known in Generator"; 01407 throw Exception("vGenerator::ClrMarkedState(..)", errstr.str(), 90); 01408 } 01409 #endif 01410 ClrMarkedState(index); 01411 } 01412 01413 // ClrMarkedState(pos) 01414 StateSet::Iterator vGenerator::ClrMarkedState(StateSet::Iterator pos) { 01415 FD_DG("vGenerator(" << this << ")::ClrMarkedState(" << *pos << ")"); 01416 return mMarkedStates.Erase(pos); 01417 } 01418 01419 // ClearMarkedStates() 01420 void vGenerator::ClearMarkedStates(void) { 01421 mMarkedStates.Clear(); 01422 } 01423 01424 // InjectTransition(newtrans) 01425 void vGenerator::InjectTransition(const Transition& rTrans) { 01426 FD_DG("vGenerator::InjectTransition(" << TStr(rTrans) << ")"); 01427 mpTransRel->Insert(rTrans); 01428 } 01429 01430 // InjectTransRel(newtransrel) 01431 void vGenerator::InjectTransRel(const TransSet& rNewTransrel) { 01432 FD_DG("vGenerator::InjectTransRel(...)"); 01433 *mpTransRel=rNewTransrel; 01434 mpTransRel->Name("TransRel"); 01435 } 01436 01437 // SetTransition(rX1, rEv, rX2) 01438 bool vGenerator::SetTransition(const std::string& rX1, const std::string& rEv, const std::string& rX2) { 01439 FD_DG("vGenerator(" << this << ")::SetTransition(\"" 01440 << rX1 << "\", \"" << rEv << "\", \"" << rX2 << "\")"); 01441 Idx x1 = StateIndex(rX1); 01442 Idx x2 = StateIndex(rX2); 01443 #ifdef FAUDES_CHECKED 01444 if (x1 == 0) { 01445 FD_ERR("vGenerator::SetTransition: state " << rX1 01446 << " not in stateset"); 01447 std::stringstream errstr; 01448 errstr << "State name " << rX1 << " not found in Generator"; 01449 throw Exception("vGenerator::SetTransition(..)", errstr.str(), 90); 01450 } 01451 if (! mpAlphabet->Exists(rEv)) { 01452 FD_ERR("vGenerator::SetTransition: event " << rEv << " not in alphabet"); 01453 std::stringstream errstr; 01454 errstr << "Event name " << rEv << " not found in event domain of Generator"; 01455 throw Exception("vGenerator::SetTransition(..)", errstr.str(), 95); 01456 } 01457 if (x2 == 0) { 01458 FD_ERR("vGenerator::SetTransition: state " << rX2 << " not in stateset"); 01459 std::stringstream errstr; 01460 errstr << "State name " << rX2 << " not found in Generator"; 01461 throw Exception("vGenerator::SetTransition(..)", errstr.str(), 90); 01462 } 01463 #endif 01464 return SetTransition(Transition(x1, EventIndex(rEv), x2)); 01465 } 01466 01467 01468 // SetTransition(x1, ev, x2) 01469 bool vGenerator::SetTransition(Idx x1, Idx ev, Idx x2) { 01470 return SetTransition(Transition(x1,ev,x2)); 01471 } 01472 01473 // SetTransition(rTransition) 01474 bool vGenerator::SetTransition(const Transition& rTransition) { 01475 FD_DG("vGenerator(" << this << ")::SetTransition(" << rTransition.X1 << "," 01476 << rTransition.Ev << "," << rTransition.X2 << ")"); 01477 #ifdef FAUDES_CHECKED 01478 if (! mpStates->Exists(rTransition.X1)) { 01479 std::stringstream errstr; 01480 errstr << "vGenerator::SetTransition: state " << rTransition.X1 01481 << " not in stateset"; 01482 throw Exception("vGenerator::SetTransition(..)", errstr.str(), 95); 01483 } 01484 if (! mpAlphabet->Exists(rTransition.Ev)) { 01485 std::stringstream errstr; 01486 errstr << "vGenerator::SetTransition: event " << rTransition.Ev 01487 << " not in alphabet "; 01488 throw Exception("vGenerator::SetTransition(..)", errstr.str(), 95); 01489 } 01490 if (! mpStates->Exists(rTransition.X2)) { 01491 std::stringstream errstr; 01492 errstr << "vGenerator::SetTransition: state " << rTransition.X2 01493 << " not in stateset"; 01494 throw Exception("vGenerator::SetTransition(..)", errstr.str(), 95); 01495 } 01496 #endif 01497 return mpTransRel->Insert(rTransition); 01498 } 01499 01500 // ClrTransition.X1, ev, x2) 01501 void vGenerator::ClrTransition(Idx x1, Idx ev, Idx x2) { 01502 FD_DG("vGenerator(" << this << ")::ClrTransition(" 01503 << x1 << "," << ev << "," << x2 << ")"); 01504 mpTransRel->Erase(x1, ev, x2); 01505 } 01506 01507 // ClrTransition(rTransition) 01508 void vGenerator::ClrTransition(const Transition& rTransition) { 01509 FD_DG("vGenerator(" << this << ")::ClrTransition(" << TStr(rTransition) << ")"); 01510 mpTransRel->Erase(rTransition); 01511 } 01512 01513 // ClrTransition(it) 01514 TransSet::Iterator vGenerator::ClrTransition(TransSet::Iterator it) { 01515 FD_DG("vGenerator(" << this << ")::ClrTransition(" << TStr(*it)<< ")" ); 01516 return mpTransRel->Erase(it); 01517 } 01518 01519 // TransAttribute(trans, attr) 01520 void vGenerator::TransAttribute(const Transition& rTrans, const Type& rAttr) { 01521 FD_DG("vGenerator(" << this << ")::TransAttribute(" 01522 << TStr(rTrans) << ",\"" << rAttr.ToString() << "\")"); 01523 mpTransRel->Attribute(rTrans, rAttr); 01524 } 01525 01526 // TransAttributep(trans) 01527 AttributeVoid* vGenerator::TransAttributep(const Transition& rTrans) { 01528 return mpTransRel->Attributep(rTrans); 01529 } 01530 01531 01532 // TransAttribute(trans) 01533 const AttributeVoid& vGenerator::TransAttribute(const Transition& rTrans) const { 01534 return mpTransRel->Attribute(rTrans); 01535 } 01536 01537 // ClrTransAttribute(trans) 01538 void vGenerator::ClrTransAttribute(const Transition& rTrans) { 01539 mpTransRel->ClrAttribute(rTrans); 01540 } 01541 01542 01543 // ClearTransRel() 01544 void vGenerator::ClearTransRel(void) { 01545 mpTransRel->Clear(); 01546 } 01547 01548 // EventAttribute(index, attr) 01549 void vGenerator::EventAttribute(Idx index, const Type& rAttr) { 01550 FD_DG("vGenerator(" << this << ")::EventAttribute(" 01551 << EStr(index) << ",\"" << rAttr.ToString() << "\")"); 01552 mpAlphabet->Attribute(index, rAttr); 01553 } 01554 01555 01556 // EventAttributes(set) 01557 void vGenerator::EventAttributes(const EventSet& rEventSet) { 01558 FD_DG("vGenerator(" << this << ")::EventAttributes(" 01559 << rEventSet.ToString() << "\")"); 01560 mpAlphabet->Attributes(rEventSet); 01561 } 01562 01563 // ClrEventAttribute(index) 01564 void vGenerator::ClrEventAttribute(Idx index) { 01565 FD_DG("vGenerator(" << this << ")::ClrEventAttribute(\"" << EStr(index) << "\")"); 01566 mpAlphabet->ClrAttribute(index); 01567 } 01568 01569 // StateAttribute(index, attr) 01570 void vGenerator::StateAttribute(Idx index, const Type& rAttr) { 01571 FD_DG("vGenerator(" << this << ")::StateAttribute(" 01572 << SStr(index) << ",\"" << rAttr.ToString() << "\")"); 01573 mpStates->Attribute(index, rAttr); 01574 } 01575 01576 // ClrStateAttribute(index) 01577 void vGenerator::ClrStateAttribute(Idx index) { 01578 FD_DG("vGenerator(" << this << ")::ClrStateAttribute(\"" << index << "\")"); 01579 mpStates->ClrAttribute(index); 01580 } 01581 01582 // ExistsEvent(index) 01583 bool vGenerator::ExistsEvent(Idx index) const { 01584 return mpAlphabet->Exists(index); 01585 } 01586 01587 // ExistsEvent(rName) 01588 bool vGenerator::ExistsEvent(const std::string& rName) const { 01589 return mpAlphabet->Exists(rName); 01590 } 01591 01592 // FindEvent(index) const 01593 EventSet::Iterator vGenerator::FindEvent(Idx index) const { 01594 return mpAlphabet->Find(index); 01595 } 01596 01597 // FindEvent(rName) 01598 EventSet::Iterator vGenerator::FindEvent(const std::string& rName) const { 01599 return mpAlphabet->Find(rName); 01600 } 01601 01602 // ExistsState(index) 01603 bool vGenerator::ExistsState(Idx index) const { 01604 return mpStates->Exists(index); 01605 } 01606 01607 // ExistsName(name) 01608 bool vGenerator::ExistsState(const std::string& rName) const { 01609 return ExistsState(StateIndex(rName)); 01610 } 01611 01612 // FindState(rName) const 01613 StateSet::Iterator vGenerator::FindState(const std::string& rName) const { 01614 return mpStates->Find(mpStateSymbolTable->Index(rName)); 01615 } 01616 01617 // FindState(index) const 01618 StateSet::Iterator vGenerator::FindState(Idx index) const { 01619 return mpStates->Find(index); 01620 } 01621 01622 // ExistsInitState(index) 01623 bool vGenerator::ExistsInitState(Idx index) const { 01624 return mInitStates.Exists(index); 01625 } 01626 01627 // FindInitState(index) 01628 StateSet::Iterator vGenerator::FindInitState(Idx index) const { 01629 return mInitStates.Find(index); 01630 } 01631 01632 // ExistsMarkedState(index) 01633 bool vGenerator::ExistsMarkedState(Idx index) const { 01634 return mMarkedStates.Exists(index); 01635 } 01636 01637 // FindMarkedState(index) 01638 StateSet::Iterator vGenerator::FindMarkedState(Idx index) const { 01639 return mMarkedStates.Find(index); 01640 } 01641 01642 // EventAttribute(index) 01643 const AttributeVoid& vGenerator::EventAttribute(Idx index) const { 01644 return mpAlphabet->Attribute(index); 01645 } 01646 01647 // EventAttributep(index) 01648 AttributeVoid* vGenerator::EventAttributep(Idx index) { 01649 return mpAlphabet->Attributep(index); 01650 } 01651 01652 // EventAttribute(rName) 01653 const AttributeVoid& vGenerator::EventAttribute(const std::string& rName) const { 01654 return EventAttribute(EventIndex(rName)); 01655 } 01656 01657 // EventAttributep(rName) 01658 AttributeVoid* vGenerator::EventAttributep(const std::string& rName) { 01659 return EventAttributep(EventIndex(rName)); 01660 } 01661 01662 // StateAttribute(index) 01663 const AttributeVoid& vGenerator::StateAttribute(Idx index) const { 01664 return mpStates->Attribute(index); 01665 } 01666 01667 // StateAttributep(index) 01668 AttributeVoid* vGenerator::StateAttributep(Idx index) { 01669 return mpStates->Attributep(index); 01670 } 01671 01672 // GlobalAttribute(attr) 01673 void vGenerator::GlobalAttribute(const Type& rAttr) { 01674 FD_DG("vGenerator(" << this << ")::GlobalAttribute(" 01675 << rAttr.ToString() << "\")"); 01676 // set to void is ok for silient ignore 01677 if(typeid(rAttr)==typeid(AttributeVoid)) return; 01678 // error: 01679 std::stringstream errstr; 01680 errstr << "cannot cast global attribute " << rAttr.ToString() << " for generator " << Name(); 01681 throw Exception("vGenerator::GlobalAttribute", errstr.str(), 63); 01682 } 01683 01684 // GlobalAttributeTry(attr) 01685 void vGenerator::GlobalAttributeTry(const Type& rAttr) { 01686 FD_DG("vGenerator(" << this << ")::GlobalAttributeTry(" 01687 << rAttr.ToString() << "\")"); 01688 // ignore 01689 } 01690 01691 // GlobalAttribute() 01692 const AttributeVoid& vGenerator::GlobalAttribute(void) const { 01693 FD_DG("vGenerator(" << this << ")::GlobalAttribute()"); 01694 return *mpGlobalAttribute; 01695 } 01696 01697 // GlobalAttributep() 01698 AttributeVoid* vGenerator::GlobalAttributep(void) { 01699 FD_DG("vGenerator(" << this << ")::GlobalAttributep()"); 01700 return mpGlobalAttribute; 01701 } 01702 01703 01704 // Alphabet() 01705 const EventSet& vGenerator::Alphabet(void) const { 01706 return *mpAlphabet; 01707 } 01708 01709 // States() 01710 const StateSet& vGenerator::States(void) const { 01711 return *mpStates; 01712 } 01713 01714 // TransRel() 01715 const TransSet& vGenerator::TransRel(void) const { 01716 return *mpTransRel; 01717 } 01718 01719 01720 // TransRel(res) 01721 void vGenerator::TransRel(TransSetX1EvX2& res) const { mpTransRel->ReSort(res); } 01722 void vGenerator::TransRel(TransSetEvX1X2& res) const { mpTransRel->ReSort(res); } 01723 void vGenerator::TransRel(TransSetEvX2X1& res) const { mpTransRel->ReSort(res); } 01724 void vGenerator::TransRel(TransSetX2EvX1& res) const { mpTransRel->ReSort(res); } 01725 void vGenerator::TransRel(TransSetX2X1Ev& res) const { mpTransRel->ReSort(res); } 01726 void vGenerator::TransRel(TransSetX1X2Ev& res) const { mpTransRel->ReSort(res); } 01727 01728 01729 Transition vGenerator::TransitionByNames( 01730 const std::string& rX1, const std::string& rEv, const std::string& rX2) const { 01731 return Transition(StateIndex(rX1),EventIndex(rEv),StateIndex(rX2)); 01732 } 01733 01734 // InitStates() 01735 const StateSet& vGenerator::InitStates(void) const { 01736 return mInitStates; 01737 } 01738 01739 // MarkedStates() 01740 const StateSet& vGenerator::MarkedStates(void) const { 01741 return mMarkedStates; 01742 } 01743 01744 // MinimizeAlphabet() 01745 void vGenerator::MinimizeAlphabet(void) { 01746 mpAlphabet->NameSet::EraseSet(UnusedEvents()); 01747 } 01748 01749 // UsedEvents() 01750 EventSet vGenerator::UsedEvents(void) const { 01751 EventSet resultset = NewEventSet(); 01752 TransSet::Iterator it; 01753 for (it = mpTransRel->Begin(); it != mpTransRel->End(); ++it) { 01754 resultset.Insert(it->Ev); 01755 } 01756 return resultset; 01757 } 01758 01759 // UnusedEvents() 01760 EventSet vGenerator::UnusedEvents(void) const { 01761 return *mpAlphabet - UsedEvents(); 01762 } 01763 01764 // ActiveEventSet(x1) 01765 EventSet vGenerator::ActiveEventSet(Idx x1) const { 01766 EventSet result = NewEventSet(); 01767 TransSet::Iterator it; 01768 for (it = TransRelBegin(x1); it != TransRelEnd(x1); ++it) { 01769 result.Insert(it->Ev); 01770 } 01771 return result; 01772 } 01773 01774 // ActiveTransSet(x1) 01775 TransSet vGenerator::ActiveTransSet(Idx x1) const { 01776 TransSet result; 01777 TransSet::Iterator it; 01778 for (it = TransRelBegin(x1); it != TransRelEnd(x1); ++it) { 01779 result.Insert(*it); 01780 } 01781 return result; 01782 } 01783 01784 // TransRelStateSpace() 01785 StateSet vGenerator::TransRelStateSpace(void) const { 01786 StateSet states; 01787 TransSet::Iterator it; 01788 for (it=mpTransRel->Begin(); it != mpTransRel->End(); ++it) { 01789 states.Insert(it->X1); 01790 states.Insert(it->X2); 01791 } 01792 return states; 01793 } 01794 01795 // TransRelStateSpace(x1) 01796 StateSet vGenerator::TransRelStateSpace(Idx x1) const { 01797 StateSet states; 01798 TransSet::Iterator it = mpTransRel->Begin(x1); 01799 TransSet::Iterator it_end = mpTransRel->End(x1); 01800 for (; it != it_end; ++it) { 01801 states.Insert(it->X2); 01802 } 01803 return states; 01804 } 01805 01806 01807 // CheckAccessible(accessibleset, startState) 01808 void vGenerator::CheckAccessible(StateSet& accessibleset, Idx startState) const { 01809 if (! accessibleset.Exists(startState)) { 01810 accessibleset.Insert(startState); 01811 TransSet::Iterator it = TransRelBegin(startState); 01812 TransSet::Iterator it_end = TransRelEnd(startState); 01813 for (; it != it_end; ++it) { 01814 CheckAccessible(accessibleset, it->X2); 01815 } 01816 } 01817 } 01818 01819 // CheckCoaccessible(coaccessibleset, rtransrel, startState) 01820 void vGenerator::CheckCoaccessible(StateSet& coaccessibleset, const TransSetX2EvX1& rtrel, Idx startState) const { 01821 if (! coaccessibleset.Exists(startState)) { 01822 coaccessibleset.Insert(startState); 01823 TransSetX2EvX1::Iterator it = rtrel.BeginByX2(startState); 01824 TransSetX2EvX1::Iterator it_end = rtrel.EndByX2(startState); 01825 for (; it != it_end; ++it) { 01826 CheckCoaccessible(coaccessibleset, rtrel, it->X1); 01827 } 01828 } 01829 } 01830 01831 // AccessibleSet() 01832 StateSet vGenerator::AccessibleSet(void) const { 01833 StateSet accessibleset; 01834 StateSet::Iterator it; 01835 for (it = InitStatesBegin(); it != InitStatesEnd(); ++it) { 01836 CheckAccessible(accessibleset, *it); 01837 } 01838 accessibleset.Name("AccessibleSet"); 01839 return accessibleset; 01840 } 01841 01842 // Accessible() 01843 bool vGenerator::Accessible(void) { 01844 StateSet accessibleset = AccessibleSet(); 01845 StateSet not_accessible = *mpStates - accessibleset; 01846 DelStates(not_accessible); 01847 // return true if there is an initial state 01848 if (!mInitStates.Empty()) { 01849 FD_DF("vGenerator::accessible: generator is accessible"); 01850 return true; 01851 } 01852 else { 01853 FD_DF("vGenerator::accessible: generator is accessible but empty"); 01854 return false; 01855 } 01856 01857 } 01858 01859 // IsAccessible() 01860 bool vGenerator::IsAccessible(void) const { 01861 if (AccessibleSet() == *mpStates) { 01862 FD_DF("vGenerator::accessible: generator is accessible"); 01863 return true; 01864 } 01865 else { 01866 FD_DF("vGenerator::accessible: generator is not accessible"); 01867 return false; 01868 } 01869 } 01870 01871 // CoaccessibleSet() 01872 StateSet vGenerator::CoaccessibleSet(void) const { 01873 StateSet coaccessibleset; 01874 StateSet::Iterator it; 01875 // build reverse transition relation 01876 TransSetX2EvX1 rtrel; 01877 TransRel(rtrel); 01878 for (it = MarkedStatesBegin(); it != MarkedStatesEnd(); ++it) { 01879 CheckCoaccessible(coaccessibleset, rtrel, *it); 01880 } 01881 coaccessibleset.Name("CoaccessibleSet"); 01882 return coaccessibleset; 01883 } 01884 01885 // Coaccessible() 01886 bool vGenerator::Coaccessible(void) { 01887 StateSet coaccessibleset = CoaccessibleSet(); 01888 StateSet not_coaccessible = *mpStates - coaccessibleset; 01889 DelStates(not_coaccessible); 01890 // return true if there is a marked state 01891 if (! mMarkedStates.Empty()) { 01892 FD_DF("vGenerator::coaccessible: generator is coaccessible"); 01893 return true; 01894 } 01895 else { 01896 FD_DF("vGenerator::coaccessible: generator is not coaccessible"); 01897 return false; 01898 } 01899 } 01900 01901 // IsCoaccessible() 01902 bool vGenerator::IsCoaccessible(void) const { 01903 if (CoaccessibleSet() == *mpStates) { 01904 FD_DF("vGenerator::coaccessible: generator is coaccessible"); 01905 return true; 01906 } 01907 else { 01908 FD_DF("vGenerator::coaccessible: generator is not coaccessible"); 01909 return false; 01910 } 01911 } 01912 01913 // TrimSet() 01914 StateSet vGenerator::TrimSet(void) const { 01915 FD_DF("vGenerator::trimset: trim states: " 01916 << StateSet(AccessibleSet() * CoaccessibleSet()).ToString()); 01917 StateSet res=AccessibleSet() * CoaccessibleSet(); 01918 res.Name("TrimSet"); 01919 return res; 01920 } 01921 01922 // Trim() 01923 bool vGenerator::Trim(void) { 01924 FD_DF("vGenerator::trim: generator states: " << mpStates->ToString()); 01925 // better: compute sets and do one state delete 01926 bool accessiblebool = Accessible(); 01927 bool coaccessiblebool = Coaccessible(); 01928 FD_DF("vGenerator::trim: trim states: " << mpStates->ToString()); 01929 if (accessiblebool && coaccessiblebool) { 01930 FD_DF("vGenerator::Trim(): generator is nontrivial"); 01931 return true; 01932 } 01933 FD_DF("vGenerator::Trim(): generator is trivial"); 01934 return false; 01935 } 01936 01937 01938 // IsTrim() 01939 bool vGenerator::IsTrim(void) const { 01940 bool res=true; 01941 if(!IsAccessible()) res=false; 01942 else if(!IsCoaccessible()) res=false; 01943 FD_DF("vGenerator::IsTrim(): result " << res); 01944 return res; 01945 } 01946 01947 01948 // BlockingStates() 01949 StateSet vGenerator::BlockingStates(void) const { 01950 FD_DF("vGenerator::BlockingSet: blocking states: " 01951 << StateSet(AccessibleSet() - CoaccessibleSet()).ToString()); 01952 return AccessibleSet() - CoaccessibleSet(); 01953 } 01954 01955 01956 01957 // IsComplete 01958 bool vGenerator::IsComplete(const StateSet& rStates) const { 01959 FD_DG("IsComplete(" << Name() << ")"); 01960 01961 // loop over provided states 01962 StateSet::Iterator sit=rStates.Begin(); 01963 StateSet::Iterator sit_end=rStates.End(); 01964 for(;sit!=sit_end;sit++){ 01965 TransSet::Iterator tit=TransRelBegin(*sit); 01966 TransSet::Iterator tit_end=TransRelEnd(*sit); 01967 if(tit==tit_end) break; 01968 } 01969 // return true if no terminal state has been found 01970 return sit==sit_end; 01971 } 01972 01973 // IsComplete 01974 bool vGenerator::IsComplete(void) const { 01975 return IsComplete(States()); 01976 } 01977 01978 // Complete 01979 bool vGenerator::Complete(void) { 01980 // states to remove 01981 StateSet termset = TerminalStates(); 01982 // iterative search ... 01983 bool done; 01984 do { 01985 // ... over all states 01986 StateSet::Iterator sit = States().Begin(); 01987 StateSet::Iterator sit_end = States().End(); 01988 done=true; 01989 for(; sit!=sit_end; ++sit) { 01990 if(termset.Exists(*sit)) continue; 01991 TransSet::Iterator tit = TransRelBegin(*sit); 01992 TransSet::Iterator tit_end = TransRelEnd(*sit); 01993 for (; tit != tit_end; ++tit) { 01994 if(!termset.Exists(tit->X2)) break; 01995 } 01996 if(tit==tit_end) { 01997 termset.Insert(*sit); 01998 done=false; 01999 } 02000 } 02001 } while(!done); 02002 // remove those states 02003 DelStates(termset); 02004 // done 02005 return !InitStates().Empty(); 02006 } 02007 02008 02009 // TerminalStates() 02010 StateSet vGenerator::TerminalStates(const StateSet& rStates) const { 02011 FD_DG("Generator::TerminalStates(" << Name() << ")"); 02012 02013 // prepare result 02014 StateSet res; 02015 02016 // loop states 02017 StateSet::Iterator sit=rStates.Begin(); 02018 StateSet::Iterator sit_end=rStates.End(); 02019 for(;sit!=sit_end;sit++){ 02020 TransSet::Iterator tit=TransRelBegin(*sit); 02021 TransSet::Iterator tit_end=TransRelEnd(*sit); 02022 if(tit==tit_end) res.Insert(*sit); 02023 } 02024 // return terminal states 02025 res.Name("TerminalStates"); 02026 return res; 02027 } 02028 02029 // TerminalStates() 02030 StateSet vGenerator::TerminalStates(void) const { 02031 return TerminalStates(States()); 02032 } 02033 02034 02035 // OmegaTrim 02036 bool vGenerator::OmegaTrim(void) { 02037 02038 // note: this really is inefficient; at least we should 02039 // record the inverse transition relation for the coaccessile 02040 // iteration 02041 02042 // first we make the generator accessible 02043 Accessible(); 02044 // iterate coaccessible and complete until convergence in oserved 02045 while(1) { 02046 Idx osize=States().Size(); 02047 Coaccessible(); 02048 Complete(); 02049 if(States().Size()==osize) break; 02050 } 02051 // done 02052 return !InitStates().Empty() && !MarkedStates().Empty(); 02053 } 02054 02055 02056 // IsOmegaTrim() 02057 bool vGenerator::IsOmegaTrim(void) const { 02058 bool res=true; 02059 if(!IsAccessible()) res=false; 02060 else if(!IsCoaccessible()) res=false; 02061 else if(!IsComplete()) res=false; 02062 FD_DF("vGenerator::IsOmegaTrim(): result " << res); 02063 return res; 02064 } 02065 02066 02067 02068 // IsDeterministic() 02069 bool vGenerator::IsDeterministic(void) const { 02070 // if there is more than one initial state ... nondet 02071 if (InitStatesSize() != 1) { 02072 FD_DG("vGenerator::IsDeterministic: number of initial states not 1"); 02073 return false; 02074 } 02075 // if there is a state/event pair with non-unique successor ... nondet 02076 if (TransRelSize() < 2) return true; 02077 TransSet::Iterator it1; 02078 TransSet::Iterator it2; 02079 for (it1 = TransRelBegin(), it2 = it1++; it1 != TransRelEnd(); it2 = it1++) { 02080 if ((it1->X1 == it2->X1) && (it1->Ev == it2->Ev)) { 02081 FD_DG("IsDeterministic(): at least one state " 02082 << "contains more than on transition with same event: " 02083 << TStr(*it1)); 02084 return false; 02085 } 02086 } 02087 // in all other cases generator is deterministic 02088 return true; 02089 } 02090 02091 // DoWrite() 02092 void vGenerator::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const { 02093 (void) pContext; 02094 // figure section 02095 std::string label=rLabel; 02096 if(label=="") label="Generator"; 02097 FD_DG("vGenerator(" << this << ")::DoWrite(): section " << label); 02098 // reindex for file output 02099 if(rTw.FileMode()) SetMinStateIndexMap(); 02100 // write generator 02101 rTw.WriteBegin(label); 02102 rTw << mMyName; 02103 rTw << "\n"; 02104 rTw << "\n"; 02105 SWrite(rTw); 02106 rTw << "\n"; 02107 mpAlphabet->Write(rTw); 02108 rTw << "\n"; 02109 WriteStateSet(rTw, *mpStates); 02110 rTw << "\n"; 02111 WriteTransRel(rTw); 02112 rTw << "\n"; 02113 WriteStateSet(rTw, mInitStates); 02114 rTw << "\n"; 02115 WriteStateSet(rTw, mMarkedStates); 02116 rTw << "\n"; 02117 mpGlobalAttribute->Write(rTw); 02118 rTw << "\n"; 02119 rTw.WriteEnd(label); 02120 // end of reindex 02121 ClearMinStateIndexMap(); 02122 } 02123 02124 // DoDWrite() 02125 void vGenerator::DoDWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const { 02126 (void) pContext; 02127 // figure section 02128 std::string label=rLabel; 02129 if(label=="") label="Generator"; 02130 FD_DG("vGenerator(" << this << ")::DoDWrite(): section " << label); 02131 // write generator 02132 rTw.WriteBegin(label); 02133 rTw << mMyName; 02134 rTw << "\n"; 02135 rTw << "\n"; 02136 SWrite(rTw); 02137 rTw << "\n"; 02138 mpAlphabet->DWrite(rTw); 02139 rTw << "\n"; 02140 DWriteStateSet(rTw, *mpStates); 02141 rTw << "\n"; 02142 DWriteTransRel(rTw); 02143 rTw << "\n"; 02144 DWriteStateSet(rTw, mInitStates); 02145 rTw << "\n"; 02146 DWriteStateSet(rTw, mMarkedStates); 02147 rTw << "\n"; 02148 mpGlobalAttribute->Write(rTw); 02149 rTw << "\n"; 02150 rTw.WriteEnd(label); 02151 rTw << "\n"; 02152 } 02153 02154 // WriteAlphabet() 02155 void vGenerator::WriteAlphabet(void) const { 02156 TokenWriter tw(TokenWriter::Stdout); 02157 WriteAlphabet(tw); 02158 } 02159 02160 // AlphabetToString() 02161 std::string vGenerator::AlphabetToString(void) const { 02162 TokenWriter tw(TokenWriter::String); 02163 WriteAlphabet(tw); 02164 return tw.Str(); 02165 } 02166 02167 // WriteAlphabet(rTw&) 02168 void vGenerator::WriteAlphabet(TokenWriter& rTw) const { 02169 mpAlphabet->Write(rTw); 02170 } 02171 02172 // WriteStateSet(rStateSet&) 02173 void vGenerator::WriteStateSet(const StateSet& rStateSet) const { 02174 TokenWriter tw(TokenWriter::Stdout); 02175 WriteStateSet(tw,rStateSet); 02176 } 02177 02178 // StateSetToString() 02179 std::string vGenerator::StateSetToString(const StateSet& rStateSet) const { 02180 TokenWriter tw(TokenWriter::String); 02181 WriteStateSet(tw,rStateSet); 02182 return tw.Str(); 02183 } 02184 02185 // StateSetToText() 02186 std::string vGenerator::StateSetToText(const StateSet& rStateSet) const { 02187 TokenWriter tw(TokenWriter::String); 02188 tw.Endl(true); 02189 WriteStateSet(tw,rStateSet); 02190 return tw.Str(); 02191 } 02192 02193 02194 // WriteStateSet(rTw&, rStateSet&) 02195 void vGenerator::WriteStateSet(TokenWriter& rTw, const StateSet& rStateSet) const { 02196 rTw.WriteBegin(rStateSet.Name()); 02197 // build reverse index map of states to write ( fileidx->idx ) 02198 // (this ensures named states to be written first; see SetMinStateIndexMap()) 02199 std::map<Idx,Idx> reversemap; 02200 std::map<Idx,Idx>::const_iterator minit; 02201 StateSet::Iterator sit; 02202 for (sit = rStateSet.Begin(); sit != rStateSet.End(); ++sit) { 02203 reversemap[MinStateIndex(*sit)] = *sit; 02204 } 02205 // iterate states to write 02206 for(minit = reversemap.begin(); minit != reversemap.end(); ++minit) { 02207 // identify anonymous block (consecutive state indices) 02208 std::map<Idx,Idx>::const_iterator conit=minit; 02209 Idx start = conit->first; 02210 Idx anoncount = 0; 02211 for(; conit != reversemap.end(); ++conit) { 02212 if(StateName(conit->second) != "") break; 02213 if(!StateAttribute(conit->second).IsDefault()) break; 02214 if(conit->first != start+anoncount) break; 02215 ++anoncount; 02216 } 02217 // write anonymous block 02218 if (anoncount > FD_CONSECUTIVE) { 02219 rTw.WriteBegin("Consecutive"); 02220 rTw << start; 02221 rTw << start+anoncount-1; 02222 rTw.WriteEnd("Consecutive"); 02223 minit=conit; 02224 } 02225 // break loop 02226 if(minit == reversemap.end() ) 02227 break; 02228 // write non anonymous state name/idx 02229 std::string statename = StateName(minit->second); 02230 if (statename != "") { 02231 rTw << statename; 02232 } else { 02233 rTw << minit->first; 02234 } 02235 // write state attribute 02236 const AttributeVoid& attr=rStateSet.Attribute(minit->second); 02237 attr.Write(rTw); 02238 } 02239 rTw.WriteEnd(rStateSet.Name()); 02240 } 02241 02242 02243 // DWriteStateSet(rTw&, rStateSet&) 02244 void vGenerator::DWriteStateSet(TokenWriter& rTw, const StateSet& rStateSet) const { 02245 rTw.WriteBegin(rStateSet.Name()); 02246 StateSet::Iterator lit; 02247 std::map<Idx,Idx>::const_iterator minit; 02248 for(lit = rStateSet.Begin(); lit != rStateSet.End(); ++lit) { 02249 rTw << SStr(*lit); 02250 const AttributeVoid& attr=rStateSet.Attribute(*lit); 02251 attr.Write(rTw); 02252 } 02253 rTw.WriteEnd(rStateSet.Name()); 02254 } 02255 02256 02257 // StatesToString() 02258 std::string vGenerator::StatesToString(void) const { 02259 return StateSetToString(*mpStates); 02260 } 02261 02262 // StatesToText() 02263 std::string vGenerator::StatesToText(void) const { 02264 return StateSetToText(*mpStates); 02265 } 02266 02267 // MarkedStatesToString() 02268 std::string vGenerator::MarkedStatesToString(void) const { 02269 return StateSetToString(mMarkedStates); 02270 } 02271 02272 // InitStatesToString() 02273 std::string vGenerator::InitStatesToString(void) const { 02274 return StateSetToString(mInitStates); 02275 } 02276 02277 02278 // WriteTransRel() 02279 void vGenerator::WriteTransRel(void) const { 02280 TokenWriter tw(TokenWriter::Stdout); 02281 WriteTransRel(tw); 02282 } 02283 02284 // TransRelToString() 02285 std::string vGenerator::TransRelToString(void) const { 02286 TokenWriter tw(TokenWriter::String); 02287 WriteTransRel(tw); 02288 return tw.Str(); 02289 } 02290 02291 // TransRelToText() 02292 std::string vGenerator::TransRelToText(void) const { 02293 TokenWriter tw(TokenWriter::String); 02294 tw.Endl(true); 02295 WriteTransRel(tw); 02296 return tw.Str(); 02297 } 02298 02299 // WriteTransRel(rTw&) 02300 void vGenerator::WriteTransRel(TokenWriter& rTw) const { 02301 TransSet::Iterator tit; 02302 int oldcolumns = rTw.Columns(); 02303 rTw.Columns(3); 02304 rTw.WriteBegin("TransRel"); 02305 bool smalltransrel = (Size() < FD_SMALLTRANSREL); 02306 02307 // loop all transitions 02308 for(tit = mpTransRel->Begin(); tit != mpTransRel->End(); ++tit) { 02309 02310 // write x1 02311 Idx x1=MinStateIndex(tit->X1); 02312 if (smalltransrel) { 02313 std::string x1name = StateName(tit->X1); 02314 if (x1name != "") { 02315 rTw << x1name; 02316 } else { 02317 rTw << x1; 02318 } 02319 } else { 02320 rTw << x1; 02321 } 02322 02323 // write ev 02324 rTw << EventName(tit->Ev); 02325 02326 // write x2 02327 Idx x2=MinStateIndex(tit->X2); 02328 if (smalltransrel) { 02329 std::string x2name = StateName(tit->X2); 02330 if (x2name != "") { 02331 rTw << x2name; 02332 } else { 02333 rTw << x2; 02334 } 02335 } else { 02336 rTw << x2; 02337 } 02338 02339 // write attributes 02340 TransAttribute(*tit).Write(rTw); 02341 02342 } 02343 rTw.WriteEnd("TransRel"); 02344 rTw.Columns(oldcolumns); 02345 } 02346 02347 // DWriteTransRel(rTw&) 02348 void vGenerator::DWriteTransRel(TokenWriter& rTw) const { 02349 TransSet::Iterator tit; 02350 int oldcolumns = rTw.Columns(); 02351 rTw.Columns(3); 02352 rTw.WriteBegin("TransRel"); 02353 // iterate all transitions 02354 for (tit = mpTransRel->Begin(); tit != mpTransRel->End(); ++tit) { 02355 // write x1 02356 std::ostringstream ox1; 02357 Idx x1= tit->X1; 02358 std::string x1name = StateName(x1); 02359 if (x1name != "") { 02360 ox1 << x1name << "[" << x1 << "]"; 02361 } else { 02362 ox1 << x1; 02363 } 02364 rTw << ox1.str(); 02365 // write ev 02366 std::ostringstream oev; 02367 Idx ev= tit->Ev; 02368 std::string evname = EventName(ev); 02369 oev << evname << "[" << ev << "]"; 02370 rTw << oev.str(); 02371 // write x2 02372 std::ostringstream ox2; 02373 Idx x2= tit->X2; 02374 std::string x2name = StateName(x2); 02375 if (x2name != "") { 02376 ox2 << x2name << "[" << x2 << "]"; 02377 } else { 02378 ox2 << x2; 02379 } 02380 rTw << ox2.str(); 02381 // attribute 02382 mpTransRel->Attribute(*tit).Write(rTw); 02383 } 02384 rTw.WriteEnd("TransRel"); 02385 rTw.Columns(oldcolumns); 02386 } 02387 02388 02389 // DoSWrite(rTw&) 02390 void vGenerator::DoSWrite(TokenWriter& rTw) const 02391 { 02392 Type::DoSWrite(rTw); 02393 rTw.WriteComment(" States: " + ToStringInteger(Size()) ); 02394 rTw.WriteComment(" Init/Marked: " + ToStringInteger(mInitStates.Size()) 02395 + "/" + ToStringInteger(mMarkedStates.Size())); 02396 rTw.WriteComment(" Events: " + ToStringInteger(mpAlphabet->Size()) ); 02397 rTw.WriteComment(" Transitions: " + ToStringInteger(mpTransRel->Size()) ); 02398 rTw.WriteComment(" StateSymbols: " + ToStringInteger(mpStateSymbolTable->Size()) ); 02399 rTw.WriteComment(" Attrib. E/S/T: " + ToStringInteger(mpAlphabet->AttributesSize()) 02400 + "/" + ToStringInteger(mpStates->AttributesSize()) 02401 + "/" + ToStringInteger(mpTransRel->AttributesSize()) ); 02402 rTw.WriteComment(""); 02403 } 02404 02405 // DotWrite(rFileName) 02406 void vGenerator::DotWrite(const std::string& rFileName) const { 02407 FD_DG("vGenerator(" << this << ")::DotWrite(" << rFileName << ")"); 02408 SetMinStateIndexMap(); 02409 StateSet::Iterator lit; 02410 TransSet::Iterator tit; 02411 try { 02412 std::ofstream stream; 02413 stream.exceptions(std::ios::badbit|std::ios::failbit); 02414 stream.open(rFileName.c_str()); 02415 stream << "// dot output generated by libFAUDES vGenerator" << std::endl; 02416 stream << "digraph \"" << Name() << "\" {" << std::endl; 02417 stream << " rankdir=LR" << std::endl; 02418 stream << " node [shape=circle];" << std::endl; 02419 stream << std::endl; 02420 stream << " // initial states" << std::endl; 02421 int i = 1; 02422 for (lit = InitStatesBegin(); lit != InitStatesEnd(); ++lit) { 02423 std::string xname= StateName(*lit); 02424 if(xname=="") xname=ToStringInteger(MinStateIndex(*lit)); 02425 stream << " dot_dummyinit_" << i << " [shape=none, label=\"\" ];" << std::endl; 02426 stream << " dot_dummyinit_" << i << " -> \"" << xname << "\";" << std::endl; 02427 i++; 02428 } 02429 stream << std::endl; 02430 stream << " // mstates" << std::endl; 02431 for (lit = MarkedStatesBegin(); lit != MarkedStatesEnd(); ++lit) { 02432 std::string xname= StateName(*lit); 02433 if(xname=="") xname=ToStringInteger(MinStateIndex(*lit)); 02434 stream << " \"" << xname << "\" [shape=doublecircle];" << std::endl; 02435 } 02436 stream << std::endl; 02437 stream << " // rest of stateset" << std::endl; 02438 for (lit = StatesBegin(); lit != StatesEnd(); ++lit) { 02439 if (! (ExistsInitState(*lit) || ExistsMarkedState(*lit)) ) { 02440 std::string xname= StateName(*lit); 02441 if(xname=="") xname=ToStringInteger(MinStateIndex(*lit)); 02442 stream << " \"" << xname << "\";" << std::endl; 02443 } 02444 } 02445 stream << std::endl; 02446 stream << " // transition relation" << std::endl; 02447 for(tit = TransRelBegin(); tit != TransRelEnd(); ++tit) { 02448 std::string x1name= StateName(tit->X1); 02449 if(x1name=="") x1name=ToStringInteger(MinStateIndex(tit->X1)); 02450 std::string x2name= StateName(tit->X2); 02451 if(x2name=="") x2name=ToStringInteger(MinStateIndex(tit->X2)); 02452 stream << " \"" << x1name << "\" -> \"" << x2name 02453 << "\" [label=\"" << EventName(tit->Ev) << "\"];" << std::endl; 02454 } 02455 stream << "};" << std::endl; 02456 stream.close(); 02457 } 02458 catch (std::ios::failure&) { 02459 throw Exception("vGenerator::DotWrite", 02460 "Exception opening/writing dotfile \""+rFileName+"\"", 2); 02461 } 02462 ClearMinStateIndexMap(); 02463 } 02464 02465 // DDotWrite(rFileName) 02466 void vGenerator::DDotWrite(const std::string& rFileName) const { 02467 FD_DG("vGenerator(" << this << ")::DDotWrite(" << rFileName << ")"); 02468 StateSet::Iterator lit; 02469 TransSet::Iterator tit; 02470 try { 02471 std::ofstream stream; 02472 stream.exceptions(std::ios::badbit|std::ios::failbit); 02473 stream.open(rFileName.c_str()); 02474 stream << "digraph \"" << Name() << "\" {" << std::endl; 02475 stream << " rankdir=LR" << std::endl; 02476 stream << " node [shape=circle];" << std::endl; 02477 stream << std::endl; 02478 stream << " // istates" << std::endl; 02479 int i = 1; 02480 for (lit = InitStatesBegin(); lit != InitStatesEnd(); ++lit) { 02481 stream << " dot_dummyinit_" << i << " [shape=none, label=\"\" ];" << std::endl; 02482 stream << " dot_dummyinit_" << i << " -> \"" 02483 << SStr(*lit) << "\";" << std::endl; 02484 i++; 02485 } 02486 stream << std::endl; 02487 stream << " // mstates" << std::endl; 02488 for (lit = MarkedStatesBegin(); lit != MarkedStatesEnd(); ++lit) { 02489 stream << " \"" << SStr(*lit) << "\" [shape=doublecircle];" << std::endl; 02490 } 02491 stream << std::endl; 02492 stream << " // rest of stateset" << std::endl; 02493 for (lit = StatesBegin(); lit != StatesEnd(); ++lit) { 02494 // if not in mInitStates or mMarkedStates 02495 if (! (ExistsInitState(*lit) || ExistsMarkedState(*lit)) ) { 02496 stream << " \"" << SStr(*lit) << "\";" << std::endl; 02497 } 02498 } 02499 stream << std::endl; 02500 stream << " // transition relation" << std::endl; 02501 for (tit = TransRelBegin(); tit != TransRelEnd(); ++tit) { 02502 stream << " \"" << SStr(tit->X1) 02503 << "\" -> \"" << SStr(tit->X2) 02504 << "\" [label=\"" << EventName(tit->Ev) << "\"];" << std::endl; 02505 } 02506 stream << "};" << std::endl; 02507 stream.close(); 02508 } 02509 catch (std::ios::failure&) { 02510 throw Exception("vGenerator::DotWrite", 02511 "Exception opening/writing dotfile \""+rFileName+"\"", 2); 02512 } 02513 } 02514 02515 02516 // XDotWrite(rFileName) 02517 void vGenerator::XDotWrite(const std::string& rFileName) const { 02518 FD_DG("vGenerator(" << this << ")::XDotWrite(" << rFileName << ")"); 02519 StateSet::Iterator lit; 02520 TransSet::Iterator tit; 02521 try { 02522 std::ofstream stream; 02523 stream.exceptions(std::ios::badbit|std::ios::failbit); 02524 stream.open(rFileName.c_str()); 02525 stream << "digraph \"___" << Name() << "___\" {" << std::endl; 02526 stream << " rankdir=LR" << std::endl; 02527 stream << " node [shape=circle];" << std::endl; 02528 stream << std::endl; 02529 stream << " // stateset" << std::endl; 02530 for (lit = InitStatesBegin(); lit != InitStatesEnd(); ++lit) { 02531 stream << " \"s" << *lit << "\";" << std::endl; 02532 } 02533 for (lit = MarkedStatesBegin(); lit != MarkedStatesEnd(); ++lit) { 02534 stream << " \"s" << *lit << "\";" << std::endl; 02535 } 02536 for (lit = StatesBegin(); lit != StatesEnd(); ++lit) { 02537 if(ExistsInitState(*lit)) continue; 02538 if(ExistsMarkedState(*lit)) continue; 02539 stream << " \"s" << *lit << "\";" << std::endl; 02540 } 02541 stream << std::endl; 02542 stream << " // transition relation" << std::endl; 02543 for (tit = TransRelBegin(); tit != TransRelEnd(); ++tit) { 02544 stream << " \"s" << tit->X1 02545 << "\" -> \"s" << tit->X2 02546 << "\" [label=\"e" << tit->Ev << "\" " << "polyline" << "];" << std::endl; 02547 } 02548 stream << "};" << std::endl; 02549 stream.close(); 02550 } 02551 catch (std::ios::failure&) { 02552 throw Exception("vGenerator::XDotWrite", 02553 "Exception opening/writing dotfile \""+rFileName+"\"", 2); 02554 } 02555 } 02556 02557 // DoRead(tr) 02558 void vGenerator::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) { 02559 (void) pContext; 02560 std::string label=rLabel; 02561 if(label=="") label="Generator"; 02562 FD_DG("vGenerator(" << this << ")::DoRead(): file " << rTr.FileName() << " section " << label); 02563 // Clear old stuff 02564 Clear(); 02565 // find Genertor in any of our current file formats 02566 rTr.ReadBegin(label); 02567 // get the Generator "name" token 02568 ReadGeneratorName(rTr); 02569 // read mAlphabet 02570 ReadAlphabet(rTr); 02571 // read stateset 02572 ReadStates(rTr); 02573 // read transrel 02574 ReadTransRel(rTr); 02575 // read istates 02576 ReadStateSet(rTr, "InitStates", mInitStates); 02577 // read mstates 02578 ReadStateSet(rTr, "MarkedStates", mMarkedStates); 02579 // read attribute 02580 mpGlobalAttribute->Read(rTr); 02581 // skip unknown global attributes 02582 AttributeVoid::Skip(rTr); 02583 // read end 02584 rTr.ReadEnd(label); 02585 FD_DG("vGenerator(" << this << ")::DoRead(): done"); 02586 } 02587 02588 // ReadGeneratorName(rFileName) 02589 void vGenerator::ReadGeneratorName(const std::string& rFileName) { 02590 TokenReader tr(rFileName); 02591 tr.ReadBegin("Generator"); // mimique old behaviour .. use "ReadBegin" instead 02592 ReadGeneratorName(tr); 02593 } 02594 02595 // ReadGeneratorName(tr) 02596 void vGenerator::ReadGeneratorName(TokenReader& rTr) { 02597 FD_DG("vGenerator(" << this << ")::ReadGeneratorName(\"" 02598 << rTr.FileName() << "\")"); 02599 mMyName=rTr.ReadString(); 02600 } 02601 02602 // ReadAlphabet(rFileName) 02603 void vGenerator::ReadAlphabet(const std::string& rFileName) { 02604 FD_DG("vGenerator(" << this << ")::ReadAlphabet(\"" << rFileName << "\")"); 02605 mpAlphabet->Read(rFileName,"Alphabet"); 02606 } 02607 02608 // ReadAlphabet(rTr) 02609 void vGenerator::ReadAlphabet(TokenReader& rTr) { 02610 FD_DG("vGenerator(" << this << ")::ReadAlphabet(\"" 02611 << rTr.FileName() << "\")"); 02612 mpAlphabet->Read(rTr,"Alphabet"); 02613 } 02614 02615 // ReadStates(rFileName) 02616 void vGenerator::ReadStates(const std::string& rFileName) { 02617 TokenReader tr(rFileName); 02618 ReadStates(tr); 02619 } 02620 02621 // ReadStates(tr) 02622 void vGenerator::ReadStates(TokenReader& rTr) { 02623 FD_DG("vGenerator(" << this << ")::ReadStates(\"" << rTr.FileName() << "\")"); 02624 // HELPERS: 02625 Token token; 02626 AttributeVoid* attrp = mpStates->Attribute().New(); 02627 FD_DG("vGenerator(" << this << ")::ReadStates(..): attribute type " << typeid(*attrp).name()); 02628 // ALGORITHM: 02629 mpStates->Clear(); 02630 mpStates->Name("States"); 02631 mStateSymbolTable.Clear(); 02632 rTr.ReadBegin("States"); 02633 while(rTr.Peek(token)) { 02634 // break end of section 02635 if (token.Type() == Token::End) { 02636 break; 02637 } 02638 // read state by index 02639 if (token.Type() == Token::Integer) { 02640 rTr.Get(token); 02641 Idx index = token.IntegerValue(); 02642 FD_DG("vGenerator(" << this << ")::ReadStates(\"" << rTr.FileName() << "\"): by index " << index); 02643 if(mpStates->Exists(index)) { 02644 delete attrp; 02645 std::stringstream errstr; 02646 errstr << "Token " << token.IntegerValue() << " appears twice in stateset" 02647 << rTr.FileLine(); 02648 throw Exception("vGenerator::ReadStates", errstr.str(), 80); 02649 } 02650 // read attribute 02651 attrp->Read(rTr,"",this); 02652 // skip unknown attributes 02653 AttributeVoid::Skip(rTr); 02654 // insert element with attribute 02655 InsState(index); 02656 StateAttribute(index,*attrp); 02657 continue; 02658 } 02659 // read state by name 02660 if (token.Type() == Token::String) { 02661 rTr.Get(token); 02662 FD_DG("vGenerator(" << this << ")::ReadStates(\"" << rTr.FileName() << "\"): by name " << token.StringValue()); 02663 if(ExistsState(token.StringValue())) { 02664 delete attrp; 02665 std::stringstream errstr; 02666 errstr << "Token " << token.StringValue() << " appears twice in stateset" 02667 << rTr.FileLine(); 02668 throw Exception("vGenerator::ReadStates", errstr.str(), 80); 02669 } 02670 // read attribute 02671 attrp->Read(rTr,"",this); 02672 // skip unknown attributes 02673 AttributeVoid::Skip(rTr); 02674 // insert element with attribute 02675 Idx index=InsState(token.StringValue()); 02676 StateAttribute(index,*attrp); 02677 continue; 02678 } 02679 // read consecutive block of anonymous states 02680 if (token.Type() == Token::Begin && token.StringValue() == "Consecutive") { 02681 rTr.ReadBegin("Consecutive"); 02682 Token token1,token2; 02683 rTr.Get(token1); 02684 rTr.Get(token2); 02685 FD_DG("vGenerator(" << this << ")::ReadStates(\"" << rTr.FileName() << "\"): consecutive range"); 02686 if ((token1.Type() != Token::Integer) || (token2.Type() != Token::Integer)) { 02687 delete attrp; 02688 std::stringstream errstr; 02689 errstr << "Invalid range of consecutive states" << rTr.FileLine(); 02690 throw Exception("vGenerator::ReadStates", errstr.str(), 80); 02691 } 02692 for(Idx index = (Idx) token1.IntegerValue(); index <= (Idx) token2.IntegerValue(); ++index) { 02693 if(mpStates->Exists(index)) { 02694 delete attrp; 02695 std::stringstream errstr; 02696 errstr << "Index " << index << " appears twice in stateset" 02697 << rTr.FileLine(); 02698 throw Exception("vGenerator::ReadStates", errstr.str(), 80); 02699 } 02700 InsState(index); 02701 } 02702 rTr.ReadEnd("Consecutive"); 02703 continue; 02704 } 02705 // cannot process token 02706 delete attrp; 02707 std::stringstream errstr; 02708 errstr << "Invalid token" << rTr.FileLine(); 02709 throw Exception("vGenerator::ReadStates", errstr.str(), 80); 02710 } 02711 rTr.ReadEnd("States"); 02712 // dispose attribute 02713 delete attrp; 02714 FD_DG("vGenerator(" << this << ")::ReadStates(\"" << rTr.FileName() << "\"): done"); 02715 } 02716 02717 02718 // ReadStateSet(tr, rLabel, rStateSet) 02719 void vGenerator::ReadStateSet(TokenReader& rTr, const std::string& rLabel, StateSet& rStateSet) const { 02720 FD_DG("vGenerator(" << this << ")::ReadStateSet(\"" << rLabel<< "\")"); 02721 // HELPERS: 02722 Token token; 02723 AttributeVoid* attrp = rStateSet.Attribute().New(); 02724 FD_DG("vGenerator(" << this << ")::ReadStateSet(..): attribute type " << typeid(*attrp).name()); 02725 // ALGORITHM: 02726 rStateSet.Clear(); 02727 rTr.ReadBegin(rLabel); 02728 rStateSet.Name(rLabel); 02729 while(rTr.Peek(token)) { 02730 02731 // break end of section 02732 if(token.IsEnd()) { 02733 break; 02734 } 02735 // read state by index 02736 if(token.IsInteger()) { 02737 rTr.Get(token); 02738 Idx index = token.IntegerValue(); 02739 if(!ExistsState(index)) { 02740 delete attrp; 02741 std::stringstream errstr; 02742 errstr << "Token " << token.IntegerValue() << " not in stateset" 02743 << rTr.FileLine(); 02744 throw Exception("vGenerator::ReadStateSet", errstr.str(), 80); 02745 } 02746 // read attribute 02747 attrp->Read(rTr,"",this); 02748 // skip unknown attributes 02749 AttributeVoid::Skip(rTr); 02750 // insert element with attribute 02751 rStateSet.Insert(index); 02752 rStateSet.Attribute(index,*attrp); 02753 continue; 02754 } 02755 // read state by name 02756 if(token.IsString()) { 02757 rTr.Get(token); 02758 Idx index =StateIndex(token.StringValue()); 02759 if(index==0) { 02760 delete attrp; 02761 std::stringstream errstr; 02762 errstr << "Token " << token.StringValue() << " not in stateset" 02763 << rTr.FileLine(); 02764 throw Exception("vGenerator::ReadStateSet", errstr.str(), 80); 02765 } 02766 // read attribute 02767 attrp->Read(rTr,"",this); 02768 // skip unknown attributes 02769 AttributeVoid::Skip(rTr); 02770 // insert element with attribute 02771 rStateSet.Insert(index); 02772 rStateSet.Attribute(index,*attrp); 02773 continue; 02774 } 02775 // read consecutve block of anonymous states 02776 if(token.IsBegin() && token.StringValue() == "Consecutive") { 02777 rTr.ReadBegin("Consecutive"); 02778 Token token1,token2; 02779 rTr.Get(token1); 02780 rTr.Get(token2); 02781 if(!token1.IsInteger() || !token2.IsInteger()) { 02782 delete attrp; 02783 std::stringstream errstr; 02784 errstr << "Invalid range of consecutive states" << rTr.FileLine(); 02785 throw Exception("vGenerator::ReadStateSet", errstr.str(), 80); 02786 } 02787 for(Idx index = (Idx) token1.IntegerValue(); index <= (Idx) token2.IntegerValue(); ++index) { 02788 if(!ExistsState(index)) { 02789 std::stringstream errstr; 02790 errstr << "Token " << token.IntegerValue() << " not in stateset" 02791 << rTr.FileLine(); 02792 throw Exception("vGenerator::ReadStateSet", errstr.str(), 80); 02793 } 02794 rStateSet.Insert(index); 02795 } 02796 rTr.ReadEnd("Consecutive"); 02797 continue; 02798 } 02799 // cannot process token 02800 delete attrp; 02801 std::stringstream errstr; 02802 errstr << "Invalid token" << rTr.FileLine(); 02803 throw Exception("vGenerator::ReadStateSet", errstr.str(), 50); 02804 } 02805 rTr.ReadEnd(rLabel); 02806 // dispose attribute 02807 delete attrp; 02808 } 02809 02810 // ReadTransRel(rFileName) 02811 void vGenerator::ReadTransRel(const std::string& rFileName) { 02812 TokenReader tr(rFileName); 02813 ReadTransRel(tr); 02814 } 02815 02816 // ReadTransRel(tr) 02817 void vGenerator::ReadTransRel(TokenReader& rTr) { 02818 FD_DG("vGenerator(" << this << ")::ReadTransRel(\"" << rTr.FileName() << "\")"); 02819 AttributeVoid* attrp = mpTransRel->Attribute().New(); 02820 FD_DG("vGenerator(" << this << ")::ReadTransRel(..): attribute type " << typeid(*attrp).name()); 02821 try { 02822 Token token; 02823 rTr.ReadBegin("TransRel"); 02824 // Read tokens 02825 while (rTr.Peek(token)) { 02826 02827 // clear my transition 02828 Idx x1 = 0, ev = 0, x2 = 0; 02829 02830 // 0: end of transition relation 02831 if(token.IsEnd()) break; 02832 02833 02834 // 1: the x1 token 02835 rTr >> token; 02836 if(token.IsInteger()) { 02837 x1=token.IntegerValue(); 02838 } else if (token.IsString()) { 02839 token.StringValue(); 02840 x1=StateIndex(token.StringValue()); 02841 } else break; 02842 02843 // 2: the event token 02844 rTr >> token; 02845 if(token.IsInteger()) { 02846 ev=token.IntegerValue(); 02847 } else if(token.IsString()) { 02848 token.StringValue(); 02849 ev=EventIndex(token.StringValue()); 02850 } else break; 02851 02852 // 3: the x2 token 02853 rTr >> token; 02854 if(token.IsInteger()) { 02855 x2=token.IntegerValue(); 02856 } else if(token.IsString()) { 02857 token.StringValue(); 02858 x2=StateIndex(token.StringValue()); 02859 } else break; 02860 02861 // 4: attributes 02862 attrp->Read(rTr,"",this); 02863 02864 // 5: skip unknown attributes 02865 AttributeVoid::Skip(rTr); 02866 02867 // check values 02868 if(!ExistsState(x1)){ 02869 std::stringstream errstr; 02870 errstr << "invalid state x1 " << x1 << " " << rTr.FileLine(); 02871 throw Exception("vGenerator::ReadTransRel", errstr.str(), 85); 02872 } 02873 if(!ExistsState(x2)){ 02874 std::stringstream errstr; 02875 errstr << "invalid state x2 " << x2 << " " << rTr.FileLine(); 02876 throw Exception("vGenerator::ReadTransRel", errstr.str(), 85); 02877 } 02878 if(!ExistsEvent(ev)) { 02879 std::stringstream errstr; 02880 errstr << "invalid event " << ev << " " << rTr.FileLine(); 02881 throw Exception("vGenerator::ReadTransRel", errstr.str(), 85); 02882 } 02883 02884 // insert transition 02885 Transition trans=Transition(x1,ev,x2); 02886 SetTransition(trans); 02887 TransAttribute(trans,*attrp); 02888 02889 } // end while 02890 rTr.ReadEnd("TransRel"); 02891 } 02892 02893 catch (faudes::Exception& oex) { 02894 delete attrp; 02895 std::stringstream errstr; 02896 errstr << "Reading TransRel failed in " << rTr.FileLine() << oex.What(); 02897 throw Exception("vGenerator::ReadTransRel", errstr.str(), 50); 02898 } 02899 FD_DG("vGenerator(" << this << ")::ReadTransRel(\"" << rTr.FileName() << "\"): sone"); 02900 02901 // dispose attribute 02902 delete attrp; 02903 } 02904 02905 02906 // EStr(index) 02907 std::string vGenerator::EStr(Idx index) const { 02908 return EventName(index); 02909 } 02910 02911 // SStr(index) 02912 std::string vGenerator::SStr(Idx index) const { 02913 std::string name = StateName(index); 02914 if(name == "") name=ToStringInteger(index); 02915 return name+"["+faudes::ToStringInteger(index)+"]"; 02916 } 02917 02918 // TStr(index) 02919 std::string vGenerator::TStr(const Transition& trans) const { 02920 return SStr(trans.X1) + "--(" + EStr(trans.Ev) + ")-->" + SStr(trans.X2); 02921 } 02922 02923 02924 // GraphWrite(rFileName,rOutFormat) 02925 void vGenerator::GraphWrite(const std::string& rFileName, const std::string& rOutFormat, 02926 const std::string& rDotExec) const { 02927 FD_DG("vGenerator::GraphWrite(...): " << typeid(*this).name()); 02928 // generate temp dot ibput file 02929 std::string dotin = CreateTempFile(); 02930 if(dotin == "") { 02931 std::stringstream errstr; 02932 errstr << "Exception opening temp file"; 02933 throw Exception("vGenerator::GraphWrite", errstr.str(), 2); 02934 } 02935 try{ 02936 DotWrite(dotin); 02937 } 02938 catch (faudes::Exception& exception) { 02939 RemoveFile(dotin); 02940 std::stringstream errstr; 02941 errstr << "Exception writing dot input file"; 02942 throw Exception("vGenerator::GraphWrite", errstr.str(), 2); 02943 } 02944 try{ 02945 faudes::ProcessDot(dotin,rFileName,rOutFormat,rDotExec); 02946 } 02947 catch (faudes::Exception& exception) { 02948 RemoveFile(dotin); 02949 std::stringstream errstr; 02950 errstr << "Exception processing dot file"; 02951 throw Exception("vGenerator::GraphWrite", errstr.str(), 3); 02952 } 02953 RemoveFile(dotin); 02954 } 02955 02956 // rti wrapper 02957 bool IsAccessible(const vGenerator& rGen) { 02958 return rGen.IsAccessible(); 02959 } 02960 02961 // rti wrapper 02962 bool IsCoaccessible(const vGenerator& rGen) { 02963 return rGen.IsCoaccessible(); 02964 } 02965 02966 // rti wrapper 02967 bool IsTrim(const vGenerator& rGen) { 02968 return rGen.IsTrim(); 02969 } 02970 02971 // rti wrapper 02972 bool IsOmegaTrim(const vGenerator& rGen) { 02973 return rGen.IsOmegaTrim(); 02974 } 02975 02976 // rti wrapper 02977 bool IsComplete(const vGenerator& rGen) { 02978 return rGen.IsComplete(); 02979 } 02980 02981 // rti wrapper 02982 bool IsComplete(const vGenerator& rGen, const StateSet& rStateSet) { 02983 return rGen.IsComplete(rStateSet); 02984 } 02985 02986 // rti wrapper 02987 bool IsDeterministic(const vGenerator& rGen) { 02988 return rGen.IsDeterministic(); 02989 } 02990 02991 02992 // rti wrapper 02993 void Accessible(vGenerator& rGen) { 02994 rGen.Accessible(); 02995 } 02996 02997 // rti wrapper 02998 void Accessible(const vGenerator& rGen, vGenerator& rRes) { 02999 rRes=rGen; 03000 rRes.Accessible(); 03001 } 03002 03003 // rti wrapper 03004 void Coaccessible(vGenerator& rGen) { 03005 rGen.Coaccessible(); 03006 } 03007 03008 // rti wrapper 03009 void Coaccessible(const vGenerator& rGen, vGenerator& rRes) { 03010 rRes=rGen; 03011 rRes.Coaccessible(); 03012 } 03013 03014 // rti wrapper 03015 void Complete(vGenerator& rGen) { 03016 rGen.Complete(); 03017 } 03018 03019 // rti wrapper 03020 void Complete(const vGenerator& rGen, vGenerator& rRes) { 03021 rRes=rGen; 03022 rRes.Complete(); 03023 } 03024 03025 // rti wrapper 03026 void Trim(vGenerator& rGen) { 03027 rGen.Trim(); 03028 } 03029 03030 // rti wrapper 03031 void Trim(const vGenerator& rGen, vGenerator& rRes) { 03032 rRes=rGen; 03033 rRes.Trim(); 03034 } 03035 03036 // rti wrapper 03037 void OmegaTrim(vGenerator& rGen) { 03038 rGen.OmegaTrim(); 03039 } 03040 03041 // rti wrapper 03042 void OmegaTrim(const vGenerator& rGen, vGenerator& rRes) { 03043 rRes=rGen; 03044 rRes.OmegaTrim(); 03045 } 03046 03047 // rti wrapper 03048 void MarkAllStates(vGenerator& rGen) { 03049 rGen.InjectMarkedStates(rGen.States()); 03050 } 03051 03052 03053 // rti wrapper 03054 void AlphabetExtract(const vGenerator& rGen, EventSet& rRes) { 03055 // This function is an ideal debugging case for lbp_function.cpp. 03056 // FD_WARN("AlphabetExtract(): gen at " << &rGen << " sig at " << &rRes); 03057 // FD_WARN("AlphabetExtract(): gen id " << typeid(rGen).name() << " sig id " << typeid(rRes).name()); 03058 rRes = rGen.Alphabet(); 03059 // rRes.Write(); 03060 } 03061 03062 // rti convenience function 03063 void SetIntersection(const GeneratorVector& rGenVec, EventSet& rRes) { 03064 // prepare result 03065 rRes.Clear(); 03066 // ignore empty 03067 if(rGenVec.Size()==0) return; 03068 // copy first 03069 rRes.Assign(rGenVec.At(0).Alphabet()); 03070 // perform intersecttion 03071 for(GeneratorVector::Position i=1; i<rGenVec.Size(); i++) 03072 SetIntersection(rGenVec.At(i).Alphabet(),rRes,rRes); 03073 } 03074 03075 03076 // rti convenience function 03077 void SetUnion(const GeneratorVector& rGenVec, EventSet& rRes) { 03078 // prepare result 03079 rRes.Clear(); 03080 // ignore empty 03081 if(rGenVec.Size()==0) return; 03082 // copy first 03083 rRes.Assign(rGenVec.At(0).Alphabet()); 03084 // perform intersecttion 03085 for(GeneratorVector::Position i=1; i<rGenVec.Size(); i++) 03086 SetUnion(rGenVec.At(i).Alphabet(),rRes,rRes); 03087 } 03088 03089 // rti convenience function 03090 void SetIntersection(const vGenerator& rGenA, const vGenerator& rGenB, EventSet& rRes) { 03091 SetIntersection(rGenA.Alphabet(),rGenB.Alphabet(),rRes); 03092 } 03093 03094 // rti convenience function 03095 void SetUnion(const vGenerator& rGenA, const vGenerator& rGenB, EventSet& rRes) { 03096 SetUnion(rGenA.Alphabet(),rGenB.Alphabet(),rRes); 03097 } 03098 03099 // rti convenience function 03100 void SetDifference(const vGenerator& rGenA, const vGenerator& rGenB, EventSet& rRes) { 03101 SetDifference(rGenA.Alphabet(),rGenB.Alphabet(),rRes); 03102 } 03103 03104 03105 } // name space 03106 03107 |
libFAUDES 2.18b --- 2010-12-17 --- c++ source docu by doxygen 1.6.3