About
User Reference
C++ API
luafaudes
Developer
Links
libFAUDES online
libFAUDES

Sections

Index

cfl_transset.h

Go 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 predecessor state x1 and event ev.
00335    *
00336    * @param x1
00337    *   State index
00338    * @param ev
00339    *   Event index
00340    * @exception Exception
00341    *   - sorting mismatch (id 68)
00342    */
00343 void EraseByX1Ev(Idx x1, Idx ev);
00344 
00345   /**
00346    * Remove all transitions containing successor state x2.
00347    * This function iterates over all transitions to work with any sorting.
00348    * 
00349    * @param x2
00350    *   State index
00351    */
00352   void EraseByX2(Idx x2);
00353 
00354   /**
00355    * Remove all transitions containing event ev.
00356    * This function iterates over all transitions to work with any sorting.
00357    *
00358    * @param ev
00359    *   Event index
00360    */
00361   void EraseByEv(Idx ev);
00362     
00363   /**
00364    * Remove all transitions containing state x,
00365    * This function iterates over all transitions to work with any sorting.
00366    * 
00367    * @param x
00368    *   State index
00369    */
00370   void EraseByX1OrX2(Idx x);
00371 
00372   /**
00373    * Remove all transitions containing a specified state. 
00374    * This function iterates over all transitions to work with any sorting.
00375    * 
00376    * @param rStates
00377    *   Set of states to remore
00378    */
00379   void EraseByX1OrX2(const StateSet& rStates);
00380 
00381   /**
00382    * Find transition given by x1, ev, x2
00383    *
00384    * 
00385    * @param x1
00386    *   Predecessor state
00387    * @param ev
00388    *   Event
00389    * @param x2
00390    *   Successor state
00391    *
00392    * @return
00393    *   Iterator to transition or End() if not exists
00394    */
00395   Iterator Find(Idx x1, Idx ev, Idx x2) const;
00396 
00397   /**
00398    * Find specified transition
00399    *
00400    * 
00401    * @param t
00402    *   Transition
00403    *
00404    * @return
00405    *   Iterator to transition or End() if not exists
00406    */
00407   Iterator Find(const Transition& t) const;
00408 
00409 
00410   /**
00411    * Test existence
00412    *
00413    * @param t
00414    *   Transition
00415    *
00416    * @return
00417    *   bool
00418    */
00419   bool Exists(const Transition& t) const;
00420 
00421   /**
00422    * Test existence
00423    *
00424    * @param x1
00425    *   Predecessor state Idx
00426    * @param ev
00427    *   Event Idx
00428    * @param x2
00429    *   Successor state Idx
00430    *
00431    * @return
00432    *   bool
00433    */
00434   bool Exists(Idx x1, Idx ev, Idx x2) const;
00435 
00436   /**
00437    * Test existence
00438    *
00439    * @param x1
00440    *   Predecessor state Idx
00441    * @param ev
00442    *   Event Idx
00443    *
00444    * @return
00445    *   bool
00446    */
00447    bool ExistsByX1Ev(Idx x1, Idx ev) const;
00448 
00449   /**
00450    * Test existence
00451    *
00452    * @param x1
00453    *   Predecessor state Idx
00454    * @param ev
00455    *   Event Idx
00456    *
00457    * @return
00458    *   bool
00459    */
00460    bool ExistsByX1(Idx x1) const;
00461 
00462   /**
00463    * Tests if a transition with specified predecessor or successor state
00464    * exists.
00465    *
00466    * @param x
00467    *   State Idx
00468    *
00469    * @return
00470    *   bool
00471    */
00472   bool ExistsByX1OrX2(Idx x) const;
00473 
00474 
00475 
00476   /** @} doxygen group */
00477 
00478   /** @name Transition iterators 
00479    *
00480    *  A variaty of iterators are provided to examine specified
00481    *  segments of the transition relation, e.g. all transitions starting
00482    *  from a given state. Note that implemetation of these iterators
00483    *  requires the transition set to be of sorted accordingly. Eg.
00484    *  scanning all transitions that are labled with a particular event
00485    *  requires a sorting TransSOrt::EvX1X2 orT ransSOrt::EvX2X1.
00486    *
00487    *
00488    */
00489  
00490   /** @{ doxygen group: iterators */
00491 
00492   /** 
00493    * Iterator to begin of set 
00494    *
00495    * @return
00496    *   TTransSet<Cmp>::Iterator
00497    */
00498   Iterator Begin(void) const;
00499 
00500   /** 
00501    * Iterator to end of set 
00502    *
00503    * @return
00504    *   TTransSet<Cmp>::Iterator
00505    */
00506   Iterator End(void) const;  
00507 
00508   
00509   /** 
00510    * Iterator to first Transition specified by current state.
00511    *
00512    * @param x1
00513    *   Predecessor state index
00514    *
00515    * @return
00516    *   TTransSet<Cmp>::Iterator
00517    *
00518    * @exception Exception
00519    *   - Sorting mismatch (id 68)
00520    */
00521   Iterator Begin(Idx x1) const;
00522 
00523   /** 
00524    * Iterator to end or Transitions with specified current state.
00525    *
00526    * @param x1
00527    *   Predecessor state index
00528    *
00529    * @return
00530    *   TTransSet<Cmp>::Iterator
00531    *
00532    * @exception Exception
00533    *   - Sorting mismatch (id 68)
00534    */
00535   Iterator End(Idx x1) const;
00536 
00537   /** 
00538    * Iterator to first Transitions specified by current state and event.
00539    *
00540    * @param x1
00541    *   Predecessor state index
00542    * @param ev
00543    *   Event index
00544    *
00545    * @return
00546    *   TTransSet<Cmp>::Iterator 
00547    *
00548    * @exception Exception
00549    *   - Sorting mismatch (id 68)
00550    */
00551   Iterator Begin(Idx x1, Idx ev) const;
00552 
00553   /** 
00554    * Iterator to first Transition after spcified current state and event. 
00555    *
00556    * @param x1
00557    *   Predecessor state index
00558    * @param ev
00559    *   Event index
00560    *
00561    * @return
00562    *   TTransSet<Cmp>::Iterator
00563    *
00564    * @exception Exception
00565    *   - sorting mismatch (id 68)
00566    */
00567   Iterator End(Idx x1, Idx ev) const;
00568 
00569   /**
00570    * Iterator to first Transition specified by event.
00571    * This function requires sorting TransSort::EvX1X2 or TransSort::EvX2X1. 
00572    * 
00573    * @param ev
00574    *   Event index
00575    *   
00576    * @return
00577    *   TTransSet<Cmp>::iterator
00578    *
00579    * @exception Exception
00580    *   - sorting mismatch (id 68)
00581    */
00582   Iterator BeginByEv(Idx ev) const;
00583 
00584   /**
00585    * Iterator to first Transition after specified by event.
00586    * This function requires sorting TransSort::EvX1X2 or TransSort::EvX2X1 
00587    *
00588    * @param ev
00589    *   Predecessor state index
00590    *   
00591    * @return
00592    *   TTransSet<Cmp>::Iterator
00593    *
00594    * @exception Exception
00595    *   - sorting mismatch (id 68)
00596    */
00597   Iterator EndByEv(Idx ev) const;
00598 
00599   /**
00600    * Iterator to first Transition specified by event and current state.
00601    * This function requires sorting TransSort::EvX1X2. 
00602    * 
00603    * @param ev
00604    *   Event index
00605    * @param x1
00606    *   Predecessor state index
00607    *   
00608    * @return
00609    *   TTransSet<Cmp>::iterator
00610    *
00611    * @exception Exception
00612    *   - sorting mismatch (id 68)
00613    */
00614   Iterator BeginByEvX1(Idx ev, Idx x1) const;
00615 
00616   /**
00617    * Iterator to first Transition after specified ev and current state.
00618    * This function requires sorting TransSort::EvX1X2. 
00619    * 
00620    * @param ev
00621    *   Event index
00622    * @param x1
00623    *   Predecessor state index
00624    *   
00625    * @return
00626    *   TTransSet<Cmp>::Iterator
00627    *
00628    * @exception Exception
00629    *   - sorting mismatch (id 68)
00630    */
00631   Iterator EndByEvX1(Idx ev, Idx x1) const;
00632 
00633   /**
00634    * Iterator to first Transition specified by event and next state.
00635    * This function requires sorting TransSort::EvX2X1. 
00636    * 
00637    * @param ev
00638    *   Event index
00639    * @param x2
00640    *   Predecessor state index
00641    *   
00642    * @return
00643    *   TTransSet<Cmp>::Iterator
00644    *
00645    * @exception Exception
00646    *   - sorting mismatch (id 68)
00647    */
00648   Iterator BeginByEvX2(Idx ev, Idx x2) const;
00649 
00650   /**
00651    * Iterator to first Transition after specified event and next state.
00652    * This function requires sorting TransSort::EvX2X1. 
00653    * 
00654    * @param ev
00655    *   Event index
00656    * @param x2
00657    *   Predecessor state index
00658    *   
00659    * @return
00660    *   TTransSet<Cmp>::Iterator
00661    *
00662    * @exception Exception
00663    *   - sorting mismatch (id 68)
00664    */
00665   Iterator EndByEvX2(Idx ev, Idx x2) const;
00666 
00667   /**
00668    * Iterator to first Transition specified by successor state x2.
00669    * This function requires sorting TransSort::X2EvX1 or TransSort::X2X1Ev.  
00670    * 
00671    * @param x2
00672    *   Predecessor state index
00673    *   
00674    * @return
00675    *   TTransSet<Cmp>::iterator
00676    *
00677    * @exception Exception
00678    *   - sorting mismatch (id 68)
00679    */
00680   Iterator BeginByX2(Idx x2) const;
00681 
00682   /**
00683    * Iterator to first Transition after specified successor state x2.
00684    * This function requires sorting TransSort::X2EvX1 or TransSort::X2X1Ev  
00685    * 
00686    * @param x2
00687    *   Predecessor state index
00688    *   
00689    * @return
00690    *   TTransSet<Cmp>::Iterator
00691    *
00692    * @exception Exception
00693    *   - sorting mismatch (id 68)
00694    */
00695   Iterator EndByX2(Idx x2) const;
00696 
00697   /**
00698    * Iterator to first Transition specified by successor x2  and ev.
00699    * This function requires sorting TransSort::X2EvX1.
00700    * 
00701    * @param x2
00702    *   Predecessor state index
00703    * @param ev
00704    *   Event index
00705    *   
00706    * @return
00707    *   TTransSet<Cmp>::Iterator
00708    *
00709    * @exception Exception
00710    *   - sorting mismatch (id 68)
00711    */
00712   Iterator BeginByX2Ev(Idx x2, Idx ev) const;
00713 
00714   /**
00715    * Iterator to first Transition after specified  successor x2  and ev.
00716    * This function requires sorting TransSort::X2EvX1.
00717    * 
00718    * @param x2
00719    *   Predecessor state index
00720    * @param ev
00721    *   Event index
00722    *   
00723    * @return
00724    *   TTransSet<Cmp>::Iterator
00725    *
00726    * @exception Exception
00727    *   - sorting mismatch (id 68)
00728    */
00729   Iterator EndByX2Ev(Idx x2, Idx ev) const;
00730 
00731   /** @} doxygen group */
00732 
00733   /** @name Misc */
00734   /** @{ doxygen group */
00735 
00736   /**
00737    * Get copy of trantision relation  sorted by other compare 
00738    * operator, e.g. TSort::X2EvX1
00739    * 
00740    * @return
00741    *   Transition relation
00742    */
00743   template<class OtherCmp>
00744   void ReSort(TTransSet<OtherCmp>& res) const;
00745 
00746   /** 
00747    * Get state space covered by transition set 
00748    *
00749    * @return
00750    *   Set of state indices used by some transition
00751    */
00752   StateSet StateSpace(void) const;
00753 
00754   /**
00755    * Get set of successor states for specified current state
00756    * 
00757    * @param x1
00758    *   Current state
00759    *
00760    * @return
00761    *   Set of state indices
00762    */
00763   StateSet StateSpaceX2(Idx x1) const;
00764 
00765   /**
00766    * Get set of successor states for specified current state and event
00767    * 
00768    * @param x1
00769    *   Current state
00770    * @param ev
00771    *   Event
00772    *
00773    * @return
00774    *   Set of state indices
00775    */
00776   StateSet StateSpaceX2(Idx x1, Idx ev) const;
00777 
00778   /**
00779    * Get set of events that are active for a specified current state
00780    * Since a transition set does not refer to a SymbolTable, this function
00781    * returns a set of plain indices. In order to interpret the set as an EventSet, 
00782    * the relevant SymbolTable must be supplied as second argument. If obmitting the second
00783    * argument, the defult SymbolTable is used.
00784    *
00785    * @param x1
00786    *   Current state
00787    * @param pSymTab
00788    *   SymbolTable to refer to
00789    *
00790    * @return 
00791    *   Set of events. 
00792    */
00793   EventSet ActiveEvents(Idx x1, SymbolTable* pSymTab=NULL) const;
00794 
00795   /**
00796    * Return pretty printable string representation.
00797    * Primary meant for debugging messages.
00798    *
00799    * @param rTrans
00800    *   Transition to print
00801    *
00802    * @return
00803    *   String
00804    */
00805   std::string Str(const Transition& rTrans) const { return rTrans.Str();} ;
00806 
00807 
00808   /** @} doxygen group */
00809 
00810   protected:
00811 
00812 
00813   /**
00814    * Assign my members. 
00815    *
00816    * @param rSource 
00817    *    Source to copy from
00818    * @return
00819    *    Ref to this set
00820    */
00821   virtual void DoAssign(const TTransSet& rSource);
00822 
00823   /** 
00824    * Write to TokenWriter, see Type::Write for public wrappers.
00825    *
00826    * @param rTw
00827    *   Reference to TokenWriter
00828    * @param rLabel
00829    *   Label of section to write, defaults to name of set
00830    * @param pContext
00831    *   Write context eg symboltables
00832    *
00833    * @exception Exception
00834    *   - IO errors (id 2)
00835    */
00836 
00837   virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="", const Type* pContext=0) const;
00838 
00839 
00840 };
00841 
00842 /** Type definition for default sorted TTransSet */
00843 typedef TTransSet<TransSort::X1EvX2> TransSet;
00844 
00845 /** Type definition for default sorted TTransSet */
00846 typedef TTransSet<TransSort::X1EvX2> TransSetX1EvX2;
00847 
00848 /** Type definition for ev, x1, x2 sorted TTransSet */
00849 typedef TTransSet<TransSort::EvX1X2> TransSetEvX1X2;
00850 
00851 /** Type definition for ev, x2, x1 sorted TTransSet */
00852 typedef TTransSet<TransSort::EvX2X1> TransSetEvX2X1;
00853 
00854 /** Type definition for x2, ev, x1 sorted TTransSet */
00855 typedef TTransSet<TransSort::X2EvX1> TransSetX2EvX1;
00856 
00857 /** Type definition for x2, x1, ev sorted TTransSet */
00858 typedef TTransSet<TransSort::X2X1Ev> TransSetX2X1Ev;
00859 
00860 /** Type definition for x1, x2, ev sorted TTransSet */
00861 typedef TTransSet<TransSort::X1X2Ev> TransSetX1X2Ev;
00862 
00863 
00864 /** 
00865  * Set of Transitions with attributes.
00866  *
00867  * This container class is derived from TTransSet to provide attributes as an
00868  * additional feature. As with TaBaseSet, the template parameter specifies the attribute class,
00869  * which in turn must provide some basic funtionality. In contrast to the TTransSet, the TaTransSet
00870  * is restricted to standard ordering. 
00871  *
00872  * Note that it is the context of a Generator that
00873  * actually allows to interpret a TaTransSet as a set of transitions as opposed to
00874  * a set of triples of indices with attributes. In particular, file IO of transitions is provided
00875  * by the generator class (although TaTransSet provides output functions for debugging)
00876  */
00877 
00878 
00879 template <class Attr>
00880 class TaTransSet : public TransSet, public TaBaseSet<Transition,Attr,TransSort::X1EvX2> {
00881 
00882 FAUDES_TYPE_DECLARATION(Void,TaTransSet,TransSet)
00883 
00884 public:
00885 
00886 
00887   /** @name Constructors & Destructor */ 
00888   /** @{ doxygen group */
00889 
00890   /** Construct an empty TaTransSet object */
00891   TaTransSet(void); 
00892 
00893   /**
00894    * Copy-constructor (incl attributes) 
00895    */
00896   TaTransSet(const TaTransSet& rOtherSet);
00897 
00898   /**
00899    * Copy-Constructor (set attributes to default)
00900    */
00901   TaTransSet(const TTransSet<TransSort::X1EvX2>& rOtherSet);
00902 
00903   /** Virtual destructor */
00904   virtual ~TaTransSet() {}
00905     
00906   /** Relaxed assignment method. Maintains attributes provided they can be casted.
00907    *
00908    * @param rSrc 
00909    *    Source from which to assign
00910    * @return
00911    *    Ref to this set
00912    */
00913   virtual TaTransSet& Assign(const TransSet& rSrc);
00914 
00915   /** Relaxed assignment operator. Maintains attributes provided they can be casted.
00916    *
00917    * @param rSrc 
00918    *    Source from which to assign
00919    * @return
00920    *    Ref to this set
00921    */
00922   virtual TaTransSet& operator=(const TransSet& rSrc);
00923 
00924   /** @} doxygen group */
00925 
00926 
00927 
00928   /** @name Accessing individual transitions */ 
00929   /** @{ doxygen group */
00930     
00931   /** Clear all transitions incl attributes */
00932   void Clear(void);
00933 
00934   /** Iterator on transition */
00935   typedef typename TTransSet<TransSort::X1EvX2>::Iterator Iterator;
00936 
00937   /** 
00938    * Add a Transition by indices
00939    *
00940    * @param x1
00941    *   Predecessor state
00942    * @param ev
00943    *   Event
00944    * @param x2
00945    *   Successor state
00946    *
00947    * @return
00948    *   True if the transition was new to the set
00949    */
00950   bool Insert(Idx x1, Idx ev, Idx x2);
00951     
00952   /** 
00953    * Add a Transition directly. If the transition already
00954    * exists, the attribute is maintained. Otherwise, the transition
00955    * is inserted with default attribute.
00956    * 
00957    * @param rTransition 
00958    *   Reference to transition object
00959    *
00960    * @return
00961    *   True if the transition was new to the set
00962    */
00963   bool Insert(const Transition& rTransition);
00964     
00965   /** 
00966    * Add a Transition with attribute.
00967    * 
00968    * @param rTransition 
00969    *   Reference to transition object
00970    * @param rAttr 
00971    *   Reference to attribute
00972    *
00973    * @return
00974    *   True if the transition was new to the set
00975    */
00976   bool Insert(const Transition& rTransition, const Attr& rAttr);
00977     
00978   /**
00979    * Inserts transitions of rOtherSet.
00980    * Attributes of this set are maintained, newly inserted transitions have default attribute.
00981    *
00982    *
00983    * @param rOtherSet
00984    *   Other IndexSet
00985    */
00986    virtual void InsertSet(const TransSet& rOtherSet);
00987 
00988   /**
00989    * Inserts transitions of rOtherSet.
00990    * Attributes of this set are maintained, new transitions are inserted with attribute.
00991    *
00992    * @param rOtherSet
00993    *   Other IndexSet
00994    */
00995    virtual void InsertSet(const TaTransSet& rOtherSet);
00996 
00997   /** 
00998    * Remove a Transition
00999    *
01000    * @return
01001    *   True if transition did exist
01002    */
01003   bool Erase(const Transition& t);
01004     
01005   /** 
01006    * Remove a Transition
01007    *
01008    * @return
01009    *   True if transition did exist
01010    */
01011   bool Erase(Idx x1, Idx ev, Idx x2);
01012 
01013   /**
01014    * Remove a Transition by iterator 
01015    *
01016    * @return
01017    *   Iterator to next transition
01018    */
01019   Iterator Erase(const Iterator& it);
01020 
01021   /**
01022    * Remove all transitions containing predecessor state x1.
01023    *
01024    * @param x1
01025    *   State index
01026    */
01027   void EraseByX1(Idx x1);
01028 
01029   /**
01030    * Remove all transitions containing successor state x2.
01031    *
01032    * @param x2
01033    *   State index
01034    */
01035   void EraseByX2(Idx x2);
01036 
01037   /**
01038    * Remove all transitions containing event ev.
01039    *
01040    * @param ev
01041    *   Event index
01042    */
01043   void EraseByEv(Idx ev);
01044     
01045   /**
01046    * Remove all transitions containing state x.
01047    * 
01048    * @param x
01049    *   State index
01050    */
01051   void EraseByX1OrX2(Idx x);
01052 
01053   /**
01054    * Remove all transitions containing a specified state. 
01055    * This function iterates over all transitions to work with any sorting.
01056    * 
01057    * @param rStateSet
01058    *   Set of states to remore
01059    */
01060   void EraseByX1OrX2(const StateSet& rStateSet);
01061 
01062 
01063   /** 
01064    * Erase elements given by other set. This function
01065    * ignores the attributes of the other set and maintains the attributes 
01066    * of the remaining elements in this set.
01067    *
01068    * @param rOtherSet 
01069    *    Elements to erase
01070    */
01071    void EraseSet(const TransSet& rOtherSet);
01072 
01073   /** 
01074    * Restrict to specified subset. Erases any elements no in
01075    * the specified set. This function
01076    * ignores the attributes of the other set and maintains the attributes 
01077    * of the remaining elements in this set.
01078    *
01079    * @param rOtherSet 
01080    *    Elements to erase
01081    */
01082    void RestrictSet(const TransSet& rOtherSet);
01083 
01084 
01085   /**
01086    * Set attributes. Provided that rOtherSet has attributes that can be
01087    * casted to the appropriate type, attributes are copied per element from rOtherSet. 
01088    * Elements of this set which are not in rOtherSet maintain their attribute. 
01089    *
01090    * @param rOtherSet
01091    *   Other IndexSet
01092    * @exception Exception
01093    *   - Element does not exist (63)
01094    *   - Cannot cast attribute type (63)
01095    */
01096   virtual void Attributes(const TransSet& rOtherSet);
01097 
01098   /**
01099    * Set attributes. Attributes are copied per element from rOtherSet. 
01100    * Elements of this set which are not in rOtherSet maintain their attribute. 
01101    *
01102    * @param rOtherSet
01103    *   Other IndexSet
01104    */
01105   virtual void Attributes(const TaTransSet& rOtherSet);
01106 
01107 
01108   /** @} doxygen group */
01109 
01110 
01111  protected:
01112 
01113   /**
01114    * Assign my members. Maintain attributes.
01115    *
01116    * @param rSource 
01117    *    Source to copy from
01118    * @return
01119    *    Ref to this set
01120    */
01121   virtual void DoAssign(const TaTransSet& rSource);
01122 
01123 };
01124 
01125 /** @} doxygen group*/
01126 
01127 
01128 /*
01129 *************************************************************************************************
01130 *************************************************************************************************
01131 * Implementation of transset without attributes
01132 *************************************************************************************************
01133 *************************************************************************************************
01134 */
01135 
01136 
01137 /* convenience access to relevant scopes */
01138 #define THIS TTransSet<Cmp>
01139 #define TEMP template<class Cmp>      
01140 #define BASE TBaseSet<Transition,Cmp>
01141 
01142 // std faudes type
01143 FAUDES_TYPE_TIMPLEMENTATION(TransSet,THIS,BASE,TEMP)
01144 
01145 // TTransSet(void)
01146 TEMP THIS::TTransSet(void) : BASE()
01147 {
01148   FD_DC("TTransSet(" << this << ")::TTransSet()");
01149 }
01150 
01151 // TTransSet(othertransrel)
01152  TEMP THIS::TTransSet(const TBaseSet<Transition,Cmp>& rOtherSet) : 
01153   BASE()
01154 {
01155   FD_DC("TTransSet(" << this << ")::TTransSet(rOtherSet "<< &rOtherSet <<")");
01156   Assign(rOtherSet);
01157 }
01158 
01159 // TTransSet(othertransrel othersort)
01160 TEMP template<class OtherCmp>
01161 THIS::TTransSet(const TTransSet<OtherCmp>& rOtherSet) : 
01162   BASE() 
01163 {
01164   FD_DC("TTransSet(" << this << ")::TTransSet(rOtherSet/ReSort "<< &rOtherSet <<")");
01165   rOtherSet.ReSort(*this);
01166 }
01167 
01168 // assignment  (maintain/cast attributes)
01169 TEMP void THIS::DoAssign(const TTransSet& rSourceSet) {
01170   FD_DC("TTransSet(" << this << ")::DoAssign(..)");
01171   // call base; incl virtual clear incl attributes
01172   BASE::DoAssign(rSourceSet);
01173 } 
01174 
01175 // iterator Begin() const
01176 TEMP typename THIS::Iterator THIS::Begin(void) const {
01177   return BASE::Begin();
01178 }
01179 
01180 // iterator End() const
01181 TEMP typename THIS::Iterator THIS::End(void) const {
01182   return BASE::End();
01183 }
01184 
01185 
01186 // Convenience macro for order typecheck
01187 #define SORT_EXCEPTION  { std::stringstream errstr; \
01188   errstr << "Transition set order mismatch " << std::endl; \
01189   throw Exception("TransSet::Iterator()", errstr.str(), 68); }
01190 
01191 
01192 // iterator Begin(x1) const
01193 TEMP typename THIS::Iterator THIS::Begin(Idx x1) const {
01194 #ifdef FAUDES_CHECKED
01195   if(typeid(Cmp)!=typeid(TransSort::X1EvX2)) 
01196     if(typeid(Cmp)!=typeid(TransSort::X1X2Ev)) 
01197       SORT_EXCEPTION;
01198 #endif
01199   Transition tlx(x1,0,0);
01200   return ThisIterator(BASE::pSet->lower_bound(tlx));
01201 }
01202 
01203 // iterator End(x1) const
01204 TEMP typename THIS::Iterator THIS::End(Idx x1) const {
01205 #ifdef FAUDES_CHECKED
01206   if(typeid(Cmp)!=typeid(TransSort::X1EvX2)) 
01207     if(typeid(Cmp)!=typeid(TransSort::X1X2Ev)) 
01208       SORT_EXCEPTION;
01209 #endif
01210   Transition tlx(x1+1,0,0);
01211   return ThisIterator(BASE::pSet->lower_bound(tlx));
01212 }
01213 
01214 // iterator Begin(x1,ev) const
01215 TEMP typename THIS::Iterator THIS::Begin(Idx x1, Idx ev) const {
01216 #ifdef FAUDES_CHECKED
01217   if(typeid(Cmp)!=typeid(TransSort::X1EvX2)) 
01218     SORT_EXCEPTION;
01219 #endif
01220   Transition tlx(x1,ev,0);
01221   return ThisIterator(BASE::pSet->lower_bound(tlx));
01222 }
01223 
01224 // iterator End(x1,ev) const
01225 TEMP typename THIS::Iterator THIS::End(Idx x1, Idx ev) const {
01226 #ifdef FAUDES_CHECKED
01227   if(typeid(Cmp)!=typeid(TransSort::X1EvX2)) 
01228     SORT_EXCEPTION;
01229 #endif
01230   Transition tlx(x1,ev+1, 0);
01231   return ThisIterator(BASE::pSet->lower_bound(tlx));
01232 }
01233 
01234 // iterator BeginByEv(ev) const
01235 TEMP typename THIS::Iterator THIS::BeginByEv(Idx ev) const {
01236 #ifdef FAUDES_CHECKED
01237   if(typeid(Cmp)!=typeid(TransSort::EvX1X2)) 
01238     if(typeid(Cmp)!=typeid(TransSort::EvX2X1)) 
01239       SORT_EXCEPTION;
01240 #endif
01241   Transition tlx(0,ev,0);
01242   return ThisIterator(BASE::pSet->lower_bound(tlx));
01243 }
01244 
01245 // iterator EndByEv(ev) const
01246 TEMP typename THIS::Iterator THIS::EndByEv(Idx ev) const {
01247 #ifdef FAUDES_CHECKED
01248   if(typeid(Cmp)!=typeid(TransSort::EvX1X2)) 
01249     if(typeid(Cmp)!=typeid(TransSort::EvX2X1)) 
01250       SORT_EXCEPTION;
01251 #endif
01252   Transition tlx(0,ev+1,0);
01253   return ThisIterator(BASE::pSet->lower_bound(tlx));
01254 }
01255 
01256 // iterator BeginByEvX1(ev,x1) const
01257 TEMP typename THIS::Iterator THIS::BeginByEvX1(Idx ev, Idx x1) const {
01258 #ifdef FAUDES_CHECKED
01259   if(typeid(Cmp)!=typeid(TransSort::EvX1X2)) 
01260     SORT_EXCEPTION;
01261 #endif
01262   Transition tlx(x1,ev,0);
01263   return ThisIterator(BASE::pSet->lower_bound(tlx));
01264 }
01265 
01266 // iterator EndByEvX1(ev,x1) const
01267 TEMP typename THIS::Iterator THIS::EndByEvX1(Idx ev, Idx x1) const {
01268 #ifdef FAUDES_CHECKED
01269   if(typeid(Cmp)!=typeid(TransSort::EvX1X2)) 
01270     SORT_EXCEPTION;
01271 #endif
01272   Transition tlx(x1+1,ev,0);
01273   return ThisIterator(BASE::pSet->lower_bound(tlx));
01274 }
01275 
01276 // iterator BeginByEvX2(ev,x2) const
01277 TEMP typename THIS::Iterator THIS::BeginByEvX2(Idx ev, Idx x2) const {
01278 #ifdef FAUDES_CHECKED
01279   if(typeid(Cmp)!=typeid(TransSort::EvX2X1)) 
01280     SORT_EXCEPTION;
01281 #endif
01282   Transition tlx(0,ev,x2);
01283   return ThisIterator(BASE::pSet->lower_bound(tlx));
01284 }
01285 
01286 // iterator EndByEvX2(ev,x2) const
01287 TEMP typename THIS::Iterator THIS::EndByEvX2(Idx ev, Idx x2) const {
01288 #ifdef FAUDES_CHECKED
01289   if(typeid(Cmp)!=typeid(TransSort::EvX2X1)) 
01290     SORT_EXCEPTION;
01291 #endif
01292   Transition tlx(0,ev,x2+1);
01293   return ThisIterator(BASE::pSet->lower_bound(tlx));
01294 }
01295 
01296 // iterator BeginByX2(x2) const
01297 TEMP typename THIS::Iterator THIS::BeginByX2(Idx x2) const {
01298 #ifdef FAUDES_CHECKED
01299   if(typeid(Cmp)!=typeid(TransSort::X2EvX1)) 
01300     if(typeid(Cmp)!=typeid(TransSort::X2X1Ev)) 
01301       SORT_EXCEPTION;
01302 #endif
01303   Transition tlx(0,0,x2);
01304   return ThisIterator(BASE::pSet->lower_bound(tlx));
01305 }
01306 
01307 // iterator EndByX2(x2) const
01308 TEMP typename THIS::Iterator THIS::EndByX2(Idx x2) const {
01309 #ifdef FAUDES_CHECKED
01310   if(typeid(Cmp)!=typeid(TransSort::X2EvX1)) 
01311     if(typeid(Cmp)!=typeid(TransSort::X2X1Ev)) 
01312       SORT_EXCEPTION;
01313 #endif
01314   Transition tlx(0,0,x2+1);
01315   return ThisIterator(BASE::pSet->lower_bound(tlx));
01316 }
01317 
01318 // iterator BeginByX2Ev(x2,ev) const
01319 TEMP typename THIS::Iterator THIS::BeginByX2Ev(Idx x2, Idx ev) const {
01320 #ifdef FAUDES_CHECKED
01321   if(typeid(Cmp)!=typeid(TransSort::X2EvX1)) 
01322     SORT_EXCEPTION;
01323 #endif
01324   Transition tlx(0,ev,x2);
01325   return ThisIterator(BASE::pSet->lower_bound(tlx));
01326 }
01327 
01328 // iterator EndByX2Ev(x2,ev) const
01329 TEMP typename THIS::Iterator THIS::EndByX2Ev(Idx x2, Idx ev) const {
01330 #ifdef FAUDES_CHECKED
01331   if(typeid(Cmp)!=typeid(TransSort::X2EvX1)) 
01332     SORT_EXCEPTION;
01333 #endif
01334   Transition tlx(0,ev+1,x2);
01335   return ThisIterator(BASE::pSet->lower_bound(tlx));
01336 }
01337 
01338 
01339 
01340 // DoWrite(rw,label)
01341 TEMP void THIS::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const
01342 {
01343   (void) pContext;
01344   std::string label=rLabel;
01345   if(label=="") label=BASE::Name(); 
01346   rTw.WriteBegin(label);
01347   int oldcolumns = rTw.Columns();
01348   rTw.Columns(3);
01349 
01350   Iterator tit;
01351   for (tit = Begin(); tit != End(); ++tit) {
01352     rTw << tit->X1; rTw << tit->Ev; rTw << tit->X2;
01353   }
01354 
01355   rTw.WriteEnd(label);
01356   rTw.Columns(oldcolumns);
01357 }
01358 
01359 
01360 // Insert(transition)
01361 TEMP bool THIS::Insert(const Transition& t) {
01362   return BASE::Insert(t);
01363 }
01364 
01365 // Insert(x1,ev,x2)
01366 TEMP bool  THIS::Insert(Idx x1, Idx ev, Idx x2) {
01367   FD_DC("TTransSet(" << this << ")::Insert(" << x1 << "-" << ev << "-" << x2 << ")");
01368   return BASE::Insert(Transition(x1, ev, x2));
01369 }
01370 
01371 // Erase(transition)
01372 TEMP bool THIS::Erase(const Transition& t) {
01373   return BASE::Erase(t);  
01374 }
01375     
01376 // Erase(x1,ev,x2)
01377 TEMP bool THIS::Erase(Idx x1, Idx ev, Idx x2) {
01378   FD_DC("TTransSet(" << this << ")::Erase(" << x1 << "-" << ev << "-" << x2 << ")");
01379   return BASE::Erase(Transition(x1, ev, x2));
01380 }
01381 
01382 // Erase(it)
01383 TEMP typename THIS::Iterator THIS::Erase(const Iterator& it) {
01384   FD_DC("TTransSet(" << this << ")::Erase(" << it->X1 << "-" << it->Ev 
01385   << "-" << it->X2 << ")");
01386   return BASE::Erase(it);
01387 }
01388 
01389 // EraseByX1(x)
01390 TEMP void THIS::EraseByX1(Idx x1) {
01391   FD_DC("TTransSet(" << this << ")::EraseByX1(" << x1 << ")");
01392 #ifdef FAUDES_CHECKED
01393   if(typeid(Cmp)!=typeid(TransSort::X1EvX2)) 
01394     if(typeid(Cmp)!=typeid(TransSort::X1X2Ev)) 
01395       SORT_EXCEPTION;
01396 #endif
01397   this->Detach();
01398   typename BASE::iterator lower, upper, it;
01399   Transition tl(x1,0,0);
01400   Transition tu(x1+1,0,0);
01401   lower = BASE::pSet->lower_bound(tl);
01402   upper = BASE::pSet->upper_bound(tu);
01403   BASE::pSet->erase(lower, upper);
01404 }
01405 
01406 // EraseByX1Ev(x,e)
01407 TEMP void THIS::EraseByX1Ev(Idx x1, Idx ev) {
01408   FD_DC("TTransSet(" << this << ")::EraseByX1Ev(" << x1 << "," << ev << ")");
01409 #ifdef FAUDES_CHECKED
01410   if(typeid(Cmp)!=typeid(TransSort::X1EvX2)) 
01411     SORT_EXCEPTION;
01412 #endif
01413   this->Detach();
01414   typename BASE::iterator lower, upper, it;
01415   Transition tl(x1,ev,0);
01416   Transition tu(x1,ev+1,0);
01417   lower = BASE::pSet->lower_bound(tl);
01418   upper = BASE::pSet->upper_bound(tu);
01419   BASE::pSet->erase(lower, upper);
01420 }
01421 
01422 // EraseByX2(x)
01423 TEMP void THIS::EraseByX2(Idx x2) {
01424   FD_DC("TTransSet(" << this << ")::EraseByX2(" << x2 << ")");
01425   this->Detach();
01426   typename BASE::iterator it, tmpit;
01427   for(it = BASE::pSet->begin(); it != BASE::pSet->end();) {
01428     if (it->X2 == x2) {
01429       tmpit = it;
01430       it++;
01431       BASE::pSet->erase(tmpit);
01432       continue;
01433     }
01434     it++;
01435   }
01436 }
01437 
01438 // EraseByEv(ev)
01439 TEMP void THIS::EraseByEv(Idx ev) {
01440   FD_DC("TTransSet(" << this << ")::EraseByEv(" << ev << ")");
01441   this->Detach();
01442   typename BASE::iterator it, tmpit;
01443   for(it = BASE::pSet->begin(); it != BASE::pSet->end();) {
01444     if (it->Ev == ev) {
01445       tmpit = it;
01446       it++;
01447       BASE::pSet->erase(tmpit);
01448       continue;
01449     }
01450     it++;
01451   }
01452 }
01453 
01454 
01455 
01456 // EraseByX1OrX2(x)
01457 TEMP void THIS::EraseByX1OrX2(Idx x) {
01458   FD_DC("TTransSet(" << this << ")::EraseByX1OrX2(" << x << ")");
01459   this->Detach();
01460   typename BASE::iterator it, tmpit;
01461   for(it = BASE::pSet->begin(); it != BASE::pSet->end();) {
01462     if ((it->X1 == x) || (it->X2 == x)) {
01463       tmpit = it;
01464       it++;
01465       BASE::pSet->erase(tmpit);
01466       continue;
01467     }
01468     it++;
01469   }
01470   FD_DC("TTransSet(" << this << ")::EraseByX1OrX2(" << x << "): done");
01471 }
01472 
01473 
01474 // EraseByX1OrX2(xset)
01475 TEMP void THIS::EraseByX1OrX2(const StateSet& rStates) {
01476   FD_DC("TTransSet(" << this << ")::EraseByX1OrX2(#" << rStates.Size() <<")");
01477   this->Detach();
01478   typename BASE::iterator it, tmpit;
01479   for(it = BASE::pSet->begin(); it != BASE::pSet->end();) {
01480     if(rStates.Exists(it->X1) || rStates.Exists(it->X2)) {
01481       tmpit = it;
01482       it++;
01483       BASE::pSet->erase(tmpit);
01484       continue;
01485     }
01486     it++;
01487   }
01488   FD_DC("TTransSet(" << this << ")::EraseByX1OrX2(): done");
01489 }
01490 
01491 
01492 // iterator Find(x1,ev,x2)
01493 TEMP typename THIS::Iterator THIS::Find(Idx x1, Idx ev, Idx x2) const {
01494   return BASE::Find(Transition(x1,ev,x2));
01495 }
01496 
01497 
01498 // iterator Find(t)
01499 TEMP typename THIS::Iterator THIS::Find(const Transition& t) const{
01500   return BASE::Find(t);
01501 }
01502 
01503 // Exists(t)
01504 TEMP bool THIS::Exists(const Transition& t) const {
01505   return BASE::Exists(t);
01506 }
01507 
01508 // Exists(x1, ev, x2)
01509 TEMP bool THIS::Exists(Idx x1, Idx ev, Idx x2) const {
01510   return BASE::Exists(Transition(x1,ev,x2));
01511 }
01512 
01513 // Exists(x)
01514 TEMP bool THIS::ExistsByX1OrX2(Idx x) const {
01515   typename BASE::iterator it;
01516   for(it = BASE::pSet->begin(); it != BASE::pSet->end(); ++it) {
01517     if ((it->X1 == x) || (it->X2 == x)) {
01518       return true;
01519     }
01520   }
01521   return false;
01522 }
01523 
01524 // ExistsByX1Ev(x,e)
01525 TEMP bool THIS::ExistsByX1Ev(Idx x1, Idx ev) const {
01526   FD_DC("TTransSet(" << this << ")::ExistsByX1Ev(" << x1 << "," << ev << ")");
01527 #ifdef FAUDES_CHECKED
01528   if(typeid(Cmp)!=typeid(TransSort::X1EvX2)) 
01529     SORT_EXCEPTION;
01530 #endif
01531   this->Detach();
01532   typename BASE::iterator lower, upper, it;
01533   Transition tl(x1,ev,0);
01534   Transition tu(x1,ev+1,0);
01535   lower = BASE::pSet->lower_bound(tl);
01536   upper = BASE::pSet->upper_bound(tu);
01537   return lower != upper;
01538 }
01539 
01540 // ExistsByX1(x)
01541 TEMP bool THIS::ExistsByX1(Idx x1) const {
01542   FD_DC("TTransSet(" << this << ")::ExistsByX1(" << x1  << ")");
01543 #ifdef FAUDES_CHECKED
01544   if(typeid(Cmp)!=typeid(TransSort::X1EvX2)) 
01545   if(typeid(Cmp)!=typeid(TransSort::X1X2Ev)) 
01546     SORT_EXCEPTION;
01547 #endif
01548   this->Detach();
01549   typename BASE::iterator lower, upper, it;
01550   Transition tl(x1,0,0);
01551   Transition tu(x1+1,0,0);
01552   lower = BASE::pSet->lower_bound(tl);
01553   upper = BASE::pSet->upper_bound(tu);
01554   return lower != upper;
01555 }
01556 
01557 
01558 // ReSort(res)
01559 TEMP template<class OtherCmp>
01560 void THIS::ReSort(TTransSet<OtherCmp>& res) const {
01561   Iterator it;
01562   res.Clear();
01563   for (it = Begin(); it != End(); ++it) {
01564     res.Insert(*it);
01565   }
01566 }
01567 
01568 // StateSpace()
01569 TEMP StateSet THIS::StateSpace(void) const {
01570   StateSet states;
01571   Iterator it;
01572   for (it=Begin(); it!=End(); ++it) {
01573     states.Insert(it->X1);
01574     states.Insert(it->X2);
01575   }
01576   return states;
01577 }
01578 
01579 // StateSpaceX2(x1)
01580 TEMP StateSet THIS::StateSpaceX2(Idx x1) const {
01581   StateSet states;
01582   Iterator it = Begin(x1);
01583   Iterator it_end = End(x1);
01584   while (it != it_end) {
01585     states.Insert(it->X2);
01586     ++it;
01587   }
01588   return states;
01589 }
01590 
01591 // StateSpaceX2(x1, ev)
01592 TEMP StateSet THIS::StateSpaceX2(Idx x1, Idx ev) const {
01593   StateSet states;
01594   Iterator it = Begin(x1, ev);
01595   Iterator it_end = End(x1, ev);
01596   while (it != it_end) {
01597     states.Insert(it->X2);
01598     ++it;
01599   }
01600   return states;
01601 }
01602 
01603 // ActiveEvents(x1,pSymTab)
01604 TEMP EventSet THIS::ActiveEvents(Idx x1, SymbolTable* pSymTab) const {
01605   Iterator it = Begin(x1);
01606   Iterator it_end = End(x1);
01607   EventSet result;
01608   if(pSymTab!=NULL) result.SymbolTablep(pSymTab);
01609   for (; it != it_end; ++it) {
01610     result.Insert(it->Ev);
01611   }
01612   return result;
01613 }
01614 
01615 
01616 #undef THIS
01617 #undef TEMP
01618 #undef BASE
01619 
01620 /*
01621 *************************************************************************************************
01622 *************************************************************************************************
01623 * Implementation of transset with attributes
01624 *************************************************************************************************
01625 *************************************************************************************************
01626 */
01627 
01628 
01629 /* convenience access to relevant scopes */
01630 #define THIS TaTransSet<Attr>
01631 #define TEMP template <class Attr>
01632 #define BASE TTransSet<TransSort::X1EvX2>
01633 #define ABASE TaBaseSet<Transition,Attr,TransSort::X1EvX2>        
01634 #define VBASE TBaseSet<Transition,TransSort::X1EvX2>        
01635 
01636 // std faudes type
01637 FAUDES_TYPE_TIMPLEMENTATION(Void,THIS,BASE,TEMP)
01638 
01639 // TaTransSet(void)
01640 TEMP THIS::TaTransSet(void) : 
01641   VBASE(),
01642   BASE(),
01643   ABASE() 
01644 {
01645   FD_DC("TaTransSet(" << this << ")::TaTransSet()");
01646 }
01647 
01648 // TaTransSet(othertransrel)
01649 TEMP THIS::TaTransSet(const TaTransSet& rOtherSet) : 
01650   VBASE(),
01651   BASE(),
01652   ABASE()
01653 {
01654   FD_DC("TaTransSet(" << this << ")::TaTransSet(rOtherSet "<< &rOtherSet <<")");
01655   DoAssign(rOtherSet);
01656 }
01657 
01658 
01659 // TaTransSet(othertransrel)
01660 TEMP THIS::TaTransSet(const BASE& rOtherSet) :
01661   VBASE(),
01662   BASE(),
01663   ABASE() 
01664 {
01665   FD_DC("TaTransSet(" << this << ")::TaTransSet(rOtherSet "<< &rOtherSet <<")");
01666   Assign(rOtherSet);
01667 }
01668 
01669 
01670 // copy to known same attributes
01671 TEMP void THIS::DoAssign(const THIS& rSourceSet) {  
01672   // call base incl attributes
01673   ABASE::DoAssign(rSourceSet);
01674 }
01675 
01676 // Relaxed Assign()
01677 TEMP THIS& THIS::Assign(const TransSet& rSourceSet) {
01678   FD_DC("TaTransSet(" << this << ")::Assign([v] " << &rSourceSet<<")");
01679   FD_DC("TaTransSet(" << this << ")::Assign(): src type " << typeid(rSourceSet).name());
01680   FD_DC("TaTransSet(" << this << ")::Assign(): dst type " << typeid(*this).name());
01681   // call attribute smart base
01682   ABASE::Assign(rSourceSet);
01683   // done
01684   return *this;
01685 }
01686 
01687 // Relaxed Assignment Operator(rSet)
01688 TEMP THIS& THIS::operator=(const TransSet& rSourceSet) {
01689   return Assign(rSourceSet);
01690 }
01691 
01692 // Clear()
01693 TEMP void THIS::Clear(void) {
01694   FD_DC("TaTransSet(" << this << ")::Clear()");
01695   ABASE::Clear();
01696 }
01697 
01698 // Insert(transition)
01699 TEMP bool THIS::Insert(const Transition& t) {
01700   FD_DC("TaTransSet(" << this << ")::Insert(" << t.Str() << ")");
01701   return ABASE::Insert(t);
01702 }
01703 
01704 // Insert(x1,ev,x2)
01705 TEMP bool THIS::Insert(Idx x1, Idx ev, Idx x2) {
01706   FD_DC("TaTransSet(" << this << ")::Insert(" << x1 << "-" << ev << "-" << x2 << ")");
01707   Transition t(x1, ev, x2);
01708   return ABASE::Insert(t);
01709 }
01710 
01711 // Insert(transition,attr)
01712 TEMP bool THIS::Insert(const Transition& t, const Attr& attr) {
01713   return ABASE::Insert(t,attr);
01714 }
01715 
01716 // InsertSet(set)
01717 TEMP void THIS::InsertSet(const TaTransSet& rOtherSet) {
01718   FD_DC("TaIndexSet(" << this << ")::InsertSet( [v] " << &rOtherSet << ")");
01719   ABASE::InsertSet(rOtherSet);
01720 }
01721 
01722 // InsertSet(set)
01723 TEMP void THIS::InsertSet(const TransSet& rOtherSet) {
01724   FD_DC("TaIndexSet(" << this << ")::InsertSet( [a] " << &rOtherSet << ")");
01725   ABASE::InsertSet(rOtherSet);
01726 }
01727 
01728 
01729 // Erase(transition)
01730 TEMP bool THIS::Erase(const Transition& t) {
01731   return ABASE::Erase(t);
01732 }
01733     
01734 // Erase(x1,ev,x2)
01735 TEMP bool THIS::Erase(Idx x1, Idx ev, Idx x2) {
01736   FD_DC("TaTransSet(" << this << ")::Erase(" << x1 << "-" << ev << "-" << x2 << ")");
01737   Transition t(x1, ev, x2);
01738   return ABASE::Erase(t);
01739 }
01740 
01741 // Erase(it)
01742 TEMP typename THIS::Iterator THIS::Erase(const Iterator& it) {
01743 #ifdef FAUDES_CHECKED
01744   if (it == End()) {
01745     std::stringstream errstr;
01746     errstr << "iterator out of range " << std::endl;
01747     throw Exception("TTransSet::Erase", errstr.str(), 69);
01748   }
01749 #endif
01750   return ABASE::Erase(it);
01751 }
01752 
01753 // EraseByX1(x)
01754 TEMP void THIS::EraseByX1(Idx x1) {
01755   FD_DC("TaTransSet(" << this << ")::EraseByX1(" << x1 << ")");
01756   this->Detach();
01757   Transition tl(x1,0,0);
01758   Transition tu(x1+1,0,0);
01759   BASE::iterator lower = BASE::pSet->lower_bound(tl);
01760   BASE::iterator upper = BASE::pSet->upper_bound(tu);
01761   BASE::iterator it;
01762   if(this->AttributeSize()!=0) 
01763     for(it=lower; it!=upper; ++it)
01764       ABASE::ClrAttribute(*it);
01765   BASE::pSet->erase(lower, upper);
01766 }
01767 
01768 // EraseByX2(x)
01769 TEMP void THIS::EraseByX2(Idx x2) {
01770   FD_DC("TaTransSet(" << this << ")::EraseByX2(" << x2 << ")");
01771   this->Detach();
01772   BASE::iterator it, tmpit;
01773   for(it = BASE::pSet->begin(); it !=BASE::pSet->end();) {
01774     if (it->X2 == x2) {
01775       tmpit = it;
01776       it++;
01777       ABASE::ClrAttribute(*tmpit);
01778       BASE::pSet->erase(tmpit);
01779       continue;
01780     }
01781     it++;
01782   }
01783 }
01784 
01785 // EraseByEv(ev)
01786 TEMP void THIS::EraseByEv(Idx ev) {
01787   FD_DC("TaTransSet(" << this << ")::EraseByEv(" << ev << ")");
01788   this->Detach();
01789   BASE::iterator it, tmpit;
01790   for(it = BASE::pSet->begin(); it !=BASE::pSet->end();) {
01791     if (it->Ev == ev) {
01792       tmpit = it;
01793       it++;
01794       ABASE::ClrAttribute(*tmpit);
01795       BASE::pSet->erase(tmpit);
01796       continue;
01797     }
01798     it++;
01799   }
01800 }
01801 
01802 
01803 // EraseByX1OrX2(x)
01804 TEMP void THIS::EraseByX1OrX2(Idx x) {
01805   FD_DC("TaTransSet(" << this << ")::EraseByX1OrX2(" << x << ")");
01806   this->Detach();
01807   BASE::iterator it, tmpit;
01808   for(it = BASE::pSet->begin(); it !=BASE::pSet->end();) {
01809     if ((it->X1 == x) || (it->X2 == x)) {
01810       tmpit = it;
01811       it++;
01812       ABASE::ClrAttribute(*tmpit);
01813       BASE::pSet->erase(tmpit);
01814       continue;
01815     }
01816     it++;
01817   }
01818 }
01819 
01820 
01821 // EraseByX1OrX2(xset)
01822 TEMP void THIS::EraseByX1OrX2(const StateSet& rStates) {
01823   FD_DC("TaTransSet(" << this << ")::EraseByX1OrX2(#" << rStates.Size() <<")");
01824   this->Detach();
01825   typename BASE::iterator it, tmpit;
01826   for(it = BASE::pSet->begin(); it != BASE::pSet->end();) {
01827     if(rStates.Exists(it->X1) || rStates.Exists(it->X2)) {
01828       tmpit = it;
01829       it++;
01830       ABASE::ClrAttribute(*tmpit);
01831       BASE::pSet->erase(tmpit);
01832       continue;
01833     }
01834     it++;
01835   }
01836   FD_DC("TaTransSet(" << this << ")::EraseByX1OrX2(): done");
01837 }
01838 
01839 // Attributes(set)
01840 TEMP void THIS::Attributes(const TaTransSet& rOtherSet) {
01841   FD_DC("TaTransSet(" << this << ")::Attributes(set) with type " << typeid(rOtherSet.Attribute()).name());
01842   ABASE::Attributes(rOtherSet);
01843 }
01844 
01845 // Attributes(set)
01846 TEMP void THIS::Attributes(const TransSet& rOtherSet) {
01847   FD_DC("TaTransSet(" << this << ")::Attributes(set) with type " << typeid(rOtherSet.Attribute()).name());
01848   ABASE::Attributes(rOtherSet);
01849 }
01850 
01851 
01852 #undef THIS
01853 #undef TEMP
01854 #undef BASE
01855 #undef ABASE
01856 
01857 #undef SORT_EXECPTION
01858 
01859 } // namespace faudes
01860 
01861 
01862 
01863 
01864 #define FAUDES_TRANSSET_H
01865 #endif
01866 

libFAUDES 2.22k --- 2013.04.02 --- c++ source docu by doxygen