| |
libFAUDES
Sections
Index
|
transset.hGo to the documentation of this file.00001 /** @file 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 "definitions.h" 00033 #include "baseset.h" 00034 #include "abaseset.h" 00035 #include "indexset.h" 00036 #include "nameset.h" 00037 #include "attributes.h" 00038 #include "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 else 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 else 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 else 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 else 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 else 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 else 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(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 TTransSet& 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 virtual TransSet, public virtual TaBaseSet<Transition,Attr,TransSort::X1EvX2> { 00843 00844 FAUDES_TYPE_DECLARATION(TaTransSet,TransSet) 00845 00846 public: 00847 00848 /** 00849 * We implement "protected privacy for template classes" by friendship. 00850 * This is used for the pragmatic implemention conversion constructors. 00851 */ 00852 //friend class TransSet; 00853 00854 /** @name Constructors & Destructor */ 00855 /** @{ doxygen group */ 00856 00857 /** Construct an empty TaTransSet object */ 00858 TaTransSet(void); 00859 00860 /** 00861 * Copy-constructor (incl attributes) 00862 */ 00863 TaTransSet(const TaTransSet& rOtherSet); 00864 00865 /** 00866 * Copy-Constructor (set attributes to default) 00867 */ 00868 TaTransSet(const TTransSet<TransSort::X1EvX2>& rOtherSet); 00869 00870 /** Virtual destructor */ 00871 virtual ~TaTransSet() {} 00872 00873 /** Relaxed assignment method. Maintains attributes provided they can be casted. 00874 * 00875 * @param rSrc 00876 * Source from which to assign 00877 * @return 00878 * Ref to this set 00879 */ 00880 virtual TaTransSet& Assign(const TransSet& rSrc); 00881 00882 /** Relaxed assignment operator. Maintains attributes provided they can be casted. 00883 * 00884 * @param rSrc 00885 * Source from which to assign 00886 * @return 00887 * Ref to this set 00888 */ 00889 virtual TaTransSet& operator=(const TransSet& rSrc); 00890 00891 /** @} doxygen group */ 00892 00893 00894 00895 /** @name Accessing individual transitions */ 00896 /** @{ doxygen group */ 00897 00898 /** Clear all transitions incl attributes */ 00899 void Clear(void); 00900 00901 /** Iterator on transition */ 00902 typedef typename TTransSet<TransSort::X1EvX2>::Iterator Iterator; 00903 00904 /** 00905 * Add a Transition by indices 00906 * 00907 * @param x1 00908 * Predecessor state 00909 * @param ev 00910 * Event 00911 * @param x2 00912 * Successor state 00913 * 00914 * @return 00915 * True if the transition was new to the set 00916 */ 00917 bool Insert(Idx x1, Idx ev, Idx x2); 00918 00919 /** 00920 * Add a Transition directly. If the transition already 00921 * exists, the attribute is maintained. Otherwise, the transition 00922 * is inserted with default attribute. 00923 * 00924 * @param rTransition 00925 * Reference to transition object 00926 * 00927 * @return 00928 * True if the transition was new to the set 00929 */ 00930 bool Insert(const Transition& rTransition); 00931 00932 /** 00933 * Add a Transition with attribute. 00934 * 00935 * @param rTransition 00936 * Reference to transition object 00937 * @param rAttr 00938 * Reference to attribute 00939 * 00940 * @return 00941 * True if the transition was new to the set 00942 */ 00943 bool Insert(const Transition& rTransition, const Attr& rAttr); 00944 00945 /** 00946 * Inserts transitions of rOtherSet. 00947 * Attributes of this set are maintained, newly inserted transitions have default attribute. 00948 * 00949 * 00950 * @param rOtherSet 00951 * Other IndexSet 00952 */ 00953 virtual void InsertSet(const TransSet& rOtherSet); 00954 00955 /** 00956 * Inserts transitions of rOtherSet. 00957 * Attributes of this set are maintained, new transitions are inserted with attribute. 00958 * 00959 * @param rOtherSet 00960 * Other IndexSet 00961 */ 00962 virtual void InsertSet(const TaTransSet& rOtherSet); 00963 00964 /** 00965 * Remove a Transition 00966 * 00967 * @return 00968 * True if transition did exist 00969 */ 00970 bool Erase(const Transition& t); 00971 00972 /** 00973 * Remove a Transition 00974 * 00975 * @return 00976 * True if transition did exist 00977 */ 00978 bool Erase(Idx x1, Idx ev, Idx x2); 00979 00980 /** 00981 * Remove a Transition by iterator 00982 * 00983 * @return 00984 * Iterator to next transition 00985 */ 00986 Iterator Erase(const Iterator& it); 00987 00988 /** 00989 * Remove all transitions containing predecessor state x1. 00990 * 00991 * @param x1 00992 * State index 00993 */ 00994 void EraseByX1(Idx x1); 00995 00996 /** 00997 * Remove all transitions containing successor state x2. 00998 * 00999 * @param x2 01000 * State index 01001 */ 01002 void EraseByX2(Idx x2); 01003 01004 /** 01005 * Remove all transitions containing event ev. 01006 * 01007 * @param ev 01008 * Event index 01009 */ 01010 void EraseByEv(Idx ev); 01011 01012 /** 01013 * Remove all transitions containing state x. 01014 * 01015 * @param x 01016 * State index 01017 */ 01018 void EraseByX1OrX2(Idx x); 01019 01020 /** 01021 * Remove all transitions containing a specified state. 01022 * This function iterates over all transitions to work with any sorting. 01023 * 01024 * @param rStateSet 01025 * Set of states to remore 01026 */ 01027 void EraseByX1OrX2(const StateSet& rStateSet); 01028 01029 01030 /** 01031 * Erase elements given by other set. This function 01032 * ignores the attributes of the other set and maintains the attributes 01033 * of the remaining elements in this set. 01034 * 01035 * @param rOtherSet 01036 * Elements to erase 01037 */ 01038 void EraseSet(const TransSet& rOtherSet); 01039 01040 /** 01041 * Restrict to specified subset. Erases any elements no in 01042 * the specified set. This function 01043 * ignores the attributes of the other set and maintains the attributes 01044 * of the remaining elements in this set. 01045 * 01046 * @param rOtherSet 01047 * Elements to erase 01048 */ 01049 void RestrictSet(const TransSet& rOtherSet); 01050 01051 01052 /** 01053 * Set attributes. Provided that rOtherSet has attributes that can be 01054 * casted to the appropriate type, attributes are copied per element from rOtherSet. 01055 * Elements of this set which are not in rOtherSet maintain their attribute. 01056 * 01057 * @param rOtherSet 01058 * Other IndexSet 01059 * @exception Exception 01060 * - Element does not exist (63) 01061 * - Cannot cast attribute type (63) 01062 */ 01063 virtual void Attributes(const TransSet& rOtherSet); 01064 01065 /** 01066 * Set attributes. Attributes are copied per element from rOtherSet. 01067 * Elements of this set which are not in rOtherSet maintain their attribute. 01068 * 01069 * @param rOtherSet 01070 * Other IndexSet 01071 */ 01072 virtual void Attributes(const TaTransSet& rOtherSet); 01073 01074 01075 /** @} doxygen group */ 01076 01077 01078 protected: 01079 01080 /** 01081 * Assign my members. Maintain attributes. 01082 * 01083 * @param rSource 01084 * Source to copy from 01085 * @return 01086 * Ref to this set 01087 */ 01088 virtual TaTransSet& DoAssign(const TaTransSet& rSource); 01089 01090 }; 01091 01092 /** @} doxygen group*/ 01093 01094 01095 /* 01096 ************************************************************************************************* 01097 ************************************************************************************************* 01098 * Implementation of transset without attributes 01099 ************************************************************************************************* 01100 ************************************************************************************************* 01101 */ 01102 01103 01104 /* convenience access to relevant scopes */ 01105 #define THIS TTransSet<Cmp> 01106 #define TEMP template<class Cmp> 01107 #define BASE TBaseSet<Transition,Cmp> 01108 01109 // std faudes type 01110 FAUDES_TYPE_IMPLEMENTATION(THIS,BASE,TEMP) 01111 01112 // TTransSet(void) 01113 TEMP THIS::TTransSet(void) : BASE() 01114 { 01115 FD_DC("TTransSet(" << this << ")::TTransSet()"); 01116 } 01117 01118 // TTransSet(othertransrel) 01119 TEMP THIS::TTransSet(const TBaseSet<Transition,Cmp>& rOtherSet) : 01120 BASE(rOtherSet) 01121 { 01122 FD_DC("TTransSet(" << this << ")::TTransSet(rOtherSet "<< &rOtherSet <<")"); 01123 } 01124 01125 // TTransSet(othertransrel othersort) 01126 TEMP template<class OtherCmp> 01127 THIS::TTransSet(const TTransSet<OtherCmp>& rOtherSet) : 01128 BASE() 01129 { 01130 FD_DC("TTransSet(" << this << ")::TTransSet(rOtherSet/ReSort "<< &rOtherSet <<")"); 01131 rOtherSet.ReSort(*this); 01132 } 01133 01134 // assignment (maintain/cast attributes) 01135 TEMP THIS& THIS::DoAssign(const TTransSet& rSourceSet) { 01136 FD_DC("TTransSet(" << this << ")::DoAssign(..)"); 01137 // call base; incl virtual clear incl attributes 01138 BASE::DoAssign(rSourceSet); 01139 // done 01140 return *this; 01141 } 01142 01143 // iterator Begin() const 01144 TEMP typename THIS::Iterator THIS::Begin(void) const { 01145 return BASE::Begin(); 01146 } 01147 01148 // iterator End() const 01149 TEMP typename THIS::Iterator THIS::End(void) const { 01150 return BASE::End(); 01151 } 01152 01153 01154 // Convenience macro for order typecheck 01155 #define SORT_EXCEPTION { std::stringstream errstr; \ 01156 errstr << "transition set order mismatch " << std::endl; \ 01157 throw Exception("TransSet::Iterator()", errstr.str(), 68); } 01158 01159 01160 // iterator Begin(x1) const 01161 TEMP typename THIS::Iterator THIS::Begin(Idx x1) const { 01162 #ifdef FAUDES_CHECKED 01163 if(typeid(Cmp)!=typeid(TransSort::X1EvX2)) 01164 if(typeid(Cmp)!=typeid(TransSort::X1X2Ev)) 01165 SORT_EXCEPTION; 01166 #endif 01167 Transition tlx(x1,0,0); 01168 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01169 } 01170 01171 // iterator End(x1) const 01172 TEMP typename THIS::Iterator THIS::End(Idx x1) const { 01173 #ifdef FAUDES_CHECKED 01174 if(typeid(Cmp)!=typeid(TransSort::X1EvX2)) 01175 if(typeid(Cmp)!=typeid(TransSort::X1X2Ev)) 01176 SORT_EXCEPTION; 01177 #endif 01178 Transition tlx(x1+1,0,0); 01179 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01180 } 01181 01182 // iterator Begin(x1,ev) const 01183 TEMP typename THIS::Iterator THIS::Begin(Idx x1, Idx ev) const { 01184 #ifdef FAUDES_CHECKED 01185 if(typeid(Cmp)!=typeid(TransSort::X1EvX2)) 01186 SORT_EXCEPTION; 01187 #endif 01188 Transition tlx(x1,ev,0); 01189 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01190 } 01191 01192 // iterator End(x1,ev) const 01193 TEMP typename THIS::Iterator THIS::End(Idx x1, Idx ev) const { 01194 #ifdef FAUDES_CHECKED 01195 if(typeid(Cmp)!=typeid(TransSort::X1EvX2)) 01196 SORT_EXCEPTION; 01197 #endif 01198 Transition tlx(x1,ev+1, 0); 01199 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01200 } 01201 01202 // iterator BeginByEv(ev) const 01203 TEMP typename THIS::Iterator THIS::BeginByEv(Idx ev) const { 01204 #ifdef FAUDES_CHECKED 01205 if(typeid(Cmp)!=typeid(TransSort::EvX1X2)) 01206 if(typeid(Cmp)!=typeid(TransSort::EvX2X1)) 01207 SORT_EXCEPTION; 01208 #endif 01209 Transition tlx(0,ev,0); 01210 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01211 } 01212 01213 // iterator EndByEv(ev) const 01214 TEMP typename THIS::Iterator THIS::EndByEv(Idx ev) const { 01215 #ifdef FAUDES_CHECKED 01216 if(typeid(Cmp)!=typeid(TransSort::EvX1X2)) 01217 if(typeid(Cmp)!=typeid(TransSort::EvX2X1)) 01218 SORT_EXCEPTION; 01219 #endif 01220 Transition tlx(0,ev+1,0); 01221 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01222 } 01223 01224 // iterator BeginByEvX1(ev,x1) const 01225 TEMP typename THIS::Iterator THIS::BeginByEvX1(Idx ev, Idx x1) const { 01226 #ifdef FAUDES_CHECKED 01227 if(typeid(Cmp)!=typeid(TransSort::EvX1X2)) 01228 SORT_EXCEPTION; 01229 #endif 01230 Transition tlx(x1,ev,0); 01231 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01232 } 01233 01234 // iterator EndByEvX1(ev,x1) const 01235 TEMP typename THIS::Iterator THIS::EndByEvX1(Idx ev, Idx x1) const { 01236 #ifdef FAUDES_CHECKED 01237 if(typeid(Cmp)!=typeid(TransSort::EvX1X2)) 01238 SORT_EXCEPTION; 01239 #endif 01240 Transition tlx(x1+1,ev,0); 01241 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01242 } 01243 01244 // iterator BeginByEvX2(ev,x2) const 01245 TEMP typename THIS::Iterator THIS::BeginByEvX2(Idx ev, Idx x2) const { 01246 #ifdef FAUDES_CHECKED 01247 if(typeid(Cmp)!=typeid(TransSort::EvX2X1)) 01248 SORT_EXCEPTION; 01249 #endif 01250 Transition tlx(0,ev,x2); 01251 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01252 } 01253 01254 // iterator EndByEvX2(ev,x2) const 01255 TEMP typename THIS::Iterator THIS::EndByEvX2(Idx ev, Idx x2) const { 01256 #ifdef FAUDES_CHECKED 01257 if(typeid(Cmp)!=typeid(TransSort::EvX2X1)) 01258 SORT_EXCEPTION; 01259 #endif 01260 Transition tlx(0,ev,x2+1); 01261 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01262 } 01263 01264 // iterator BeginByX2(x2) const 01265 TEMP typename THIS::Iterator THIS::BeginByX2(Idx x2) const { 01266 #ifdef FAUDES_CHECKED 01267 if(typeid(Cmp)!=typeid(TransSort::X2EvX1)) 01268 if(typeid(Cmp)!=typeid(TransSort::X2X1Ev)) 01269 SORT_EXCEPTION; 01270 #endif 01271 Transition tlx(0,0,x2); 01272 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01273 } 01274 01275 // iterator EndByX2(x2) const 01276 TEMP typename THIS::Iterator THIS::EndByX2(Idx x2) const { 01277 #ifdef FAUDES_CHECKED 01278 if(typeid(Cmp)!=typeid(TransSort::X2EvX1)) 01279 if(typeid(Cmp)!=typeid(TransSort::X2X1Ev)) 01280 SORT_EXCEPTION; 01281 #endif 01282 Transition tlx(0,0,x2+1); 01283 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01284 } 01285 01286 // iterator BeginByX2Ev(x2,ev) const 01287 TEMP typename THIS::Iterator THIS::BeginByX2Ev(Idx x2, Idx ev) const { 01288 #ifdef FAUDES_CHECKED 01289 if(typeid(Cmp)!=typeid(TransSort::X2EvX1)) 01290 SORT_EXCEPTION; 01291 #endif 01292 Transition tlx(0,ev,x2); 01293 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01294 } 01295 01296 // iterator EndByX2Ev(x2,ev) const 01297 TEMP typename THIS::Iterator THIS::EndByX2Ev(Idx x2, Idx ev) const { 01298 #ifdef FAUDES_CHECKED 01299 if(typeid(Cmp)!=typeid(TransSort::X2EvX1)) 01300 SORT_EXCEPTION; 01301 #endif 01302 Transition tlx(0,ev+1,x2); 01303 return ThisIterator(BASE::pSet->lower_bound(tlx)); 01304 } 01305 01306 01307 01308 // DoWrite(rw,label) 01309 TEMP void THIS::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const 01310 { 01311 (void) pContext; 01312 std::string label=rLabel; 01313 if(label=="") label=BASE::Name(); 01314 rTw.WriteBegin(label); 01315 int oldcolumns = rTw.Columns(); 01316 rTw.Columns(3); 01317 01318 Iterator tit; 01319 for (tit = Begin(); tit != End(); ++tit) { 01320 rTw << tit->X1; rTw << tit->Ev; rTw << tit->X2; 01321 } 01322 01323 rTw.WriteEnd(label); 01324 rTw.Columns(oldcolumns); 01325 } 01326 01327 01328 // Insert(transition) 01329 TEMP bool THIS::Insert(const Transition& t) { 01330 return BASE::Insert(t); 01331 } 01332 01333 // Insert(x1,ev,x2) 01334 TEMP bool THIS::Insert(Idx x1, Idx ev, Idx x2) { 01335 FD_DC("TTransSet(" << this << ")::Insert(" << x1 << "-" << ev << "-" << x2 << ")"); 01336 return BASE::Insert(Transition(x1, ev, x2)); 01337 } 01338 01339 // Erase(transition) 01340 TEMP bool THIS::Erase(const Transition& t) { 01341 return BASE::Erase(t); 01342 } 01343 01344 // Erase(x1,ev,x2) 01345 TEMP bool THIS::Erase(Idx x1, Idx ev, Idx x2) { 01346 FD_DC("TTransSet(" << this << ")::Erase(" << x1 << "-" << ev << "-" << x2 << ")"); 01347 return BASE::Erase(Transition(x1, ev, x2)); 01348 } 01349 01350 // Erase(it) 01351 TEMP typename THIS::Iterator THIS::Erase(const Iterator& it) { 01352 FD_DC("TTransSet(" << this << ")::Erase(" << it->X1 << "-" << it->Ev 01353 << "-" << it->X2 << ")"); 01354 return BASE::Erase(it); 01355 } 01356 01357 // EraseByX1(x) 01358 TEMP void THIS::EraseByX1(Idx x1) { 01359 FD_DC("TTransSet(" << this << ")::EraseByX1(" << x1 << ")"); 01360 #ifdef FAUDES_CHECKED 01361 if(typeid(Cmp)!=typeid(TransSort::X1EvX2)) 01362 if(typeid(Cmp)!=typeid(TransSort::X1X2Ev)) 01363 SORT_EXCEPTION; 01364 #endif 01365 this->Detach(); 01366 typename BASE::iterator lower, upper, it; 01367 Transition tl(x1,0,0); 01368 Transition tu(x1+1,0,0); 01369 lower = BASE::pSet->lower_bound(tl); 01370 upper = BASE::pSet->upper_bound(tu); 01371 BASE::pSet->erase(lower, upper); 01372 } 01373 01374 // EraseByX2(x) 01375 TEMP void THIS::EraseByX2(Idx x2) { 01376 FD_DC("TTransSet(" << this << ")::EraseByX2(" << x2 << ")"); 01377 this->Detach(); 01378 typename BASE::iterator it, tmpit; 01379 for(it = BASE::pSet->begin(); it != BASE::pSet->end();) { 01380 if (it->X2 == x2) { 01381 tmpit = it; 01382 it++; 01383 BASE::pSet->erase(tmpit); 01384 continue; 01385 } 01386 it++; 01387 } 01388 } 01389 01390 // EraseByEv(ev) 01391 TEMP void THIS::EraseByEv(Idx ev) { 01392 FD_DC("TTransSet(" << this << ")::EraseByEv(" << ev << ")"); 01393 this->Detach(); 01394 typename BASE::iterator it, tmpit; 01395 for(it = BASE::pSet->begin(); it != BASE::pSet->end();) { 01396 if (it->Ev == ev) { 01397 tmpit = it; 01398 it++; 01399 BASE::pSet->erase(tmpit); 01400 continue; 01401 } 01402 it++; 01403 } 01404 } 01405 01406 01407 01408 // EraseByX1OrX2(x) 01409 TEMP void THIS::EraseByX1OrX2(Idx x) { 01410 FD_DC("TTransSet(" << this << ")::EraseByX1OrX2(" << x << ")"); 01411 this->Detach(); 01412 typename BASE::iterator it, tmpit; 01413 for(it = BASE::pSet->begin(); it != BASE::pSet->end();) { 01414 if ((it->X1 == x) || (it->X2 == x)) { 01415 tmpit = it; 01416 it++; 01417 BASE::pSet->erase(tmpit); 01418 continue; 01419 } 01420 it++; 01421 } 01422 FD_DC("TTransSet(" << this << ")::EraseByX1OrX2(" << x << "): done"); 01423 } 01424 01425 01426 // EraseByX1OrX2(xset) 01427 TEMP void THIS::EraseByX1OrX2(const StateSet& rStates) { 01428 FD_DC("TTransSet(" << this << ")::EraseByX1OrX2(#" << rStates.Size() <<")"); 01429 this->Detach(); 01430 typename BASE::iterator it, tmpit; 01431 for(it = BASE::pSet->begin(); it != BASE::pSet->end();) { 01432 if(rStates.Exists(it->X1) || rStates.Exists(it->X2)) { 01433 tmpit = it; 01434 it++; 01435 BASE::pSet->erase(tmpit); 01436 continue; 01437 } 01438 it++; 01439 } 01440 FD_DC("TTransSet(" << this << ")::EraseByX1OrX2(): done"); 01441 } 01442 01443 01444 // iterator Find(x1,ev,x2) 01445 TEMP typename THIS::Iterator THIS::Find(Idx x1, Idx ev, Idx x2) const { 01446 return BASE::Find(Transition(x1,ev,x2)); 01447 } 01448 01449 01450 // iterator Find(t) 01451 TEMP typename THIS::Iterator THIS::Find(const Transition& t) const{ 01452 return BASE::Find(t); 01453 } 01454 01455 // Exists(t) 01456 TEMP bool THIS::Exists(const Transition& t) const { 01457 return BASE::Exists(t); 01458 } 01459 01460 // Exists(x1, ev, x2) 01461 TEMP bool THIS::Exists(Idx x1, Idx ev, Idx x2) const { 01462 return BASE::Exists(Transition(x1,ev,x2)); 01463 } 01464 01465 // Exists(x) 01466 TEMP bool THIS::Exists(Idx x) const { 01467 typename BASE::iterator it; 01468 for(it = BASE::pSet->begin(); it != BASE::pSet->end(); ++it) { 01469 if ((it->X1 == x) || (it->X2 == x)) { 01470 return true; 01471 } 01472 } 01473 return false; 01474 } 01475 01476 01477 01478 // ReSort(res) 01479 TEMP template<class OtherCmp> 01480 void THIS::ReSort(TTransSet<OtherCmp>& res) const { 01481 Iterator it; 01482 res.Clear(); 01483 for (it = Begin(); it != End(); ++it) { 01484 res.Insert(*it); 01485 } 01486 } 01487 01488 // StateSpace() 01489 TEMP StateSet THIS::StateSpace(void) const { 01490 StateSet states; 01491 Iterator it; 01492 for (it=Begin(); it!=End(); ++it) { 01493 states.Insert(it->X1); 01494 states.Insert(it->X2); 01495 } 01496 return states; 01497 } 01498 01499 // StateSpaceX2(x1) 01500 TEMP StateSet THIS::StateSpaceX2(Idx x1) const { 01501 StateSet states; 01502 Iterator it = Begin(x1); 01503 Iterator it_end = End(x1); 01504 while (it != it_end) { 01505 states.Insert(it->X2); 01506 ++it; 01507 } 01508 return states; 01509 } 01510 01511 // StateSpaceX2(x1, ev) 01512 TEMP StateSet THIS::StateSpaceX2(Idx x1, Idx ev) const { 01513 StateSet states; 01514 Iterator it = Begin(x1, ev); 01515 Iterator it_end = End(x1, ev); 01516 while (it != it_end) { 01517 states.Insert(it->X2); 01518 ++it; 01519 } 01520 return states; 01521 } 01522 01523 // ActiveEvents(x1,pSymTab) 01524 TEMP EventSet THIS::ActiveEvents(Idx x1, SymbolTable* pSymTab) const { 01525 Iterator it = Begin(x1); 01526 Iterator it_end = End(x1); 01527 EventSet result; 01528 if(pSymTab!=NULL) result.SymbolTablep(pSymTab); 01529 for (; it != it_end; ++it) { 01530 result.Insert(it->Ev); 01531 } 01532 return result; 01533 } 01534 01535 01536 #undef THIS 01537 #undef TEMP 01538 #undef BASE 01539 01540 /* 01541 ************************************************************************************************* 01542 ************************************************************************************************* 01543 * Implementation of transset with attributes 01544 ************************************************************************************************* 01545 ************************************************************************************************* 01546 */ 01547 01548 01549 /* convenience access to relevant scopes */ 01550 #define THIS TaTransSet<Attr> 01551 #define TEMP template <class Attr> 01552 #define BASE TTransSet<TransSort::X1EvX2> 01553 #define ABASE TaBaseSet<Transition,Attr,TransSort::X1EvX2> 01554 #define VBASE TBaseSet<Transition,TransSort::X1EvX2> 01555 01556 // std faudes type 01557 FAUDES_TYPE_IMPLEMENTATION(THIS,BASE,TEMP) 01558 01559 // TaTransSet(void) 01560 TEMP THIS::TaTransSet(void) : 01561 VBASE(), 01562 BASE(), 01563 ABASE() 01564 { 01565 FD_DC("TaTransSet(" << this << ")::TaTransSet()"); 01566 } 01567 01568 // TaTransSet(othertransrel) 01569 TEMP THIS::TaTransSet(const TaTransSet& rOtherSet) : 01570 VBASE(), 01571 BASE(), 01572 ABASE() 01573 { 01574 FD_DC("TaTransSet(" << this << ")::TaTransSet(rOtherSet "<< &rOtherSet <<")"); 01575 DoAssign(rOtherSet); 01576 } 01577 01578 01579 // TaTransSet(othertransrel) 01580 TEMP THIS::TaTransSet(const BASE& rOtherSet) : 01581 VBASE(), 01582 BASE(), 01583 ABASE() 01584 { 01585 FD_DC("TaTransSet(" << this << ")::TaTransSet(rOtherSet "<< &rOtherSet <<")"); 01586 Assign(rOtherSet); 01587 } 01588 01589 01590 // copy to known same attributes 01591 TEMP THIS& THIS::DoAssign(const THIS& rSourceSet) { 01592 // call base incl attributes 01593 ABASE::DoAssign(rSourceSet); 01594 // done 01595 return *this; 01596 } 01597 01598 // Relaxed Assign() 01599 TEMP THIS& THIS::Assign(const TransSet& rSourceSet) { 01600 FD_DC("TaTransSet(" << this << ")::Assign([v] " << &rSourceSet<<")"); 01601 FD_DC("TaTransSet(" << this << ")::Assign(): src type " << typeid(rSourceSet).name()); 01602 FD_DC("TaTransSet(" << this << ")::Assign(): dst type " << typeid(*this).name()); 01603 // call attribute smart base 01604 ABASE::Assign(rSourceSet); 01605 // done 01606 return *this; 01607 } 01608 01609 // Relaxed Assignment Operator(rSet) 01610 TEMP THIS& THIS::operator=(const TransSet& rSourceSet) { 01611 return Assign(rSourceSet); 01612 } 01613 01614 // Clear() 01615 TEMP void THIS::Clear(void) { 01616 FD_DC("TaTransSet(" << this << ")::Clear()"); 01617 ABASE::Clear(); 01618 } 01619 01620 // Insert(transition) 01621 TEMP bool THIS::Insert(const Transition& t) { 01622 FD_DC("TaTransSet(" << this << ")::Insert(" << t.Str() << ")"); 01623 return ABASE::Insert(t); 01624 } 01625 01626 // Insert(x1,ev,x2) 01627 TEMP bool THIS::Insert(Idx x1, Idx ev, Idx x2) { 01628 FD_DC("TaTransSet(" << this << ")::Insert(" << x1 << "-" << ev << "-" << x2 << ")"); 01629 Transition t(x1, ev, x2); 01630 return ABASE::Insert(t); 01631 } 01632 01633 // Insert(transition,attr) 01634 TEMP bool THIS::Insert(const Transition& t, const Attr& attr) { 01635 return ABASE::Insert(t,attr); 01636 } 01637 01638 // InsertSet(set) 01639 TEMP void THIS::InsertSet(const TaTransSet& rOtherSet) { 01640 FD_DC("TaIndexSet(" << this << ")::InsertSet( [v] " << &rOtherSet << ")"); 01641 ABASE::InsertSet(rOtherSet); 01642 } 01643 01644 // InsertSet(set) 01645 TEMP void THIS::InsertSet(const TransSet& rOtherSet) { 01646 FD_DC("TaIndexSet(" << this << ")::InsertSet( [a] " << &rOtherSet << ")"); 01647 ABASE::InsertSet(rOtherSet); 01648 } 01649 01650 01651 // Erase(transition) 01652 TEMP bool THIS::Erase(const Transition& t) { 01653 return ABASE::Erase(t); 01654 } 01655 01656 // Erase(x1,ev,x2) 01657 TEMP bool THIS::Erase(Idx x1, Idx ev, Idx x2) { 01658 FD_DC("TaTransSet(" << this << ")::Erase(" << x1 << "-" << ev << "-" << x2 << ")"); 01659 Transition t(x1, ev, x2); 01660 return ABASE::Erase(t); 01661 } 01662 01663 // Erase(it) 01664 TEMP typename THIS::Iterator THIS::Erase(const Iterator& it) { 01665 #ifdef FAUDES_CHECKED 01666 if (it == End()) { 01667 std::stringstream errstr; 01668 errstr << "iterator out of range " << std::endl; 01669 throw Exception("TTransSet::Erase", errstr.str(), 69); 01670 } 01671 #endif 01672 return ABASE::Erase(it); 01673 } 01674 01675 // EraseByX1(x) 01676 TEMP void THIS::EraseByX1(Idx x1) { 01677 FD_DC("TaTransSet(" << this << ")::EraseByX1(" << x1 << ")"); 01678 this->Detach(); 01679 Transition tl(x1,0,0); 01680 Transition tu(x1+1,0,0); 01681 BASE::iterator lower = BASE::pSet->lower_bound(tl); 01682 BASE::iterator upper = BASE::pSet->upper_bound(tu); 01683 BASE::iterator it; 01684 if(this->AttributeSize()!=0) 01685 for(it=lower; it!=upper; ++it) 01686 ABASE::ClrAttribute(*it); 01687 BASE::pSet->erase(lower, upper); 01688 } 01689 01690 // EraseByX2(x) 01691 TEMP void THIS::EraseByX2(Idx x2) { 01692 FD_DC("TaTransSet(" << this << ")::EraseByX2(" << x2 << ")"); 01693 this->Detach(); 01694 BASE::iterator it, tmpit; 01695 for(it = BASE::pSet->begin(); it !=BASE::pSet->end();) { 01696 if (it->X2 == x2) { 01697 tmpit = it; 01698 it++; 01699 ABASE::ClrAttribute(*tmpit); 01700 BASE::pSet->erase(tmpit); 01701 continue; 01702 } 01703 it++; 01704 } 01705 } 01706 01707 // EraseByEv(ev) 01708 TEMP void THIS::EraseByEv(Idx ev) { 01709 FD_DC("TaTransSet(" << this << ")::EraseByEv(" << ev << ")"); 01710 this->Detach(); 01711 BASE::iterator it, tmpit; 01712 for(it = BASE::pSet->begin(); it !=BASE::pSet->end();) { 01713 if (it->Ev == ev) { 01714 tmpit = it; 01715 it++; 01716 ABASE::ClrAttribute(*tmpit); 01717 BASE::pSet->erase(tmpit); 01718 continue; 01719 } 01720 it++; 01721 } 01722 } 01723 01724 01725 // EraseByX1OrX2(x) 01726 TEMP void THIS::EraseByX1OrX2(Idx x) { 01727 FD_DC("TaTransSet(" << this << ")::EraseByX1OrX2(" << x << ")"); 01728 this->Detach(); 01729 BASE::iterator it, tmpit; 01730 for(it = BASE::pSet->begin(); it !=BASE::pSet->end();) { 01731 if ((it->X1 == x) || (it->X2 == x)) { 01732 tmpit = it; 01733 it++; 01734 ABASE::ClrAttribute(*tmpit); 01735 BASE::pSet->erase(tmpit); 01736 continue; 01737 } 01738 it++; 01739 } 01740 } 01741 01742 01743 // EraseByX1OrX2(xset) 01744 TEMP void THIS::EraseByX1OrX2(const StateSet& rStates) { 01745 FD_DC("TaTransSet(" << this << ")::EraseByX1OrX2(#" << rStates.Size() <<")"); 01746 this->Detach(); 01747 typename BASE::iterator it, tmpit; 01748 for(it = BASE::pSet->begin(); it != BASE::pSet->end();) { 01749 if(rStates.Exists(it->X1) || rStates.Exists(it->X2)) { 01750 tmpit = it; 01751 it++; 01752 ABASE::ClrAttribute(*tmpit); 01753 BASE::pSet->erase(tmpit); 01754 continue; 01755 } 01756 it++; 01757 } 01758 FD_DC("TaTransSet(" << this << ")::EraseByX1OrX2(): done"); 01759 } 01760 01761 // Attributes(set) 01762 TEMP void THIS::Attributes(const TaTransSet& rOtherSet) { 01763 FD_DC("TaTransSet(" << this << ")::Attributes(set) with type " << typeid(rOtherSet.Attribute()).name()); 01764 ABASE::Attributes(rOtherSet); 01765 } 01766 01767 // Attributes(set) 01768 TEMP void THIS::Attributes(const TransSet& rOtherSet) { 01769 FD_DC("TaTransSet(" << this << ")::Attributes(set) with type " << typeid(rOtherSet.Attribute()).name()); 01770 ABASE::Attributes(rOtherSet); 01771 } 01772 01773 01774 #undef THIS 01775 #undef TEMP 01776 #undef BASE 01777 #undef ABASE 01778 01779 #undef SORT_EXECPTION 01780 01781 } // namespace faudes 01782 01783 01784 01785 01786 #define FAUDES_TRANSSET_H 01787 #endif 01788 |
libFAUDES 2.14g --- 2009-12-3 --- c++ source docu by doxygen 1.5.6