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

libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen