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

libFAUDES 2.18b --- 2010-12-17 --- c++ source docu by doxygen 1.6.3