libFAUDES
Sections
Index
|
cfl_transset.hGo to the documentation of this file.00001 /** @file cfl_transset.h @brief Classes Transition, TTransSet and TaTransSet */ 00002 00003 /* FAU Discrete Event Systems Library (libfaudes) 00004 00005 Copyright (C) 2006 Bernd Opitz 00006 Copyright (C) 2007 Thomas Moor 00007 00008 Exclusive copyright is granted to Klaus Schmidt 00009 00010 This library is free software; you can redistribute it and/or 00011 modify it under the terms of the GNU Lesser General Public 00012 License as published by the Free Software Foundation; either 00013 version 2.1 of the License, or (at your option) any later version. 00014 00015 This library is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 Lesser General Public License for more details. 00019 00020 You should have received a copy of the GNU Lesser General Public 00021 License along with this library; if not, write to the Free Software 00022 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 00023 00024 00025 #ifndef FAUDES_TRANSSET_H 00026 00027 #include <sstream> 00028 #include <map> 00029 #include <iostream> 00030 #include <typeinfo> 00031 00032 #include "cfl_definitions.h" 00033 #include "cfl_baseset.h" 00034 #include "cfl_abaseset.h" 00035 #include "cfl_indexset.h" 00036 #include "cfl_nameset.h" 00037 #include "cfl_attributes.h" 00038 #include "cfl_tokenreader.h" 00039 00040 00041 namespace faudes { 00042 00043 /** @addtogroup ContainerClasses */ 00044 /** @{*/ 00045 00046 /** 00047 * Triple (X1,Ev,X2) to represent current state, event and next state. 00048 * This class provides the triple in struct like fashion where the components 00049 * are of type faudes::Idx. While default order is lexographic, the transition 00050 * container TTransSet allows for alternative sorting. Since technically a 00051 * Transition is just a triple of indices, it is only the context of a generator 00052 * that actually makes it a transition (eg by providing mandatory symbolic event 00053 * names). 00054 */ 00055 class Transition { 00056 00057 public: 00058 00059 /** Construct invalid Transition */ 00060 Transition(void) : X1(0), Ev(0), X2(0) {}; 00061 00062 /** 00063 * Construct from values. 00064 * @param x1 00065 * Index of current state 00066 * @param ev 00067 * Index of Event 00068 * @param x2 00069 * Index of next state 00070 */ 00071 Transition(Idx x1, Idx ev,Idx x2) : 00072 X1(x1), Ev(ev), X2(x2) {} 00073 00074 /** Default order for sorting container of Transition (lexographic) */ 00075 inline bool operator < (const Transition& othertrans) const { 00076 if (X1 < othertrans.X1) return true; 00077 if (X1 > othertrans.X1) return false; 00078 if (Ev < othertrans.Ev) return true; 00079 if (Ev > othertrans.Ev) return false; 00080 if (X2 < othertrans.X2) return true; 00081 return false; 00082 } 00083 00084 /** Equality operator */ 00085 inline bool operator == (const Transition& othertrans) const { 00086 return ((X1 == othertrans.X1) && (Ev == othertrans.Ev) && (X2 == othertrans.X2)); 00087 }; 00088 00089 /** Inequality operator */ 00090 inline bool operator != (const Transition& othertrans) const { 00091 return ((X1 != othertrans.X1) || (Ev != othertrans.Ev) || (X2 != othertrans.X2)); 00092 }; 00093 00094 /** Test validity (all indices !=0 */ 00095 inline bool Valid(void) const { 00096 return (X1!=0) && (Ev!=0) && (X2!=0); 00097 }; 00098 00099 /** Current state */ 00100 Idx X1; 00101 00102 /** Event */ 00103 Idx Ev; 00104 00105 /** Next state */ 00106 Idx X2; 00107 00108 /** Pretty print to string */ 00109 std::string Str(void) const { 00110 return ToStringInteger(X1)+"--("+ToStringInteger(Ev) + ")->" + ToStringInteger(X2);} 00111 }; 00112 00113 00114 00115 00116 /** 00117 * Alternative ordering of Transitions. This class provides binary predicates 00118 * for sorting transition containers by variant lexographic order. 00119 */ 00120 00121 class TransSort { 00122 00123 public: 00124 00125 /** Binary predicate for sorting transitions in order Ev, X1, X2 */ 00126 struct EvX1X2 { 00127 inline bool operator () (const Transition& left, const Transition& right) const { 00128 if (left.Ev < right.Ev) return true; 00129 if (left.Ev > right.Ev) return false; 00130 if (left.X1 < right.X1) return true; 00131 if (left.X1 > right.X1) return false; 00132 if (left.X2 < right.X2) return true; 00133 return false; 00134 } 00135 }; 00136 00137 /** Binary predicate for sorting transitions in order Ev, X2, X1 */ 00138 struct EvX2X1 { 00139 inline bool operator () (const Transition& left, const Transition& right) const { 00140 if (left.Ev < right.Ev) return true; 00141 if (left.Ev > right.Ev) return false; 00142 if (left.X2 < right.X2) return true; 00143 if (left.X2 > right.X2) return false; 00144 if (left.X1 < right.X1) return true; 00145 return false; 00146 } 00147 }; 00148 00149 /** Binary predicate for sorting transitions in order X2, Ev, X1 */ 00150 struct X2EvX1 { 00151 inline bool operator () (const Transition& left, const Transition& right) const { 00152 if (left.X2 < right.X2) return true; 00153 if (left.X2 > right.X2) return false; 00154 if (left.Ev < right.Ev) return true; 00155 if (left.Ev > right.Ev) return false; 00156 if (left.X1 < right.X1) return true; 00157 return false; 00158 } 00159 }; 00160 00161 /** Binary predicate for sorting transitions in order X2, X1, Ev */ 00162 struct X2X1Ev { 00163 inline bool operator () (const Transition& left, const Transition& right) const { 00164 if (left.X2 < right.X2) return true; 00165 if (left.X2 > right.X2) return false; 00166 if (left.X1 < right.X1) return true; 00167 if (left.X1 > right.X1) return false; 00168 if (left.Ev < right.Ev) return true; 00169 return false; 00170 } 00171 }; 00172 00173 /** Binary predicate for sorting transitions in order X1, X2, Ev */ 00174 struct X1X2Ev { 00175 inline bool operator () (const Transition& left, const Transition& right) const { 00176 if (left.X1 < right.X1) return true; 00177 if (left.X1 > right.X1) return false; 00178 if (left.X2 < right.X2) return true; 00179 if (left.X2 > right.X2) return false; 00180 if (left.Ev < right.Ev) return true; 00181 return false; 00182 } 00183 }; 00184 00185 /** Binary predicate for sorting transitions in order X1, Ev, X2 */ 00186 struct X1EvX2 { 00187 inline bool operator () (const Transition& left, const Transition& right) const { 00188 if (left.X1 < right.X1) return true; 00189 if (left.X1 > right.X1) return false; 00190 if (left.Ev < right.Ev) return true; 00191 if (left.Ev > right.Ev) return false; 00192 if (left.X2 < right.X2) return true; 00193 return false; 00194 } 00195 }; 00196 00197 }; 00198 00199 00200 00201 /** 00202 * Set of Transitions. 00203 * 00204 * This container class provides similar functionality and interface as BaseSet, but 00205 * for Transitions rather than indices. The additional feature is a template parameter 00206 * that allows to specify alternative sorting. For algorithms that examine a transition 00207 * relation by e.g. the successor state X2, it may be worthwhile to copy a given 00208 * TTransRel<TransSort::X1EvX2> to a TTransRel<TransSort::X2EvX1>. Example, 00209 * assuming some transition relation is given in default order 00210 * 00211 * \code 00212 * TransSet transrel; // transrel default order X1-Ev-X2 00213 * 00214 * // ... some operation to set up transrel 00215 * 00216 * TTransSet<TransSort::X2EvX1> transByX2; // alternative order X2-Ev-X1 00217 * transrel.ReSort(transByX2); // copy and re-order transrel 00218 * Iterator tit =transByX2.BeginByX2(x2) // begin iterator, X2 specified 00219 * Iterator tit_end=transByX2.EndByX2(x2) // end iterator, X2 specified 00220 * for(; tit!=tit_end; ++tit) { // loop over all transitions with specified x2 00221 * 00222 * // ... code to examine tramsitions with specified x2 00223 * 00224 * } 00225 * 00226 * \endcode 00227 * 00228 * Note that it is the context of a Generator that 00229 * actually allows to interpret a TTransSet as a set of transitions as opposed to 00230 * a set of triples of indices. In particular, file IO of transitions is provided 00231 * by the generator class (although TTransSet provides basic output functions for debugging) 00232 */ 00233 00234 template <class Cmp=TransSort::X1EvX2> 00235 class TTransSet : public virtual TBaseSet<Transition,Cmp> { 00236 00237 FAUDES_TYPE_DECLARATION(TransSet,TTransSet,(TBaseSet<Transition,Cmp>)) 00238 00239 00240 public: 00241 00242 /** @name Constructors & Destructor */ 00243 /** @{ doxygen group */ 00244 00245 /** Construct an empty TTransSet object */ 00246 TTransSet(void); 00247 00248 /** 00249 * Copy-constructor 00250 */ 00251 TTransSet(const TBaseSet<Transition,Cmp>& rOtherSet); 00252 00253 /** 00254 * Re-Sort Copy-constructor 00255 */ 00256 template<class OtherCmp> 00257 TTransSet(const TTransSet<OtherCmp>& res); 00258 00259 /** Virtual destructor */ 00260 virtual ~TTransSet() {}; 00261 00262 00263 /** @} doxygen group */ 00264 00265 00266 /** Iterator on transition */ 00267 typedef typename TBaseSet<Transition, Cmp>::Iterator Iterator; 00268 00269 00270 /** @name Accessing individual transitions */ 00271 /** @{ doxygen group */ 00272 00273 /** 00274 * Add a Transition. 00275 * 00276 * @param rTransition 00277 * Reference to transition object 00278 * @return 00279 * True if the transition was new to the set 00280 * 00281 */ 00282 bool Insert(const Transition& rTransition); 00283 00284 /** 00285 * Add a Transition by indices 00286 * 00287 * @param x1 00288 * Predecessor state 00289 * @param ev 00290 * Event 00291 * @param x2 00292 * Successor state 00293 * @return 00294 * True if the transition was new to the set 00295 * 00296 */ 00297 bool Insert(Idx x1, Idx ev, Idx x2); 00298 00299 /** 00300 * Remove a Transition 00301 * 00302 * @return 00303 * True if transition did exist 00304 */ 00305 bool Erase(const Transition& t); 00306 00307 /** 00308 * Remove a Transition by x1, ev, x2 00309 * 00310 * @return 00311 * True if transition did exist 00312 */ 00313 bool Erase(Idx x1, Idx ev, Idx x2); 00314 00315 /** 00316 * Remove a Transition by iterator 00317 * 00318 * @return 00319 * Iterator to next transition 00320 */ 00321 Iterator Erase(const Iterator& it); 00322 00323 /** 00324 * Remove all transitions containing predecessor state x1. 00325 * 00326 * @param x1 00327 * State index 00328 * @exception Exception 00329 * - sorting mismatch (id 68) 00330 */ 00331 void EraseByX1(Idx x1); 00332 00333 /** 00334 * Remove all transitions containing successor state x2. 00335 * This function iterates over all transitions to work with any sorting. 00336 * 00337 * @param x2 00338 * State index 00339 */ 00340 void EraseByX2(Idx x2); 00341 00342 /** 00343 * Remove all transitions containing event ev. 00344 * This function iterates over all transitions to work with any sorting. 00345 * 00346 * @param ev 00347 * Event index 00348 */ 00349 void EraseByEv(Idx ev); 00350 00351 /** 00352 * Remove all transitions containing state x, 00353 * This function iterates over all transitions to work with any sorting. 00354 * 00355 * @param x 00356 * State index 00357 */ 00358 void EraseByX1OrX2(Idx x); 00359 00360 /** 00361 * Remove all transitions containing a specified state. 00362 * This function iterates over all transitions to work with any sorting. 00363 * 00364 * @param rStates 00365 * Set of states to remore 00366 */ 00367 void EraseByX1OrX2(const StateSet& rStates); 00368 00369 /** 00370 * Find transition given by x1, ev, x2 00371 * 00372 * 00373 * @param x1 00374 * Predecessor state 00375 * @param ev 00376 * Event 00377 * @param x2 00378 * Successor state 00379 * 00380 * @return 00381 * Iterator to transition or End() if not exists 00382 */ 00383 Iterator Find(Idx x1, Idx ev, Idx x2) const; 00384 00385 /** 00386 * Find specified transition 00387 * 00388 * 00389 * @param t 00390 * Transition 00391 * 00392 * @return 00393 * Iterator to transition or End() if not exists 00394 */ 00395 Iterator Find(const Transition& t) const; 00396 00397 00398 /** 00399 * Test existence 00400 * 00401 * @param t 00402 * Transition 00403 * 00404 * @return 00405 * bool 00406 */ 00407 bool Exists(const Transition& t) const; 00408 00409 /** 00410 * Test existence 00411 * 00412 * @param x1 00413 * Predecessor state Idx 00414 * @param ev 00415 * Event Idx 00416 * @param x2 00417 * Successor state Idx 00418 * 00419 * @return 00420 * bool 00421 */ 00422 bool Exists(Idx x1, Idx ev, Idx x2) const; 00423 00424 /** 00425 * Tests if a transition with specified predecessor or successor state 00426 * exists. 00427 * 00428 * @param x 00429 * State Idx 00430 * 00431 * @return 00432 * bool 00433 */ 00434 bool Exists(Idx x) const; 00435 00436 00437 00438 /** @} doxygen group */ 00439 00440 /** @name Transition iterators 00441 * 00442 * A variaty of iterators are provided to examine specified 00443 * segments of the transition relation, e.g. all transitions starting 00444 * from a given state. Note that implemetation of these iterators 00445 * requires the transition set to be of sorted accordingly. Eg. 00446 * scanning all transitions that are labled with a particular event 00447 * requires a sorting TransSOrt::EvX1X2 orT ransSOrt::EvX2X1. 00448 * 00449 * 00450 */ 00451 00452 /** @{ doxygen group: iterators */ 00453 00454 /** 00455 * Iterator to begin of set 00456 * 00457 * @return 00458 * TTransSet<Cmp>::Iterator 00459 */ 00460 Iterator Begin(void) const; 00461 00462 /** 00463 * Iterator to end of set 00464 * 00465 * @return 00466 * TTransSet<Cmp>::Iterator 00467 */ 00468 Iterator End(void) const; 00469 00470 00471 /** 00472 * Iterator to first Transition specified by current state. 00473 * 00474 * @param x1 00475 * Predecessor state index 00476 * 00477 * @return 00478 * TTransSet<Cmp>::Iterator 00479 * 00480 * @exception Exception 00481 * - Sorting mismatch (id 68) 00482 */ 00483 Iterator Begin(Idx x1) const; 00484 00485 /** 00486 * Iterator to end or Transitions with specified current state. 00487 * 00488 * @param x1 00489 * Predecessor state index 00490 * 00491 * @return 00492 * TTransSet<Cmp>::Iterator 00493 * 00494 * @exception Exception 00495 * - Sorting mismatch (id 68) 00496 */ 00497 Iterator End(Idx x1) const; 00498 00499 /** 00500 * Iterator to first Transitions specified by current state and event. 00501 * 00502 * @param x1 00503 * Predecessor state index 00504 * @param ev 00505 * Event index 00506 * 00507 * @return 00508 * TTransSet<Cmp>::Iterator 00509 * 00510 * @exception Exception 00511 * - Sorting mismatch (id 68) 00512 */ 00513 Iterator Begin(Idx x1, Idx ev) const; 00514 00515 /** 00516 * Iterator to first Transition after spcified current state and event. 00517 * 00518 * @param x1 00519 * Predecessor state index 00520 * @param ev 00521 * Event index 00522 * 00523 * @return 00524 * TTransSet<Cmp>::Iterator 00525 * 00526 * @exception Exception 00527 * - sorting mismatch (id 68) 00528 */ 00529 Iterator End(Idx x1, Idx ev) const; 00530 00531 /** 00532 * Iterator to first Transition specified by event. 00533 * This function requires sorting TransSort::EvX1X2 or TransSort::EvX2X1. 00534 * 00535 * @param ev 00536 * Event index 00537 * 00538 * @return 00539 * TTransSet<Cmp>::iterator 00540 * 00541 * @exception Exception 00542 * - sorting mismatch (id 68) 00543 */ 00544 Iterator BeginByEv(Idx ev) const; 00545 00546 /** 00547 * Iterator to first Transition after specified by event. 00548 * This function requires sorting TransSort::EvX1X2 or TransSort::EvX2X1 00549 * 00550 * @param ev 00551 * Predecessor state index 00552 * 00553 * @return 00554 * TTransSet<Cmp>::Iterator 00555 * 00556 * @exception Exception 00557 * - sorting mismatch (id 68) 00558 */ 00559 Iterator EndByEv(Idx ev) const; 00560 00561 /** 00562 * Iterator to first Transition specified by event and current state. 00563 * This function requires sorting TransSort::EvX1X2. 00564 * 00565 * @param ev 00566 * Event index 00567 * @param x1 00568 * Predecessor state index 00569 * 00570 * @return 00571 * TTransSet<Cmp>::iterator 00572 * 00573 * @exception Exception 00574 * - sorting mismatch (id 68) 00575 */ 00576 Iterator BeginByEvX1(Idx ev, Idx x1) const; 00577 00578 /** 00579 * Iterator to first Transition after specified ev and current state. 00580 * This function requires sorting TransSort::EvX1X2. 00581 * 00582 * @param ev 00583 * Event index 00584 * @param x1 00585 * Predecessor state index 00586 * 00587 * @return 00588 * TTransSet<Cmp>::Iterator 00589 * 00590 * @exception Exception 00591 * - sorting mismatch (id 68) 00592 */ 00593 Iterator EndByEvX1(Idx ev, Idx x1) const; 00594 00595 /** 00596 * Iterator to first Transition specified by event and next state. 00597 * This function requires sorting TransSort::EvX2X1. 00598 * 00599 * @param ev 00600 * Event index 00601 * @param x2 00602 * Predecessor state index 00603 * 00604 * @return 00605 * TTransSet<Cmp>::Iterator 00606 * 00607 * @exception Exception 00608 * - sorting mismatch (id 68) 00609 */ 00610 Iterator BeginByEvX2(Idx ev, Idx x2) const; 00611 00612 /** 00613 * Iterator to first Transition after specified event and next state. 00614 * This function requires sorting TransSort::EvX2X1. 00615 * 00616 * @param ev 00617 * Event index 00618 * @param x2 00619 * Predecessor state index 00620 * 00621 * @return 00622 * TTransSet<Cmp>::Iterator 00623 * 00624 * @exception Exception 00625 * - sorting mismatch (id 68) 00626 */ 00627 Iterator EndByEvX2(Idx ev, Idx x2) const; 00628 00629 /** 00630 * Iterator to first Transition specified by successor state x2. 00631 * This function requires sorting TransSort::X2EvX1 or TransSort::X2X1Ev. 00632 * 00633 * @param x2 00634 * Predecessor state index 00635 * 00636 * @return 00637 * TTransSet<Cmp>::iterator 00638 * 00639 * @exception Exception 00640 * - sorting mismatch (id 68) 00641 */ 00642 Iterator BeginByX2(Idx x2) const; 00643 00644 /** 00645 * Iterator to first Transition after specified successor state x2. 00646 * This function requires sorting TransSort::X2EvX1 or TransSort::X2X1Ev 00647 * 00648 * @param x2 00649 * Predecessor state index 00650 * 00651 * @return 00652 * TTransSet<Cmp>::Iterator 00653 * 00654 * @exception Exception 00655 * - sorting mismatch (id 68) 00656 */ 00657 Iterator EndByX2(Idx x2) const; 00658 00659 /** 00660 * Iterator to first Transition specified by successor x2 and ev. 00661 * This function requires sorting TransSort::X2EvX1. 00662 * 00663 * @param x2 00664 * Predecessor state index 00665 * @param ev 00666 * Event index 00667 * 00668 * @return 00669 * TTransSet<Cmp>::Iterator 00670 * 00671 * @exception Exception 00672 * - sorting mismatch (id 68) 00673 */ 00674 Iterator BeginByX2Ev(Idx x2, Idx ev) const; 00675 00676 /** 00677 * Iterator to first Transition after specified successor x2 and ev. 00678 * This function requires sorting TransSort::X2EvX1. 00679 * 00680 * @param x2 00681 * Predecessor state index 00682 * @param ev 00683 * Event index 00684 * 00685 * @return 00686 * TTransSet<Cmp>::Iterator 00687 * 00688 * @exception Exception 00689 * - sorting mismatch (id 68) 00690 */ 00691 Iterator EndByX2Ev(Idx x2, Idx ev) const; 00692 00693 /** @} doxygen group */ 00694 00695 /** @name Misc */ 00696 /** @{ doxygen group */ 00697 00698 /** 00699 * Get copy of trantision relation sorted by other compare 00700 * operator, e.g. TSort::X2EvX1 00701 * 00702 * @return 00703 * Transition relation 00704 */ 00705 template<class OtherCmp> 00706 void ReSort(TTransSet<OtherCmp>& res) const; 00707 00708 /** 00709 * Get state space covered by transition set 00710 * 00711 * @return 00712 * Set of state indices used by some transition 00713 */ 00714 StateSet StateSpace(void) const; 00715 00716 /** 00717 * Get set of successor states for specified current state 00718 * 00719 * @param x1 00720 * Current state 00721 * 00722 * @return 00723 * Set of state indices 00724 */ 00725 StateSet StateSpaceX2(Idx x1) const; 00726 00727 /** 00728 * Get set of successor states for specified current state and event 00729 * 00730 * @param x1 00731 * Current state 00732 * @param ev 00733 * Event 00734 * 00735 * @return 00736 * Set of state indices 00737 */ 00738 StateSet StateSpaceX2(Idx x1, Idx ev) const; 00739 00740 /** 00741 * Get set of events that are active for a specified current state 00742 * Since a transition set does not refer to a SymbolTable, this function 00743 * returns a set of plain indices. In order to interpret the set as an EventSet, 00744 * the relevant SymbolTable must be supplied as second argument. If obmitting the second 00745 * argument, the defult SymbolTable is used. 00746 * 00747 * @param x1 00748 * Current state 00749 * @param pSymTab 00750 * SymbolTable to refer to 00751 * 00752 * @return 00753 * Set of events. 00754 */ 00755 EventSet ActiveEvents(Idx x1, SymbolTable* pSymTab=NULL) const; 00756 00757 /** 00758 * Return pretty printable string representation. 00759 * Primary meant for debugging messages. 00760 * 00761 * @param rTrans 00762 * Transition to print 00763 * 00764 * @return 00765 * String 00766 */ 00767 std::string Str(const Transition& rTrans) const { return rTrans.Str();} ; 00768 00769 00770 /** @} doxygen group */ 00771 00772 protected: 00773 00774 00775 /** 00776 * Assign my members. 00777 * 00778 * @param rSource 00779 * Source to copy from 00780 * @return 00781 * Ref to this set 00782 */ 00783 virtual void DoAssign(const TTransSet& rSource); 00784 00785 /** 00786 * Write to TokenWriter, see Type::Write for public wrappers. 00787 * 00788 * @param rTw 00789 * Reference to TokenWriter 00790 * @param rLabel 00791 * Label of section to write, defaults to name of set 00792 * @param pContext 00793 * Write context eg symboltables 00794 * 00795 * @exception Exception 00796 * - IO errors (id 2) 00797 */ 00798 00799 virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="", const Type* pContext=0) const; 00800 00801 00802 }; 00803 00804 /** Type definition for default sorted TTransSet */ 00805 typedef TTransSet<TransSort::X1EvX2> TransSet; 00806 00807 /** Type definition for default sorted TTransSet */ 00808 typedef TTransSet<TransSort::X1EvX2> TransSetX1EvX2; 00809 00810 /** Type definition for ev, x1, x2 sorted TTransSet */ 00811 typedef TTransSet<TransSort::EvX1X2> TransSetEvX1X2; 00812 00813 /** Type definition for ev, x2, x1 sorted TTransSet */ 00814 typedef TTransSet<TransSort::EvX2X1> TransSetEvX2X1; 00815 00816 /** Type definition for x2, ev, x1 sorted TTransSet */ 00817 typedef TTransSet<TransSort::X2EvX1> TransSetX2EvX1; 00818 00819 /** Type definition for x2, x1, ev sorted TTransSet */ 00820 typedef TTransSet<TransSort::X2X1Ev> TransSetX2X1Ev; 00821 00822 /** Type definition for x1, x2, ev sorted TTransSet */ 00823 typedef TTransSet<TransSort::X1X2Ev> TransSetX1X2Ev; 00824 00825 00826 /** 00827 * Set of Transitions with attributes. 00828 * 00829 * This container class is derived from TTransSet to provide attributes as an 00830 * additional feature. As with TaBaseSet, the template parameter specifies the attribute class, 00831 * which in turn must provide some basic funtionality. In contrast to the TTransSet, the TaTransSet 00832 * is restricted to standard ordering. 00833 * 00834 * Note that it is the context of a Generator that 00835 * actually allows to interpret a TaTransSet as a set of transitions as opposed to 00836 * a set of triples of indices with attributes. In particular, file IO of transitions is provided 00837 * by the generator class (although TaTransSet provides output functions for debugging) 00838 */ 00839 00840 00841 template <class Attr> 00842 class TaTransSet : public TransSet, public TaBaseSet<Transition,Attr,TransSort::X1EvX2> { 00843 00844 FAUDES_TYPE_DECLARATION(Void,TaTransSet,TransSet) 00845 00846 public: 00847 00848 00849 /** @name Constructors & Destructor */ 00850 /** @{ doxygen group */ 00851 00852 /** Construct an empty TaTransSet object */ 00853 TaTransSet(void); 00854 00855 /** 00856 * Copy-constructor (incl attributes) 00857 */ 00858 TaTransSet(const TaTransSet& rOtherSet); 00859 00860 /** 00861 * Copy-Constructor (set attributes to default) 00862 */ 00863 TaTransSet(const TTransSet<TransSort::X1EvX2>& rOtherSet); 00864 00865 /** Virtual destructor */ 00866 virtual ~TaTransSet() {} 00867 00868 /** Relaxed assignment method. Maintains attributes provided they can be casted. 00869 * 00870 * @param rSrc 00871 * Source from which to assign 00872 * @return 00873 * Ref to this set 00874 */ 00875 virtual TaTransSet& Assign(const TransSet& rSrc); 00876 00877 /** Relaxed assignment operator. Maintains attributes provided they can be casted. 00878 * 00879 * @param rSrc 00880 * Source from which to assign 00881 * @return 00882 * Ref to this set 00883 */ 00884 virtual TaTransSet& operator=(const TransSet& rSrc); 00885 00886 /** @} doxygen group */ 00887 00888 00889 00890 /** @name Accessing individual transitions */ 00891 /** @{ doxygen group */ 00892 00893 /** Clear all transitions incl attributes */ 00894 void Clear(void); 00895 00896 /** Iterator on transition */ 00897 typedef typename TTransSet<TransSort::X1EvX2>::Iterator Iterator; 00898 00899 /** 00900 * Add a Transition by indices 00901 * 00902 * @param x1 00903 * Predecessor state 00904 * @param ev 00905 * Event 00906 * @param x2 00907 * Successor state 00908 * 00909 * @return 00910 * True if the transition was new to the set 00911 */ 00912 bool Insert(Idx x1, Idx ev, Idx x2); 00913 00914 /** 00915 * Add a Transition directly. If the transition already 00916 * exists, the attribute is maintained. Otherwise, the transition 00917 * is inserted with default attribute. 00918 * 00919 * @param rTransition 00920 * Reference to transition object 00921 * 00922 * @return 00923 * True if the transition was new to the set 00924 */ 00925 bool Insert(const Transition& rTransition); 00926 00927 /** 00928 * Add a Transition with attribute. 00929 * 00930 * @param rTransition 00931 * Reference to transition object 00932 * @param rAttr 00933 * Reference to attribute 00934 * 00935 * @return 00936 * True if the transition was new to the set 00937 */ 00938 bool Insert(const Transition& rTransition, const Attr& rAttr); 00939 00940 /** 00941 * Inserts transitions of rOtherSet. 00942 * Attributes of this set are maintained, newly inserted transitions have default attribute. 00943 * 00944 * 00945 * @param rOtherSet 00946 * Other IndexSet 00947 */ 00948 virtual void InsertSet(const TransSet& rOtherSet); 00949 00950 /** 00951 * Inserts transitions of rOtherSet. 00952 * Attributes of this set are maintained, new transitions are inserted with attribute. 00953 * 00954 * @param rOtherSet 00955 * Other IndexSet 00956 */ 00957 virtual void InsertSet(const TaTransSet& rOtherSet); 00958 00959 /** 00960 * Remove a Transition 00961 * 00962 * @return 00963 * True if transition did exist 00964 */ 00965 bool Erase(const Transition& t); 00966 00967 /** 00968 * Remove a Transition 00969 * 00970 * @return 00971 * True if transition did exist 00972 */ 00973 bool Erase(Idx x1, Idx ev, Idx x2); 00974 00975 /** 00976 * Remove a Transition by iterator 00977 * 00978 * @return 00979 * Iterator to next transition 00980 */ 00981 Iterator Erase(const Iterator& it); 00982 00983 /** 00984 * Remove all transitions containing predecessor state x1. 00985 * 00986 * @param x1 00987 * State index 00988 */ 00989 void EraseByX1(Idx x1); 00990 00991 /** 00992 * Remove all transitions containing successor state x2. 00993 * 00994 * @param x2 00995 * State index 00996 */ 00997 void EraseByX2(Idx x2); 00998 00999 /** 01000 * Remove all transitions containing event ev. 01001 * 01002 * @param ev 01003 * Event index 01004 */ 01005 void EraseByEv(Idx ev); 01006 01007 /** 01008 * Remove all transitions containing state x. 01009 * 01010 * @param x 01011 * State index 01012 */ 01013 void EraseByX1OrX2(Idx x); 01014 01015 /** 01016 * Remove all transitions containing a specified state. 01017 * This function iterates over all transitions to work with any sorting. 01018 * 01019 * @param rStateSet 01020 * Set of states to remore 01021 */ 01022 void EraseByX1OrX2(const StateSet& rStateSet); 01023 01024 01025 /** 01026 * Erase elements given by other set. This function 01027 * ignores the attributes of the other set and maintains the attributes 01028 * of the remaining elements in this set. 01029 * 01030 * @param rOtherSet 01031 * Elements to erase 01032 */ 01033 void EraseSet(const TransSet& rOtherSet); 01034 01035 /** 01036 * Restrict to specified subset. Erases any elements no in 01037 * the specified set. This function 01038 * ignores the attributes of the other set and maintains the attributes 01039 * of the remaining elements in this set. 01040 * 01041 * @param rOtherSet 01042 * Elements to erase 01043 */ 01044 void RestrictSet(const TransSet& rOtherSet); 01045 01046 01047 /** 01048 * Set attributes. Provided that rOtherSet has attributes that can be 01049 * casted to the appropriate type, attributes are copied per element from rOtherSet. 01050 * Elements of this set which are not in rOtherSet maintain their attribute. 01051 * 01052 * @param rOtherSet 01053 * Other IndexSet 01054 * @exception Exception 01055 * - Element does not exist (63) 01056 * - Cannot cast attribute type (63) 01057 */ 01058 virtual void Attributes(const TransSet& rOtherSet); 01059 01060 /** 01061 * Set attributes. Attributes are copied per element from rOtherSet. 01062 * Elements of this set which are not in rOtherSet maintain their attribute. 01063 * 01064 * @param rOtherSet 01065 * Other IndexSet 01066 */ 01067 virtual void Attributes(const TaTransSet& rOtherSet); 01068 01069 01070 /** @} doxygen group */ 01071 01072 01073 protected: 01074 01075 /** 01076 * Assign my members. Maintain attributes. 01077 * 01078 * @param rSource 01079 * Source to copy from 01080 * @return 01081 * Ref to this set 01082 */ 01083 virtual void DoAssign(const TaTransSet& rSource); 01084 01085 }; 01086 01087 /** @} doxygen group*/ 01088 01089 01090 /* 01091 ************************************************************************************************* 01092 ************************************************************************************************* 01093 * Implementation of transset without attributes 01094 ************************************************************************************************* 01095 ************************************************************************************************* 01096 */ 01097 01098 01099 /* convenience access to relevant scopes */ 01100 #define THIS TTransSet<Cmp> 01101 #define TEMP template<class Cmp> 01102 #define BASE TBaseSet<Transition,Cmp> 01103 01104 // std faudes type 01105 FAUDES_TYPE_TIMPLEMENTATION(TransSet,THIS,BASE,TEMP) 01106 01107 // TTransSet(void) 01108 TEMP THIS::TTransSet(void) : BASE() 01109 { 01110 FD_DC("TTransSet(" << this << ")::TTransSet()"); 01111 } 01112 01113 // TTransSet(othertransrel) 01114 TEMP THIS::TTransSet(const TBaseSet<Transition,Cmp>& rOtherSet) : 01115 BASE() 01116 { 01117 FD_DC("TTransSet(" << this << ")::TTransSet(rOtherSet "<< &rOtherSet <<")"); 01118 Assign(rOtherSet); 01119 } 01120 01121 // TTransSet(othertransrel othersort) 01122 TEMP template<class OtherCmp> 01123 THIS::TTransSet(const TTransSet<OtherCmp>& rOtherSet) : 01124 BASE() 01125 { 01126 FD_DC("TTransSet(" << this << ")::TTransSet(rOtherSet/ReSort "<< &rOtherSet <<")"); 01127 rOtherSet.ReSort(*this); 01128 } 01129 01130 // assignment (maintain/cast attributes) 01131 TEMP void THIS::DoAssign(const TTransSet& rSourceSet) { 01132 FD_DC("TTransSet(" << this << ")::DoAssign(..)"); 01133 // call base; incl virtual clear incl attributes 01134 BASE::DoAssign(rSourceSet); 01135 } 01136 01137 // iterator Begin() const 01138 TEMP typename THIS::Iterator THIS::Begin(void) const { 01139 return BASE::Begin(); 01140 } 01141 01142 // iterator End() const 01143 TEMP typename THIS::Iterator THIS::End(void) const { 01144 return BASE::End(); 01145 } 01146 01147 01148 // Convenience macro for order typecheck 01149 #define SORT_EXCEPTION { std::stringstream errstr; \ 01150 errstr << "Transition set order mismatch " << std::endl; \ 01151 throw Exception("TransSet::Iterator()", errstr.str(), 68); } 01152 01153 01154 // iterator Begin(x1) const 01155 TEMP typename THIS::Iterator THIS::Begin(Idx x1) const { 01156 #ifdef FAUDES_CHECKED 01157 if(typeid(Cmp)!=typeid(TransSort::X1EvX2)) 01158 if(typeid(Cmp)!=typeid(TransSort::X1X2Ev)) 01159 SORT_EXCEPTION; 01160 #endif 01161 Transition tlx(x1,0,0); 01162 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01163 } 01164 01165 // iterator End(x1) const 01166 TEMP typename THIS::Iterator THIS::End(Idx x1) const { 01167 #ifdef FAUDES_CHECKED 01168 if(typeid(Cmp)!=typeid(TransSort::X1EvX2)) 01169 if(typeid(Cmp)!=typeid(TransSort::X1X2Ev)) 01170 SORT_EXCEPTION; 01171 #endif 01172 Transition tlx(x1+1,0,0); 01173 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01174 } 01175 01176 // iterator Begin(x1,ev) const 01177 TEMP typename THIS::Iterator THIS::Begin(Idx x1, Idx ev) const { 01178 #ifdef FAUDES_CHECKED 01179 if(typeid(Cmp)!=typeid(TransSort::X1EvX2)) 01180 SORT_EXCEPTION; 01181 #endif 01182 Transition tlx(x1,ev,0); 01183 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01184 } 01185 01186 // iterator End(x1,ev) const 01187 TEMP typename THIS::Iterator THIS::End(Idx x1, Idx ev) const { 01188 #ifdef FAUDES_CHECKED 01189 if(typeid(Cmp)!=typeid(TransSort::X1EvX2)) 01190 SORT_EXCEPTION; 01191 #endif 01192 Transition tlx(x1,ev+1, 0); 01193 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01194 } 01195 01196 // iterator BeginByEv(ev) const 01197 TEMP typename THIS::Iterator THIS::BeginByEv(Idx ev) const { 01198 #ifdef FAUDES_CHECKED 01199 if(typeid(Cmp)!=typeid(TransSort::EvX1X2)) 01200 if(typeid(Cmp)!=typeid(TransSort::EvX2X1)) 01201 SORT_EXCEPTION; 01202 #endif 01203 Transition tlx(0,ev,0); 01204 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01205 } 01206 01207 // iterator EndByEv(ev) const 01208 TEMP typename THIS::Iterator THIS::EndByEv(Idx ev) const { 01209 #ifdef FAUDES_CHECKED 01210 if(typeid(Cmp)!=typeid(TransSort::EvX1X2)) 01211 if(typeid(Cmp)!=typeid(TransSort::EvX2X1)) 01212 SORT_EXCEPTION; 01213 #endif 01214 Transition tlx(0,ev+1,0); 01215 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01216 } 01217 01218 // iterator BeginByEvX1(ev,x1) const 01219 TEMP typename THIS::Iterator THIS::BeginByEvX1(Idx ev, Idx x1) const { 01220 #ifdef FAUDES_CHECKED 01221 if(typeid(Cmp)!=typeid(TransSort::EvX1X2)) 01222 SORT_EXCEPTION; 01223 #endif 01224 Transition tlx(x1,ev,0); 01225 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01226 } 01227 01228 // iterator EndByEvX1(ev,x1) const 01229 TEMP typename THIS::Iterator THIS::EndByEvX1(Idx ev, Idx x1) const { 01230 #ifdef FAUDES_CHECKED 01231 if(typeid(Cmp)!=typeid(TransSort::EvX1X2)) 01232 SORT_EXCEPTION; 01233 #endif 01234 Transition tlx(x1+1,ev,0); 01235 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01236 } 01237 01238 // iterator BeginByEvX2(ev,x2) const 01239 TEMP typename THIS::Iterator THIS::BeginByEvX2(Idx ev, Idx x2) const { 01240 #ifdef FAUDES_CHECKED 01241 if(typeid(Cmp)!=typeid(TransSort::EvX2X1)) 01242 SORT_EXCEPTION; 01243 #endif 01244 Transition tlx(0,ev,x2); 01245 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01246 } 01247 01248 // iterator EndByEvX2(ev,x2) const 01249 TEMP typename THIS::Iterator THIS::EndByEvX2(Idx ev, Idx x2) const { 01250 #ifdef FAUDES_CHECKED 01251 if(typeid(Cmp)!=typeid(TransSort::EvX2X1)) 01252 SORT_EXCEPTION; 01253 #endif 01254 Transition tlx(0,ev,x2+1); 01255 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01256 } 01257 01258 // iterator BeginByX2(x2) const 01259 TEMP typename THIS::Iterator THIS::BeginByX2(Idx x2) const { 01260 #ifdef FAUDES_CHECKED 01261 if(typeid(Cmp)!=typeid(TransSort::X2EvX1)) 01262 if(typeid(Cmp)!=typeid(TransSort::X2X1Ev)) 01263 SORT_EXCEPTION; 01264 #endif 01265 Transition tlx(0,0,x2); 01266 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01267 } 01268 01269 // iterator EndByX2(x2) const 01270 TEMP typename THIS::Iterator THIS::EndByX2(Idx x2) const { 01271 #ifdef FAUDES_CHECKED 01272 if(typeid(Cmp)!=typeid(TransSort::X2EvX1)) 01273 if(typeid(Cmp)!=typeid(TransSort::X2X1Ev)) 01274 SORT_EXCEPTION; 01275 #endif 01276 Transition tlx(0,0,x2+1); 01277 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01278 } 01279 01280 // iterator BeginByX2Ev(x2,ev) const 01281 TEMP typename THIS::Iterator THIS::BeginByX2Ev(Idx x2, Idx ev) const { 01282 #ifdef FAUDES_CHECKED 01283 if(typeid(Cmp)!=typeid(TransSort::X2EvX1)) 01284 SORT_EXCEPTION; 01285 #endif 01286 Transition tlx(0,ev,x2); 01287 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01288 } 01289 01290 // iterator EndByX2Ev(x2,ev) const 01291 TEMP typename THIS::Iterator THIS::EndByX2Ev(Idx x2, Idx ev) const { 01292 #ifdef FAUDES_CHECKED 01293 if(typeid(Cmp)!=typeid(TransSort::X2EvX1)) 01294 SORT_EXCEPTION; 01295 #endif 01296 Transition tlx(0,ev+1,x2); 01297 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01298 } 01299 01300 01301 01302 // DoWrite(rw,label) 01303 TEMP void THIS::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const 01304 { 01305 (void) pContext; 01306 std::string label=rLabel; 01307 if(label=="") label=BASE::Name(); 01308 rTw.WriteBegin(label); 01309 int oldcolumns = rTw.Columns(); 01310 rTw.Columns(3); 01311 01312 Iterator tit; 01313 for (tit = Begin(); tit != End(); ++tit) { 01314 rTw << tit->X1; rTw << tit->Ev; rTw << tit->X2; 01315 } 01316 01317 rTw.WriteEnd(label); 01318 rTw.Columns(oldcolumns); 01319 } 01320 01321 01322 // Insert(transition) 01323 TEMP bool THIS::Insert(const Transition& t) { 01324 return BASE::Insert(t); 01325 } 01326 01327 // Insert(x1,ev,x2) 01328 TEMP bool THIS::Insert(Idx x1, Idx ev, Idx x2) { 01329 FD_DC("TTransSet(" << this << ")::Insert(" << x1 << "-" << ev << "-" << x2 << ")"); 01330 return BASE::Insert(Transition(x1, ev, x2)); 01331 } 01332 01333 // Erase(transition) 01334 TEMP bool THIS::Erase(const Transition& t) { 01335 return BASE::Erase(t); 01336 } 01337 01338 // Erase(x1,ev,x2) 01339 TEMP bool THIS::Erase(Idx x1, Idx ev, Idx x2) { 01340 FD_DC("TTransSet(" << this << ")::Erase(" << x1 << "-" << ev << "-" << x2 << ")"); 01341 return BASE::Erase(Transition(x1, ev, x2)); 01342 } 01343 01344 // Erase(it) 01345 TEMP typename THIS::Iterator THIS::Erase(const Iterator& it) { 01346 FD_DC("TTransSet(" << this << ")::Erase(" << it->X1 << "-" << it->Ev 01347 << "-" << it->X2 << ")"); 01348 return BASE::Erase(it); 01349 } 01350 01351 // EraseByX1(x) 01352 TEMP void THIS::EraseByX1(Idx x1) { 01353 FD_DC("TTransSet(" << this << ")::EraseByX1(" << x1 << ")"); 01354 #ifdef FAUDES_CHECKED 01355 if(typeid(Cmp)!=typeid(TransSort::X1EvX2)) 01356 if(typeid(Cmp)!=typeid(TransSort::X1X2Ev)) 01357 SORT_EXCEPTION; 01358 #endif 01359 this->Detach(); 01360 typename BASE::iterator lower, upper, it; 01361 Transition tl(x1,0,0); 01362 Transition tu(x1+1,0,0); 01363 lower = BASE::pSet->lower_bound(tl); 01364 upper = BASE::pSet->upper_bound(tu); 01365 BASE::pSet->erase(lower, upper); 01366 } 01367 01368 // EraseByX2(x) 01369 TEMP void THIS::EraseByX2(Idx x2) { 01370 FD_DC("TTransSet(" << this << ")::EraseByX2(" << x2 << ")"); 01371 this->Detach(); 01372 typename BASE::iterator it, tmpit; 01373 for(it = BASE::pSet->begin(); it != BASE::pSet->end();) { 01374 if (it->X2 == x2) { 01375 tmpit = it; 01376 it++; 01377 BASE::pSet->erase(tmpit); 01378 continue; 01379 } 01380 it++; 01381 } 01382 } 01383 01384 // EraseByEv(ev) 01385 TEMP void THIS::EraseByEv(Idx ev) { 01386 FD_DC("TTransSet(" << this << ")::EraseByEv(" << ev << ")"); 01387 this->Detach(); 01388 typename BASE::iterator it, tmpit; 01389 for(it = BASE::pSet->begin(); it != BASE::pSet->end();) { 01390 if (it->Ev == ev) { 01391 tmpit = it; 01392 it++; 01393 BASE::pSet->erase(tmpit); 01394 continue; 01395 } 01396 it++; 01397 } 01398 } 01399 01400 01401 01402 // EraseByX1OrX2(x) 01403 TEMP void THIS::EraseByX1OrX2(Idx x) { 01404 FD_DC("TTransSet(" << this << ")::EraseByX1OrX2(" << x << ")"); 01405 this->Detach(); 01406 typename BASE::iterator it, tmpit; 01407 for(it = BASE::pSet->begin(); it != BASE::pSet->end();) { 01408 if ((it->X1 == x) || (it->X2 == x)) { 01409 tmpit = it; 01410 it++; 01411 BASE::pSet->erase(tmpit); 01412 continue; 01413 } 01414 it++; 01415 } 01416 FD_DC("TTransSet(" << this << ")::EraseByX1OrX2(" << x << "): done"); 01417 } 01418 01419 01420 // EraseByX1OrX2(xset) 01421 TEMP void THIS::EraseByX1OrX2(const StateSet& rStates) { 01422 FD_DC("TTransSet(" << this << ")::EraseByX1OrX2(#" << rStates.Size() <<")"); 01423 this->Detach(); 01424 typename BASE::iterator it, tmpit; 01425 for(it = BASE::pSet->begin(); it != BASE::pSet->end();) { 01426 if(rStates.Exists(it->X1) || rStates.Exists(it->X2)) { 01427 tmpit = it; 01428 it++; 01429 BASE::pSet->erase(tmpit); 01430 continue; 01431 } 01432 it++; 01433 } 01434 FD_DC("TTransSet(" << this << ")::EraseByX1OrX2(): done"); 01435 } 01436 01437 01438 // iterator Find(x1,ev,x2) 01439 TEMP typename THIS::Iterator THIS::Find(Idx x1, Idx ev, Idx x2) const { 01440 return BASE::Find(Transition(x1,ev,x2)); 01441 } 01442 01443 01444 // iterator Find(t) 01445 TEMP typename THIS::Iterator THIS::Find(const Transition& t) const{ 01446 return BASE::Find(t); 01447 } 01448 01449 // Exists(t) 01450 TEMP bool THIS::Exists(const Transition& t) const { 01451 return BASE::Exists(t); 01452 } 01453 01454 // Exists(x1, ev, x2) 01455 TEMP bool THIS::Exists(Idx x1, Idx ev, Idx x2) const { 01456 return BASE::Exists(Transition(x1,ev,x2)); 01457 } 01458 01459 // Exists(x) 01460 TEMP bool THIS::Exists(Idx x) const { 01461 typename BASE::iterator it; 01462 for(it = BASE::pSet->begin(); it != BASE::pSet->end(); ++it) { 01463 if ((it->X1 == x) || (it->X2 == x)) { 01464 return true; 01465 } 01466 } 01467 return false; 01468 } 01469 01470 01471 01472 // ReSort(res) 01473 TEMP template<class OtherCmp> 01474 void THIS::ReSort(TTransSet<OtherCmp>& res) const { 01475 Iterator it; 01476 res.Clear(); 01477 for (it = Begin(); it != End(); ++it) { 01478 res.Insert(*it); 01479 } 01480 } 01481 01482 // StateSpace() 01483 TEMP StateSet THIS::StateSpace(void) const { 01484 StateSet states; 01485 Iterator it; 01486 for (it=Begin(); it!=End(); ++it) { 01487 states.Insert(it->X1); 01488 states.Insert(it->X2); 01489 } 01490 return states; 01491 } 01492 01493 // StateSpaceX2(x1) 01494 TEMP StateSet THIS::StateSpaceX2(Idx x1) const { 01495 StateSet states; 01496 Iterator it = Begin(x1); 01497 Iterator it_end = End(x1); 01498 while (it != it_end) { 01499 states.Insert(it->X2); 01500 ++it; 01501 } 01502 return states; 01503 } 01504 01505 // StateSpaceX2(x1, ev) 01506 TEMP StateSet THIS::StateSpaceX2(Idx x1, Idx ev) const { 01507 StateSet states; 01508 Iterator it = Begin(x1, ev); 01509 Iterator it_end = End(x1, ev); 01510 while (it != it_end) { 01511 states.Insert(it->X2); 01512 ++it; 01513 } 01514 return states; 01515 } 01516 01517 // ActiveEvents(x1,pSymTab) 01518 TEMP EventSet THIS::ActiveEvents(Idx x1, SymbolTable* pSymTab) const { 01519 Iterator it = Begin(x1); 01520 Iterator it_end = End(x1); 01521 EventSet result; 01522 if(pSymTab!=NULL) result.SymbolTablep(pSymTab); 01523 for (; it != it_end; ++it) { 01524 result.Insert(it->Ev); 01525 } 01526 return result; 01527 } 01528 01529 01530 #undef THIS 01531 #undef TEMP 01532 #undef BASE 01533 01534 /* 01535 ************************************************************************************************* 01536 ************************************************************************************************* 01537 * Implementation of transset with attributes 01538 ************************************************************************************************* 01539 ************************************************************************************************* 01540 */ 01541 01542 01543 /* convenience access to relevant scopes */ 01544 #define THIS TaTransSet<Attr> 01545 #define TEMP template <class Attr> 01546 #define BASE TTransSet<TransSort::X1EvX2> 01547 #define ABASE TaBaseSet<Transition,Attr,TransSort::X1EvX2> 01548 #define VBASE TBaseSet<Transition,TransSort::X1EvX2> 01549 01550 // std faudes type 01551 FAUDES_TYPE_TIMPLEMENTATION(Void,THIS,BASE,TEMP) 01552 01553 // TaTransSet(void) 01554 TEMP THIS::TaTransSet(void) : 01555 VBASE(), 01556 BASE(), 01557 ABASE() 01558 { 01559 FD_DC("TaTransSet(" << this << ")::TaTransSet()"); 01560 } 01561 01562 // TaTransSet(othertransrel) 01563 TEMP THIS::TaTransSet(const TaTransSet& rOtherSet) : 01564 VBASE(), 01565 BASE(), 01566 ABASE() 01567 { 01568 FD_DC("TaTransSet(" << this << ")::TaTransSet(rOtherSet "<< &rOtherSet <<")"); 01569 DoAssign(rOtherSet); 01570 } 01571 01572 01573 // TaTransSet(othertransrel) 01574 TEMP THIS::TaTransSet(const BASE& rOtherSet) : 01575 VBASE(), 01576 BASE(), 01577 ABASE() 01578 { 01579 FD_DC("TaTransSet(" << this << ")::TaTransSet(rOtherSet "<< &rOtherSet <<")"); 01580 Assign(rOtherSet); 01581 } 01582 01583 01584 // copy to known same attributes 01585 TEMP void THIS::DoAssign(const THIS& rSourceSet) { 01586 // call base incl attributes 01587 ABASE::DoAssign(rSourceSet); 01588 } 01589 01590 // Relaxed Assign() 01591 TEMP THIS& THIS::Assign(const TransSet& rSourceSet) { 01592 FD_DC("TaTransSet(" << this << ")::Assign([v] " << &rSourceSet<<")"); 01593 FD_DC("TaTransSet(" << this << ")::Assign(): src type " << typeid(rSourceSet).name()); 01594 FD_DC("TaTransSet(" << this << ")::Assign(): dst type " << typeid(*this).name()); 01595 // call attribute smart base 01596 ABASE::Assign(rSourceSet); 01597 // done 01598 return *this; 01599 } 01600 01601 // Relaxed Assignment Operator(rSet) 01602 TEMP THIS& THIS::operator=(const TransSet& rSourceSet) { 01603 return Assign(rSourceSet); 01604 } 01605 01606 // Clear() 01607 TEMP void THIS::Clear(void) { 01608 FD_DC("TaTransSet(" << this << ")::Clear()"); 01609 ABASE::Clear(); 01610 } 01611 01612 // Insert(transition) 01613 TEMP bool THIS::Insert(const Transition& t) { 01614 FD_DC("TaTransSet(" << this << ")::Insert(" << t.Str() << ")"); 01615 return ABASE::Insert(t); 01616 } 01617 01618 // Insert(x1,ev,x2) 01619 TEMP bool THIS::Insert(Idx x1, Idx ev, Idx x2) { 01620 FD_DC("TaTransSet(" << this << ")::Insert(" << x1 << "-" << ev << "-" << x2 << ")"); 01621 Transition t(x1, ev, x2); 01622 return ABASE::Insert(t); 01623 } 01624 01625 // Insert(transition,attr) 01626 TEMP bool THIS::Insert(const Transition& t, const Attr& attr) { 01627 return ABASE::Insert(t,attr); 01628 } 01629 01630 // InsertSet(set) 01631 TEMP void THIS::InsertSet(const TaTransSet& rOtherSet) { 01632 FD_DC("TaIndexSet(" << this << ")::InsertSet( [v] " << &rOtherSet << ")"); 01633 ABASE::InsertSet(rOtherSet); 01634 } 01635 01636 // InsertSet(set) 01637 TEMP void THIS::InsertSet(const TransSet& rOtherSet) { 01638 FD_DC("TaIndexSet(" << this << ")::InsertSet( [a] " << &rOtherSet << ")"); 01639 ABASE::InsertSet(rOtherSet); 01640 } 01641 01642 01643 // Erase(transition) 01644 TEMP bool THIS::Erase(const Transition& t) { 01645 return ABASE::Erase(t); 01646 } 01647 01648 // Erase(x1,ev,x2) 01649 TEMP bool THIS::Erase(Idx x1, Idx ev, Idx x2) { 01650 FD_DC("TaTransSet(" << this << ")::Erase(" << x1 << "-" << ev << "-" << x2 << ")"); 01651 Transition t(x1, ev, x2); 01652 return ABASE::Erase(t); 01653 } 01654 01655 // Erase(it) 01656 TEMP typename THIS::Iterator THIS::Erase(const Iterator& it) { 01657 #ifdef FAUDES_CHECKED 01658 if (it == End()) { 01659 std::stringstream errstr; 01660 errstr << "iterator out of range " << std::endl; 01661 throw Exception("TTransSet::Erase", errstr.str(), 69); 01662 } 01663 #endif 01664 return ABASE::Erase(it); 01665 } 01666 01667 // EraseByX1(x) 01668 TEMP void THIS::EraseByX1(Idx x1) { 01669 FD_DC("TaTransSet(" << this << ")::EraseByX1(" << x1 << ")"); 01670 this->Detach(); 01671 Transition tl(x1,0,0); 01672 Transition tu(x1+1,0,0); 01673 BASE::iterator lower = BASE::pSet->lower_bound(tl); 01674 BASE::iterator upper = BASE::pSet->upper_bound(tu); 01675 BASE::iterator it; 01676 if(this->AttributeSize()!=0) 01677 for(it=lower; it!=upper; ++it) 01678 ABASE::ClrAttribute(*it); 01679 BASE::pSet->erase(lower, upper); 01680 } 01681 01682 // EraseByX2(x) 01683 TEMP void THIS::EraseByX2(Idx x2) { 01684 FD_DC("TaTransSet(" << this << ")::EraseByX2(" << x2 << ")"); 01685 this->Detach(); 01686 BASE::iterator it, tmpit; 01687 for(it = BASE::pSet->begin(); it !=BASE::pSet->end();) { 01688 if (it->X2 == x2) { 01689 tmpit = it; 01690 it++; 01691 ABASE::ClrAttribute(*tmpit); 01692 BASE::pSet->erase(tmpit); 01693 continue; 01694 } 01695 it++; 01696 } 01697 } 01698 01699 // EraseByEv(ev) 01700 TEMP void THIS::EraseByEv(Idx ev) { 01701 FD_DC("TaTransSet(" << this << ")::EraseByEv(" << ev << ")"); 01702 this->Detach(); 01703 BASE::iterator it, tmpit; 01704 for(it = BASE::pSet->begin(); it !=BASE::pSet->end();) { 01705 if (it->Ev == ev) { 01706 tmpit = it; 01707 it++; 01708 ABASE::ClrAttribute(*tmpit); 01709 BASE::pSet->erase(tmpit); 01710 continue; 01711 } 01712 it++; 01713 } 01714 } 01715 01716 01717 // EraseByX1OrX2(x) 01718 TEMP void THIS::EraseByX1OrX2(Idx x) { 01719 FD_DC("TaTransSet(" << this << ")::EraseByX1OrX2(" << x << ")"); 01720 this->Detach(); 01721 BASE::iterator it, tmpit; 01722 for(it = BASE::pSet->begin(); it !=BASE::pSet->end();) { 01723 if ((it->X1 == x) || (it->X2 == x)) { 01724 tmpit = it; 01725 it++; 01726 ABASE::ClrAttribute(*tmpit); 01727 BASE::pSet->erase(tmpit); 01728 continue; 01729 } 01730 it++; 01731 } 01732 } 01733 01734 01735 // EraseByX1OrX2(xset) 01736 TEMP void THIS::EraseByX1OrX2(const StateSet& rStates) { 01737 FD_DC("TaTransSet(" << this << ")::EraseByX1OrX2(#" << rStates.Size() <<")"); 01738 this->Detach(); 01739 typename BASE::iterator it, tmpit; 01740 for(it = BASE::pSet->begin(); it != BASE::pSet->end();) { 01741 if(rStates.Exists(it->X1) || rStates.Exists(it->X2)) { 01742 tmpit = it; 01743 it++; 01744 ABASE::ClrAttribute(*tmpit); 01745 BASE::pSet->erase(tmpit); 01746 continue; 01747 } 01748 it++; 01749 } 01750 FD_DC("TaTransSet(" << this << ")::EraseByX1OrX2(): done"); 01751 } 01752 01753 // Attributes(set) 01754 TEMP void THIS::Attributes(const TaTransSet& rOtherSet) { 01755 FD_DC("TaTransSet(" << this << ")::Attributes(set) with type " << typeid(rOtherSet.Attribute()).name()); 01756 ABASE::Attributes(rOtherSet); 01757 } 01758 01759 // Attributes(set) 01760 TEMP void THIS::Attributes(const TransSet& rOtherSet) { 01761 FD_DC("TaTransSet(" << this << ")::Attributes(set) with type " << typeid(rOtherSet.Attribute()).name()); 01762 ABASE::Attributes(rOtherSet); 01763 } 01764 01765 01766 #undef THIS 01767 #undef TEMP 01768 #undef BASE 01769 #undef ABASE 01770 01771 #undef SORT_EXECPTION 01772 01773 } // namespace faudes 01774 01775 01776 01777 01778 #define FAUDES_TRANSSET_H 01779 #endif 01780 |
libFAUDES 2.20s --- 2011.10.12 --- c++ source docu by doxygen