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

libFAUDES 2.16b --- 2010-9-8 --- c++ source docu by doxygen 1.6.3