pd_pdgenerator.h
Go to the documentation of this file.
1 /** @file pd_pdgenerator.h pushdown generator class TpdGenerator */
2 
3 /* Pushdown plugin for FAU Discrete Event Systems Library (libfaudes)
4 
5  Copyright (C) 2013/14 Stefan Jacobi, Ramon Barakat, Sven Schneider, Anne-Kathrin Hess
6 
7 */
8 
9 #ifndef FAUDES_PD_PDGENERATOR_H
10 #define FAUDES_PD_PDGENERATOR_H
11 //#define FAUDES_DEBUG_GENERATOR
12 //#define FAUDES_DEBUG_CONTAINER
13 
14 #include "corefaudes.h"
15 #include "pd_attributes.h"
16 #include "pd_grammar.h"
17 
18 
19 namespace faudes {
20 
21 
22 
23 /**
24  * Generator with push down extensions.
25  *
26  *
27  * @ingroup PushdownPlugin
28  *
29  * @section Overview
30  * tratarterteartawrtrae
31  *
32  * @section Contents
33  * fvdgdthrthorthtiop
34  */
35 
36 template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
37 class TpdGenerator : public TcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr> {
38 
39 public:
40 
41 
42  /**
43  * Constructor
44  */
45  TpdGenerator(void);
46 
47  /**
48  * Copy constructor
49  *
50  * @param rOtherGen
51  */
52  TpdGenerator(const TpdGenerator& rOtherGen);
53 
54  /**
55  * Copy constructor (no attributes)
56  *
57  * @param rOtherGen
58  */
59  TpdGenerator(const vGenerator& rOtherGen);
60 
61  /**
62  * Assignment operator (uses copy)
63  * Note: you must reimplement this operator in derived
64  * classes in order to handle internal pointers correctly
65  *
66  * @param rOtherGen
67  * Other generator
68  */
69  virtual TpdGenerator& operator= (const TpdGenerator& rOtherGen) {this->Assign(rOtherGen); return *this;};
70 
71  /**
72  * Assignment operator (uses copy)
73  *
74  * @param rOtherGen
75  * Other generator
76  */
77  virtual TpdGenerator& operator= (const vGenerator& rOtherGen) {this->Assign(rOtherGen); return *this;};
78 
79  /**
80  * Construct from file
81  *
82  * @param rFileName
83  * Name of file
84  *
85  * @exception Exception
86  * - file format errors (id 1, 50, 51, 52)
87  */
88  TpdGenerator(const std::string& rFileName);
89 
90  /**
91  * Construct on heap.
92  * Constructs a TpdGenerator on heap.
93  *
94  * @return
95  * new Generator
96  */
97  TpdGenerator* New(void) const;
98 
99  /**
100  * Construct copy on heap.
101  * Constructs a TpdGenerator on heap.
102  *
103  * @return
104  * new Generator
105  */
106  TpdGenerator* Copy(void) const;
107 
108  /**
109  * Type test.
110  * Uses C++ dynamic cast to test whether the specified object
111  * casts to a PushdownGenerator.
112  *
113  * @return
114  * TpdGenerator reference if dynamic cast succeeds, else NULL
115  */
116  virtual const Type* Cast(const Type* pOther) const {
117  return dynamic_cast< const TpdGenerator* > (pOther);
118  };
119 
120 
121  /**
122  * Construct on stack.
123  * Constructs a TpdGenerator on stack.
124  *
125  * @return
126  * new Generator
127  */
128  TpdGenerator NewPdGen(void) const;
129 
130  /**
131  * Get Pointer to global StackSymbolTable. This is
132  * a static member of SymbolTable and used as default
133  * for all derived generator classes and instantiated objects.
134  *
135  * @return
136  * Pointer to global StackSymbolTable
137  */
138  static SymbolTable* GlobalStackSymbolTablep(void);
139 
140  /**
141  * XXX: NEW !
142  * Return pretty printable state name (eg for debugging)
143  *
144  * @param idx
145  * index
146  *
147  * @return State name or Idx:<idx> for nonexistent name
148  */
149  std::string StateStr(Idx idx) const;
150 
151  /**
152  * XXX: NEW !
153  * Return pretty printable event name (eg for debugging)
154  *
155  * @param idx
156  * index
157  *
158  * @return Event name or Idx:<idx> for nonexistent name
159  */
160  std::string EventStr(Idx idx) const;
161 
162  /**
163  * Get Pointer to mpStackSymbolTable.
164  *
165  * @return Pointer mpStackSymbolTable
166  */
167  SymbolTable* StackSymbolTablep(void) const;
168 
169  /**
170  * Set StackSymbolTable.
171  *
172  * @param pStackSymTab
173  * Pointer SymbolTable
174  */
175  void StackSymbolTablep(SymbolTable* pStackSymTab);
176 
177  /**
178  * Return a NameSet with generator's StackSymbolTable
179  *
180  * @return
181  * New empty StackSymbolSet on stack
182  */
183  StackSymbolSet NewStackSymbolSet(void) const;
184 
185  /**
186  * Construct a stack symbol on heap.
187  *
188  * @return
189  * Pointer to new empty StackSymbolSet on heap
190  */
191  StackSymbolSet* NewStackSymbolSetp(void) const;
192 
193  /**
194  * Number of stacks symbols in mStackSymbols
195  *
196  * @return Number of stack symbols in mStackSymbols
197  */
198  Idx StackSymbolsSize(void) const;
199 
200  /**
201  * Get stack symbol set as const reference
202  *
203  * @return mStackSymbols
204  */
205  const StackSymbolSet& StackSymbols(void) const;
206 
207 
208  /**
209  * Get stack symbol set as pointer
210  *
211  * @return mStackSymbols
212  */
214 
215  /**
216  * Overwrites mStackSymbols with new stack symbols without consistency check
217  *
218  * @param newstacksymbols
219  * New stack symbols that are written to mStackSymbols
220  */
221  void InjectStackSymbols(const StackSymbolSet& newstacksymbols);
222 
223  /**
224  * Looks up stack symbol name for given index
225  *
226  * @param index
227  * Stack symbol index
228  *
229  * @return Stack symbol name
230  */
231  std::string StackSymbolName(Idx index) const;
232 
233 
234  /** XXX:NEW
235  * Set new stack symbol name for existing index.
236  * FAUDES_CHECKED checks if index exists in NameSet.
237  *
238  * @param index
239  * Index to edit
240  * @param rName
241  * New name
242  *
243  * @exception Exception
244  * - index not in this set (id 60)
245  * - index not found in SymbolTable (id 42)
246  * - name already associated with another index (id 44)
247  */
248  void StackSymbolName(Idx index, const std::string& rName) const;
249 
250  /**
251  * Returns stack symbol for given index
252  *
253  * @param index
254  * Stack symbol index
255  *
256  * @return Stack symbol object
257  */
258  StackSymbol StackSymbolObj(Idx index) const;
259 
260  /**
261  * Looks up stack symbol index for given name
262  *
263  * @param rName
264  * Stack symbol name
265  *
266  * @return Stack symbol index or 0 for nonexistent
267  */
268  Idx StackSymbolIndex(const std::string& rName) const;
269 
270  /**
271  * XXX:NEW !
272  * Get string of stack symbol for given index
273  *
274  * @param rName
275  * Stack symbol name
276  *
277  * @return Stack symbol name or Idx:<idx> for nonexistent name
278  */
279  std::string StackSymbolStr(Idx idx) const;
280 
281  /**
282  * Add named stack symbol to generator. An entry in the mpStackSymbolTable will
283  * be made if stack symbol is new.
284  *
285  * @param rName
286  * Name of the stack symbol to add
287  *
288  * @return
289  * New unique index
290  */
291  Idx InsStackSymbol(const std::string& rName);
292 
293  /**
294  * Add stack symbol to generator. An entry in the mpStackSymbolTable will
295  * be made if stack symbol is new.
296  *
297  * @param rSymbol
298  * The stack symbol to add
299  *
300  * @return
301  * New unique index
302  */
303  Idx InsStackSymbol(const StackSymbol& rSymbol);
304 
305  /**
306  * Add named stack bottom to generator. An entry in the mpStackSymbolTable will
307  * be made if stack symbol is new. This will replace any old stack bottom symbol.
308  *
309  * @param rName
310  * Name of the stack bottom symbol to add
311  *
312  * @return
313  * Stack bottom symbol index
314  */
315  Idx SetStackBottom(const std::string& rName);
316 
317  /**
318  * Add stack bottom to generator. An entry in the mpStackSymbolTable will
319  * be made if stack symbol is new. This will replace any old stack bottom symbol.
320  *
321  * @param rSymbol
322  * The stack bottom symbol to add
323  *
324  * @return
325  * Stack bottom symbol index
326  */
327  Idx SetStackBottom(const StackSymbol& rSymbol);
328 
329  /**
330  * Add stack bottom to generator. An entry in the mpStackSymbolTable will
331  * be made if stack symbol is new. This will replace any old stack bottom symbol.
332  *
333  * @param idx
334  * The index of the stack bottom symbol to add
335  *
336  * @return
337  * Stack bottom symbol index
338  */
339  Idx SetStackBottom(const Idx idx);
340 
341  /**
342  * Get the index of the stack bottom symbol
343  *
344  * @return
345  * index of the stack bottom symbol
346  */
347  Idx StackBottom() const;
348 
349  /**
350  * Add new named stack symbols to generator.
351  *
352  * @param rStackSymbolSet
353  * StackSymbolSet
354  */
355  void InsStackSymbols(const StackSymbolSet& rStackSymbolSet);
356 
357  /**
358  * Delete stack symbol from generator by index.
359  *
360  * @param index
361  * Index of stack symbol
362  * @return
363  * True if stack symbol did exist
364  *
365  */
366  bool DelStackSymbol(Idx index);
367 
368  /**
369  * Delete stack symbol from generator by name. mpStackSymbolTable stays untouched.
370  *
371  * @param rName
372  * Name of stack symbol
373  * @return
374  * True if stack symbol did exist
375  */
376  bool DelStackSymbol(const std::string& rName);
377 
378  /**
379  * Delete a set of stack symbols from generator.
380  *
381  * @param rStackSymbols
382  * StackSymbolSet containing stack symbols to remove
383  */
384  void DelStackSymbols(const StackSymbolSet& rStackSymbols);
385 
386  /**
387  * Test existence of stack symbol in mStackSymbols
388  *
389  * @param index
390  * Stack symbol index
391  *
392  * @return
393  * true / false
394  */
395  bool ExistsStackSymbol(Idx index) const;
396 
397  /**
398  * Test existence of stack symbol in mStackSymbols
399  *
400  * @param rName
401  * Stack symbol name
402  *
403  * @return
404  * True if stack symbol exists
405  */
406  bool ExistsStackSymbol(const std::string& rName) const;
407 
408  /**
409  * Returns an iterator to stack symbol index in mStackSymbols
410  *
411  * @param index
412  * Index to find
413  *
414  * @return
415  * StackSymbolSet::Iterator to stack symbol index
416  */
417  StackSymbolSet::Iterator FindStackSymbol(Idx index) const;
418 
419  /**
420  * Returns an iterator to stack symbol index in mStackSymbols
421  *
422  * @param rName
423  * Stack symbol name of index to find
424  *
425  * @return
426  * StackSymbolSet::Iterator to stack symbol index
427  */
428  StackSymbolSet::Iterator FindStackSymbol(const std::string& rName) const;
429 
430  /**
431  * XXX NEW
432  * Get unique stack symbole name
433  *
434  * @param rName
435  * The name prefix
436  * @return string
437  * The unique name
438  */
439  std::string UniqueStackSymbolName(const std::string& rName) const;
440 
441  /**
442  * Iterator to Begin() of mStackSymbols
443  *
444  * @return iterator to begin of mStackSymbols
445  */
446  StackSymbolSet::Iterator StackSymbolsBegin(void) const;
447 
448  /**
449  * Iterator to End() of mStackSymbols
450  *
451  * @return iterator to end of mStackSymbols
452  */
453  StackSymbolSet::Iterator StackSymbolsEnd(void) const;
454 
455  /**
456  * Converts a vector of stack symbols to a vector of Idx
457  *
458  * @param symbols
459  * the vector of stack symbols
460  * @return
461  * vector of Idx
462  */
463  std::vector<Idx> StackSymbolsToIndices(const std::vector<StackSymbol> symbols) const;
464 
465  /** XXX:NEW
466  * Converts a vector of stack symbol names to a vector of Idx
467  *
468  * @param symbols
469  * the vector of stack symbol names
470  * @return
471  * vector of Idx
472  */
473  std::vector<Idx> StackSymbolNamesToIndices(const std::vector<std::string> symbolnames) const;
474 
475  /**
476  * Check if the pushdown generator is deterministic.
477  *
478  * A pushdown generator is deterministic iff distinct steps from a reachable configuration
479  * append elements of the Alphabet to the history variable.
480  * Note that this implies that the existence of an outgoing transition, which event is lambda,
481  * in state q requiring stack-top A prevents other outgoing transitions in q requiring stack-top A.
482  *
483  * @ return
484  * true, if the generator is deterministic
485  */
486  bool IsDeterministic() const;
487 
488  /**
489  * Get number of transitions including pop-push-pairs
490  *
491  * @return
492  * number of transitions
493  */
494  Idx TransRelSize() const;
495 
496  /**
497  * Add a transition to generator by indices. States and event
498  * must already exist!
499  *
500  * Define FAUDES_CHECKED for consistency checks.
501  *
502  * @param x1
503  * Predecessor state index
504  * @param ev
505  * Event index
506  * @param x2
507  * Successor state index
508  *
509  * @return
510  * True, if the transition was new the generator
511  *
512  * @exception Exception
513  * - state or event not in generator (id 95)
514  */
515  bool SetTransition(Idx x1, Idx ev, Idx x2);
516 
517  /**
518  * Add a transition to generator by names. Statename and eventname
519  * must already exist!
520  *
521  * @param rX1
522  * Predecessor state name
523  * @param rEv
524  * Event name
525  * @param rX2
526  * Successor state name
527  *
528  * @return
529  * True, if the transition was new the generator
530  *
531  * @exception Exception
532  * - state or event not in generator (id 95)
533  * - state name not known (id 90)
534  * - event name not known (id 66)
535  */
536  bool SetTransition(const std::string& rX1, const std::string& rEv,
537  const std::string& rX2);
538 
539  /**
540  * Add a transition with attribute to generator. States and event
541  * must already exist!
542  *
543  * Define FAUDES_CHECKED for consistency checks.
544  *
545  * @param rTransition
546  * transition
547  * @param rAttr
548  * attribute
549  *
550  * @return
551  * True, if the transition was new the generator
552  *
553  */
554  bool SetTransition(const Transition& rTransition, const TransAttr& rAttr);
555 
556  /**
557  * Inserts new PushdownTransition constructed from parameters.
558  * Performs consistency checks for x1, x2, ev and all stack symbols in rPop and rPush.
559  *
560  * @param rTrans
561  * new transition
562  * @param rPop
563  * Stack symbol vector to be popped when transitioning
564  * @param rPush
565  * Stack symbol vector to be pushed when transitioning
566  * @return
567  * True, if the transition was new to the generator
568  */
569  bool SetTransition(const Transition& rTrans, const std::vector<StackSymbol>& rPop, const std::vector<StackSymbol>& rPush);
570 
571  /** XXX:NEW
572  * Inserts new PushdownTransition constructed from parameters.
573  * Performs consistency checks for x1, x2, ev and all stack symbols in rPop and rPush.
574  *
575  * @param rTrans
576  * new transition
577  * @param rPop
578  * Stack symbol vector to be popped when transitioning
579  * @param rPush
580  * Stack symbol vector to be pushed when transitioning
581  * @return
582  * True, if the transition was new to the generator
583  */
584  bool SetTransition(const Transition& trans, const std::vector<std::string>& rPop, const std::vector<std::string>& rPush);
585 
586  /**
587  * Inserts new PushdownTransition constructed from parameters.
588  * Performs consistency checks for x1, x2, ev and all stack symbols in rPop and rPush.
589  *
590  * @param rTrans
591  * new transition
592  * @param rPop
593  * Stack symbol vector to be popped when transitioning
594  * @param rPush
595  * Stack symbol vector to be pushed when transitioning
596  * @return
597  * True, if the transition was new to the generator
598  */
599  bool SetTransition(const Transition& rTrans, const std::vector<Idx>& rPop, const std::vector<Idx>& rPush);
600 
601 
602  /**
603  * Inserts new PushdownTransition constructed from parameters.
604  * Performs consistency checks for x1, x2, ev and stack symbols in rPop and rPush.
605  *
606  * @param x1
607  * Start state of new PushdownTransition.
608  * @param ev
609  * Event of new PushdownTransition.
610  * @param x2
611  * End state of new PushdownTransition.
612  * @param rPop
613  * Stack symbol vector to be popped when transitioning
614  * @param rPush
615  * Stack symbol vector to be pushed when transitioning
616  * @return
617  * True, if the transition was new to the generator
618  */
619  bool SetTransition(Idx x1, Idx ev, Idx x2,
620  const std::vector<StackSymbol>& rPop, const std::vector<StackSymbol>& rPush);
621 
622  /**
623  * Inserts new PushdownTransition constructed from parameters.
624  * Performs consistency checks for x1, x2, ev and stack symbols in rPop and rPush.
625  *
626  * @param x1
627  * Start state of new PushdownTransition.
628  * @param ev
629  * Event of new PushdownTransition.
630  * @param x2
631  * End state of new PushdownTransition.
632  * @param rPop
633  * Stack symbol vector to be popped when transitioning
634  * @param rPush
635  * Stack symbol vector to be pushed when transitioning
636  * @return
637  * True, if the transition was new to the generator
638  */
639  bool SetTransition(Idx x1, Idx ev, Idx x2,
640  const std::vector<Idx>& rPop, const std::vector<Idx>& rPush);
641 
642  /**
643  * Inserts new PushdownTransition constructed from parameters.
644  * Performs consistency checks for x1, x2, ev and stack symbols in rPop and rPush.
645  *
646  * @param rX1
647  * Start state of new PushdownTransition.
648  * @param rEv
649  * Event of new PushdownTransition.
650  * @param rX2
651  * End state of new PushdownTransition.
652  * @param rPop
653  * Stack symbol vector to be popped when transitioning
654  * @param rPush
655  * Stack symbol vector to be pushed when transitioning
656  * @return
657  * True, if the transition was new to the generator
658  */
659  bool SetTransition(const std::string& rX1, const std::string& rEv, const std::string& rX2, const std::vector<StackSymbol>& rPop, const std::vector<StackSymbol>& rPush);
660 
661  /**
662  * XXX NEW !
663  * Inserts new PushdownTransition constructed from parameters.
664  * Performs consistency checks for x1, x2, ev and stack symbols in rPop and rPush.
665  * (Note: necessary for parsing .dot files)
666  *
667  * @param rX1
668  * Start state of new PushdownTransition.
669  * @param rEv
670  * Event of new PushdownTransition.
671  * @param rX2
672  * End state of new PushdownTransition.
673  * @param rPop
674  * Vector of Stack symbol names to be popped when transitioning
675  * @param rPush
676  * Vector of Stack symbol names to be pushed when transitioning
677  * @return
678  * True, if the transition was new to the generator
679  */
680  bool SetTransition(const std::string& rX1, const std::string& rEv, const std::string& rX2, const std::vector<std::string>& rPop, const std::vector<std::string>& rPush);
681 
682  /**
683  * XXX NEW !
684  * Inserts new PushdownTransition constructed from parameters.
685  * Performs consistency checks for x1, x2, ev and stack symbols in rPop and rPush.
686  * (Note: necessary for parsing .dot files)
687  *
688  * @param rX1
689  * Start state of new PushdownTransition.
690  * @param rEv
691  * Event of new PushdownTransition.
692  * @param rX2
693  * End state of new PushdownTransition.
694  * @param rPop
695  * Vector of Stack symbol names to be popped when transitioning
696  * @param rPush
697  * Vector of Stack symbol names to be pushed when transitioning
698  * @return
699  * True, if the transition was new to the generator
700  */
701  bool SetTransition(Idx x1, Idx ev, Idx x2, const std::vector<std::string>& rPop, const std::vector<std::string>& rPush);
702 
703  /**
704  * Inserts new PushdownTransition constructed from parameters.
705  * Performs consistency checks for x1, x2, ev and stack symbols in rPop and rPush.
706  *
707  * @param rX1
708  * Start state of new PushdownTransition.
709  * @param rEv
710  * Event of new PushdownTransition.
711  * @param rX2
712  * End state of new PushdownTransition.
713  * @param rPop
714  * Stack symbol vector to be popped when transitioning
715  * @param rPush
716  * Stack symbol vector to be pushed when transitioning
717  * @return
718  * True, if the transition was new to the generator
719  */
720  bool SetTransition(const std::string& rX1, const std::string& rEv, const std::string& rX2, const std::vector<Idx>& rPop, const std::vector<Idx>& rPush);
721 
722 
723  /**
724  * XXX: NEW
725  * Inserts new PushdownTransition constructed from parameters.
726  * Performs consistency checks for x1, x2, ev and stack symbols in pop and push.
727  * Pop and Push vector are given as strings where stack symbol names
728  * written in squared brackets separated by comma
729  *
730  * (Function specially to access from LuaFAUDES)
731  *
732  * @param rX1
733  * Start state of new PushdownTransition.
734  * @param rEv
735  * Event of new PushdownTransition.
736  * @param rPop
737  * String of to be popped stack symbols when transitioning
738  * @param rPush
739  * String of to be pushed stack symbols when transitioning
740  * @param rX2
741  * End state of new PushdownTransition.
742  *
743  * @return
744  * True, if the transition was new to the generator
745  */
746  bool SetTransition(const std::string& rX1, const std::string& rEv, const std::string& rPop,
747  const std::string& rPush, const std::string& rX2);
748 
749  /**
750  * XXX: NEW
751  * Delete an existing PushdownTransition constructed with the provided parameters.
752  * Pop and Push vector are given as strings where stack symbol names
753  * written in squared brackets separated by comma
754  *
755  * (Function specially to access from LuaFAUDES)
756  *
757  * @param rX1
758  * Start state of new PushdownTransition.
759  * @param rEv
760  * Event of new PushdownTransition.
761  * @param rPop
762  * String of to be popped stack symbols when transitioning
763  * @param rPush
764  * String of to be pushed stack symbols when transitioning
765  * @param rX2
766  * End state of new PushdownTransition.
767  *
768  * @return
769  * True, if the transition was deleted from the generator
770  */
771  bool ClrTransition(const std::string& rX1, const std::string& rEv, const std::string& rPop,
772  const std::string& rPush, const std::string& rX2);
773 
774  /**
775  * Delete an exisiting PushdownTransition with the provided parameters.
776  *
777  * @param x1
778  * Start state of the PushdownTransition.
779  * @param ev
780  * Event of the PushdownTransition.
781  * @param x2
782  * End state of the PushdownTransition.
783  * @param rPop
784  * Stack symbol vector to be popped when transitioning
785  * @param rPush
786  * Stack symbol vector to be pushed when transitioning
787  * @return
788  * True, if the transition was deleted from the generator
789  */
790  bool ClrTransition(Idx x1, Idx ev, Idx x2, const std::vector<StackSymbol>& rPop, const std::vector<StackSymbol>& rPush);
791 
792  /**
793  * Delete an exisiting PushdownTransition with the provided parameters.
794  *
795  * @param x1
796  * Start state of the PushdownTransition.
797  * @param ev
798  * Event of the PushdownTransition.
799  * @param x2
800  * End state of the PushdownTransition.
801  * @param rPop
802  * Stack symbol vector to be popped when transitioning
803  * @param rPush
804  * Stack symbol vector to be pushed when transitioning
805  * @return
806  * True, if the transition was deleted from the generator
807  */
808  bool ClrTransition(Idx x1, Idx ev, Idx x2, const std::vector<Idx>& rPop, const std::vector<Idx>& rPush);
809 
810  /**XXX:NEW
811  * Delete an exisiting PushdownTransition with the provided parameters.
812  *
813  * @param x1
814  * Start state of the PushdownTransition.
815  * @param ev
816  * Event of the PushdownTransition.
817  * @param x2
818  * End state of the PushdownTransition.
819  * @param rPop
820  * Stack symbol vector to be popped when transitioning
821  * @param rPush
822  * Stack symbol vector to be pushed when transitioning
823  * @return
824  * True, if the transition was deleted from the generator
825  */
826  bool ClrTransition(Idx x1, Idx ev, Idx x2,const std::vector<std::string>& rPop, const std::vector<std::string>& rPush);
827 
828  /**XXX:NEW
829  * Delete an exisiting PushdownTransition with the provided parameters.
830  *
831  * @param x1
832  * Start state of the PushdownTransition.
833  * @param ev
834  * Event of the PushdownTransition.
835  * @param x2
836  * End state of the PushdownTransition.
837  * @param rPop
838  * Stack symbol vector to be popped when transitioning
839  * @param rPush
840  * Stack symbol vector to be pushed when transitioning
841  * @return
842  * True, if the transition was deleted from the generator
843  */
844  bool ClrTransition(std::string x1, std::string ev, std::string x2, const std::vector<Idx>& rPop, const std::vector<Idx>& rPush);
845 
846  /**XXX:NEW
847  * Delete an exisiting PushdownTransition with the provided parameters.
848  *
849  * @param x1
850  * Start state of the PushdownTransition.
851  * @param ev
852  * Event of the PushdownTransition.
853  * @param x2
854  * End state of the PushdownTransition.
855  * @param rPop
856  * Stack symbol vector to be popped when transitioning
857  * @param rPush
858  * Stack symbol vector to be pushed when transitioning
859  * @return
860  * True, if the transition was deleted from the generator
861  */
862  bool ClrTransition(std::string x1, std::string ev, std::string x2, const std::vector<StackSymbol>& rPop, const std::vector<StackSymbol>& rPush);
863 
864  /**XXX:NEW
865  * Delete an exisiting PushdownTransition with the provided parameters.
866  *
867  * @param x1
868  * Start state of the PushdownTransition.
869  * @param ev
870  * Event of the PushdownTransition.
871  * @param x2
872  * End state of the PushdownTransition.
873  * @param rPop
874  * Stack symbol vector to be popped when transitioning
875  * @param rPush
876  * Stack symbol vector to be pushed when transitioning
877  * @return
878  * True, if the transition was deleted from the generator
879  */
880  bool ClrTransition(std::string x1, std::string ev, std::string x2, const std::vector<std::string>& rPop, const std::vector<std::string>& rPush);
881 
882  /**
883  * Delete an exisiting PushdownTransition with the provided parameters.
884  *
885  * @param rTrans
886  * the transition
887  * @param rPop
888  * Stack symbol vector to be popped when transitioning
889  * @param rPush
890  * Stack symbol vector to be pushed when transitioning
891  * @return
892  * True, if the transition was deleted from the generator
893  */
894  bool ClrTransition(const Transition& rTrans, const std::vector<StackSymbol>& rPop, const std::vector<StackSymbol>& rPush);
895 
896  /** XXX:NEW
897  * Delete an exisiting PushdownTransition with the provided parameters.
898  *
899  * @param rTrans
900  * the transition
901  * @param rPop
902  * Stack symbol name vector to be popped when transitioning
903  * @param rPush
904  * Stack symbol name vector to be pushed when transitioning
905  * @return
906  * True, if the transition was deleted from the generator
907  */
908  bool ClrTransition(const Transition& rTrans, const std::vector<std::string>& rPop,const std::vector<std::string>& rPush);
909 
910  /**
911  * Delete an exisiting PushdownTransition with the provided parameters.
912  *
913  * @param rTrans
914  * the transition
915  * @param rPop
916  * Stack symbol vector to be popped when transitioning
917  * @param rPush
918  * Stack symbol vector to be pushed when transitioning
919  * @return
920  * True, if the transition was deleted from the generator
921  */
922  bool ClrTransition(const Transition& rTrans, const std::vector<Idx>& rPop, const std::vector<Idx>& rPush);
923 
924 
925  /**
926  * Test for transition given by x1, ev, x2
927  *
928  *
929  * @param rX1
930  * name of Predecessor state
931  * @param rEv
932  * name of Event
933  * @param rX2
934  * name of Successor state
935  *
936  * @return
937  * true / false
938  */
939  bool ExistsTransition(
940  const std::string& rX1, const std::string& rEv, const std::string& rX2) const;
941 
942  /**
943  * Test for transition given by x1, ev, x2
944  *
945  * @param x1
946  * Predecessor state
947  * @param ev
948  * Event
949  * @param x2
950  * Successor state
951  *
952  * @return
953  * true / false
954  */
955  bool ExistsTransition(Idx x1, Idx ev, Idx x2) const;
956 
957  /**
958  * Test for transition
959  *
960  *
961  * @param rTrans
962  * transition
963  *
964  * @return
965  * true / false
966  */
967  bool ExistsTransition(const Transition& rTrans) const;
968 
969  /**
970  * Test for transition given by x1, ev
971  *
972  * @param x1
973  * Predecessor state
974  * @param ev
975  * Event
976  *
977  * @return
978  * true / false
979  */
980  bool ExistsTransition(Idx x1, Idx ev) const;
981 
982  /**
983  * Test for transition given by x1
984  *
985  * @param x1
986  * Predecessor state
987  *
988  * @return
989  * true / false
990  */
991  bool ExistsTransition(Idx x1) const;
992 
993  /**
994  * XXX NEW !
995  * Test for transition given by x1, ev, x2, pop, push
996  *
997  * @param x1
998  * Predecessor state
999  * @param ev
1000  * Event
1001  * @param x2
1002  * Successor state
1003  * @param rPop
1004  * Vector of stacksym indices to be popped
1005  * @param rPush
1006  * Vector of stacksym indices to be pushed
1007  *
1008  * @return
1009  * true / false
1010  */
1011  bool ExistsTransition(Idx x1, Idx ev, Idx x2, const std::vector<Idx>& pop, const std::vector<Idx>& push) const;
1012 
1013  /**
1014  * XXX NEW !
1015  * Test for transition given by x1, ev, x2, pop, push
1016  *
1017  * @param x1
1018  * Predecessor state
1019  * @param ev
1020  * Event
1021  * @param x2
1022  * Successor state
1023  * @param rPop
1024  * Vector of stacksym names to be popped
1025  * @param rPush
1026  * Vector of stacksym names to be pushed
1027  *
1028  * @return
1029  * true / false
1030  */
1031  bool ExistsTransition(Idx x1, Idx ev, Idx x2, const std::vector<std::string>& pop, const std::vector<std::string>& push) const;
1032 
1033  /**
1034  * XXX NEW !
1035  * Test for transition given by x1, ev, x2, pop, push
1036  *
1037  * @param x1
1038  * Predecessor state
1039  * @param ev
1040  * Event
1041  * @param x2
1042  * Successor state
1043  * @param rPop
1044  * Stack symbol vector to be popped
1045  * @param rPush
1046  * Stack symbol vector to be pushed
1047  *
1048  * @return
1049  * true / false
1050  */
1051  bool ExistsTransition(Idx x1, Idx ev, Idx x2, const std::vector<StackSymbol>& rPop, const std::vector<StackSymbol>& rPush)const;
1052 
1053  /**
1054  * XXX NEW !
1055  * Test for transition given by x1, ev, x2, pop, push
1056  *
1057  * @param x1
1058  * Name of predecessor state
1059  * @param ev
1060  * Name of event
1061  * @param x2
1062  * Name of successor state
1063  * @param rPop
1064  * Stack symbol vector to be popped
1065  * @param rPush
1066  * Stack symbol vector to be pushed
1067  *
1068  * @return
1069  * true / false
1070  */
1071  bool ExistsTransition(const std::string& x1, const std::string& ev, const std::string& x2, const std::vector<StackSymbol>& pop, const std::vector<StackSymbol>& push) const;
1072 
1073  /**
1074  * XXX NEW !
1075  * Test for transition given by x1, ev, x2, pop, push
1076  *
1077  * @param x1
1078  * Name of predecessor state
1079  * @param ev
1080  * Name of event
1081  * @param x2
1082  * Name of successor state
1083  * @param rPop
1084  * Vector of stacksym names to be popped
1085  * @param rPush
1086  * Vector of stacksym names to be pushed
1087  *
1088  * @return
1089  * true / false
1090  */
1091  bool ExistsTransition(const std::string& x1, const std::string& ev, const std::string& x2, const std::vector<std::string>& pop, const std::vector<std::string>& push) const;
1092 
1093  /**
1094  * XXX NEW !
1095  * Test for transition given by x1, ev, x2, pop, push
1096  *
1097  * @param x1
1098  * Name of predecessor state
1099  * @param ev
1100  * Name of event
1101  * @param x2
1102  * Name of successor state
1103  * @param rPop
1104  * Vector of stacksym indices to be popped
1105  * @param rPush
1106  * Vector of stacksym indices to be pushed
1107  *
1108  * @return
1109  * true / false
1110  */
1111  bool ExistsTransition(const std::string& x1, const std::string& ev, const std::string& x2, const std::vector<Idx>& pop, const std::vector<Idx>& push) const;
1112 
1113  /**
1114  * XXX NEW !
1115  * Test for transition given by transition, pop, push
1116  *
1117  * @param rTrans
1118  * Transition
1119  * @param rPop
1120  * Vector of stacksymbols to be popped
1121  * @param rPush
1122  * Vector of stacksymbols to be pushed
1123  *
1124  * @return
1125  * true / false
1126  */
1127  bool ExistsTransition(const Transition& rTrans, const std::vector<StackSymbol>& rPop,const std::vector<StackSymbol>& rPush)const;
1128 
1129  /**
1130  * XXX NEW !
1131  * Test for transition given by transition, pop, push
1132  *
1133  * @param rTrans
1134  * Transition
1135  * @param rPop
1136  * Vector of stacksym names to be popped
1137  * @param rPush
1138  * Vector of stacksym names to be pushed
1139  *
1140  * @return
1141  * true / false
1142  */
1143  bool ExistsTransition(const Transition& rTrans, const std::vector<std::string>& rPop, const std::vector<std::string>& rPush) const;
1144 
1145  /**
1146  * XXX: NEW !
1147  * Test for transition given trans, pop, push
1148  *
1149  * @param rTrans
1150  * The transition
1151  * @param rPop
1152  * Stack symbol vector to be popped
1153  * @param rPush
1154  * Stack symbol vector to be pushed
1155  *
1156  * @return
1157  * true / false
1158  */
1159  bool ExistsTransition(const Transition& rTrans, const std::vector<Idx>& pop, const std::vector<Idx>& push) const;
1160 
1161  /**
1162  * XXX: NEW
1163  * Test for transition given with the provided parameters.
1164  * Pop and Push vector are given as strings where stack symbol names
1165  * written in squared brackets separated by comma
1166  *
1167  * (Function specially to access from LuaFAUDES)
1168  *
1169  * @param rX1
1170  * Start state of new PushdownTransition.
1171  * @param rEv
1172  * Event of new PushdownTransition.
1173  * @param rPop
1174  * String of to be popped stack symbols when transitioning
1175  * @param rPush
1176  * String of to be pushed stack symbols when transitioning
1177  * @param rX2
1178  * End state of new PushdownTransition.
1179  *
1180  * @return
1181  * True, if the transition was deleted from the generator
1182  */
1183  bool ExistsTransition(const std::string& x1, const std::string& ev, const std::string& pop,const std::string& push, const std::string& x2) const;
1184 
1185 
1186  /**
1187  * Get the pop/push set attached to this transition
1188  *
1189  * @param rTrans
1190  * the transition
1191  * @return
1192  * the pop/push set
1193  */
1194  const PopPushSet& PopPush(const Transition& rTrans) const;
1195 
1196  /**
1197  * Get an iterator to the beginning of the pop/push set attached to this
1198  * transition
1199  *
1200  * @param rTrans
1201  * the transition
1202  * @return
1203  * iterator to the beginning of the pop/push set
1204  */
1205  PopPushSet::const_iterator PopPushBegin(const Transition& rTrans) const;
1206 
1207  /**
1208  * Get an iterator to the end of the pop/push set attached to this
1209  * transition
1210  *
1211  * @param rTrans
1212  * the transition
1213  * @return
1214  * iterator to the end of the pop/push set
1215  */
1216  PopPushSet::const_iterator PopPushEnd(const Transition& rTrans) const;
1217 
1218  /**XXX: NEW
1219  * Add lambda stack symbol to generator or return existing one
1220  *
1221  * @return
1222  * index of lambda stack symbol
1223  */
1225 
1226  /**
1227  * determine if the stack symbol associated with the given index is lambda
1228  *
1229  * @param index
1230  * index of a stack symbol
1231  * @return
1232  * true if the associated stack symbol is lambda, else false
1233  */
1234  bool IsStackSymbolLambda(Idx index) const;
1235 
1236  /**
1237  * determine if the event associated with the given index is lambda
1238  *
1239  * @param index
1240  * index of an event
1241  * @return
1242  * true if the associated event is lambda, else false
1243  */
1244  bool IsEventLambda(Idx index) const;
1245 
1246 
1247  /**
1248  * Throw exception if stack symbol refers to stack symbol not
1249  * in stack symbol set
1250  *
1251  * @exception Exception
1252  * - invalid stack symbol (id 1001)
1253  */
1254  void ConsistentStackSymbol(const StackSymbol& rStackSymbol) const;
1255 
1256  /**
1257  * Throw exception if stack symbol refers to stack symbol not
1258  * in stack symbol set
1259  *
1260  * @exception Exception
1261  * - invalid stack symbol (id 1001)
1262  */
1263  void ConsistentStackSymbol(Idx idx) const;
1264 
1265  /**
1266  * Throw exception if vector of stack symbols contains stack symbols not
1267  * in generators stack symbol set
1268  *
1269  * @exception Exception
1270  * - invalid stack symbol (id 1001)
1271  */
1272  void ConsistentVectorStackSymbol(const std::vector<StackSymbol>& rVector) const;
1273 
1274  /**
1275  * Throw exception if vector of stack symbols contains stack symbols not
1276  * in generators stack symbol set
1277  *
1278  * @exception Exception
1279  * - invalid stack symbol (id 1001)
1280  */
1281  void ConsistentVectorStackSymbol(const std::vector<Idx>& rVector) const;
1282 
1283  /**
1284  * Throw exception if vector of stack symbols is empty
1285  *
1286  * @exception Exception
1287  * - invalid stack symbol (id 1001)
1288  */
1289  void EmptyVectorPopPush(const std::vector<StackSymbol>& rVector) const;
1290 
1291  /**
1292  * Throw exception if vector of stack symbols is empty
1293  *
1294  * @exception Exception
1295  * - invalid stack symbol (id 1001)
1296  */
1297  void EmptyVectorPopPush(const std::vector<Idx>& rVector) const;
1298 
1299  /**
1300  * Marks a state as being merged from other data type by setting mpMerge.
1301  *
1302  * @param stateName
1303  * the name of the state to mark
1304  * @param rMerge
1305  * the merged state
1306  */
1307  void SetMerge(const std::string& stateName, MergeAbstract& rMerge);
1308 
1309  /**
1310  * Marks a state as being merged from other data type by setting mpMerge.
1311  *
1312  * @param index
1313  * the index of the state to mark
1314  * @param rMerge
1315  * the merged state
1316  */
1317  void SetMerge(Idx index, MergeAbstract& rMerge);
1318 
1319  /**
1320  * Return the merge attribute of a state.
1321  *
1322  * @param index
1323  * the index of the state
1324  */
1325  const MergeAbstract* Merge(Idx index) const;
1326 
1327  /**
1328  * Marks a state as being derived from the intersection with a DFA.
1329  *
1330  * @param stateName
1331  * the name of the state to mark
1332  * @param dfaIndex
1333  * the index of the DFA state
1334  */
1335  void SetDfaState(const std::string& stateName, Idx dfaIndex);
1336 
1337  /**
1338  * Marks a state as being derived from the intersection with a DPA.
1339  *
1340  * @param index
1341  * the index of the state to mark
1342  * @param dfaIndex
1343  * the index of the DFA state
1344  */
1345  void SetDfaState(Idx index, Idx dfaIndex);
1346 
1347  /**
1348  * Return the dfaState attribute of a state.
1349  *
1350  * @param index
1351  * the index of the state
1352  */
1353  Idx DfaState(Idx index) const;
1354 
1355  /**
1356  * Check if generator is valid
1357  *
1358  * @return
1359  * Success
1360  */
1361  virtual bool Valid(void);
1362 
1363  /**
1364  * XXX: NEW !
1365  * Writes generator to dot input format.
1366  * The dot file format is specified by the graphviz package; see http://www.graphviz.org.
1367  * The package includes the dot command line tool to generate a graphical
1368  * representation of the generators graph. See also vGenerator::GraphWrite().
1369  *
1370  *
1371  * @param rFileName
1372  * File to write
1373  *
1374  * @exception Exception
1375  * - IO errors (id 2)
1376  */
1377  virtual void DotWrite(const std::string& rFileName) const;
1378 
1379  /**
1380  * XXX: NEW !
1381  * Writes generator to dot input format.
1382  * The dot file format is specified by the graphviz package; see http://www.graphviz.org.
1383  * The package includes the dot command line tool to generate a graphical
1384  * representation of the generators graph.
1385  *
1386  *
1387  * @param rFileName
1388  * File to write
1389  *
1390  * @param printInfo
1391  * Printing contained informations
1392  * (eg. Alphabet, Stack symbols etc.)
1393  *
1394  * @param lr
1395  * Create graph from left to right
1396  *
1397  * @exception Exception
1398  * - IO errors (id 2)
1399  */
1400  virtual void DotWrite(const std::string& rFileName, bool printInfo, bool lr) const;
1401 
1402  /**
1403  * XXX: NEW !
1404  * Create generator from dot input format.
1405  * The dot file format is specified by the graphviz package (see http://www.graphviz.org).
1406  * The package includes the dot command line tool to generate a graphical
1407  * representation of the generators graph.
1408  * (For more details see pd_dotparser.h)
1409  *
1410  * Note: Function will clear current generator.
1411  *
1412  *
1413  * @param rFileName
1414  * File to parse
1415  *
1416  * @exception Exception
1417  * - IO errors (id 2)
1418  */
1419  virtual void DotRead(const std::string& rFileName);
1420 
1421 
1422 
1423 private:
1424 
1425  /**
1426  * Get stack symbols from given string.
1427  * stack symbol names should be written in squared brackets separated by comma
1428  */
1429  std::vector<std::string> ParseStackSymbolNames(const std::string& rStr) const;
1430 
1431 }; //end class TpdGenerator
1432 
1433 /** Convenience typedef for PushdownGenerator */
1434 typedef TpdGenerator<AttributePushdownGlobal, AttributePushdownState,
1436 
1438 
1439 
1440 // convenient scope macros
1441 #define THIS TpdGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
1442 #define BASE TcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
1443 #define TEMP template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
1444 
1445 // TpdGenerator(void)
1446 TEMP THIS::TpdGenerator(void) : BASE() {
1447  // set basic members (cosmetic)
1448  BASE::pGlobalAttribute->mStackSymbols.Name("StackSymbols");
1449  BASE::pGlobalAttribute->mpStackSymbolTable=StackSymbolSet::StaticSymbolTablep();
1450  FD_DG("PushdownGenerator(" << this << ")::PushdownGenerator() with csymtab "
1451  << (BASE::pGlobalAttribute->mpStackSymbolTable ));
1452 }
1453 
1454 
1455 
1456 // TpdGenerator(rOtherGen)
1457 TEMP THIS::TpdGenerator(const TpdGenerator& rOtherGen) : BASE(rOtherGen) {
1458  FD_DG("PushdownGenerator(" << this << ")::PushdownGenerator(rOtherGen) with csymtab"
1459  << "(BASE::pGlobalAttribute->mpStackSymbolTable)" );
1460 }
1461 
1462 // TpdGenerator(rOtherGen)
1463 TEMP THIS::TpdGenerator(const vGenerator& rOtherGen) : BASE(rOtherGen) {
1464  // set basic members (cosmetic)
1465  BASE::pGlobalAttribute->mStackSymbols.Name("StackSymbols");
1466  BASE::pGlobalAttribute->mpStackSymbolTable=StackSymbolSet::StaticSymbolTablep();
1467  FD_DG("PushdownGenerator(" << this << ")::PushdownGenerator(rOtherGen) with csymtab"
1468  << "(BASE::pGlobalAttribute->mpStackSymbolTable)" );
1469 }
1470 
1471 // TpdGenerator(rFilename)
1472 TEMP THIS::TpdGenerator(const std::string& rFileName)/* : BASE(rFileName)*/ {
1473  FD_DG("PushdownGenerator(" << this << ")::PushdownGenerator(" << rFileName << ") with csymtab"
1474  << "(BASE::pGlobalAttribute->mpStackSymbolTable)" );
1475  if(rFileName.substr(rFileName.find_last_of(".") + 1) == "dot")
1476  {
1477  // set basic members (cosmetic)
1478  BASE::pGlobalAttribute->mStackSymbols.Name("StackSymbols");
1479  BASE::pGlobalAttribute->mpStackSymbolTable=StackSymbolSet::StaticSymbolTablep();
1480  THIS::DotRead(rFileName);
1481  }
1482  else
1483  BASE(rFileName);
1484 }
1485 
1486 //StateStr(idx)
1487 TEMP std::string THIS::StateStr(Idx idx) const{
1488  FD_DG("TpdGenerator(" << this << ")::StateStr("<< idx <<"\")");
1489  #ifdef FAUDES_CHECKED
1490  if (! BASE::ExistsState(idx)) {
1491  std::stringstream errstr;
1492  errstr << "state \"" << idx << "\" not found in generator \""
1493  << BASE::Name() << "\"";
1494  throw Exception("TpdGenerator::StateStr(idx)", errstr.str(), 89);
1495  }
1496  #endif
1497 
1498  std::string str= BASE::StateName(idx);
1499  if(str =="") str="Idx:" + ToStringInteger(idx);
1500  return str;
1501 }
1502 
1503 //EventStr(idx)
1504 TEMP std::string THIS::EventStr(Idx idx) const{
1505  FD_DG("TpdGenerator(" << this << ")::EventStr("<< idx <<"\")");
1506  #ifdef FAUDES_CHECKED
1507  if (! BASE::ExistsEvent(idx)) {
1508  std::stringstream errstr;
1509  errstr << "event \"" << idx << "\" not found in generator \""
1510  << BASE::Name() << "\"";
1511  throw Exception("TpdGenerator::EventStr(idx)", errstr.str(), 89);
1512  }
1513  #endif
1514 
1515  std::string str= BASE::EventName(idx);
1516  if(str =="") str="Idx:" + ToStringInteger(idx);
1517  return str;
1518 }
1519 
1520 //GlobalStackSymbolTablep
1521 TEMP SymbolTable* THIS::GlobalStackSymbolTablep(void) {
1523 }
1524 
1525 // StackSymbolTablep()
1526 TEMP SymbolTable* THIS::StackSymbolTablep(void) const {
1527  return BASE::pGlobalAttribute->mpStackSymbolTable;
1528 }
1529 
1530 // StackSymbolTablep(pSymTab)
1531 TEMP void THIS::StackSymbolTablep(SymbolTable* pSymTab) {
1532  BASE::Clear();
1533  BASE::pGlobalAttribute->mpStackSymbolTable=pSymTab;
1534 }
1535 
1536 // New
1537 TEMP THIS* THIS::New(void) const {
1538  // allocate
1539  THIS* res = new THIS;
1540  // fix base data
1541  res->EventSymbolTablep(BASE::mpEventSymbolTable);
1542  res->mStateNamesEnabled=BASE::mStateNamesEnabled;
1543  res->mReindexOnWrite=BASE::mReindexOnWrite;
1544  // fix my data
1545  res->StackSymbolTablep(StackSymbolTablep());
1546  return res;
1547 }
1548 
1549 // Copy
1550 TEMP THIS* THIS::Copy(void) const {
1551  // allocate
1552  THIS* res = new THIS(*this);
1553  // done
1554  return res;
1555 }
1556 
1557 // NewTGen
1558 TEMP THIS THIS::NewPdGen(void) const {
1559  // call base (fixes by assignment constructor)
1560  THIS res= BASE::NewCGen();
1561  // fix my data
1562  res.StackSymbolTablep(StackSymbolTablep());
1563  return res;
1564 }
1565 
1566 // StackSymbolsSize() const
1567 TEMP Idx THIS::StackSymbolsSize(void) const {
1568  return BASE::pGlobalAttribute->mStackSymbols.Size();
1569 }
1570 
1571 // StackSymbols()
1572 TEMP const StackSymbolSet& THIS::StackSymbols(void) const {
1573  return BASE::pGlobalAttribute->mStackSymbols;
1574 }
1575 
1576 // StackSymbolssp()
1577 TEMP StackSymbolSet* THIS::StackSymbolsp(void) {
1578  return &BASE::pGlobalAttribute->mStackSymbols;
1579 }
1580 
1581 // InjectStackSymbols(set)
1582 TEMP void THIS::InjectStackSymbols(const StackSymbolSet& newstacksymbols) {
1583  BASE::pGlobalAttribute->mStackSymbols=newstacksymbols;
1584  BASE::pGlobalAttribute->mStackSymbols.Name("StackSymbols");
1585 }
1586 
1587 // StackSymbolName(index)
1588 TEMP std::string THIS::StackSymbolName(Idx index) const {
1589  return BASE::pGlobalAttribute->mStackSymbols.SymbolicName(index);
1590 }
1591 
1592 // StackSymbolName(index,name)
1593 TEMP void THIS::StackSymbolName(Idx index, const std::string& rName) const {
1594  FD_DG("TpdGenerator(" << this << ")::StackSymbolName("
1595  << index << ",\"" << rName << "\")");
1596  #ifdef FAUDES_CHECKED
1597  if (! ExistsStackSymbol(index)) {
1598  std::stringstream errstr;
1599  errstr << "stack symbol idex \"" << index << "\" not found in generator \""
1600  << BASE::Name() << "\"";
1601  throw Exception("TpdGenerator::StateName(index, name)", errstr.str(), 90);
1602  }
1603  #endif
1604  BASE::pGlobalAttribute->mStackSymbols.SymbolicName(index, rName);
1605 }
1606 
1607 //StackSymbolObj(index)
1608 TEMP StackSymbol THIS::StackSymbolObj(Idx index) const {
1609  return StackSymbol(BASE::pGlobalAttribute->mStackSymbols.SymbolicName(index));
1610 }
1611 
1612 // StackSymbolIndex(name)
1613 TEMP Idx THIS::StackSymbolIndex(const std::string& rName) const {
1614  return BASE::pGlobalAttribute->mStackSymbols.Index(rName);
1615 }
1616 
1617 // InsStackSymbol(name)
1618 TEMP Idx THIS::InsStackSymbol(const std::string& rName) {
1619  return BASE::pGlobalAttribute->mStackSymbols.Insert(rName);
1620 }
1621 
1622 //InsStackSymbol(symbol)
1623 TEMP Idx THIS::InsStackSymbol(const StackSymbol& rSymbol){
1624  return BASE::pGlobalAttribute->mStackSymbols.Insert(rSymbol.Symbol());
1625 }
1626 
1627 // InsStackSymbols(set)
1628 TEMP void THIS::InsStackSymbols(const StackSymbolSet& rStackSymbolSet) {
1629  BASE::pGlobalAttribute->mStackSymbols.InsertSet(rStackSymbolSet);
1630 }
1631 
1632 // SetStackBottom(name)
1633 TEMP Idx THIS::SetStackBottom(const std::string& rName) {
1634  Idx i = BASE::pGlobalAttribute->mStackSymbols.Insert(rName);
1635  BASE::pGlobalAttribute->mStackBottom = i;
1636  return i;
1637 }
1638 
1639 //SetStackBottom(symbol)
1640 TEMP Idx THIS::SetStackBottom(const StackSymbol& rSymbol){
1641  Idx i = BASE::pGlobalAttribute->mStackSymbols.Insert(rSymbol.Symbol());
1642  BASE::pGlobalAttribute->mStackBottom = i;
1643  return i;
1644 }
1645 
1646 //SetStackBottom(index)
1647 TEMP Idx THIS::SetStackBottom(const Idx idx){
1648  if(!ExistsStackSymbol(idx)) {
1649  std::stringstream errstr;
1650  errstr << "stack symbol with index " << idx << " not found in generator. " << std::endl;
1651  throw Exception("PushdownGenerator::SetStackBottom(idx)", errstr.str(), 200);
1652  }
1653  BASE::pGlobalAttribute->mStackBottom = StackSymbol(StackSymbolName(idx));
1654  return idx;
1655 }
1656 
1657 //StackBottom()
1658 TEMP Idx THIS::StackBottom() const{
1659  return BASE::pGlobalAttribute->mStackBottom;
1660 }
1661 
1662 // DelStackSymbol(index)
1663 TEMP bool THIS::DelStackSymbol(Idx index) {
1664  FD_DG("PushdownGenerator(" << this << ")::DelStackSymbol(" << index << ")");
1665  return BASE::pGlobalAttribute->mStackSymbols.Erase(index);
1666 }
1667 
1668 // DelStackSymbol(name)
1669 TEMP bool THIS::DelStackSymbol(const std::string& rName) {
1670  Idx index=BASE::pGlobalAttribute->mStackSymbols.Index(rName);
1671  return DelStackSymbol(index);
1672 }
1673 
1674 // DelStackSymbols(set)
1675 TEMP void THIS::DelStackSymbols(const StackSymbolSet& rStackSymbols) {
1676  StackSymbolSet::Iterator it=StackSymbolsBegin();
1677  while(it!=StackSymbolsEnd()){
1678  DelStackSymbol(*(it++)); // fixed: 2013-12-17
1679  }
1680 }
1681 
1682 // ExistsStackSymbol(index)
1683 TEMP bool THIS::ExistsStackSymbol(Idx index) const {
1684  return BASE::pGlobalAttribute->mStackSymbols.Exists(index);
1685 }
1686 
1687 // ExistsStackSymbol(name)
1688 TEMP bool THIS::ExistsStackSymbol(
1689  const std::string& rName) const {
1690  return BASE::pGlobalAttribute->mStackSymbols.Exists(rName);
1691 }
1692 
1693 // FindStackSymbol(index)
1694 TEMP StackSymbolSet::Iterator THIS::FindStackSymbol(Idx index) const {
1695  return BASE::pGlobalAttribute->mStackSymbols.Find(index);
1696 }
1697 
1698 // FindStackSymbol(name)
1699 TEMP StackSymbolSet::Iterator THIS::FindStackSymbol(const std::string& rName) const {
1700  return BASE::pGlobalAttribute->mStackSymbols.Find(rName);
1701 }
1702 
1703 //StackSymbolStr(idx)
1704 TEMP std::string THIS::StackSymbolStr(Idx idx) const{
1705  FD_DG("TpdGenerator(" << this << ")::StackSymbolStr("<< idx <<"\")");
1706  #ifdef FAUDES_CHECKED
1707  if (! ExistsStackSymbol(idx)) {
1708  std::stringstream errstr;
1709  errstr << "stack symbol \"" << idx << "\" not found in generator \""
1710  << BASE::Name() << "\"";
1711  throw Exception("TpdGenerator::StackSymbolStr(idx)", errstr.str(), 89);
1712  }
1713  #endif
1714  std::string str= THIS::StackSymbolName(idx);
1715  if(str =="") str="Idx:" + ToStringInteger(idx);
1716  return str;
1717 }
1718 
1719 //UniqueStackSymbolName(rName)
1720 TEMP std::string THIS::UniqueStackSymbolName(const std::string& rName) const {
1721  FD_DG("PushdownGenerator(" << this << ")::UniqueStackSymbolName(" << rName << ")");
1722  std::string name=rName;
1723  if(name=="") name="s";
1724  return BASE::pGlobalAttribute->mpStackSymbolTable->UniqueSymbol(name) ;
1725 }
1726 
1727 //Iterator StackSymbolsBegin() const
1728 TEMP StackSymbolSet::Iterator THIS::StackSymbolsBegin(void) const {
1729  return BASE::pGlobalAttribute->mStackSymbols.Begin();
1730 }
1731 
1732 //Iterator StackSymbolsEnd() const
1733 TEMP StackSymbolSet::Iterator THIS::StackSymbolsEnd(void) const {
1734  return BASE::pGlobalAttribute->mStackSymbols.End();
1735 }
1736 //StackSymbolsToIndices
1737 TEMP std::vector<Idx> THIS::StackSymbolsToIndices(const std::vector<StackSymbol> symbols) const{
1738  std::vector<StackSymbol>::const_iterator ssit;
1739  std::vector<Idx> rV;
1740  for(ssit = symbols.begin(); ssit != symbols.end(); ssit++){
1741  rV.push_back(StackSymbolIndex(ssit->Symbol()));
1742  }
1743  return rV;
1744 }
1745 
1746 //StackSymbolNamesToIndices
1747 TEMP std::vector<Idx> THIS::StackSymbolNamesToIndices(const std::vector<std::string> symbolnames) const{
1748  std::vector<std::string>::const_iterator ssit;
1749  std::vector<Idx> rV;
1750  for(ssit = symbolnames.begin(); ssit != symbolnames.end(); ssit++){
1751  rV.push_back(StackSymbolIndex(*ssit));
1752  }
1753  return rV;
1754 }
1755 
1756 //IsDeterministic() const
1758 
1759  StateSet::Iterator stateit;
1760  TransSet::Iterator transit1, transit2;
1761  PopPushSet::iterator ppit1, ppit2;
1762 
1763  //for each state
1764  for(stateit = BASE::StatesBegin(); stateit != BASE::StatesEnd(); ++stateit){
1765  //check each transition pair
1766  for(transit1 = BASE::TransRelBegin(*stateit); transit1 != BASE::TransRelEnd(*stateit); ++transit1){
1767  for(transit2 = transit1; transit2 != BASE::TransRelEnd(*stateit); ++transit2){
1768  //if same event or one event is lambda
1769  if((transit1->Ev == transit2->Ev) ||
1770  THIS::IsEventLambda(transit2->Ev) ||
1771  THIS::IsEventLambda(transit1->Ev)){
1772 
1773  uint matches = 0;
1774 
1775  //check popped stack symbols
1776  for(ppit1 = THIS::PopPushBegin(*transit1); ppit1 != THIS::PopPushEnd(*transit1); ++ppit1){
1777  for(ppit2 = THIS::PopPushBegin(*transit2); ppit2 != THIS::PopPushEnd(*transit2); ++ppit2){
1778  if(ppit1->first == ppit2->first)
1779  matches++;
1780  }
1781  if(transit1 == transit2){
1782  // decrease matches counter because for sure there will be one match (with the transition itself)
1783  matches--;
1784  }
1785  if(matches > 0)
1786  return false;
1787  }
1788  }
1789  }
1790  }
1791  }
1792 
1793  return true;
1794 }
1795 
1796 TEMP Idx THIS::TransRelSize() const{
1797 
1798  TransSet::Iterator transit;
1799  Idx s = 0;
1800  for(transit = BASE::TransRelBegin(); transit != BASE::TransRelEnd(); transit++){
1801  s += PopPush(*transit).size();
1802  }
1803  return s;
1804 }
1805 
1806 // SetTransition(rX1, rEv, rX2)
1807 TEMP bool THIS::SetTransition(const std::string& rX1, const std::string& rEv, const std::string& rX2) {
1808  return BASE::SetTransition(rX1,rEv,rX2);
1809 }
1810 
1811 
1812 // SetTransition(x1, ev, x2)
1813 TEMP bool THIS::SetTransition(Idx x1, Idx ev, Idx x2) {
1814  return BASE::SetTransition(Transition(x1,ev,x2));
1815 }
1816 
1817 // SetTransition(rTransition, rAttr)
1818 TEMP bool THIS::SetTransition(const Transition& rTransition, const TransAttr& rAttr) {
1819  return BASE::SetTransition(rTransition,rAttr);
1820 }
1821 
1822 // SetTransition(trans,....)
1823 TEMP bool THIS::SetTransition(const Transition& rTrans, const std::vector<StackSymbol>& rPop, const std::vector<StackSymbol>& rPush) {
1824  return SetTransition(rTrans, StackSymbolsToIndices(rPop), StackSymbolsToIndices(rPush));
1825 }
1826 
1827 TEMP bool THIS::SetTransition(const Transition& rTrans,const std::vector<Idx>& rPop, const std::vector<Idx>& rPush) {
1828  FD_DG("PushdownGenerator(" << this << ")::SetTransition(" << (BASE::TStr(rTrans)) <<", " <<
1829  ", PopVector" << ", " << "PushVector" << ") const");
1830 #ifdef FAUDES_CHECKED
1831  EmptyVectorPopPush(rPop);
1832  EmptyVectorPopPush(rPush);
1833 #endif
1834  BASE::SetTransition(rTrans);
1835  //get the transition attribute or take new one if it does not exist
1836  TransAttr attr;
1837  if(BASE::TransAttributep(rTrans) != 0){
1838  attr = *BASE::TransAttributep(rTrans);
1839  }
1840  std::pair<std::vector<Idx>, std::vector<Idx> > popPushPair;
1841  popPushPair.first = rPop;
1842  popPushPair.second = rPush;
1843  //add new PopPushPair
1844  attr.mPopPush.insert(popPushPair);
1845 #ifdef FAUDES_CHECKED
1846  ConsistentVectorStackSymbol(rPop);
1847  ConsistentVectorStackSymbol(rPush);
1848 #endif
1849  return BASE::SetTransition(rTrans,attr);
1850 }
1851 
1852 // SetTransition(x1,ev,x2, pop, push)
1853 TEMP bool THIS::SetTransition(Idx x1, Idx ev, Idx x2, const std::vector<StackSymbol>& rPop, const std::vector<StackSymbol>& rPush) {
1854  return SetTransition(Transition(x1,ev,x2),rPop,rPush);
1855 }
1856 
1857 // SetTransition(x1,ev,x2, pop, push)
1858 TEMP bool THIS::SetTransition(Idx x1, Idx ev, Idx x2, const std::vector<Idx>& rPop, const std::vector<Idx>& rPush) {
1859  return SetTransition(Transition(x1,ev,x2),rPop,rPush);
1860 }
1861 
1862 TEMP bool THIS::SetTransition(const Transition& rTrans, const std::vector<std::string>& rPop, const std::vector<std::string>& rPush) {
1863  return SetTransition(rTrans,StackSymbolNamesToIndices(rPop),StackSymbolNamesToIndices(rPush));
1864 }
1865 
1866 // SetTransition(X1,Ev,X2, ...)
1867 TEMP bool THIS::SetTransition(const std::string& rX1, const std::string& rEv, const std::string& rX2, const std::vector<StackSymbol>& rPop, const std::vector<StackSymbol>& rPush) {
1868  FD_DG("PushdownGenerator(" << this << ")::SetTransition(" << rX1 << " " << rEv <<" " << rX2 <<
1869  ", PopVector" << ", " << "PushVector" << ") const");
1870  //try to add transition, will do nothing if transition exists
1871  bool res=BASE::SetTransition(rX1,rEv,rX2);
1872  //get transition via iterator
1873  Transition rTrans = *(BASE::FindTransition(rX1,rEv,rX2));
1874 #ifdef FAUDES_CHECKED
1875  EmptyVectorPopPush(rPop);
1876  EmptyVectorPopPush(rPush);
1877 #endif
1878  //get the transition attribute or take new one if it does not exist
1879  TransAttr attr;
1880  if(BASE::TransAttributep(rTrans) != 0){
1881  attr = *BASE::TransAttributep(rTrans);
1882  }
1883  std::pair<std::vector<Idx>, std::vector<Idx> > popPushPair;
1884  popPushPair.first = StackSymbolsToIndices(rPop);
1885  popPushPair.second = StackSymbolsToIndices(rPush);
1886  //add new PopPushPair
1887  attr.mPopPush.insert(popPushPair);
1888 #ifdef FAUDES_CHECKED
1889  ConsistentVectorStackSymbol(rPop);
1890  ConsistentVectorStackSymbol(rPush);
1891 #endif
1892  BASE::TransAttribute(Transition(BASE::StateIndex(rX1),BASE::EventIndex(rEv),BASE::StateIndex(rX2)),attr);
1893  return res;
1894 }
1895 
1896 // SetTransition(x1,ev,x2,rPop,rPush)
1897 TEMP bool THIS::SetTransition(Idx x1, Idx ev, Idx x2, const std::vector<std::string>& rPop, const std::vector<std::string>& rPush) {
1898  return SetTransition(Transition(x1,ev,x2),rPop,rPush);
1899 }
1900 
1901 // SetTransition(x1,ev,x2,rPop,rPush)
1902 TEMP bool THIS::SetTransition(const std::string& rX1, const std::string& rEv, const std::string& rX2, const std::vector<std::string>& rPop, const std::vector<std::string>& rPush) {
1903  return SetTransition(Transition(BASE::StateIndex(rX1),BASE::EventIndex(rEv),BASE::StateIndex(rX2)),rPop,rPush);
1904 }
1905 
1906 // SetTransition(x1,ev,x2,rPop,rPush)
1907 TEMP bool THIS::SetTransition(const std::string& rX1, const std::string& rEv, const std::string& rX2, const std::vector<Idx>& rPop, const std::vector<Idx>& rPush) {
1908  return SetTransition(Transition(BASE::StateIndex(rX1),BASE::EventIndex(rEv),BASE::StateIndex(rX2)),rPop,rPush);
1909 }
1910 
1911 // ParseStackSymbolNames("[X,Y]")
1912 TEMP std::vector<std::string> THIS::ParseStackSymbolNames(const std::string& rStr) const{
1913  std::string::size_type end_position,pos= 0;
1914  std::vector<std::string> syms;
1915  std::string s = rStr;
1916 
1917  //remove spaces from string
1918  s.erase(std::remove_if(s.begin(), s.end(), ::isspace), s.end());
1919 
1920  //get pop/push symbols
1921  pos = s.find("[");
1922  if (pos != std::string::npos)
1923  {
1924  //get stacksymbols
1925  end_position = s.find("]",++pos);
1926  if (end_position != std::string::npos)
1927  {
1928  //get string between squared brackets
1929  std::string found_text = s.substr(pos, end_position-pos);
1930 
1931  if (!found_text.empty()) {
1932  std::string::size_type curr = 0, end = 0;
1933 
1934  //substring
1935  std::string sub;
1936 
1937  //while comma separator exists from current position
1938  while ((end = found_text.find(",", curr)) != std::string::npos) {
1939  sub = found_text.substr(curr, end - curr);
1940  syms.push_back(sub);
1941  curr = end + 1;
1942  }
1943 
1944  //add last symbol
1945  if (curr < found_text.size())
1946  syms.push_back(found_text.substr(curr));
1947  }
1948  }
1949  #ifdef FAUDES_CHECKED
1950  else{
1951  std::stringstream errstr;
1952  errstr << " Missing ']' for pop or push ." << std::endl;
1953  throw Exception("TpdGenerator::parsePPString", errstr.str(), 200);
1954  }
1955  #endif
1956  }
1957  #ifdef FAUDES_CHECKED
1958  else{
1959  std::stringstream errstr;
1960  errstr << " Missing '[' for pop or push ." << std::endl;
1961  throw Exception("TpdGenerator::parsePPString", errstr.str(), 200);
1962  }
1963  #endif
1964 
1965  //if no stacksym find, add lambda
1966  if(syms.empty())
1967  syms.push_back(FAUDES_PD_LAMBDA);
1968 
1969  return syms;
1970 }
1971 
1972 // SetTransition(rX1,rEv,rPop,rPush, rX2) (note: luabinding)
1973 TEMP bool THIS::SetTransition(const std::string& rX1, const std::string& rEv, const std::string& rPop,
1974  const std::string& rPush, const std::string& rX2){
1975  return SetTransition(rX1,rEv,rX2,ParseStackSymbolNames(rPop),ParseStackSymbolNames(rPush));
1976 }
1977 
1978 //clearTransition(x1,ev,x2,rPop,rPush)
1979 TEMP bool THIS::ClrTransition(Idx x1, Idx ev, Idx x2, const std::vector<Idx>& rPop, const std::vector<Idx>& rPush){
1980  return ClrTransition(Transition(x1,ev,x2),rPop,rPush);
1981 }
1982 
1983 //clearTransition(x1,ev,x2,rPop,rPush)
1984 TEMP bool THIS::ClrTransition(Idx x1, Idx ev, Idx x2, const std::vector<StackSymbol>& rPop, const std::vector<StackSymbol>& rPush){
1985  return ClrTransition(Transition(x1,ev,x2),rPop,rPush);
1986 }
1987 
1988 //clearTransition(x1,ev,x2,rPop,rPush)
1989 TEMP bool THIS::ClrTransition(Idx x1, Idx ev, Idx x2, const std::vector<std::string>& rPop, const std::vector<std::string>& rPush){
1990  return ClrTransition(Transition(x1,ev,x2),rPop,rPush);
1991 }
1992 
1993 //clearTransition(x1,ev,x2,rPop,rPush)
1994 TEMP bool THIS::ClrTransition(std::string x1, std::string ev, std::string x2, const std::vector<Idx>& rPop, const std::vector<Idx>& rPush){
1995  return ClrTransition(Transition(BASE::StateIndex(x1),BASE::EventIndex(ev),BASE::StateIndex(x2)),rPop,rPush);
1996 }
1997 
1998 //clearTransition(x1,ev,x2,rPop,rPush)
1999 TEMP bool THIS::ClrTransition(std::string x1, std::string ev, std::string x2, const std::vector<StackSymbol>& rPop, const std::vector<StackSymbol>& rPush){
2000  return ClrTransition(Transition(BASE::StateIndex(x1),BASE::EventIndex(ev),BASE::StateIndex(x2)),rPop,rPush);
2001 }
2002 
2003 //clearTransition(x1,ev,x2,rPop,rPush)
2004 TEMP bool THIS::ClrTransition(std::string x1, std::string ev, std::string x2, const std::vector<std::string>& rPop, const std::vector<std::string>& rPush){
2005  return ClrTransition(Transition(BASE::StateIndex(x1),BASE::EventIndex(ev),BASE::StateIndex(x2)),rPop,rPush);
2006 }
2007 
2008 //clearTransition(rTrans,rPop,rPush)
2009 TEMP bool THIS::ClrTransition(const Transition& rTrans, const std::vector<StackSymbol>& rPop,const std::vector<StackSymbol>& rPush){
2010  return ClrTransition(rTrans,StackSymbolsToIndices(rPop),StackSymbolsToIndices(rPush));
2011 }
2012 
2013 //clearTransition(rTrans,rPop,rPush)
2014 TEMP bool THIS::ClrTransition(const Transition& rTrans, const std::vector<std::string>& rPop,const std::vector<std::string>& rPush){
2015  return ClrTransition(rTrans,StackSymbolNamesToIndices(rPop),StackSymbolNamesToIndices(rPush));
2016 }
2017 
2018 //clearTransition(rTrans,rPop,rPush)
2019 TEMP bool THIS::ClrTransition(const Transition& rTrans, const std::vector<Idx>& rPop,const std::vector<Idx>& rPush){
2020  //check for existence of base transition
2021  if(!BASE::ExistsTransition(rTrans)){
2022  return false;
2023  }
2024 
2025  //delete pop/push pair in said transition
2026  if(!BASE::pTransRel->Attributep(rTrans)->ClrPopPush(rPop, rPush)){
2027  return false;
2028  }
2029 
2030  //delete transition if popPush is empty
2031  if(PopPush(rTrans).empty()){
2032  BASE::ClrTransition(rTrans);
2033  }
2034 
2035  return true;
2036 }
2037 
2038 // ClrTransition(rX1,rEv,rPop,rPush, rX2) (note: luabinding)
2039 TEMP bool THIS::ClrTransition(const std::string& rX1, const std::string& rEv, const std::string& rPop,const std::string& rPush, const std::string& rX2){
2040  return ClrTransition(rX1,rEv,rX2,ParseStackSymbolNames(rPop),ParseStackSymbolNames(rPush));
2041 }
2042 
2043 // ExistsTransition(rX1,rEv,rX2)
2044 TEMP bool THIS::ExistsTransition(const std::string& rX1, const std::string& rEv, const std::string& rX2) const{
2045  return BASE::ExistsTransition(rX1,rEv,rX2);
2046 }
2047 
2048 // ExistsTransition(x1, ev, x2)
2049 TEMP bool THIS::ExistsTransition(Idx x1, Idx ev, Idx x2) const{
2050  return BASE::ExistsTransition(x1,ev,x2);
2051 }
2052 
2053 // ExistsTransition(rTrans)
2054 TEMP bool THIS::ExistsTransition(const Transition& rTrans) const{
2055  return BASE::ExistsTransition(rTrans);
2056 }
2057 
2058 // ExistsTransition(x1, ev)
2059 TEMP bool THIS::ExistsTransition(Idx x1, Idx ev) const{
2060  return BASE::ExistsTransition(x1, ev);
2061 }
2062 
2063 // ExistsTransition(x1)
2064 TEMP bool THIS::ExistsTransition(Idx x1) const{
2065  return BASE::ExistsTransition(x1);
2066 }
2067 
2068 //ExistsTransition(x1,ev,x2,pop,push)
2069 TEMP bool THIS::ExistsTransition(Idx x1, Idx ev, Idx x2, const std::vector<Idx>& pop, const std::vector<Idx>& push) const{
2070  return THIS::ExistsTransition(Transition(x1, ev, x2),pop,push);
2071 }
2072 
2073 //ExistsTransition(x1,ev,x2,pop,push)
2074 TEMP bool THIS::ExistsTransition(Idx x1, Idx ev, Idx x2, const std::vector<std::string>& pop, const std::vector<std::string>& push) const{
2075  return THIS::ExistsTransition(Transition(x1, ev, x2),pop,push);
2076 }
2077 
2078 //ExistsTransition(x1,ev,x2,rPop,rPush)
2079 TEMP bool THIS::ExistsTransition(Idx x1, Idx ev, Idx x2, const std::vector<StackSymbol>& rPop, const std::vector<StackSymbol>& rPush)const{
2080  return ExistsTransition(Transition(x1,ev,x2),rPop,rPush);
2081 }
2082 
2083 //ExistsTransition(x1,ev,x2,pop,push)
2084 TEMP bool THIS::ExistsTransition(const std::string& x1, const std::string& ev, const std::string& x2, const std::vector<StackSymbol>& pop, const std::vector<StackSymbol>& push) const{
2085  return THIS::ExistsTransition(Transition(BASE::StateIndex(x1), BASE::EventIndex(ev), BASE::StateIndex(x2)),pop,push);
2086 }
2087 
2088 //ExistsTransition(x1,ev,x2,pop,push)
2089 TEMP bool THIS::ExistsTransition(const std::string& x1, const std::string& ev, const std::string& x2, const std::vector<std::string>& pop, const std::vector<std::string>& push) const{
2090  return THIS::ExistsTransition(Transition(BASE::StateIndex(x1), BASE::EventIndex(ev), BASE::StateIndex(x2)),pop,push);
2091 }
2092 
2093 //ExistsTransition(x1,ev,x2,pop,push)
2094 TEMP bool THIS::ExistsTransition(const std::string& x1, const std::string& ev, const std::string& x2, const std::vector<Idx>& pop, const std::vector<Idx>& push) const{
2095  return THIS::ExistsTransition(Transition(BASE::StateIndex(x1), BASE::EventIndex(ev), BASE::StateIndex(x2)),pop,push);
2096 }
2097 
2098 //ExistsTransition(rTrans,rPop,rPush)
2099 TEMP bool THIS::ExistsTransition(const Transition& rTrans, const std::vector<StackSymbol>& rPop,const std::vector<StackSymbol>& rPush)const{
2100  return ExistsTransition(rTrans,StackSymbolsToIndices(rPop),StackSymbolsToIndices(rPush));
2101 }
2102 
2103 //ExistsTransition(rTrans,rPop,rPush)
2104 TEMP bool THIS::ExistsTransition(const Transition& rTrans, const std::vector<std::string>& rPop, const std::vector<std::string>& rPush) const{
2105  return ExistsTransition(rTrans,StackSymbolNamesToIndices(rPop),StackSymbolNamesToIndices(rPush));
2106 }
2107 
2108 //ExistsTransition(rTrans,rPop,rPush)
2109 TEMP bool THIS::ExistsTransition(const Transition& rTrans, const std::vector<Idx>& rPop, const std::vector<Idx>& rPush) const{
2110  if(BASE::ExistsTransition(rTrans)){
2111  PopPushSet popPushSet = PopPush(rTrans);
2112 
2113  std::pair<std::vector<Idx>, std::vector<Idx> > popPushPair;
2114  popPushPair.first = rPop;
2115  popPushPair.second = rPush;
2116 
2117  return popPushSet.find(popPushPair) != popPushSet.end();
2118  }
2119 
2120  return false;
2121 }
2122 
2123 // ExistsTransition(rX1,rEv,rPop,rPush, rX2) (note: luabinding)
2124 TEMP bool THIS::ExistsTransition(const std::string& rX1, const std::string& rEv, const std::string& rPop,
2125  const std::string& rPush, const std::string& rX2)const{
2126 
2127  return ExistsTransition(rX1,rEv,rX2,ParseStackSymbolNames(rPop),ParseStackSymbolNames(rPush));
2128 }
2129 
2130 //PopPush(trans)
2131 TEMP const PopPushSet& THIS::PopPush(const Transition& rTrans) const{
2132 #ifdef FAUDES_CHECKED
2133  if(!BASE::ExistsTransition(rTrans)) {
2134  std::stringstream errstr;
2135  errstr << "transition " << BASE::TStr(rTrans) << " not found ";
2136  errstr << std::endl;
2137  throw Exception("PushdownGenerator::PopPush(trans)", errstr.str(), 200);
2138  }
2139 #endif
2140  return BASE::pTransRel->Attribute(rTrans).PopPush();
2141 }
2142 
2143 //PopPushBegin(trans)
2144 TEMP PopPushSet::const_iterator THIS::PopPushBegin(const Transition& rTrans) const {
2145  return BASE::pTransRel->Attribute(rTrans).PopPush().begin();
2146 }
2147 
2148 //PopPushEnd(trans)
2149 TEMP PopPushSet::const_iterator THIS::PopPushEnd(const Transition& rTrans) const {
2150  return BASE::pTransRel->Attribute(rTrans).PopPush().end();
2151 }
2152 
2153 //InsLambdaStackSymbol
2154 TEMP Idx THIS::InsLambdaStackSymbol(){
2155  if(ExistsStackSymbol(FAUDES_PD_LAMBDA))
2156  return StackSymbolIndex(FAUDES_PD_LAMBDA);
2157  else
2158  return InsStackSymbol(FAUDES_PD_LAMBDA);
2159 }
2160 
2161 //IsStackSymbolLambda(index)
2162 TEMP bool THIS::IsStackSymbolLambda(Idx index) const{
2163  if(StackSymbolName(index).compare(FAUDES_PD_LAMBDA) == 0)
2164  return true;
2165  else
2166  return false;
2167 }
2168 
2169 //IsEventLambda(index)
2170 TEMP bool THIS::IsEventLambda(Idx index) const{
2171  if(BASE::EventName(index).compare(FAUDES_PD_LAMBDA) == 0)
2172  return true;
2173  else
2174  return false;
2175 }
2176 
2177 
2178 // ConsistentStackSymbol(rStackSymbol)
2179 TEMP void THIS::ConsistentStackSymbol(const StackSymbol& rStackSymbol) const {
2180  FD_DG("PushdownGenerator(" << this << ")::ConsistentStackSymbol(rStackSymbol)");
2181  if(!StackSymbols().Exists(rStackSymbol.Symbol())) {
2182  std::stringstream errstr;
2183  errstr << "stack symbol table mismatch (symbol " << rStackSymbol.mSymbol << " does not exist)" << std::endl;
2184  throw Exception("PushdownGenerator::ConsistentStackSymbol", errstr.str(), 1001);
2185  }
2186  FD_DG("PushdownGenerator(" << this << ")::ConsistentStackSymbol(rStackSymbol): ok");
2187 }
2188 
2189 // ConsistentStackSymbol(Idx)
2190 TEMP void THIS::ConsistentStackSymbol(Idx idx) const {
2191  FD_DG("PushdownGenerator(" << this << ")::ConsistentStackSymbol(idx)");
2192  if(!StackSymbols().Exists(idx)) {
2193  std::stringstream errstr;
2194  errstr << "stack symbol table mismatch (symbol with idx " << idx << " does not exist)" << std::endl;
2195  throw Exception("PushdownGenerator::ConsistentStackSymbol", errstr.str(), 1001);
2196  }
2197  FD_DG("PushdownGenerator(" << this << ")::ConsistentStackSymbol(idx): ok");
2198 }
2199 
2200 // ConsistentVectorStackSymbol(vector)
2201 TEMP void THIS::ConsistentVectorStackSymbol(const std::vector<StackSymbol>& rVector) const {
2202  FD_DG("PushdownGenerator(" << this << ")::ConsistentVectorStackSymbol(rVector)");
2203  std::vector<StackSymbol>::const_iterator it;
2204  it = rVector.begin();
2205  for ( ; it < rVector.end(); it++){
2206  if(!StackSymbols().Exists(it->Symbol())) {
2207  std::stringstream errstr;
2208  errstr << "stack symbol table mismatch (symbol " << it->mSymbol << " does not exist)" <<std::endl;
2209  throw Exception("PushdownGenerator::ConsistentVectorStackSymbol", errstr.str(), 1001);
2210  }
2211  }
2212  FD_DG("PushdownGenerator(" << this << ")::ConsistentVectorStackSymbol(rVector): ok");
2213 }
2214 
2215 // ConsistentVectorStackSymbol(vector)
2216 TEMP void THIS::ConsistentVectorStackSymbol(const std::vector<Idx>& rVector) const {
2217  FD_DG("PushdownGenerator(" << this << ")::ConsistentVectorStackSymbol(rVector)");
2218  std::vector<Idx>::const_iterator it;
2219  it = rVector.begin();
2220  for ( ; it < rVector.end(); it++){
2221  if(!StackSymbols().Exists(*it)) {
2222  std::stringstream errstr;
2223  errstr << "stack symbol table mismatch (symbol with index " << *it << " does not exist)" <<std::endl;
2224  throw Exception("PushdownGenerator::ConsistentVectorStackSymbol", errstr.str(), 1001);
2225  }
2226  }
2227  FD_DG("PushdownGenerator(" << this << ")::ConsistentVectorStackSymbol(rVector): ok");
2228 }
2229 
2230 // EmptyVector(vector)
2231 TEMP void THIS::EmptyVectorPopPush(const std::vector<StackSymbol>& rVector) const {
2232  FD_DG("PushdownGenerator(" << this << ")::EmptyVector(rVector)");
2233  if(rVector.empty()) {
2234  std::stringstream errstr;
2235  errstr << "empty vector not allowed in pop or push" <<std::endl;
2236  throw Exception("PushdownGenerator::EmptyVector", errstr.str(), 1001);
2237  }
2238  FD_DG("PushdownGenerator(" << this << ")::EmptyVectorPopPush(rVector): ok");
2239 }
2240 
2241 // EmptyVector(vector)
2242 TEMP void THIS::EmptyVectorPopPush(const std::vector<Idx>& rVector) const {
2243  FD_DG("PushdownGenerator(" << this << ")::EmptyVector(rVector)");
2244  if(rVector.empty()) {
2245  std::stringstream errstr;
2246  errstr << "empty vector not allowed in pop or push" <<std::endl;
2247  throw Exception("PushdownGenerator::EmptyVector", errstr.str(), 1001);
2248  }
2249  FD_DG("PushdownGenerator(" << this << ")::EmptyVectorPopPush(rVector): ok");
2250 }
2251 
2252 
2253 //SetMerge(stateName,rMerge)
2254 TEMP void THIS::SetMerge(const std::string& stateName, MergeAbstract& rMerge){
2255  Idx index=BASE::StateIndex(stateName);
2256  BASE::pStates->Attributep(index)->SetMerge(rMerge);
2257 }
2258 
2259 //SetMerge(index,rMerge)
2260 TEMP void THIS::SetMerge(Idx index, MergeAbstract& rMerge){
2261  BASE::pStates->Attributep(index)->SetMerge(rMerge);
2262 }
2263 
2264 //Merge(index)
2265 TEMP const MergeAbstract* THIS::Merge(Idx index) const{
2266  return BASE::pStates->Attributep(index)->Merge();
2267 }
2268 
2269 //SetDfaState(stateName, dpaIndex)
2270 TEMP void THIS::SetDfaState(const std::string& stateName, Idx dfaIndex){
2271  Idx index=BASE::StateIndex(stateName);
2272  BASE::pStates->Attributep(index)->DfaState(dfaIndex);
2273 }
2274 
2275 //SetDfaState(index, dpaIndex)
2276 TEMP void THIS::SetDfaState(Idx index, Idx dfaIndex){
2277  BASE::pStates->Attributep(index)->DfaState(dfaIndex);
2278 }
2279 
2280 //DfaState(index)
2281 TEMP Idx THIS::DfaState(Idx index) const{
2282  return BASE::pStates->Attributep(index)->DfaState();
2283 }
2284 
2285 // Valid() TODO checks?
2286 TEMP bool THIS::Valid(void) {
2287  FD_DV("PushdownGenerator(" << this << ")::Valid()");
2288  //call base
2289  if(!BASE::Valid()) return false;
2290  // check my names
2291 
2292  // check my clockset
2293 
2294  // check all clocksymboltables
2295 
2296  return true;
2297 }
2298 
2299 
2300 //DotWrite(rFileName, printInfo, lr)
2301 TEMP void THIS::DotWrite(const std::string& rFileName, bool printInfo, bool lr) const {
2302  FD_DG("TpdGenerator(" << this << ")::DotWrite(" << rFileName << ","<< printInfo << "," << lr << ")");
2303 
2304  BASE::SetMinStateIndexMap();
2305  StateSet::Iterator sit;
2306  EventSet::Iterator eit;
2307  StackSymbolSet stacksymbols = StackSymbols();
2308  StackSymbolSet::Iterator ssit;
2309  TransSet::Iterator tit;
2310  PopPushSet::iterator ppit;
2311  std::vector<Idx>::iterator pit;
2312 
2313  try {
2314  std::ofstream stream;
2315  stream.exceptions(std::ios::badbit|std::ios::failbit);
2316  stream.open(rFileName.c_str());
2317  stream << "// dot output generated by libFAUDES TpdGenerator" << std::endl;
2318  stream << "digraph \"" << BASE::Name() << "\" {";
2319  stream << std::endl;
2320 
2321  if(lr) stream << " rankdir=LR" << std::endl;
2322 
2323 
2324  std::string initState = "_", stackbottom = "_";
2325  if(BASE::ExistsState(BASE::InitState()))
2326  initState = StateStr(BASE::InitState());
2327  if(ExistsStackSymbol(StackBottom()))
2328  stackbottom = StackSymbolStr(StackBottom());
2329 
2330  if(printInfo){
2331  //"M = (Q, Sigma, Gamma, initState, stackBottom, Qm, delta)
2332  //Sigma = Sigma_c U Sigma_uc
2333  //Sigma_c = {...}
2334  //Sigma_uc = {...}
2335  //Gamma = {...}
2336  stream << " \"\" [shape = none " << std::endl;
2337  stream << " label = < " << std::endl;
2338 
2339  //"M = (Q, Sigma, Gamma, initState, stackBottom, Qm, delta)
2340  stream << " M=(Q, &Sigma; , &Gamma; , "<< initState <<" , "<< stackbottom <<", &delta;, Qm) <br align=\"LEFT\"/>" << std::endl;
2341  //Sigma = Sigma_c U Sigma_uc
2342  stream << " &Sigma; = &Sigma;c &cup; &Sigma;uc <br align=\"LEFT\"/>" << std::endl;
2343  std::stringstream ConEv,UnConEv;
2344  for(eit = BASE::AlphabetBegin(); eit != BASE::AlphabetEnd(); ++eit)
2345  if(BASE::Controllable(*eit)){
2346  if(!IsEventLambda(*eit))
2347  ConEv << " "<< EventStr(*eit) << ",";
2348  //else
2349  // ConEv << " "<< "&lambda;" << ",";
2350  }else{
2351  if(!IsEventLambda(*eit))
2352  UnConEv << " "<< EventStr(*eit) << ",";
2353  }
2354  //Sigma_c
2355  std::string evstr = ConEv.str();
2356  if(!evstr.empty()) evstr.resize(evstr.size()-1);
2357  stream << " &Sigma;c = {"<< evstr <<" } <br align=\"LEFT\"/>" << std::endl;
2358  //Sigma_uc
2359  evstr = UnConEv.str();
2360  if(!evstr.empty()) evstr.resize(evstr.size()-1);
2361  stream << " &Sigma;uc = {"<< evstr <<" } <br align=\"LEFT\"/>" << std::endl;
2362  //Gamma = {...}
2363  stream << " &Gamma; = { ";
2364  int countSymbols = 0;
2365  for(ssit = StackSymbolsBegin(); ssit != StackSymbolsEnd(); ++ssit){
2366  if(!IsStackSymbolLambda(*ssit)){
2367  if(countSymbols % 10 == 9){
2368  stream << "<br align=\"LEFT\"/>" << std::endl;
2369  stream << " ";
2370  }
2371  if(countSymbols != 0)
2372  stream << ", ";
2373  stream << StackSymbolStr(*ssit);
2374  countSymbols++;
2375  }
2376  }
2377  stream << " } <br align=\"LEFT\"/>" << std::endl;
2378  stream << " >];" << std::endl;
2379  stream << std::endl;
2380  }
2381  stream << " node [shape=circle];" << std::endl;
2382  stream << std::endl;
2383 
2384  //initial states
2385  stream << " // initial states" << std::endl;
2386  int i = 1;
2387  for (sit = BASE::InitStatesBegin(); sit != BASE::InitStatesEnd(); ++sit) {
2388  stream << " dot_dummyinit_" << i << " [shape=none, label=\"\", width=\"0.0\", height=\"0.0\" ];" << std::endl;
2389  stream << " dot_dummyinit_" << i << " -> \"" << StateStr(*sit) << "\";" << std::endl;
2390  i++;
2391  }
2392  stream << std::endl;
2393 
2394  //stackbottom
2395  stream << " // stackbottom" << std::endl;
2396  if(stackbottom != "")
2397  stream << " \"" << stackbottom << "\" [style=\"invis\", attr=\"stackbottom\"];" <<std::endl;
2398 
2399  stream << std::endl;
2400 
2401  //marked states
2402  stream << " // mstates" << std::endl;
2403  for (sit = BASE::MarkedStatesBegin(); sit != BASE::MarkedStatesEnd(); ++sit)
2404  stream << " \"" << StateStr(*sit) << "\" [shape=doublecircle];" << std::endl;
2405 
2406  stream << std::endl;
2407 
2408  //rest of stateset
2409  stream << " // rest of stateset" << std::endl;
2410  for (sit = BASE::StatesBegin(); sit != BASE::StatesEnd(); ++sit) {
2411  if (! (BASE::ExistsInitState(*sit) || BASE::ExistsMarkedState(*sit)) )
2412  stream << " \"" << StateStr(*sit) << "\";" << std::endl;
2413  }
2414  stream << std::endl;
2415 
2416  //events
2417  stream << " // events" << std::endl;
2418  for(eit = BASE::Alphabet().Begin(); eit != BASE::Alphabet().End(); ++eit) {
2419  if(!THIS::IsEventLambda(*eit)){
2420  //"e" [style="invis", attr="cOfA"];
2421  stream << " \"" <<EventStr(*eit) <<"\" [style=\"invis\", attr=\"";
2422  stream << (BASE::Controllable(*eit)? "C" : "c");
2423  stream << (BASE::Observable(*eit)? "O" : "o");
2424  stream << (BASE::Forcible(*eit)? "F" : "f");
2425  stream << (BASE::Highlevel(*eit)? "A" : "a");
2426  stream << "\"];" << std::endl;
2427  }
2428  }
2429  stream << std::endl;
2430 
2431  //transition
2432  stream << " // transition relation" << std::endl;
2433  for(tit = BASE::TransRelBegin(); tit != BASE::TransRelEnd(); ++tit) {
2434  std::string eventname;
2435  if(BASE::EventName(tit->Ev) == FAUDES_PD_LAMBDA)
2436  eventname = "&lambda;";
2437  else
2438  eventname = EventStr(tit->Ev);
2439 
2440  if(PopPush(*tit).empty()){
2441  stream << " \"" << StateStr(tit->X1) << "\" -> \"" << StateStr(tit->X2)
2442  << "\" [label=\"" << eventname << " \"];" << std::endl;
2443  }else
2444  for (ppit = PopPushBegin(*tit); ppit != PopPushEnd(*tit); ++ppit) {
2445  std::vector<Idx> vPop = (*ppit).first;
2446  std::vector<Idx> vPush = (*ppit).second;
2447 
2448  // "x1" -> "x2" [label="ev,[pop],[push]"]
2449  stream << " \"" << StateStr(tit->X1) << "\" -> \"" << StateStr(tit->X2)
2450  << "\" [label=\"" << eventname << ",";
2451 
2452  //[pop]
2453  stream << "[";
2454  for (pit = vPop.begin(); pit != vPop.end(); ++pit) {
2455  if(!IsStackSymbolLambda(*pit))
2456  stream << StackSymbolName(*pit); //stackSymbol;
2457  else
2458  stream << "&lambda;";
2459 
2460  if(pit+1 != vPop.end()) stream << ",";
2461  }
2462  stream << "]";
2463 
2464  //[push]
2465  stream << "[";
2466  for (pit = vPush.begin(); pit != vPush.end(); ++pit) {
2467  if(!IsStackSymbolLambda(*pit))
2468  stream << StackSymbolName(*pit); //stackSymbol;
2469  else
2470  stream << "&lambda;";
2471 
2472  if(pit+1 != vPush.end()) stream << ",";
2473  }
2474  stream << "]\"";
2475 
2476  // if uncontrollable event transition
2477  // "x1" -> "x2" [label="ev,[pop],[push]" style ="dashed"]
2478  if(!BASE::Controllable(tit->Ev))
2479  stream << " style=\"dashed\"";
2480 
2481  stream << " ];" << std::endl;
2482  }
2483  }
2484  stream << "}" << std::endl;
2485  stream.close();
2486  }
2487  catch (std::ios::failure&) {
2488  throw Exception("vGenerator::DotWrite",
2489  "Exception opening/writing dotfile \""+rFileName+"\"", 2);
2490  }
2491 }
2492 
2493 //DotWrite(rFileName)
2494 TEMP void THIS::DotWrite(const std::string& rFileName) const {
2495  FD_DG("TpdGenerator(" << this << ")::DotWrite(" << rFileName << ")");
2496  DotWrite(rFileName,true,true);
2497 }
2498 
2499 //CreatPdFromDot(rFileName) in pd_parseDot_pd.h
2500 TEMP void CreatPdFromDot(const std::string& rFileName,THIS& pd);
2501 
2502 //DotRead(rFileName)
2503 TEMP void THIS::DotRead(const std::string& rFileName) {
2504  FD_DG("TpdGenerator(" << this << ")::DotRead(" << rFileName << ")");
2505  this->Clear();
2506  try{
2507  CreatPdFromDot(rFileName,*this);
2508  }catch(...){
2509  std::stringstream errstr;
2510  errstr << "Unable to parse "<< rFileName << std::endl;
2511  throw Exception("TpdGenerator::DotRead", errstr.str(), 200);
2512  }
2513 }
2514 
2515 
2516 // clean up defs
2517 #undef THIS
2518 #undef BASE
2519 #undef TEMP
2520 
2521 
2522 } // namespace faudes
2523 
2524 //include "pd_dotparser.h" here because of dependencies to TpdGenerator class
2525 #include "pd_dotparser.h"
2526 
2527 #endif
2528 

libFAUDES 2.26g --- 2015.08.17 --- c++ api documentaion by doxygen