cfl_transset.h
Go to the documentation of this file.
1 /** @file cfl_transset.h @brief Classes Transition, TTransSet and TaTransSet */
2 
3 /* FAU Discrete Event Systems Library (libfaudes)
4 
5 Copyright (C) 2006 Bernd Opitz
6 Copyright (C) 2007 Thomas Moor
7 
8 Exclusive copyright is granted to Klaus Schmidt
9 
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2.1 of the License, or (at your option) any later version.
14 
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23 
24 
25 #ifndef FAUDES_TRANSSET_H
26 #define FAUDES_TRANSSET_H
27 
28 
29 #include <sstream>
30 #include <map>
31 #include <iostream>
32 #include <typeinfo>
33 
34 #include "cfl_definitions.h"
35 #include "cfl_baseset.h"
36 #include "cfl_attrmap.h"
37 #include "cfl_indexset.h"
38 #include "cfl_nameset.h"
39 #include "cfl_attributes.h"
40 #include "cfl_tokenreader.h"
41 
42 
43 namespace faudes {
44 
45 /** @addtogroup ContainerClasses */
46 /** @{*/
47 
48 /**
49  * Triple (X1,Ev,X2) to represent current state, event and next state.
50  * This class provides the triple in struct like fashion where the components
51  * are of type faudes::Idx. While default order is lexographic, the transition
52  * container TTransSet allows for alternative sorting. Since technically a
53  * Transition is just a triple of indices, it is only the context of a generator
54  * that actually makes it a transition (eg by providing mandatory symbolic event
55  * names).
56  */
58 
59  public:
60 
61  /** Construct invalid Transition */
62  Transition(void) : X1(0), Ev(0), X2(0) {};
63 
64  /**
65  * Construct from values.
66  * @param x1
67  * Index of current state
68  * @param ev
69  * Index of Event
70  * @param x2
71  * Index of next state
72  */
73  Transition(Idx x1, Idx ev,Idx x2) :
74  X1(x1), Ev(ev), X2(x2) {}
75 
76  /** Default order for sorting container of Transition (lexographic) */
77  inline bool operator < (const Transition& othertrans) const {
78  if (X1 < othertrans.X1) return true;
79  if (X1 > othertrans.X1) return false;
80  if (Ev < othertrans.Ev) return true;
81  if (Ev > othertrans.Ev) return false;
82  if (X2 < othertrans.X2) return true;
83  return false;
84  }
85 
86  /** Equality operator */
87  inline bool operator == (const Transition& othertrans) const {
88  return ((X1 == othertrans.X1) && (Ev == othertrans.Ev) && (X2 == othertrans.X2));
89  };
90 
91  /** Inequality operator */
92  inline bool operator != (const Transition& othertrans) const {
93  return ((X1 != othertrans.X1) || (Ev != othertrans.Ev) || (X2 != othertrans.X2));
94  };
95 
96  /** Test validity (all indices !=0) */
97  inline bool Valid(void) const {
98  return (X1!=0) && (Ev!=0) && (X2!=0);
99  };
100 
101  /** Current state */
102  Idx X1;
103 
104  /** Event */
105  Idx Ev;
106 
107  /** Next state */
109 
110  /** Pretty print to string */
111  std::string Str(void) const {
112  return ToStringInteger(X1)+"--("+ToStringInteger(Ev) + ")->" + ToStringInteger(X2);}
113 };
114 
115 
116 
117 
118 /**
119  * Alternative ordering of Transitions. This class provides binary predicates
120  * for sorting transition containers by variant lexographic order.
121  */
122 
124 
125  public:
126 
127  /** Binary predicate for sorting transitions in order Ev, X1, X2 */
128  struct EvX1X2 {
129  inline bool operator () (const Transition& left, const Transition& right) const {
130  if (left.Ev < right.Ev) return true;
131  if (left.Ev > right.Ev) return false;
132  if (left.X1 < right.X1) return true;
133  if (left.X1 > right.X1) return false;
134  if (left.X2 < right.X2) return true;
135  return false;
136  }
137  };
138 
139  /** Binary predicate for sorting transitions in order Ev, X2, X1 */
140  struct EvX2X1 {
141  inline bool operator () (const Transition& left, const Transition& right) const {
142  if (left.Ev < right.Ev) return true;
143  if (left.Ev > right.Ev) return false;
144  if (left.X2 < right.X2) return true;
145  if (left.X2 > right.X2) return false;
146  if (left.X1 < right.X1) return true;
147  return false;
148  }
149  };
150 
151  /** Binary predicate for sorting transitions in order X2, Ev, X1 */
152  struct X2EvX1 {
153  inline bool operator () (const Transition& left, const Transition& right) const {
154  if (left.X2 < right.X2) return true;
155  if (left.X2 > right.X2) return false;
156  if (left.Ev < right.Ev) return true;
157  if (left.Ev > right.Ev) return false;
158  if (left.X1 < right.X1) return true;
159  return false;
160  }
161  };
162 
163  /** Binary predicate for sorting transitions in order X2, X1, Ev */
164  struct X2X1Ev {
165  inline bool operator () (const Transition& left, const Transition& right) const {
166  if (left.X2 < right.X2) return true;
167  if (left.X2 > right.X2) return false;
168  if (left.X1 < right.X1) return true;
169  if (left.X1 > right.X1) return false;
170  if (left.Ev < right.Ev) return true;
171  return false;
172  }
173  };
174 
175  /** Binary predicate for sorting transitions in order X1, X2, Ev */
176  struct X1X2Ev {
177  inline bool operator () (const Transition& left, const Transition& right) const {
178  if (left.X1 < right.X1) return true;
179  if (left.X1 > right.X1) return false;
180  if (left.X2 < right.X2) return true;
181  if (left.X2 > right.X2) return false;
182  if (left.Ev < right.Ev) return true;
183  return false;
184  }
185  };
186 
187  /** Binary predicate for sorting transitions in order X1, Ev, X2 */
188  struct X1EvX2 {
189  inline bool operator () (const Transition& left, const Transition& right) const {
190  if (left.X1 < right.X1) return true;
191  if (left.X1 > right.X1) return false;
192  if (left.Ev < right.Ev) return true;
193  if (left.Ev > right.Ev) return false;
194  if (left.X2 < right.X2) return true;
195  return false;
196  }
197  };
198 
199 };
200 
201 
202 
203 /**
204  * Set of Transitions.
205  *
206  * This container class provides similar functionality and interface as BaseSet, but
207  * for Transitions rather than indices. The additional feature is a template parameter
208  * that allows to specify alternative sorting. For algorithms that examine a transition
209  * relation by e.g. the successor state X2, it may be worthwhile to copy a given
210  * TTransRel<TransSort::X1EvX2> to a TTransRel<TransSort::X2EvX1>. Example,
211  * assuming some transition relation is given in default order
212  *
213  * \code
214  * TransSet transrel; // transrel default order X1-Ev-X2
215  *
216  * // ... some operation to set up transrel
217  *
218  * TTransSet<TransSort::X2EvX1> transByX2; // alternative order X2-Ev-X1
219  * transrel.ReSort(transByX2); // copy and re-order transrel
220  * Iterator tit =transByX2.BeginByX2(x2) // begin iterator, X2 specified
221  * Iterator tit_end=transByX2.EndByX2(x2) // end iterator, X2 specified
222  * for(; tit!=tit_end; ++tit) { // loop over all transitions with specified x2
223  *
224  * // ... code to examine tramsitions with specified x2
225  *
226  * }
227  *
228  * \endcode
229  *
230  * Note: it is the context of a Generator that
231  * actually allows to interpret a TTransSet as a set of transitions as opposed to
232  * a set of triples of indices. In particular, file IO of transitions is provided
233  * by the generator class (although TTransSet provides basic output functions for debugging)
234  */
235 
236 // tweak: this appears to be a g** 4.2 (OsX) issue --- fails dynamic case if this symbol is hidden.
237 #ifdef __GNUC__
238 template <class Cmp=TransSort::X1EvX2>
239 class FAUDES_API TTransSet : public TBaseSet<Transition,Cmp> {
240 #else
241 template <class Cmp=TransSort::X1EvX2>
242 class TTransSet : public TBaseSet<Transition,Cmp> {
243 #endif
244 
246 
247 
248  public:
249 
250  /** @name Constructors & Destructor */
251  /** @{ doxygen group */
252 
253  /** Construct an empty TTransSet object */
254  TTransSet(void);
255 
256  /**
257  * Copy-constructor
258  */
259  TTransSet(const TBaseSet<Transition,Cmp>& rOtherSet);
260 
261  /**
262  * Re-Sort Copy-constructor
263  */
264  template<class OtherCmp>
265  TTransSet(const TTransSet<OtherCmp>& res);
266 
267  /** Virtual destructor */
268  virtual ~TTransSet() {};
269 
270 
271  /** @} doxygen group */
272 
273 
274  /** Iterator on transition */
275  typedef typename TBaseSet<Transition, Cmp>::Iterator Iterator;
276 
277 
278  /** @name Accessing individual transitions */
279  /** @{ doxygen group */
280 
281  /**
282  * Add a Transition.
283  *
284  * @param rTransition
285  * Reference to transition object
286  * @return
287  * True if the transition was new to the set
288  *
289  */
290  bool Insert(const Transition& rTransition);
291 
292  /**
293  * Add a Transition by indices
294  *
295  * @param x1
296  * Predecessor state
297  * @param ev
298  * Event
299  * @param x2
300  * Successor state
301  * @return
302  * True if the transition was new to the set
303  *
304  */
305  bool Insert(Idx x1, Idx ev, Idx x2);
306 
307  /**
308  * Add a Transition.
309  *
310  * @param pos
311  * Insertion hint passed to STL
312  * @param rTransition
313  * Reference to transition object
314  * @return
315  * Insertion position
316  *
317  */
318  Iterator Inject(const Iterator& pos, const Transition& rTransition);
319 
320  /**
321  * Add a Transition.
322  *
323  * @param rTransition
324  * Reference to transition object
325  * @return
326  * Insertion position
327  *
328  */
329  void Inject(const Transition& rTransition);
330 
331  /**
332  * Remove a Transition
333  *
334  * @return
335  * True if transition did exist
336  */
337  bool Erase(const Transition& t);
338 
339  /**
340  * Remove a Transition by x1, ev, x2
341  *
342  * @return
343  * True if transition did exist
344  */
345  bool Erase(Idx x1, Idx ev, Idx x2);
346 
347  /**
348  * Remove a Transition by iterator
349  *
350  * @return
351  * Iterator to next transition
352  */
353  Iterator Erase(const Iterator& it);
354 
355  /**
356  * Remove all transitions containing predecessor state x1.
357  *
358  * @param x1
359  * State index
360  * @exception Exception
361  * - sorting mismatch (id 68)
362  */
363  void EraseByX1(Idx x1);
364 
365  /**
366  * Remove all transitions containing predecessor state x1 and event ev.
367  *
368  * @param x1
369  * State index
370  * @param ev
371  * Event index
372  * @exception Exception
373  * - sorting mismatch (id 68)
374  */
375  void EraseByX1Ev(Idx x1, Idx ev);
376 
377  /**
378  * Remove all transitions containing successor state x2.
379  * This function iterates over all transitions to work with any sorting.
380  *
381  * @param x2
382  * State index
383  */
384  void EraseByX2(Idx x2);
385 
386  /**
387  * Remove all transitions containing event ev.
388  * This function iterates over all transitions to work with any sorting.
389  *
390  * @param ev
391  * Event index
392  */
393  void EraseByEv(Idx ev);
394 
395  /**
396  * Remove all transitions containing state x,
397  * This function iterates over all transitions to work with any sorting.
398  *
399  * @param x
400  * State index
401  */
402  void EraseByX1OrX2(Idx x);
403 
404  /**
405  * Remove all transitions containing a specified state.
406  * This function iterates over all transitions to work with any sorting.
407  *
408  * @param rStates
409  * Set of states to remore
410  */
411  void EraseByX1OrX2(const StateSet& rStates);
412 
413  /**
414  * Restrict to transitions with states as specified.
415  * Erases any transition with X1 or X2 not in the specified state set.
416  *
417  * @param rStateSet
418  * Set of states to keep.
419  */
420  void RestrictStates(const StateSet& rStateSet);
421 
422  /**
423  * Restrict to transitions with events as specified.
424  * Erases any transition with event not in the specified state set.
425  *
426  * @param rEventSet
427  * Set of events to keep.
428  */
429  void RestrictEvents(const EventSet& rEventSet);
430 
431  /**
432  * Find transition given by x1, ev, x2
433  *
434  *
435  * @param x1
436  * Predecessor state
437  * @param ev
438  * Event
439  * @param x2
440  * Successor state
441  *
442  * @return
443  * Iterator to transition or End() if not exists
444  */
445  Iterator Find(Idx x1, Idx ev, Idx x2) const;
446 
447  /**
448  * Find specified transition
449  *
450  *
451  * @param t
452  * Transition
453  *
454  * @return
455  * Iterator to transition or End() if not exists
456  */
457  Iterator Find(const Transition& t) const;
458 
459 
460  /**
461  * Test existence
462  *
463  * @param t
464  * Transition
465  *
466  * @return
467  * bool
468  */
469  bool Exists(const Transition& t) const;
470 
471  /**
472  * Test existence
473  *
474  * @param x1
475  * Predecessor state Idx
476  * @param ev
477  * Event Idx
478  * @param x2
479  * Successor state Idx
480  *
481  * @return
482  * bool
483  */
484  bool Exists(Idx x1, Idx ev, Idx x2) const;
485 
486  /**
487  * Test existence
488  *
489  * @param x1
490  * Predecessor state Idx
491  * @param ev
492  * Event Idx
493  *
494  * @return
495  * bool
496  */
497  bool ExistsByX1Ev(Idx x1, Idx ev) const;
498 
499  /**
500  * Test existence
501  *
502  * @param x1
503  * Predecessor state Idx
504  * @param ev
505  * Event Idx
506  *
507  * @return
508  * bool
509  */
510  bool ExistsByX1(Idx x1) const;
511 
512  /**
513  * Tests if a transition with specified predecessor or successor state
514  * exists.
515  *
516  * @param x
517  * State Idx
518  *
519  * @return
520  * bool
521  */
522  bool ExistsByX1OrX2(Idx x) const;
523 
524 
525 
526  /** @} doxygen group */
527 
528  /** @name Transition iterators
529  *
530  * A variaty of iterators are provided to examine specified
531  * segments of the transition relation, e.g. all transitions starting
532  * from a given state. Note that implemetation of these iterators
533  * requires the transition set to be of sorted accordingly. Eg.
534  * scanning all transitions that are labled with a particular event
535  * requires a sorting TransSOrt::EvX1X2 orT ransSOrt::EvX2X1.
536  *
537  *
538  */
539 
540  /** @{ doxygen group: iterators */
541 
542  /**
543  * Iterator to begin of set
544  *
545  * @return
546  * TTransSet<Cmp>::Iterator
547  */
548  Iterator Begin(void) const;
549 
550  /**
551  * Iterator to end of set
552  *
553  * @return
554  * TTransSet<Cmp>::Iterator
555  */
556  Iterator End(void) const;
557 
558 
559  /**
560  * Iterator to first Transition specified by current state.
561  *
562  * @param x1
563  * Predecessor state index
564  *
565  * @return
566  * TTransSet<Cmp>::Iterator
567  *
568  * @exception Exception
569  * - Sorting mismatch (id 68)
570  */
571  Iterator Begin(Idx x1) const;
572 
573  /**
574  * Iterator to end or Transitions with specified current state.
575  *
576  * @param x1
577  * Predecessor state index
578  *
579  * @return
580  * TTransSet<Cmp>::Iterator
581  *
582  * @exception Exception
583  * - Sorting mismatch (id 68)
584  */
585  Iterator End(Idx x1) const;
586 
587  /**
588  * Iterator to first Transitions specified by current state and event.
589  *
590  * @param x1
591  * Predecessor state index
592  * @param ev
593  * Event index
594  *
595  * @return
596  * TTransSet<Cmp>::Iterator
597  *
598  * @exception Exception
599  * - Sorting mismatch (id 68)
600  */
601  Iterator Begin(Idx x1, Idx ev) const;
602 
603  /**
604  * Iterator to first Transition after spcified current state and event.
605  *
606  * @param x1
607  * Predecessor state index
608  * @param ev
609  * Event index
610  *
611  * @return
612  * TTransSet<Cmp>::Iterator
613  *
614  * @exception Exception
615  * - sorting mismatch (id 68)
616  */
617  Iterator End(Idx x1, Idx ev) const;
618 
619  /**
620  * Iterator to first Transition specified by event.
621  * This function requires sorting TransSort::EvX1X2 or TransSort::EvX2X1.
622  *
623  * @param ev
624  * Event index
625  *
626  * @return
627  * TTransSet<Cmp>::iterator
628  *
629  * @exception Exception
630  * - sorting mismatch (id 68)
631  */
632  Iterator BeginByEv(Idx ev) const;
633 
634  /**
635  * Iterator to first Transition after specified by event.
636  * This function requires sorting TransSort::EvX1X2 or TransSort::EvX2X1
637  *
638  * @param ev
639  * Predecessor state index
640  *
641  * @return
642  * TTransSet<Cmp>::Iterator
643  *
644  * @exception Exception
645  * - sorting mismatch (id 68)
646  */
647  Iterator EndByEv(Idx ev) const;
648 
649  /**
650  * Iterator to first Transition specified by event and current state.
651  * This function requires sorting TransSort::EvX1X2.
652  *
653  * @param ev
654  * Event index
655  * @param x1
656  * Predecessor state index
657  *
658  * @return
659  * TTransSet<Cmp>::iterator
660  *
661  * @exception Exception
662  * - sorting mismatch (id 68)
663  */
664  Iterator BeginByEvX1(Idx ev, Idx x1) const;
665 
666  /**
667  * Iterator to first Transition after specified ev and current state.
668  * This function requires sorting TransSort::EvX1X2.
669  *
670  * @param ev
671  * Event index
672  * @param x1
673  * Predecessor state index
674  *
675  * @return
676  * TTransSet<Cmp>::Iterator
677  *
678  * @exception Exception
679  * - sorting mismatch (id 68)
680  */
681  Iterator EndByEvX1(Idx ev, Idx x1) const;
682 
683  /**
684  * Iterator to first Transition specified by event and next state.
685  * This function requires sorting TransSort::EvX2X1.
686  *
687  * @param ev
688  * Event index
689  * @param x2
690  * Predecessor state index
691  *
692  * @return
693  * TTransSet<Cmp>::Iterator
694  *
695  * @exception Exception
696  * - sorting mismatch (id 68)
697  */
698  Iterator BeginByEvX2(Idx ev, Idx x2) const;
699 
700  /**
701  * Iterator to first Transition after specified event and next state.
702  * This function requires sorting TransSort::EvX2X1.
703  *
704  * @param ev
705  * Event index
706  * @param x2
707  * Predecessor state index
708  *
709  * @return
710  * TTransSet<Cmp>::Iterator
711  *
712  * @exception Exception
713  * - sorting mismatch (id 68)
714  */
715  Iterator EndByEvX2(Idx ev, Idx x2) const;
716 
717  /**
718  * Iterator to first Transition specified by successor state x2.
719  * This function requires sorting TransSort::X2EvX1 or TransSort::X2X1Ev.
720  *
721  * @param x2
722  * Predecessor state index
723  *
724  * @return
725  * TTransSet<Cmp>::iterator
726  *
727  * @exception Exception
728  * - sorting mismatch (id 68)
729  */
730  Iterator BeginByX2(Idx x2) const;
731 
732  /**
733  * Iterator to first Transition after specified successor state x2.
734  * This function requires sorting TransSort::X2EvX1 or TransSort::X2X1Ev
735  *
736  * @param x2
737  * Predecessor state index
738  *
739  * @return
740  * TTransSet<Cmp>::Iterator
741  *
742  * @exception Exception
743  * - sorting mismatch (id 68)
744  */
745  Iterator EndByX2(Idx x2) const;
746 
747  /**
748  * Iterator to first Transition specified by successor x2 and ev.
749  * This function requires sorting TransSort::X2EvX1.
750  *
751  * @param x2
752  * Predecessor state index
753  * @param ev
754  * Event index
755  *
756  * @return
757  * TTransSet<Cmp>::Iterator
758  *
759  * @exception Exception
760  * - sorting mismatch (id 68)
761  */
762  Iterator BeginByX2Ev(Idx x2, Idx ev) const;
763 
764  /**
765  * Iterator to first Transition after specified successor x2 and ev.
766  * This function requires sorting TransSort::X2EvX1.
767  *
768  * @param x2
769  * Predecessor state index
770  * @param ev
771  * Event index
772  *
773  * @return
774  * TTransSet<Cmp>::Iterator
775  *
776  * @exception Exception
777  * - sorting mismatch (id 68)
778  */
779  Iterator EndByX2Ev(Idx x2, Idx ev) const;
780 
781  /** @} doxygen group */
782 
783  /** @name Misc */
784  /** @{ doxygen group */
785 
786  /**
787  * Get copy of trantision relation sorted by other compare
788  * operator, e.g. TSort::X2EvX1
789  *
790  * @return
791  * Transition relation
792  */
793  template<class OtherCmp>
794  void ReSort(TTransSet<OtherCmp>& res) const;
795 
796  /**
797  * Get state set covered by transition set
798  *
799  * @return
800  * Set of state indices used by some transition
801  */
802  StateSet States(void) const;
803 
804  /**
805  * Get set of successor states for specified current state
806  *
807  * @param x1
808  * Current state
809  *
810  * @return
811  * Set of state indices
812  */
813  StateSet SuccessorStates(Idx x1) const;
814 
815  /**
816  * Get set of successor states for specified current states
817  *
818  * @param rX1Set
819  * Current state
820  *
821  * @return
822  * Set of state indices
823  */
824  StateSet SuccessorStates(const StateSet& rX1Set) const;
825 
826  /**
827  * Get set of successor states for specified current state and event
828  *
829  * @param x1
830  * Current state
831  * @param ev
832  * Event
833  *
834  * @return
835  * Set of state indices
836  */
837  StateSet SuccessorStates(Idx x1, Idx ev) const;
838 
839  /**
840  * Get set of successor states for specified current states and events
841  *
842  * @param rX1Set
843  * Current states
844  * @param rEvSet
845  * Events
846  *
847  * @return
848  * Set of state indices
849  */
850  StateSet SuccessorStates(const StateSet& rX1Set, const EventSet& rEvSet) const;
851 
852 
853  /**
854  * Get set of events that are active for a specified current state
855  * Since a transition set does not refer to a SymbolTable, this function
856  * returns a set of plain indices. In order to interpret the set as an EventSet,
857  * the relevant SymbolTable must be supplied as second argument. If obmitting the second
858  * argument, the defult SymbolTable is used.
859  *
860  * @param x1
861  * Current state
862  * @param pSymTab
863  * SymbolTable to refer to
864  *
865  * @return
866  * Set of events.
867  */
868  EventSet ActiveEvents(Idx x1, SymbolTable* pSymTab=NULL) const;
869 
870  /**
871  * Return pretty printable string representation.
872  * Primary meant for debugging messages.
873  *
874  * @param rTrans
875  * Transition to print
876  *
877  * @return
878  * String
879  */
880  std::string Str(const Transition& rTrans) const;
881 
882 
883  /** @} doxygen group */
884 
885  protected:
886 
887 
888  /**
889  * Assign my members.
890  *
891  * @param rSource
892  * Source to copy from
893  * @return
894  * Ref to this set
895  */
896  void DoAssign(const TTransSet& rSource);
897 
898  /**
899  * Write to TokenWriter, see Type::Write for public wrappers.
900  *
901  * @param rTw
902  * Reference to TokenWriter
903  * @param rLabel
904  * Label of section to write, defaults to name of set
905  * @param pContext
906  * Write context eg symboltables
907  *
908  * @exception Exception
909  * - IO errors (id 2)
910  */
911 
912  virtual void DoWrite(TokenWriter& rTw, const std::string& rLabel="", const Type* pContext=0) const;
913 
914 
915 };
916 
917 /** Type definition for default sorted TTransSet */
919 
920 /** Type definition for default sorted TTransSet */
922 
923 /** Type definition for ev, x1, x2 sorted TTransSet */
925 
926 /** Type definition for ev, x2, x1 sorted TTransSet */
928 
929 /** Type definition for x2, ev, x1 sorted TTransSet */
931 
932 /** Type definition for x2, x1, ev sorted TTransSet */
934 
935 /** Type definition for x1, x2, ev sorted TTransSet */
937 
938 
939 /**
940  * Set of Transitions with attributes.
941  *
942  * This container class is derived from TTransSet to provide attributes as an
943  * additional feature. The template parameter specifies the attribute class,
944  * which in turn must provide some basic funtionality. In contrast to the TTransSet, the TaTransSet
945  * is restricted to standard ordering.
946  *
947  * Note that it is the context of a Generator that
948  * actually allows to interpret a TaTransSet as a set of transitions as opposed to
949  * a set of triples of indices with attributes. In particular, file IO of transitions is provided
950  * by the generator class (although TaTransSet provides output functions for debugging)
951  */
952 
953 
954 template <class Attr>
955 class TaTransSet : public TransSet, public TAttrMap<Transition,Attr,TransSort::X1EvX2> {
956 
958 
959 public:
960 
961 
962  /** @name Constructors & Destructor */
963  /** @{ doxygen group */
964 
965  /** Construct an empty TaTransSet object */
966  TaTransSet(void);
967 
968  /**
969  * Copy-constructor (incl attributes)
970  */
971  TaTransSet(const TaTransSet& rOtherSet);
972 
973  /**
974  * Copy-Constructor (set attributes to default)
975  */
976  TaTransSet(const TTransSet<TransSort::X1EvX2>& rOtherSet);
977 
978  /** Virtual destructor */
979  virtual ~TaTransSet() {}
980 
981  /** Relaxed assignment method.
982  *
983  * Runtime typecheck for TransSet, maintains attributes provided they can be casted.
984  *
985  * @param rSrc
986  * Source from which to assign
987  * @return
988  * Ref to this set
989  */
990  virtual TaTransSet& Assign(const TBaseSet<Transition,TransSort::X1EvX2>& rSrc);
991 
992  /** Relaxed assignment operator.
993  *
994  * @param rSrc
995  * Source from which to assign
996  * @return
997  * Ref to this set
998  */
999  virtual TaTransSet& operator=(const TransSet& rSrc) {return Assign(rSrc);}
1000 
1001  /** @} doxygen group */
1002 
1003 
1004 
1005  /** @name Accessing individual transitions */
1006  /** @{ doxygen group */
1007 
1008  /** Iterator on transition */
1010 
1011  /**
1012  * Add a Transition by indices
1013  *
1014  * @param x1
1015  * Predecessor state
1016  * @param ev
1017  * Event
1018  * @param x2
1019  * Successor state
1020  *
1021  * @return
1022  * True if the transition was new to the set
1023  */
1024  bool Insert(Idx x1, Idx ev, Idx x2);
1025 
1026  /**
1027  * Add a Transition directly. If the transition already
1028  * exists, the attribute is maintained. Otherwise, the transition
1029  * is inserted with default attribute.
1030  *
1031  * @param rTransition
1032  * Reference to transition object
1033  *
1034  * @return
1035  * True if the transition was new to the set
1036  */
1037  bool Insert(const Transition& rTransition);
1038 
1039  /**
1040  * Add a Transition with attribute.
1041  *
1042  * @param rTransition
1043  * Reference to transition object
1044  * @param rAttr
1045  * Reference to attribute
1046  *
1047  * @return
1048  * True if the transition was new to the set
1049  */
1050  bool Insert(const Transition& rTransition, const Attr& rAttr);
1051 
1052  /**
1053  * Inserts elements of rOtherSet.
1054  *
1055  * Attributes of this set are maintained, newly inserted elements attain the
1056  * attribute from rOtherSet if it can be casted appropriately.
1057  *
1058  *
1059  * @param rOtherSet
1060  * Other IndexSet
1061  */
1062  virtual void InsertSet(const TransSet& rOtherSet);
1063 
1064  /**
1065  * Inserts elements of rOtherSet.
1066  *
1067  * This variant uses a runtime cast to access attributes.
1068  *
1069  * @param rOtherSet
1070  * Other IndexSet
1071  * @exception Exception
1072  * - cast failed (id 67)
1073  */
1074  virtual void InsertSet(const TBaseSet<Transition,TransSort::X1EvX2>& rOtherSet);
1075 
1076  /**
1077  * Remove a Transition
1078  *
1079  * @return
1080  * True if transition did exist
1081  */
1082  bool Erase(const Transition& t);
1083 
1084  /**
1085  * Remove a Transition
1086  *
1087  * @return
1088  * True if transition did exist
1089  */
1090  bool Erase(Idx x1, Idx ev, Idx x2);
1091 
1092  /**
1093  * Remove a Transition by iterator
1094  *
1095  * @return
1096  * Iterator to next transition
1097  */
1098  Iterator Erase(const Iterator& it);
1099 
1100  /**
1101  * Inserts elements of rOtherSet.
1102  *
1103  * Attributes of this set are maintained.
1104  *
1105  *
1106  * @param rOtherSet
1107  * Other IndexSet
1108  */
1109  virtual void EraseSet(const TransSet& rOtherSet);
1110 
1111  /**
1112  * Inserts elements of rOtherSet.
1113  *
1114  * This variant uses a runtime cast to access attributes.
1115  *
1116  * @param rOtherSet
1117  * Other IndexSet
1118  * @exception Exception
1119  * - cast failed (id 67)
1120  */
1121  virtual void EraseSet(const TBaseSet<Transition,TransSort::X1EvX2>& rOtherSet);
1122 
1123 
1124  /**
1125  * Restrict to specified subset.
1126  *
1127  * Erases any elements no in the specified set. This function
1128  * ignores the attributes of the other set and maintains the attributes
1129  * of the remaining elements in this set.
1130  *
1131  * @param rOtherSet
1132  * Elements to erase
1133  */
1134  void RestrictSet(const TransSet& rOtherSet);
1135 
1136 
1137  /**
1138  * Restrict to specified subset.
1139  *
1140  * This variant uses a runtime cast to access attributes.
1141  *
1142  * @param rOtherSet
1143  * Elements to erase
1144  */
1145  void RestrictSet(const TBaseSet<Transition,TransSort::X1EvX2>& rOtherSet);
1146 
1147 
1148 
1149 
1150  /** resolve ambiguities from attribute interface ("using" wont do the job) */
1153  const Attr& Attribute(const Transition& rElem) const { return TAttrMap<Transition,Attr,TransSort::X1EvX2>::Attribute(rElem); };
1154  void Attribute(const Transition& rElem, const Attr& rAttr) { return TAttrMap<Transition,Attr,TransSort::X1EvX2>::Attribute(rElem,rAttr); };
1155  void Attribute(const Transition& rElem, const Type& rAttr) { return TAttrMap<Transition,Attr,TransSort::X1EvX2>::Attribute(rElem,rAttr); };
1156  void AttributeTry(const Transition& rElem, const Type& rAttr) { return TAttrMap<Transition,Attr,TransSort::X1EvX2>::AttributeTry(rElem,rAttr); };
1157 
1158 
1159  /** @} doxygen group */
1160 
1161 
1162  protected:
1163 
1164  /**
1165  * Assign my members. Maintain attributes.
1166  *
1167  * @param rSource
1168  * Source to copy from
1169  * @return
1170  * Ref to this set
1171  */
1172  void DoAssign(const TaTransSet& rSource);
1173 
1174 };
1175 
1176 /** @} doxygen group*/
1177 
1178 
1179 /*
1180 *************************************************************************************************
1181 *************************************************************************************************
1182 * Implementation of transset without attributes
1183 *************************************************************************************************
1184 *************************************************************************************************
1185 */
1186 
1187 
1188 /* convenience access to relevant scopes */
1189 #define THIS TTransSet<Cmp>
1190 #define TEMP template<class Cmp>
1191 #define BASE TBaseSet<Transition,Cmp>
1192 
1193 // std faudes type
1195 
1196 // TTransSet(void)
1198 {
1199  FD_DC("TTransSet(" << this << ")::TTransSet()");
1200 }
1201 
1202 // TTransSet(othertransrel)
1203  TEMP THIS::TTransSet(const TBaseSet<Transition,Cmp>& rOtherSet) :
1204  BASE()
1205 {
1206  FD_DC("TTransSet(" << this << ")::TTransSet(rOtherSet "<< &rOtherSet <<")");
1207  Assign(rOtherSet);
1208 }
1209 
1210 // TTransSet(othertransrel othersort)
1211 TEMP template<class OtherCmp>
1212 THIS::TTransSet(const TTransSet<OtherCmp>& rOtherSet) :
1213  BASE()
1214 {
1215  FD_DC("TTransSet(" << this << ")::TTransSet(rOtherSet/ReSort "<< &rOtherSet <<")");
1216  rOtherSet.ReSort(*this);
1217 }
1218 
1219 // assignment (maintain attributes)
1220 TEMP void THIS::DoAssign(const TTransSet& rSourceSet) {
1221  FD_DC("TTransSet(" << this << ")::DoAssign(..)");
1222  // call base (incl attributes if the have identival type)
1223  BASE::DoAssign(rSourceSet);
1224 }
1225 
1226 // iterator Begin() const
1227 TEMP typename THIS::Iterator THIS::Begin(void) const {
1228  return BASE::Begin();
1229 }
1230 
1231 // iterator End() const
1232 TEMP typename THIS::Iterator THIS::End(void) const {
1233  return BASE::End();
1234 }
1235 
1236 
1237 // Convenience macro for order typecheck
1238 #define SORT_EXCEPTION { std::stringstream errstr; \
1239  errstr << "Transition set order mismatch " << std::endl; \
1240  throw Exception("TransSet::Iterator()", errstr.str(), 68); }
1241 
1242 
1243 // iterator Begin(x1) const
1244 TEMP typename THIS::Iterator THIS::Begin(Idx x1) const {
1245 #ifdef FAUDES_CHECKED
1246  if(typeid(Cmp)!=typeid(TransSort::X1EvX2))
1247  if(typeid(Cmp)!=typeid(TransSort::X1X2Ev))
1249 #endif
1250  Transition tlx(x1,0,0);
1251  return THIS::ThisIterator(BASE::pSet->lower_bound(tlx));
1252 }
1253 
1254 // iterator End(x1) const
1255 TEMP typename THIS::Iterator THIS::End(Idx x1) const {
1256 #ifdef FAUDES_CHECKED
1257  if(typeid(Cmp)!=typeid(TransSort::X1EvX2))
1258  if(typeid(Cmp)!=typeid(TransSort::X1X2Ev))
1260 #endif
1261  Transition tlx(x1+1,0,0);
1262  return THIS::ThisIterator(BASE::pSet->lower_bound(tlx));
1263 }
1264 
1265 // iterator Begin(x1,ev) const
1266 TEMP typename THIS::Iterator THIS::Begin(Idx x1, Idx ev) const {
1267 #ifdef FAUDES_CHECKED
1268  if(typeid(Cmp)!=typeid(TransSort::X1EvX2))
1270 #endif
1271  Transition tlx(x1,ev,0);
1272  return THIS::ThisIterator(BASE::pSet->lower_bound(tlx));
1273 }
1274 
1275 // iterator End(x1,ev) const
1276 TEMP typename THIS::Iterator THIS::End(Idx x1, Idx ev) const {
1277 #ifdef FAUDES_CHECKED
1278  if(typeid(Cmp)!=typeid(TransSort::X1EvX2))
1280 #endif
1281  Transition tlx(x1,ev+1, 0);
1282  return THIS::ThisIterator(BASE::pSet->lower_bound(tlx));
1283 }
1284 
1285 // iterator BeginByEv(ev) const
1286 TEMP typename THIS::Iterator THIS::BeginByEv(Idx ev) const {
1287 #ifdef FAUDES_CHECKED
1288  if(typeid(Cmp)!=typeid(TransSort::EvX1X2))
1289  if(typeid(Cmp)!=typeid(TransSort::EvX2X1))
1291 #endif
1292  Transition tlx(0,ev,0);
1293  return THIS::ThisIterator(BASE::pSet->lower_bound(tlx));
1294 }
1295 
1296 // iterator EndByEv(ev) const
1297 TEMP typename THIS::Iterator THIS::EndByEv(Idx ev) const {
1298 #ifdef FAUDES_CHECKED
1299  if(typeid(Cmp)!=typeid(TransSort::EvX1X2))
1300  if(typeid(Cmp)!=typeid(TransSort::EvX2X1))
1302 #endif
1303  Transition tlx(0,ev+1,0);
1304  return THIS::ThisIterator(BASE::pSet->lower_bound(tlx));
1305 }
1306 
1307 // iterator BeginByEvX1(ev,x1) const
1308 TEMP typename THIS::Iterator THIS::BeginByEvX1(Idx ev, Idx x1) const {
1309 #ifdef FAUDES_CHECKED
1310  if(typeid(Cmp)!=typeid(TransSort::EvX1X2))
1312 #endif
1313  Transition tlx(x1,ev,0);
1314  return THIS::ThisIterator(BASE::pSet->lower_bound(tlx));
1315 }
1316 
1317 // iterator EndByEvX1(ev,x1) const
1318 TEMP typename THIS::Iterator THIS::EndByEvX1(Idx ev, Idx x1) const {
1319 #ifdef FAUDES_CHECKED
1320  if(typeid(Cmp)!=typeid(TransSort::EvX1X2))
1322 #endif
1323  Transition tlx(x1+1,ev,0);
1324  return THIS::ThisIterator(BASE::pSet->lower_bound(tlx));
1325 }
1326 
1327 // iterator BeginByEvX2(ev,x2) const
1328 TEMP typename THIS::Iterator THIS::BeginByEvX2(Idx ev, Idx x2) const {
1329 #ifdef FAUDES_CHECKED
1330  if(typeid(Cmp)!=typeid(TransSort::EvX2X1))
1332 #endif
1333  Transition tlx(0,ev,x2);
1334  return THIS::ThisIterator(BASE::pSet->lower_bound(tlx));
1335 }
1336 
1337 // iterator EndByEvX2(ev,x2) const
1338 TEMP typename THIS::Iterator THIS::EndByEvX2(Idx ev, Idx x2) const {
1339 #ifdef FAUDES_CHECKED
1340  if(typeid(Cmp)!=typeid(TransSort::EvX2X1))
1342 #endif
1343  Transition tlx(0,ev,x2+1);
1344  return THIS::ThisIterator(BASE::pSet->lower_bound(tlx));
1345 }
1346 
1347 // iterator BeginByX2(x2) const
1348 TEMP typename THIS::Iterator THIS::BeginByX2(Idx x2) const {
1349 #ifdef FAUDES_CHECKED
1350  if(typeid(Cmp)!=typeid(TransSort::X2EvX1))
1351  if(typeid(Cmp)!=typeid(TransSort::X2X1Ev))
1353 #endif
1354  Transition tlx(0,0,x2);
1355  return THIS::ThisIterator(BASE::pSet->lower_bound(tlx));
1356 }
1357 
1358 // iterator EndByX2(x2) const
1359 TEMP typename THIS::Iterator THIS::EndByX2(Idx x2) const {
1360 #ifdef FAUDES_CHECKED
1361  if(typeid(Cmp)!=typeid(TransSort::X2EvX1))
1362  if(typeid(Cmp)!=typeid(TransSort::X2X1Ev))
1364 #endif
1365  Transition tlx(0,0,x2+1);
1366  return THIS::ThisIterator(BASE::pSet->lower_bound(tlx));
1367 }
1368 
1369 // iterator BeginByX2Ev(x2,ev) const
1370 TEMP typename THIS::Iterator THIS::BeginByX2Ev(Idx x2, Idx ev) const {
1371 #ifdef FAUDES_CHECKED
1372  if(typeid(Cmp)!=typeid(TransSort::X2EvX1))
1374 #endif
1375  Transition tlx(0,ev,x2);
1376  return THIS::ThisIterator(BASE::pSet->lower_bound(tlx));
1377 }
1378 
1379 // iterator EndByX2Ev(x2,ev) const
1380 TEMP typename THIS::Iterator THIS::EndByX2Ev(Idx x2, Idx ev) const {
1381 #ifdef FAUDES_CHECKED
1382  if(typeid(Cmp)!=typeid(TransSort::X2EvX1))
1384 #endif
1385  Transition tlx(0,ev+1,x2);
1386  return THIS::ThisIterator(BASE::pSet->lower_bound(tlx));
1387 }
1388 
1389 
1390 
1391 // DoWrite(rw,label)
1392 TEMP void THIS::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const
1393 {
1394  (void) pContext;
1395  std::string label=rLabel;
1396  if(label=="") label=BASE::Name();
1397  rTw.WriteBegin(label);
1398  int oldcolumns = rTw.Columns();
1399  rTw.Columns(3);
1400 
1401  Iterator tit;
1402  for (tit = Begin(); tit != End(); ++tit) {
1403  rTw << tit->X1; rTw << tit->Ev; rTw << tit->X2;
1404  }
1405 
1406  rTw.WriteEnd(label);
1407  rTw.Columns(oldcolumns);
1408 }
1409 
1410 
1411 // Insert(transition)
1412 TEMP bool THIS::Insert(const Transition& t) {
1413  return BASE::Insert(t);
1414 }
1415 
1416 // Insert(x1,ev,x2)
1417 TEMP bool THIS::Insert(Idx x1, Idx ev, Idx x2) {
1418  FD_DC("TTransSet(" << this << ")::Insert(" << x1 << "-" << ev << "-" << x2 << ")");
1419  return BASE::Insert(Transition(x1, ev, x2));
1420 }
1421 
1422 // Inject(transition)
1423 TEMP typename THIS::Iterator THIS::Inject(const Iterator& pos, const Transition& t) {
1424  return BASE::Inject(pos,t);
1425 }
1426 
1427 // Inject(transition)
1428 TEMP void THIS::Inject(const Transition& t) {
1429  BASE::Inject(t);
1430 }
1431 
1432 
1433 // Erase(transition)
1434 TEMP bool THIS::Erase(const Transition& t) {
1435  FD_DC("TTransSet(" << this << ")::Erase(" << Str() << " [t])");
1436  return BASE::Erase(t);
1437 }
1438 
1439 // Erase(x1,ev,x2)
1440 TEMP bool THIS::Erase(Idx x1, Idx ev, Idx x2) {
1441  FD_DC("TTransSet(" << this << ")::Erase(" << x1 << "-" << ev << "-" << x2 << ")");
1442  return BASE::Erase(Transition(x1, ev, x2));
1443 }
1444 
1445 // Erase(it)
1446 TEMP typename THIS::Iterator THIS::Erase(const Iterator& it) {
1447  FD_DC("TTransSet(" << this << ")::Erase(" << this->Str(*it) << " [it])");
1448  return BASE::Erase(it);
1449 }
1450 
1451 // EraseByX1(x)
1452 TEMP void THIS::EraseByX1(Idx x1) {
1453  FD_DC("TTransSet(" << this << ")::EraseByX1(" << x1 << ")");
1454 #ifdef FAUDES_CHECKED
1455  if(typeid(Cmp)!=typeid(TransSort::X1EvX2))
1456  if(typeid(Cmp)!=typeid(TransSort::X1X2Ev))
1458 #endif
1459  this->Detach();
1460  typename BASE::iterator lower, upper, it;
1461  Transition tl(x1,0,0);
1462  Transition tu(x1+1,0,0);
1463  lower = BASE::pSet->lower_bound(tl);
1464  upper = BASE::pSet->upper_bound(tu);
1465  if(this->AttributesSize()!=0)
1466  for(it=lower; it!=upper; ++it)
1467  BASE::ClrAttribute(*it);
1468  BASE::pSet->erase(lower, upper);
1469 }
1470 
1471 // EraseByX1Ev(x,e)
1472 TEMP void THIS::EraseByX1Ev(Idx x1, Idx ev) {
1473  FD_DC("TTransSet(" << this << ")::EraseByX1Ev(" << x1 << "," << ev << ")");
1474 #ifdef FAUDES_CHECKED
1475  if(typeid(Cmp)!=typeid(TransSort::X1EvX2))
1477 #endif
1478  this->Detach();
1479  typename BASE::iterator lower, upper, it;
1480  Transition tl(x1,ev,0);
1481  Transition tu(x1,ev+1,0);
1482  lower = BASE::pSet->lower_bound(tl);
1483  upper = BASE::pSet->upper_bound(tu);
1484  if(this->AttributesSize()!=0)
1485  for(it=lower; it!=upper; ++it)
1486  BASE::ClrAttribute(*it);
1487  BASE::pSet->erase(lower, upper);
1488 }
1489 
1490 // EraseByX2(x)
1491 TEMP void THIS::EraseByX2(Idx x2) {
1492  FD_DC("TTransSet(" << this << ")::EraseByX2(" << x2 << ")");
1493  this->Detach();
1494  bool doattr = (this->AttributesSize()!=0);
1495  typename BASE::iterator it;
1496  for(it = BASE::pSet->begin(); it != BASE::pSet->end();) {
1497  if(it->X2 == x2) {
1498  if(doattr) BASE::ClrAttribute(*it);
1499  BASE::pSet->erase(it++);
1500  continue;
1501  }
1502  it++;
1503  }
1504 }
1505 
1506 // EraseByEv(ev)
1507 TEMP void THIS::EraseByEv(Idx ev) {
1508  FD_DC("TTransSet(" << this << ")::EraseByEv(" << ev << ")");
1509  this->Detach();
1510  bool doattr = (this->AttributesSize()!=0);
1511  typename BASE::iterator it;
1512  for(it = BASE::pSet->begin(); it != BASE::pSet->end();) {
1513  if (it->Ev == ev) {
1514  if(doattr) BASE::ClrAttribute(*it);
1515  BASE::pSet->erase(it++);
1516  continue;
1517  }
1518  it++;
1519  }
1520 }
1521 
1522 
1523 // EraseByX1OrX2(x)
1524 TEMP void THIS::EraseByX1OrX2(Idx x) {
1525  FD_DC("TTransSet(" << this << ")::EraseByX1OrX2(" << x << ")");
1526  this->Detach();
1527  bool doattr = (this->AttributesSize()!=0);
1528  typename BASE::iterator it;
1529  for(it = BASE::pSet->begin(); it != BASE::pSet->end();) {
1530  if ((it->X1 == x) || (it->X2 == x)) {
1531  if(doattr) BASE::ClrAttribute(*it);
1532  BASE::pSet->erase(it++);
1533  continue;
1534  }
1535  it++;
1536  }
1537  FD_DC("TTransSet(" << this << ")::EraseByX1OrX2(" << x << "): done");
1538 }
1539 
1540 
1541 // EraseByX1OrX2(xset)
1542 TEMP void THIS::EraseByX1OrX2(const StateSet& rStates) {
1543  FD_DC("TTransSet(" << this << ")::EraseByX1OrX2(#" << rStates.Size() <<")");
1544  this->Detach();
1545  bool doattr = (this->AttributesSize()!=0);
1546  typename BASE::iterator it=BASE::pSet->begin();
1547  while(it != BASE::pSet->end()) {
1548  if(!rStates.Exists(it->X1) && !rStates.Exists(it->X2)) { ++it; continue;}
1549  if(doattr) BASE::ClrAttribute(*it);
1550  BASE::pSet->erase(it++);
1551  }
1552  FD_DC("TTransSet(" << this << ")::EraseByX1OrX2(): done");
1553 }
1554 
1555 
1556 // RestrictStates(xset)
1557 TEMP void THIS::RestrictStates(const StateSet& rStates) {
1558  FD_DC("TTransSet(" << this << ")::RestrictByX1AndX2(#" << rStates.Size() <<")");
1559  this->Detach();
1560  bool doattr = (this->AttributesSize()!=0);
1561  typename BASE::iterator it;
1562  it = BASE::pSet->begin();
1563  while(it != BASE::pSet->end()) {
1564  if(rStates.Exists(it->X1) && rStates.Exists(it->X2)) { ++it; continue;}
1565  if(doattr) BASE::ClrAttribute(*it);
1566  BASE::pSet->erase(it++);
1567  }
1568  FD_DC("TTransSet(" << this << ")::EraseByX1OrX2(): done");
1569 }
1570 
1571 
1572 // RestrictEvents(eset)
1573 TEMP void THIS::RestrictEvents(const EventSet& rEvents) {
1574  FD_DC("TTransSet(" << this << ")::RestrictEvents(#" << rEvents.Size() <<")");
1575  this->Detach();
1576  bool doattr = (this->AttributesSize()!=0);
1577  typename BASE::iterator it;
1578  it = BASE::pSet->begin();
1579  while(it != BASE::pSet->end()) {
1580  if(rEvents.Exists(it->Ev)) { ++it; continue;}
1581  if(doattr) BASE::ClrAttribute(*it);
1582  BASE::pSet->erase(it++);
1583  }
1584  FD_DC("TTransSet(" << this << ")::RestrictEvents(): done");
1585 }
1586 
1587 
1588 // iterator Find(x1,ev,x2)
1589 TEMP typename THIS::Iterator THIS::Find(Idx x1, Idx ev, Idx x2) const {
1590  return BASE::Find(Transition(x1,ev,x2));
1591 }
1592 
1593 
1594 // iterator Find(t)
1595 TEMP typename THIS::Iterator THIS::Find(const Transition& t) const{
1596  return BASE::Find(t);
1597 }
1598 
1599 // Exists(t)
1600 TEMP bool THIS::Exists(const Transition& t) const {
1601  return BASE::Exists(t);
1602 }
1603 
1604 // Exists(x1, ev, x2)
1605 TEMP bool THIS::Exists(Idx x1, Idx ev, Idx x2) const {
1606  return BASE::Exists(Transition(x1,ev,x2));
1607 }
1608 
1609 // Exists(x)
1610 TEMP bool THIS::ExistsByX1OrX2(Idx x) const {
1611  typename BASE::iterator it;
1612  for(it = BASE::pSet->begin(); it != BASE::pSet->end(); ++it) {
1613  if ((it->X1 == x) || (it->X2 == x)) {
1614  return true;
1615  }
1616  }
1617  return false;
1618 }
1619 
1620 // ExistsByX1Ev(x,e)
1621 TEMP bool THIS::ExistsByX1Ev(Idx x1, Idx ev) const {
1622  FD_DC("TTransSet(" << this << ")::ExistsByX1Ev(" << x1 << "," << ev << ")");
1623 #ifdef FAUDES_CHECKED
1624  if(typeid(Cmp)!=typeid(TransSort::X1EvX2))
1626 #endif
1627  this->Detach();
1628  typename BASE::iterator lower, upper, it;
1629  Transition tl(x1,ev,0);
1630  Transition tu(x1,ev+1,0);
1631  lower = BASE::pSet->lower_bound(tl);
1632  upper = BASE::pSet->upper_bound(tu);
1633  return lower != upper;
1634 }
1635 
1636 // ExistsByX1(x)
1637 TEMP bool THIS::ExistsByX1(Idx x1) const {
1638  FD_DC("TTransSet(" << this << ")::ExistsByX1(" << x1 << ")");
1639 #ifdef FAUDES_CHECKED
1640  if(typeid(Cmp)!=typeid(TransSort::X1EvX2))
1641  if(typeid(Cmp)!=typeid(TransSort::X1X2Ev))
1643 #endif
1644  this->Detach();
1645  typename BASE::iterator lower, upper, it;
1646  Transition tl(x1,0,0);
1647  Transition tu(x1+1,0,0);
1648  lower = BASE::pSet->lower_bound(tl);
1649  upper = BASE::pSet->upper_bound(tu);
1650  return lower != upper;
1651 }
1652 
1653 
1654 // ReSort(res)
1655 TEMP template<class OtherCmp>
1656 void THIS::ReSort(TTransSet<OtherCmp>& res) const {
1657  Iterator it;
1658  res.Clear();
1659  for (it = Begin(); it != End(); ++it) {
1660  res.Insert(*it);
1661  }
1662 }
1663 
1664 // States()
1665 TEMP StateSet THIS::States(void) const {
1666  StateSet states;
1667  Iterator it;
1668  for (it=Begin(); it!=End(); ++it) {
1669  states.Insert(it->X1);
1670  states.Insert(it->X2);
1671  }
1672  return states;
1673 }
1674 
1675 // SuccessorStates(x1)
1676 TEMP StateSet THIS::SuccessorStates(Idx x1) const {
1677 #ifdef FAUDES_CHECKED
1678  if(typeid(Cmp)!=typeid(TransSort::X1EvX2))
1679  if(typeid(Cmp)!=typeid(TransSort::X1X2Ev))
1681 #endif
1682  StateSet states;
1683  Iterator it = Begin(x1);
1684  Iterator it_end = End(x1);
1685  while (it != it_end) {
1686  states.Insert(it->X2);
1687  ++it;
1688  }
1689  return states;
1690 }
1691 
1692 // SuccessorStates(x1set)
1693 TEMP StateSet THIS::SuccessorStates(const StateSet& rX1Set) const {
1694 #ifdef FAUDES_CHECKED
1695  if(typeid(Cmp)!=typeid(TransSort::X1EvX2))
1696  if(typeid(Cmp)!=typeid(TransSort::X1X2Ev))
1698 #endif
1699  StateSet states;
1700  StateSet::Iterator sit= rX1Set.Begin();
1701  StateSet::Iterator sit_end= rX1Set.End();
1702  for(;sit!=sit_end; ++sit) {
1703  Iterator tit = Begin(*sit);
1704  Iterator tit_end = End(*sit);
1705  while(tit!=tit_end) {
1706  states.Insert(tit->X2);
1707  ++tit;
1708  }
1709  }
1710  return states;
1711 }
1712 
1713 // SuccessorStates(x1, ev)
1714 TEMP StateSet THIS::SuccessorStates(Idx x1, Idx ev) const {
1715 #ifdef FAUDES_CHECKED
1716  if(typeid(Cmp)!=typeid(TransSort::X1EvX2))
1718 #endif
1719  StateSet states;
1720  Iterator it = Begin(x1, ev);
1721  Iterator it_end = End(x1, ev);
1722  while (it != it_end) {
1723  states.Insert(it->X2);
1724  ++it;
1725  }
1726  return states;
1727 }
1728 
1729 // SuccessorStates(x1set, evset)
1730 TEMP StateSet THIS::SuccessorStates(const StateSet& rX1Set, const EventSet& rEvSet) const {
1731 #ifdef FAUDES_CHECKED
1732  if(typeid(Cmp)!=typeid(TransSort::X1EvX2))
1734 #endif
1735  StateSet states;
1736  if(rEvSet.Empty()) return states;
1737  StateSet::Iterator sit= rX1Set.Begin();
1738  StateSet::Iterator sit_end= rX1Set.End();
1739  for(;sit!=sit_end; ++sit) {
1740  EventSet::Iterator eit= rEvSet.Begin();
1741  EventSet::Iterator eit_end= rEvSet.End();
1742  Iterator tit = Begin(*sit,*eit);
1743  Iterator tit_end = End(*sit);
1744  while(tit!=tit_end) {
1745  // match
1746  if(tit->Ev == *eit) {
1747  states.Insert(tit->X2);
1748  ++tit;
1749  continue;
1750  }
1751  // tit behind
1752  if(tit->Ev < *eit) {
1753  ++tit;
1754  continue;
1755  }
1756  // tit upfront
1757  ++eit;
1758  if(eit==eit_end) break;
1759  }
1760  }
1761  return states;
1762 }
1763 
1764 // ActiveEvents(x1,pSymTab)
1765 TEMP EventSet THIS::ActiveEvents(Idx x1, SymbolTable* pSymTab) const {
1766  Iterator it = Begin(x1);
1767  Iterator it_end = End(x1);
1768  EventSet result;
1769  if(pSymTab!=NULL) result.SymbolTablep(pSymTab);
1770  for (; it != it_end; ++it) {
1771  result.Insert(it->Ev);
1772  }
1773  return result;
1774 }
1775 
1776 // Prettz printable sring
1777 TEMP std::string THIS::Str(const Transition& rTrans) const {
1778  return rTrans.Str();
1779 }
1780 
1781 
1782 
1783 #undef THIS
1784 #undef TEMP
1785 #undef BASE
1786 
1787 /*
1788 *************************************************************************************************
1789 *************************************************************************************************
1790 * Implementation of transset with attributes
1791 *************************************************************************************************
1792 *************************************************************************************************
1793 */
1794 
1795 
1796 /* convenience access to relevant scopes */
1797 #define THIS TaTransSet<Attr>
1798 #define TEMP template <class Attr>
1799 #define BASE TTransSet<TransSort::X1EvX2>
1800 #define ABASE TAttrMap<Transition,Attr,TransSort::X1EvX2>
1801 
1802 // std faudes type
1804 
1805 // TaTransSet(void)
1807  BASE(),
1808  ABASE(this)
1809 {
1810  FD_DC("TaTransSet(" << this << ")::TaTransSet()");
1811 }
1812 
1813 // TaTransSet(othertransrel)
1814 TEMP THIS::TaTransSet(const TaTransSet& rOtherSet) :
1815  BASE(),
1816  ABASE(this)
1817 {
1818  FD_DC("TaTransSet(" << this << ")::TaTransSet(rOtherSet "<< &rOtherSet <<")");
1819  DoAssign(rOtherSet);
1820 }
1821 
1822 
1823 // TaTransSet(othertransrel)
1824 TEMP THIS::TaTransSet(const BASE& rOtherSet) :
1825  BASE(),
1826  ABASE(this)
1827 {
1828  FD_DC("TaTransSet(" << this << ")::TaTransSet(rOtherSet "<< &rOtherSet <<")");
1829  Assign(rOtherSet);
1830 }
1831 
1832 
1833 // copy to known same attributes
1834 TEMP void THIS::DoAssign(const THIS& rSourceSet) {
1835  // call base incl attributes
1836  BASE::DoAssign(rSourceSet);
1837 }
1838 
1839 // Relaxed Assign()
1840 TEMP THIS& THIS::Assign(const TBaseSet<Transition,TransSort::X1EvX2>& rSourceSet) {
1841  FD_DC("TaTransSet(" << this << ")::Assign([v] " << &rSourceSet<<")");
1842 #ifdef FAUDES_CHECKED
1843  FD_DC("TaTransSet(" << this << ")::Assign(): src at " << &rSourceSet);
1844  FD_DC("TaTransSet(" << this << ")::Assign(): src type " << typeid(rSourceSet).name());
1845  FD_DC("TaTransSet(" << this << ")::Assign(): dst type " << typeid(*this).name());
1846  const TransSet* tset = dynamic_cast<const TransSet*>(&rSourceSet);
1847  if(!tset) {
1848  std::stringstream errstr;
1849  errstr << "cannot cast " << typeid(rSourceSet).name() << " to TransSet" << std::endl;
1850  throw Exception("TaTransSet::Assign", errstr.str(), 67);
1851  }
1852 #endif
1853  // call attribute smart base
1854  ABASE::AssignWithAttributes(rSourceSet);
1855  // done
1856  return *this;
1857 }
1858 
1859 
1860 // Insert(transition)
1861 TEMP bool THIS::Insert(const Transition& t) {
1862  FD_DC("TaTransSet(" << this << ")::Insert(" << t.Str() << ")");
1863  return ABASE::Insert(t);
1864 }
1865 
1866 // Insert(x1,ev,x2)
1867 TEMP bool THIS::Insert(Idx x1, Idx ev, Idx x2) {
1868  FD_DC("TaTransSet(" << this << ")::Insert(" << x1 << "-" << ev << "-" << x2 << ")");
1869  Transition t(x1, ev, x2);
1870  return ABASE::Insert(t);
1871 }
1872 
1873 // Insert(transition,attr)
1874 TEMP bool THIS::Insert(const Transition& t, const Attr& attr) {
1875  return ABASE::Insert(t,attr);
1876 }
1877 
1878 
1879 // InsertSet(set)
1880 TEMP void THIS::InsertSet(const TransSet& rOtherSet) {
1881  FD_DC("TaTransSet(" << this << ")::InsertSet( [a] " << &rOtherSet << ")");
1882  ABASE::InsertSet(rOtherSet);
1883 }
1884 
1885 // InsertSet(set)
1886 TEMP void THIS::InsertSet(const TBaseSet<Transition,TransSort::X1EvX2>& rOtherSet) {
1887 #ifdef FAUDES_CHECKED
1888  FD_DC("TaTransSet(" << this << ")::InsertSet(" << rOtherSet.ToString() << ")");
1889  const TransSet* tset = dynamic_cast<const TransSet*>(&rOtherSet);
1890  if(!tset) {
1891  std::stringstream errstr;
1892  errstr << "cannot cast " << typeid(rOtherSet).name() << " to TransSet" << std::endl;
1893  throw Exception("TaTransSet::InsertSet", errstr.str(), 67);
1894  }
1895 #endif
1896  ABASE::InsertSet(rOtherSet);
1897 }
1898 
1899 
1900 // Erase(transition)
1901 TEMP bool THIS::Erase(const Transition& t) {
1902  return ABASE::Erase(t);
1903 }
1904 
1905 // Erase(x1,ev,x2)
1906 TEMP bool THIS::Erase(Idx x1, Idx ev, Idx x2) {
1907  FD_DC("TaTransSet(" << this << ")::Erase(" << x1 << "-" << ev << "-" << x2 << ")");
1908  Transition t(x1, ev, x2);
1909  return ABASE::Erase(t);
1910 }
1911 
1912 // Erase(it)
1913 TEMP typename THIS::Iterator THIS::Erase(const Iterator& it) {
1914 #ifdef FAUDES_CHECKED
1915  if (it == End()) {
1916  std::stringstream errstr;
1917  errstr << "iterator out of range " << std::endl;
1918  throw Exception("TTransSet::Erase", errstr.str(), 69);
1919  }
1920 #endif
1921  return ABASE::Erase(it);
1922 }
1923 
1924 // EraseSet(set)
1925 TEMP void THIS::EraseSet(const TransSet& rOtherSet) {
1926  FD_DC("TaTransSet(" << this << ")::RestrictSet( [a] " << &rOtherSet << ")");
1927  ABASE::EraseSet(rOtherSet);
1928 }
1929 
1930 // EraseSet(set)
1931 TEMP void THIS::EraseSet(const TBaseSet<Transition,TransSort::X1EvX2>& rOtherSet) {
1932 #ifdef FAUDES_CHECKED
1933  FD_DC("TaTransSet(" << this << ")::EraseSet(" << rOtherSet.ToString() << ")");
1934  const TransSet* tset = dynamic_cast<const TransSet*>(&rOtherSet);
1935  if(!tset) {
1936  std::stringstream errstr;
1937  errstr << "cannot cast " << typeid(rOtherSet).name() << " to TransSet" << std::endl;
1938  throw Exception("TaTransSet::EraseSet", errstr.str(), 67);
1939  }
1940 #endif
1941  ABASE::EraseSet(rOtherSet);
1942 }
1943 
1944 // RestrictSet(set)
1945 TEMP void THIS::RestrictSet(const TransSet& rOtherSet) {
1946  FD_DC("TaTransSet(" << this << ")::RestrictSet( [a] " << &rOtherSet << ")");
1947  ABASE::RestrictSet(rOtherSet);
1948 }
1949 
1950 
1951 // RestrictSet(set)
1952 TEMP void THIS::RestrictSet(const TBaseSet<Transition,TransSort::X1EvX2>& rOtherSet) {
1953 #ifdef FAUDES_CHECKED
1954  FD_DC("TaTransSet(" << this << ")::RestrictSet(" << rOtherSet.ToString() << ")");
1955  const TransSet* tset = dynamic_cast<const TransSet*>(&rOtherSet);
1956  if(!tset) {
1957  std::stringstream errstr;
1958  errstr << "cannot cast " << typeid(rOtherSet).name() << " to TransSet" << std::endl;
1959  throw Exception("TaTransSet::RestrictSet", errstr.str(), 67);
1960  }
1961 #endif
1962  ABASE::RestrictSet(rOtherSet);
1963 }
1964 
1965 
1966 
1967 #undef THIS
1968 #undef TEMP
1969 #undef BASE
1970 #undef ABASE
1971 
1972 #undef SORT_EXECPTION
1973 
1974 } // namespace faudes
1975 
1976 
1977 
1978 
1979 #endif
1980 

libFAUDES 2.28a --- 2016.09.13 --- c++ api documentaion by doxygen