cfl_agenerator.h
Go to the documentation of this file.
1 /** @file cfl_agenerator.h Attributed generator class TaGenerator */
2 
3 /* FAU Discrete Event Systems Library (libfaudes)
4 
5 Copyright (C) 2006 Bernd Opitz
6 Copyright (C) 2007 Thomas Moor
7 Exclusive copyright is granted to Klaus Schmidt
8 
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13 
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNES FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18 
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 
24 #ifndef FAUDES_AGENERATOR_H
25 #define FAUDES_AGENERATOR_H
26 
27 #include "cfl_definitions.h"
28 #include "cfl_exception.h"
29 #include "cfl_symboltable.h"
30 #include "cfl_indexset.h"
31 #include "cfl_nameset.h"
32 #include "cfl_transset.h"
33 #include "cfl_token.h"
34 #include "cfl_tokenreader.h"
35 #include "cfl_tokenwriter.h"
36 #include "cfl_generator.h"
37 #include <map>
38 #include <set>
39 #include <sstream>
40 #include <cstdlib>
41 #include <assert.h>
42 
43 namespace faudes {
44 
45 /**
46  * Generator with specified attribute types.
47  *
48  * @section Overview
49  *
50  * The TaGenerator takes four template parameters to specify attribute classes for
51  * the global attribute and state-, event- and transition-attributes.
52  *
53  * In the context of a TaGenerator, attributes still have only minimal sematics: they can be
54  * accessed in a per event, state and transition manner and they can have default or non-default value.
55  * The minimum interface that an attribute template parameter must provide, is given in
56  * faudes::AttributeVoid. Derived attribute classes are meant to provide addtional semantics, eg
57  * faudes::AttributeFlags for boolean flags and faudes::AttributeCFlags for controllability properties.
58  * The TaGenerator transparently supports extended attribute semantics, buit does not provide
59  * taylored access functions. This is done in TaGenerator
60  * derivates eg TcGenerator.
61  *
62  * Technical detail: Attributes data types must be derived from AttributeVoid, which in turn is derived from
63  * the general purpose base faudes::Type. For your derived attribute class to be fully functional,
64  * you must reimplement the faudes::Type::New().
65  *
66  * @ingroup GeneratorClasses
67  */
68 
69 template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
70 class TaGenerator : public vGenerator {
71  public:
72 
73  /** Convenience typdef for member transiton set */
75 
76  /*****************************************
77  *****************************************
78  *****************************************
79  *****************************************/
80 
81  /** @name Constructors & Destructor */
82  /** @{ doxygen group */
83 
84  /**
85  * Construct an emtpy Generator
86  */
87  TaGenerator(void);
88 
89  /**
90  * Copy-constructor (from TaGenerator, incl attributes)
91  *
92  * @param rOtherGen
93  */
94  TaGenerator(const TaGenerator& rOtherGen);
95 
96  /**
97  * Copy-constructor (from vGenerator, set attributes to default)
98  *
99  * @param rOtherGen
100  */
101  TaGenerator(const vGenerator& rOtherGen);
102 
103  /**
104  * Construct from file. This constructor
105  * effectively uses the Read(TokenReader&) function to read.
106  *
107  * @param rFileName
108  * Name of file
109  *
110  * @exception Exception
111  * - IO errors (id 1)
112  * - Token mismatch (id 50, 51, 52, 80, 85)
113  */
114  TaGenerator(const std::string& rFileName);
115 
116  /**
117  * Construct on heap.
118  * Technically not a constructor, this function creates a TaGenerator with the
119  * same event symboltable and the same attribute types. It is the callers reponsebilty to
120  * delete the object when no longer needed.
121  *
122  * @return
123  * new Generator
124  */
125  virtual TaGenerator* New(void) const;
126 
127  /**
128  * Construct copy on heap.
129  * Technically not a constructor, this function creates a TaGenerator with the
130  * same event symboltable and the same attribute types. It is the callers reponsebilty to
131  * delete the object when no longer needed.
132  *
133  * @return
134  * new Generator
135  */
136  virtual TaGenerator* Copy(void) const;
137 
138  /**
139  * Construct on stack.
140  * Technically not a constructor, this function creates a TaGenerator with the
141  * same event symboltable and the same attribute type.
142  *
143  * @return
144  * new Generator
145  */
146  virtual TaGenerator NewAGen(void) const;
147 
148  /**
149  * Type test.
150  * Uses C++ dynamic cast to test whether the specified object
151  * casts to a Generator.
152  *
153  * @return
154  * TcGenerator reference if dynamic cast succeeds, else NULL
155  */
156  virtual const Type* Cast(const Type* pOther) const;
157 
158 
159  /**
160  * Destructor
161  */
162  virtual ~TaGenerator(void);
163 
164  /** @} doxygen group */
165 
166  /*****************************************
167  *****************************************
168  *****************************************
169  *****************************************/
170 
171  /** @name Copy and Assignment */
172  /** @{ doxygen group */
173 
174 
175  /**
176  * Copy from other TaGenerator (incl attributes)
177  *
178  * @param rGen
179  * Source for copy operation.
180  */
181  virtual TaGenerator& Assign(const TaGenerator& rGen);
182 
183  /**
184  * Copy from other Generator (try to maintain attributes)
185  *
186  * @param rGen
187  * Source for copy operation.
188  */
189  virtual TaGenerator& Assign(const vGenerator& rGen);
190 
191 
192  /**
193  * Copy from other faudes Type
194  *
195  * @param rSrc
196  * Source for copy operation.
197  */
198  virtual TaGenerator& Assign(const Type& rSrc);
199 
200  /**
201  * Destructive copy to other TaGenerator
202  * Copy method with increased performance at the cost of invalidating
203  * the source data. This version will copy attributes 1:1.
204  *
205  *
206  * @param rGen
207  * Destination for copy operation.
208  */
209  virtual void Move(TaGenerator& rGen);
210 
211  /**
212  * Destructive copy to other Generator.
213  * Copy method with increased performance at the cost of invalidating
214  * the source data. Convert attributes if possible.
215  *
216  *
217  * @param rGen
218  * Destination for copy operation.
219  */
220  virtual void Move(Generator& rGen);
221 
222  /**
223  * Assignment operator (uses Copy(TaGenerator&) )
224  *
225  * @param rOtherGen
226  * Other generator
227  */
228  virtual TaGenerator& operator= (const TaGenerator& rOtherGen);
229 
230  /**
231  * Assignment operator (uses Copy(Generator&) )
232  *
233  * @param rOtherGen
234  * Other generator
235  */
236  virtual TaGenerator& operator= (const vGenerator& rOtherGen);
237 
238 
239  /** @} doxygen group */
240 
241  /*****************************************
242  *****************************************
243  *****************************************
244  *****************************************/
245 
246  /** @name Basic Maintenance */
247  /** @{ doxygen group */
248 
249  /**
250  * Check if generator is valid
251  *
252  * @return
253  * Success
254  */
255  bool Valid(void);
256 
257 
258  /**
259  * Clear generator data.
260  * Clears state set, alphabet and transitionrealtion. Behavioural flags
261  * eg StateNamesEnabled are maintained.
262  */
263  virtual void Clear(void);
264 
265 
266 
267  /** @} doxygen group */
268 
269 
270 
271  /*****************************************
272  *****************************************
273  *****************************************
274  *****************************************/
275 
276  /** @name Read Access to Core Members */
277  /** @{ doxygen group */
278 
279  /**
280  * Return const reference to alphabet
281  *
282  * @return EventSet
283  * Reference to mpAlphabet
284  */
285  const TaEventSet<EventAttr>& Alphabet(void) const;
286 
287  /**
288  * Return reference to state set
289  *
290  * @return
291  * StateSet reference incl actual attribute type
292  */
293  const TaStateSet<StateAttr>& States(void) const;
294 
295  /**
296  * Return reference to transition relation
297  *
298  * @return TransRel
299  */
300  const ATransSet& TransRel(void) const;
301 
302  /**
303  * Get copy of trantision relation sorted by other compare
304  * operator, e.g. "x2,ev,x1"
305  *
306  * @param res
307  * resulting transition relation
308  */
309  void TransRel(TransSetX1EvX2& res) const;
310  void TransRel(TransSetEvX1X2& res) const;
311  void TransRel(TransSetEvX2X1& res) const;
312  void TransRel(TransSetX2EvX1& res) const;
313  void TransRel(TransSetX2X1Ev& res) const;
314  void TransRel(TransSetX1X2Ev& res) const;
315 
316  /** @} doxygen group */
317 
318 
319 
320  /*****************************************
321  *****************************************
322  *****************************************
323  *****************************************/
324 
325  /** @name Write Access to Core Members */
326  /** @{ doxygen group */
327 
328 
329  /**
330  * Add an existing event to alphabet by index. It is an error to insert
331  * an event index that is not known to the mpEventSymbolTable.
332  *
333  * @param index
334  * Event index
335  * @return
336  * True, if event was new to alphabet
337  */
338  bool InsEvent(Idx index);
339 
340  /**
341  * Add named event to generator. An entry in the mpEventSymbolTable will
342  * be made if event name is not known so far.
343  *
344  * @param rName
345  * Name of the event to add
346  *
347  * @return
348  * New unique index
349  */
350  Idx InsEvent(const std::string& rName);
351 
352  /**
353  * Add an existing event to alphabet by index, incl. attribute
354  * If the index allready exists, the attribute is overwritten by rAttr.
355  *
356  * @param rAttr
357  * Attribute of event
358  * @param index
359  * Event index
360  * @return
361  * True, if event was new to alphabet
362  */
363  bool InsEvent(Idx index, const EventAttr& rAttr);
364 
365  /**
366  * Add named event with attribute to generator. An entry in the
367  * mpEventSymbolTable will be made if event is not kown so far.
368  * If the event allready exits in the generator, the attribute will be
369  * overwritten by rAttr.
370  *
371  * @param rName
372  * Name of the event to add
373  * @param rAttr
374  * Attribute of event
375  *
376  * @return
377  * New unique index
378  */
379  Idx InsEvent(const std::string& rName, const EventAttr& rAttr);
380 
381  /**
382  * Set mpAlphabet without consistency check.
383  * Attributes will be casted if possible or silently ignored.
384  *
385  * @param rNewalphabet
386  * EventSet with new alphabet
387  */
388  void InjectAlphabet(const EventSet& rNewalphabet);
389 
390  /**
391  * Set mpAlphabet without consistency check.
392  *
393  * @param rNewalphabet
394  * EventSet with new alphabet
395  */
396  void InjectAlphabet(const TaEventSet<EventAttr>& rNewalphabet);
397 
398  /**
399  * Add new anonymous state to generator
400  *
401  * @return
402  * Index of new unique state
403  */
404  Idx InsState(void);
405 
406  /**
407  * Add new anonymous state with attribute to generator
408  *
409  * @param attr
410  * attribute of new state
411  *
412  * @return
413  * Index of new unique state
414  */
415  Idx InsState(const StateAttr& attr);
416 
417  /**
418  * Add (perhaps new) state to generator
419  *
420  * @return
421  * true to indicate that state was new to generator
422  */
423  bool InsState(Idx index);
424 
425  /**
426  * Add new named state to generator.
427  *
428  * @param rName
429  * Name of the state to add
430  *
431  * @return
432  * Index of new unique state
433  *
434  * @exception Exception
435  * Name already exists (id 44)
436  */
437  Idx InsState(const std::string& rName);
438 
439  /**
440  * Add new named state with attribute to generator.
441  *
442  * @param rName
443  * Name of the state to add
444  * @param attr
445  * attribute of new state
446  *
447  * @return
448  * Index of new unique state
449  * @exception Exception
450  * Name already exists (id 44)
451  */
452  Idx InsState(const std::string& rName, const StateAttr& attr);
453 
454  /**
455  * Add (perhaps new) state with attribute to generator.
456  *
457  * @param index
458  * Index of state to add
459  * @param attr
460  * Attribute of new state
461  *
462  * @return
463  * True, if event was new to alphabet
464  *
465  */
466  bool InsState(Idx index, const StateAttr& attr);
467 
468  /**
469  * Inject a complete state set without consistency checks.
470  * Attributes will be casted if possible or silently ignored.
471  *
472  * @param rNewStates
473  * StateSet
474  */
475  void InjectStates(const StateSet& rNewStates);
476 
477 
478  /**
479  * Inject a complete state set without consistency checks.
480  *
481  * @param rNewStates
482  * StateSet
483  */
484  void InjectStates(const TaStateSet<StateAttr>& rNewStates);
485 
486 
487  /**
488  * Add a transition to generator by indices. States and event
489  * must already exist!
490  *
491  * Define FAUDES_CHECKED for consistency checks.
492  *
493  * @param x1
494  * Predecessor state index
495  * @param ev
496  * Event index
497  * @param x2
498  * Successor state index
499  *
500  * @return
501  * True, if the transition was new the generator
502  *
503  * @exception Exception
504  * - state or event not in generator (id 95)
505  */
506  bool SetTransition(Idx x1, Idx ev, Idx x2);
507 
508  /**
509  * Add a transition to generator by names. Statename and eventname
510  * must already exist!
511  *
512  * @param rX1
513  * Predecessor state name
514  * @param rEv
515  * Event name
516  * @param rX2
517  * Successor state name
518  *
519  * @return
520  * True, if the transition was new the generator
521  *
522  * @exception Exception
523  * - state or event not in generator (id 95)
524  * - state name not known (id 90)
525  * - event name not known (id 66)
526  */
527  bool SetTransition(const std::string& rX1, const std::string& rEv,
528  const std::string& rX2);
529 
530  /**
531  * Add a transition to generator. States and event
532  * must already exist!
533  *
534  *
535  * @param rTransition
536  * Transition
537  *
538  * @return
539  * True, if the transition was new the generator
540  * @exception Exception
541  * - state or event not in generator (id 95)
542  */
543  bool SetTransition(const Transition& rTransition);
544 
545  /**
546  * Add a transition with attribute to generator. States and event
547  * must already exist!
548  *
549  *
550  * @param rTransition
551  * transition
552  * @param rAttr
553  * attribute
554  * @return
555  * True, if the transition was new the generator
556  * @exception Exception
557  * - state or event not in generator (id 95)
558  *
559  */
560  bool SetTransition(const Transition& rTransition, const TransAttr& rAttr);
561 
562  /**
563  * Set transition relation without consistency check.
564  * Attributes will be casted if possible or silently ignored.
565  *
566  * @param rNewtransrel
567  * TransRel to insert
568  */
569  void InjectTransRel(const TransSet& rNewtransrel);
570 
571  /**
572  * Set transition relation without consistency check.
573  *
574  * @param rNewtransrel
575  * TransRel to insert
576  */
577  void InjectTransRel(const ATransSet& rNewtransrel);
578 
579  /** @} doxygen group */
580 
581 
582 
583  /*****************************************
584  *****************************************
585  *****************************************
586  *****************************************/
587 
588  /** @name Attributes */
589  /** @{ doxygen group */
590 
591 
592  /**
593  * Set attribute for existing event
594  *
595  * @param index
596  * Event index
597  * @param rAttr
598  * New attribute
599  *
600  * @exception Exception
601  * Index not found in alphabet (id 60)
602  */
603  void EventAttribute(Idx index, const EventAttr& rAttr);
604 
605  /**
606  * Set attribute for existing event.
607  * This version uses a dynamic cast
608  * to test the actual type of the provided attribute. An exception is
609  * thrown for an invalid attribute type.
610  *
611  * @param index
612  * Event index
613  * @param rAttr
614  * New attribute
615  *
616  * @exception Exception
617  * - Index not found in alphabet (id 60)
618  * - Cannot cast attribute (id 63)
619  */
620  void EventAttribute(Idx index, const Type& rAttr);
621 
622  /**
623  * Event attribute lookup
624  *
625  * @param index
626  *
627  * @return
628  * reference to attribute
629  */
630  const EventAttr& EventAttribute(Idx index) const;
631 
632  /**
633  * Event attribute lookup
634  *
635  * @param rName
636  *
637  * @return
638  * reference to attribute
639  */
640  const EventAttr& EventAttribute(const std::string& rName) const;
641 
642  /**
643  * Event attribute pointer (to access Attribute methods)
644  * note: may insert explicit default attribute
645  *
646  * @param index
647  *
648  * @return
649  * pointer to attribute
650  */
651  EventAttr* EventAttributep(Idx index);
652 
653  /**
654  * Event attribute pointer (to access Attribute methods)
655  * note: may insert explicit default attribute
656  *
657  * @param rName
658  *
659  * @return
660  * pointer to attribute
661  */
662  EventAttr* EventAttributep(const std::string& rName);
663 
664 
665  /**
666  * Set attribute for existing state
667  *
668  * @param index
669  * Index
670  * @param rAttr
671  * attriute
672  *
673  * @exception Exception
674  * Name already associated with another index (id 44)
675  */
676  void StateAttribute(Idx index, const StateAttr& rAttr);
677 
678  /**
679  * Set attribute for existing state.
680  * This version uses a dynamic cast
681  * to test the actual type of the provided attribute. An exception is
682  * thrown for an invalid attribute type.
683  *
684  * @param index
685  * State index
686  * @param rAttr
687  * New attribute
688  *
689  * @exception Exception
690  * - Index not found in Stateset (id 60)
691  * - Cannot cast attribute (id 63)
692  */
693  void StateAttribute(Idx index, const Type& rAttr);
694 
695  /**
696  * State attribute lookup
697  *
698  * @param index
699  *
700  * @return ref to attribute of state
701  */
702  const StateAttr& StateAttribute(Idx index) const;
703 
704  /**
705  * State attribute pointer (to access Attribute methods)
706  * note: may insert explicit default attribute
707  *
708  * @param index
709  *
710  * @return pointer to attribute of state
711  */
712  StateAttr* StateAttributep(Idx index);
713 
714  /**
715  * Set attribute for existing transition
716  *
717  * @param rTrans
718  * transition
719  * @param rAttr
720  * New attribute
721  *
722  */
723  void TransAttribute(const Transition& rTrans, const TransAttr& rAttr);
724 
725  /**
726  * Set attribute for existing transition.
727  * This version uses a dynamic cast
728  * to test the actual type of the provided attribute. An exception is
729  * thrown for an invalid attribute type.
730  *
731  * @param rTrans
732  * transition
733  * @param rAttr
734  * New attribute
735  *
736  * @exception Exception
737  * - Transition not found in transition relation(id 60)
738  * - Cannot cast attribute (id 63)
739  */
740  void TransAttribute(const Transition& rTrans, const Type& rAttr);
741 
742 
743  /**
744  * Get attribute for existing transition
745  *
746  * @return
747  * attribute
748  *
749  */
750  const TransAttr& TransAttribute(const Transition& rTrans) const;
751 
752  /**
753  * Get attribute pointer for existing transition
754  * note: may insert explicit default attribute
755  *
756  * @return
757  * attribute pointer
758  *
759  */
760  TransAttr* TransAttributep(const Transition& rTrans);
761 
762  /**
763  * Set global attribute
764  *
765  * @param rAttr
766  * attribute
767  */
768  void GlobalAttribute(const GlobalAttr& rAttr) {*pGlobalAttribute=rAttr;};
769 
770  /**
771  * Get global attribute ref
772  */
773  const GlobalAttr& GlobalAttribute(void) const {return *pGlobalAttribute;};
774 
775 
776  /**
777  * Get global attribute pointer
778  */
779  GlobalAttr* GlobalAttributep(void) {return pGlobalAttribute;};
780 
781 
782  /** @} doxygen group */
783 
784 
785 
786 
787  protected:
788 
789  /** Alphabet, pointer with actual attribute type */
791 
792  /** State set, pointer with actual attribute type */
794 
795  /** Transition relation, pointer with actual attribute type */
797 
798  /** Global attribute, pointer with actual attribute type */
799  GlobalAttr* pGlobalAttribute;
800 
801  /** Static default alphabet prototype (incl. attribute type) */
802  static const TaNameSet<EventAttr>& AlphabetTaGen(void);
803 
804  /** Static default state set prototype (incl. attribute type) */
805  static const TaIndexSet<StateAttr>& StatesTaGen(void);
806 
807  /** Static default transition relation prototype (incl. attribute type) */
808  static const ATransSet& TransRelTaGen(void);
809 
810  /** Static default global attribute prototype (configures global attribute type) */
811  static const GlobalAttr& GlobalTaGen(void);
812 
813  /** Allocate my heap members (attribute dependent types) */
814  virtual void NewCore(void);
815 
816  /** Update my secondary pointers for new core */
817  virtual void UpdateCore(void);
818 
819 
820 };
821 
822 
823 
824 /* convenience access to relevant scopes */
825 #define THIS TaGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
826 #define TEMP template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
827 #define BASE vGenerator
828 
829 // static default prototypes (construct on first use design pattern)
830 TEMP const TaNameSet<EventAttr>& THIS::AlphabetTaGen(void) {
831  static TaNameSet<EventAttr>* pstatic = new TaNameSet<EventAttr>();
832  return *pstatic;
833 }
834 TEMP const TaIndexSet<StateAttr>& THIS::StatesTaGen(void) {
835  static TaIndexSet<StateAttr>* pstatic = new TaIndexSet<StateAttr>();
836  return *pstatic;
837 }
838 TEMP const TaTransSet<TransAttr>& THIS::TransRelTaGen(void) {
839  static TaTransSet<TransAttr>* pstatic = new TaTransSet<TransAttr>();
840  return *pstatic;
841 }
842 TEMP const GlobalAttr& THIS::GlobalTaGen(void) {
843  static GlobalAttr* pstatic = new GlobalAttr();
844  return *pstatic;
845 }
846 
847 
848 // TaGenerator::Generator(void)
849 TEMP THIS::TaGenerator(void) :
850  // init base
851  vGenerator()
852 {
853  FD_DG("TaGenerator(" << this << ")::TaGenerator()");
854  // re-allocate core members with nontrivial attribute types
856  NewCore();
857  FD_DG("TaGenerator(" << this << ")::TaGenerator(): done");
858 }
859 
860 // TaGenerator::Generator(rOtherGen)
861 TEMP THIS::TaGenerator(const TaGenerator& rOtherGen) :
862  // init base
863  vGenerator()
864 {
865  FD_DG("TaGenerator(" << this << ")::TaGenerator(" << &rOtherGen << ")");
866  // re-allocate core members with nontrivial attribute types
868  NewCore();
869  // have a 1:1 copy (incl sym tables)
870  Assign(rOtherGen);
871 }
872 
873 
874 // TaGenerator::Generator(rOtherGen)
875 TEMP THIS::TaGenerator(const vGenerator& rOtherGen) :
876  // init base
877  vGenerator()
878 {
879  FD_DG("TaGenerator(" << this << ")::TaGenerator([v]" << &rOtherGen << ")");
880  // re-allocate core members with nontrivial attribute types
882  NewCore();
883  // have a 1:1 copy (incl sym tables)
884  Assign(rOtherGen);
885 }
886 
887 // TaGenerator::Generator(rFileName)
888 TEMP THIS::TaGenerator(const std::string& rFileName) :
889  // init base
890  vGenerator()
891 {
892  FD_DG("TaGenerator(" << this << ")::TaGenerator(" << rFileName << ")");
893  // re-allocate core members with nontrivial attribute types
895  NewCore();
896  // set some defaults
897  mStateNamesEnabled=true;
898  // do read
899  Read(rFileName);
900  // get original statenames default
902 }
903 
904 // allocate core on heap
905 TEMP void THIS::NewCore(void) {
906  FD_DG("TaGenerator(" << this << ")::NewCore()");
907  // call base, incl virtual call back of UpdateCore
908  BASE::NewCore();
909 }
910 
911 // indicate new core
912 TEMP void THIS::UpdateCore(void) {
913  // let base do an update (fixes names)
914  BASE::UpdateCore();
915  // have pointer with my attribute
916  pGlobalAttribute = dynamic_cast< GlobalAttr* >(mpGlobalAttribute);
917  pAlphabet = dynamic_cast< TaNameSet<EventAttr>* >(mpAlphabet);
918  pStates = dynamic_cast< TaIndexSet<StateAttr>* >(mpStates);
919  pTransRel = dynamic_cast< ATransSet* >(mpTransRel);
920  // check for type mismatche
921  bool tmm=false;
922  if(pGlobalAttribute==0 && mpGlobalAttribute!=0) tmm=true;
923  if(pAlphabet==0 && mpAlphabet!=0) tmm=true;
924  if(pStates==0 && mpStates!=0) tmm=true;
925  if(pTransRel==0 && mpTransRel!=0) tmm=true;
926  if(tmm) {
927  std::stringstream errstr;
928  errstr << "cannot cast attributes for generator " << Name();
929  throw Exception("Generator::UpdateCore", errstr.str(), 63);
930  }
931 }
932 
933 
934 // Copy(gen) from identical type
935 TEMP THIS& THIS::Assign(const TaGenerator& rGen) {
936  FD_DG("TaGenerator(" << this << ")::Assign(" << &rGen << ")");
937  // prepare result (call clear for virtual stuff)
938  Clear();
939  // have same event symboltable
940  EventSymbolTablep(rGen.mpEventSymbolTable);
941  // copy state symboltable
942  StateSymbolTable(rGen.mStateSymbolTable);
943  // set other members
944  Name(rGen.Name());
945  *pGlobalAttribute=*rGen.pGlobalAttribute;
946  *pStates= *rGen.pStates;
947  *pAlphabet = *rGen.pAlphabet;
948  *pTransRel= *rGen.pTransRel;
949  mInitStates = rGen.mInitStates;
950  mMarkedStates = rGen.mMarkedStates;
951  mStateNamesEnabled=rGen.mStateNamesEnabled;
952  mReindexOnWrite=rGen.mReindexOnWrite;
953  // copy add on stuff
954  mMinStateIndexMap=rGen.mMinStateIndexMap;
955 #ifdef FAUDES_DEBUG_CODE
956  if(!Valid()) {
957  FD_DG("TaGenerator()::Assign(): invalid generator");
958  DWrite();
959  abort();
960  }
961 #endif
962  return *this;
963 }
964 
965 // Copy(gen) to other generator type
966 TEMP THIS& THIS::Assign(const vGenerator& rGen) {
967  FD_DG("TaGenerator(" << this << ")::Assign([v]" << &rGen << ")");
968  FD_DG("TaGenerator(" << this << ")::Assign(): src type " << typeid(rGen).name());
969  FD_DG("TaGenerator(" << this << ")::Assign(): dst type " << typeid(*this).name());
970  // call base
971  BASE::Assign(rGen);
972  // report
973 #ifdef FAUDES_DEBUG_GENERATOR
974  // FD_DG("TaGenerator(" << this << ")::Copy([type " << typeid(rGen).name() <<"]" << &rGen << "): report");
975  // Write();
976  // rGen.Write();
977 #endif
978  return *this;
979 }
980 
981 
982 // copy from other Generator (try to convert attributes)
983 TEMP THIS& THIS::Assign(const Type& rSrc) {
984  FD_DG("TaGenerator(" << this << ")::Assign([type] " << &rSrc << ")");
985  // bail out on match
986  if(&rSrc==this) return *this;
987  Clear();
988  const vGenerator* vgen=dynamic_cast<const vGenerator*>(&rSrc);
989  if(vgen) Assign(*vgen);
990  return *this;
991 }
992 
993 
994 // Move(gen) destructive copy
995 TEMP void THIS::Move(TaGenerator& rGen) {
996  FD_DG("TaGenerator(" << this << ")::Move(" << &rGen << ")");
997  // call base
998  BASE::Move(rGen);
999 }
1000 
1001 
1002 // Move(gen) destructive copy
1003 TEMP void THIS::Move(Generator& rGen) {
1004  FD_DG("TaGenerator(" << this << ")::Move([v]" << &rGen << ")");
1005  // call base
1006  BASE::Move(rGen);
1007 }
1008 
1009 // TaGenerator::~Generator
1010 TEMP THIS::~TaGenerator(void) {
1011  FD_DG("TaGenerator(" << this << ")::~TaGenerator()");
1012 }
1013 
1014 // New
1015 TEMP THIS* THIS::New(void) const {
1016  // allocate
1017  THIS* res = new THIS;
1018  // fix base data
1019  res->EventSymbolTablep(BASE::mpEventSymbolTable);
1020  res->mStateNamesEnabled=BASE::mStateNamesEnabled;
1021  res->mReindexOnWrite=BASE::mReindexOnWrite;
1022  return res;
1023 }
1024 
1025 // Copy
1026 TEMP THIS* THIS::Copy(void) const {
1027  // allocate
1028  THIS* res = new THIS(*this);
1029  // done
1030  return res;
1031 }
1032 
1033 // NewAGen()
1034 TEMP THIS THIS::NewAGen(void) const {
1035  THIS res;
1036  // fix base data
1037  res.EventSymbolTablep(BASE::mpEventSymbolTable);
1038  res.mStateNamesEnabled=BASE::mStateNamesEnabled;
1039  res.mReindexOnWrite=BASE::mReindexOnWrite;
1040  return res;
1041 }
1042 
1043 
1044 // CAST
1045 TEMP const Type* THIS::Cast(const Type* pOther) const {
1046  return dynamic_cast< const THIS* > (pOther);
1047 }
1048 
1049 // operator=
1051  FD_DG("TaGenerator(" << this << ")::operator = " << &rOtherGen);
1052  return Assign(rOtherGen);
1053 }
1054 
1055 // operator=
1057  FD_DG("TaGenerator(" << this << ")::operator = [v]" << &rOtherGen);
1058  return Assign(rOtherGen);
1059 }
1060 
1061 // Valid()
1062 TEMP bool THIS::Valid(void) {
1063  FD_DG("TaGenerator(" << this << ")::Valid()");
1064  if(!BASE::Valid()) return false;
1065  // test types
1066  bool tmm=false;
1067  if(typeid(Alphabet().Attribute())!=typeid(const EventAttr&)) tmm=true;
1068  if(typeid(States().Attribute())!=typeid(const StateAttr&)) tmm=true;
1069  if(typeid(TransRel().Attribute())!=typeid(const TransAttr&)) tmm=true;
1070  if(typeid(GlobalAttribute())!=typeid(const GlobalAttr&)) tmm=true;
1071  if(tmm) {
1072  return false;
1073  //std::stringstream errstr;
1074  //errstr << "attribute type mismatch in generator " << Name();
1075  //throw Exception("Generator::Valid", errstr.str(), 63);
1076  }
1077  return true;
1078 }
1079 
1080 // Clear()
1081 TEMP void THIS::Clear(void) {
1082  FD_DG("TaGenerator(" << this << ")::Clear()");
1083  BASE::Clear();
1084 }
1085 
1086 
1087 // InjectAlphabet(newalphabet)
1088 TEMP void THIS::InjectAlphabet(const EventSet& rNewAlphabet) {
1089  FD_DG("TaGenerator::InjectAlphabet() " << rNewAlphabet.ToString());
1090  BASE::InjectAlphabet(rNewAlphabet);
1091 }
1092 
1093 // InjectAlphabet(newalphabet)
1094 TEMP void THIS::InjectAlphabet(const TaEventSet<EventAttr>& rNewAlphabet) {
1095  FD_DG("TaGenerator::InjectAlphabet(TaEventSet<EventAttr>) " << rNewAlphabet.ToString());
1096 #ifdef FAUDES_CHECKED
1097  if(rNewAlphabet.SymbolTablep()!=mpEventSymbolTable) {
1098  std::stringstream errstr;
1099  errstr << "symboltable mismatch aka not implemented" << std::endl;
1100  throw Exception("TaGenerator::InjectAlphabet", errstr.str(), 88);
1101  }
1102 #endif
1103  *pAlphabet=rNewAlphabet;
1104  mpAlphabet->Name("Alphabet");
1105 }
1106 
1107 // InsEvent(index)
1108 TEMP bool THIS::InsEvent(Idx index) {
1109  FD_DG("TaGenerator(" << this << ")::InsEvent(" << index << ")");
1110  return pAlphabet->Insert(index);
1111 }
1112 
1113 // InsEvent(rName)
1114 TEMP Idx THIS::InsEvent(const std::string& rName) {
1115  FD_DG("TaGenerator(" << this << ")::InsEvent(\"" << rName << "\")");
1116  return pAlphabet->Insert(rName);
1117 }
1118 
1119 // InsEvent(index, attr)
1120 TEMP bool THIS::InsEvent(Idx index, const EventAttr& attr) {
1121  FD_DG("TaGenerator(" << this << ")::InsEvent(" << index << " " << attr.ToString() << ")");
1122  return pAlphabet->Insert(index, attr);
1123 }
1124 
1125 // InsEvent(rName)
1126 TEMP Idx THIS::InsEvent(const std::string& rName, const EventAttr& attr) {
1127  FD_DG("TaGenerator(" << this << ")::InsEvent(\"" << rName << attr.ToString() << "\")");
1128  return pAlphabet->Insert(rName, attr);
1129 }
1130 
1131 // InsState()
1132 TEMP Idx THIS::InsState(void) {
1133  FD_DG("TaGenerator(" << this << ")::InsState()");
1134  return mpStates->Insert();
1135 }
1136 
1137 // InsState(attr)
1138 TEMP Idx THIS::InsState(const StateAttr& attr) {
1139  FD_DG("TaGenerator(" << this << ")::InsState(attr)");
1140  return pStates->Insert(attr);
1141 }
1142 
1143 // InsState(index)
1144 TEMP bool THIS::InsState(Idx index) {
1145  FD_DG("TaGenerator(" << this << ")::InsState(" << index << ")");
1146  return mpStates->Insert(index);
1147 }
1148 
1149 // InsState(index, attr)
1150 TEMP bool THIS::InsState(Idx index, const StateAttr& rAttr) {
1151  FD_DG("TaGenerator(" << this << ")::InsState(" << index << ",rAttr)");
1152  return pStates->Insert(index,rAttr);
1153 }
1154 
1155 // InsState(rName)
1156 TEMP Idx THIS::InsState(const std::string& rName) {
1157  FD_DG("TaGenerator(" << this << ")::InsState(\"" << rName << "\")");
1158  Idx index=mpStates->Insert();
1159  StateName(index,rName);
1160  return index;
1161 }
1162 
1163 // InsState(rName, attr)
1164 TEMP Idx THIS::InsState(const std::string& rName, const StateAttr& attr) {
1165  FD_DG("TaGenerator(" << this << ")::InsState(\"" << rName << "\", attr)");
1166  Idx index=mpStates->Insert();
1167  StateName(index,rName);
1168  StateAttribute(index,attr);
1169  return index;
1170 }
1171 
1172 
1173 // InjectStates(rNewStates)
1174 TEMP void THIS::InjectStates(const StateSet& rNewStates) {
1175  FD_DG("TaGenerator(" << this << ")::InjectStates("
1176  << rNewStates.ToString() << ")");
1177  BASE::InjectStates(rNewStates);
1178 }
1179 
1180 // InjectStates(rNewStates)
1181 TEMP void THIS::InjectStates(const TaStateSet<StateAttr>& rNewStates) {
1182  FD_DG("TaGenerator(" << this << ")::InjectStates("
1183  << rNewStates.ToString() << ")");
1184  *pStates=rNewStates;
1185  mpStates->Name("States");
1186  mpStateSymbolTable->RestrictDomain(*mpStates);
1187 }
1188 
1189 
1190 
1191 // InjectTransRel(rNewtransrel)
1192 TEMP void THIS::InjectTransRel(const TransSet& rNewTransRel) {
1193  FD_DG("TaGenerator::InjectTransRel(...)");
1194  *mpTransRel=rNewTransRel;
1195 }
1196 
1197 // InjectTransRel(rNewtransrel)
1198 TEMP void THIS::InjectTransRel(const ATransSet& rNewTransRel) {
1199  FD_DG("TaGenerator::InjectTransRel(...)");
1200  *pTransRel=rNewTransRel;
1201 }
1202 
1203 
1204 // SetTransition(rX1, rEv, rX2)
1205 TEMP bool THIS::SetTransition(const std::string& rX1, const std::string& rEv, const std::string& rX2) {
1206  return BASE::SetTransition(rX1,rEv,rX2);
1207 }
1208 
1209 
1210 // SetTransition(x1, ev, x2)
1211 TEMP bool THIS::SetTransition(Idx x1, Idx ev, Idx x2) {
1212  return SetTransition(Transition(x1,ev,x2));
1213 }
1214 
1215 // SetTransition(rTransition)
1216 TEMP bool THIS::SetTransition(const Transition& rTransition) {
1217  FD_DG("TaGenerator(" << this << ")::SetTransition(" << rTransition.X1 << ","
1218  << rTransition.Ev << "," << rTransition.X2 << ")");
1219 #ifdef FAUDES_CHECKED
1220  if (! mpStates->Exists(rTransition.X1)) {
1221  std::stringstream errstr;
1222  errstr << "TaGenerator::SetTransition: state " << rTransition.X1
1223  << " not in stateset";
1224  throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
1225  }
1226  if (! mpAlphabet->Exists(rTransition.Ev)) {
1227  std::stringstream errstr;
1228  errstr << "TaGenerator::SetTransition: event " << rTransition.Ev
1229  << " not in alphabet ";
1230  throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
1231  }
1232  if (! mpStates->Exists(rTransition.X2)) {
1233  std::stringstream errstr;
1234  errstr << "TaGenerator::SetTransition: state " << rTransition.X2
1235  << " not in stateset";
1236  throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
1237  }
1238 #endif
1239  return mpTransRel->Insert(rTransition);
1240 }
1241 
1242 // SetTransition(rTransition, rAttr)
1243 TEMP bool THIS::SetTransition(const Transition& rTransition, const TransAttr& rAttr) {
1244  FD_DG("TaGenerator(" << this << ")::SetTransition(" << rTransition.X1 << ","
1245  << rTransition.Ev << "," << rTransition.X2 << ", [attr:]" << rAttr.ToString() << ")");
1246 #ifdef FAUDES_CHECKED
1247  if (! mpStates->Exists(rTransition.X1)) {
1248  std::stringstream errstr;
1249  errstr << "TaGenerator::SetTransition: state " << rTransition.X1
1250  << " not in stateset";
1251  throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
1252  }
1253  if (! mpAlphabet->Exists(rTransition.Ev)) {
1254  std::stringstream errstr;
1255  errstr << "TaGenerator::SetTransition: event " << rTransition.Ev
1256  << " not in alphabet ";
1257  throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
1258  }
1259  if (! mpStates->Exists(rTransition.X2)) {
1260  std::stringstream errstr;
1261  errstr << "TaGenerator::SetTransition: state " << rTransition.X2
1262  << " not in stateset";
1263  throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
1264  }
1265 #endif
1266  return pTransRel->Insert(rTransition,rAttr);
1267 }
1268 
1269 // TransAttribute(trans, attr)
1270 TEMP void THIS::TransAttribute(const Transition& rTrans, const TransAttr& rAttr) {
1271  FD_DG("TaGenerator(" << this << ")::TransAttribute("
1272  << TStr(rTrans) << ",\"" << rAttr.ToString() << "\")");
1273  pTransRel->Attribute(rTrans, rAttr);
1274 }
1275 
1276 // TransAttribute(index, attr)
1277 TEMP void THIS::TransAttribute(const Transition& rTrans, const Type& rAttr) {
1278  FD_DG("TaGenerator(" << this << ")::TransAttribute("
1279  << TStr(rTrans) << ",\"" << rAttr.ToString() << "\")");
1280  const TransAttr* attrp = dynamic_cast<const TransAttr*>(&rAttr);
1281  if(!attrp) {
1282  std::stringstream errstr;
1283  errstr << "cannot cast event attribute " << rAttr.ToString() << " for generator " << Name();
1284  throw Exception("TaGenerator::TransAttribute", errstr.str(), 63);
1285  }
1286  mpTransRel->Attribute(rTrans, *attrp);
1287 }
1288 
1289 // TransAttributep(trans)
1290 TEMP TransAttr* THIS::TransAttributep(const Transition& rTrans) {
1291  return pTransRel->Attributep(rTrans);
1292 }
1293 
1294 
1295 // TransAttribute(trans)
1296 TEMP const TransAttr& THIS::TransAttribute(const Transition& rTrans) const {
1297  return pTransRel->Attribute(rTrans);
1298 }
1299 
1300 // EventAttribute(index, attr)
1301 TEMP void THIS::EventAttribute(Idx index, const EventAttr& rAttr) {
1302  FD_DG("TaGenerator(" << this << ")::EventAttribute("
1303  << EStr(index) << ",\"" << rAttr.ToString() << "\")");
1304  pAlphabet->Attribute(index, rAttr);
1305 }
1306 
1307 // EventAttribute(index, attr)
1308 TEMP void THIS::EventAttribute(Idx index, const Type& rAttr) {
1309  FD_DG("TaGenerator(" << this << ")::EventAttribute("
1310  << EStr(index) << ",\"" << rAttr.ToString() << "\")");
1311  const EventAttr* attrp = dynamic_cast<const EventAttr*>(&rAttr);
1312  if(!attrp) {
1313  std::stringstream errstr;
1314  errstr << "cannot cast event attribute " << rAttr.ToString() << " for generator " << Name();
1315  throw Exception("TaGenerator::EventAttribute", errstr.str(), 63);
1316  }
1317  pAlphabet->Attribute(index, *attrp);
1318 }
1319 
1320 // EventAttribute(index)
1321 TEMP const EventAttr& THIS::EventAttribute(Idx index) const {
1322  return pAlphabet->Attribute(index);
1323 }
1324 
1325 // EventAttributep(index)
1326 TEMP EventAttr* THIS::EventAttributep(Idx index) {
1327  return pAlphabet->Attributep(index);
1328 }
1329 
1330 // EventAttribute(rName)
1331 TEMP const EventAttr& THIS::EventAttribute(const std::string& rName) const {
1332  return EventAttribute(EventIndex(rName));
1333 }
1334 
1335 // EventAttributep(rName)
1336 TEMP EventAttr* THIS::EventAttributep(const std::string& rName) {
1337  return EventAttributep(EventIndex(rName));
1338 }
1339 
1340 // StateAttribute(index, attr)
1341 TEMP void THIS::StateAttribute(Idx index, const StateAttr& rAttr) {
1342  FD_DG("TaGenerator(" << this << ")::StateAttribute("
1343  << index << ",\"" << rAttr.ToString() << "\")");
1344  mpStates->Attribute(index, rAttr);
1345 }
1346 
1347 // StateAttribute(index, attr)
1348 TEMP void THIS::StateAttribute(Idx index, const Type& rAttr) {
1349  FD_DG("TaGenerator(" << this << ")::StateAttribute("
1350  << SStr(index) << ",\"" << rAttr.ToString() << "\")");
1351  const StateAttr* attrp = dynamic_cast<const StateAttr*>(&rAttr);
1352  if(!attrp) {
1353  std::stringstream errstr;
1354  errstr << "cannot cast event attribute " << rAttr.ToString() << " for generator " << Name();
1355  throw Exception("TaGenerator::StateAttribute", errstr.str(), 63);
1356  }
1357  mpStates->Attribute(index, *attrp);
1358 }
1359 
1360 
1361 // StateAttribute(index)
1362 TEMP const StateAttr& THIS::StateAttribute(Idx index) const {
1363  return pStates->Attribute(index);
1364 }
1365 
1366 // StateAttributep(index)
1367 TEMP StateAttr* THIS::StateAttributep(Idx index) {
1368  return pStates->Attributep(index);
1369 }
1370 
1371 // Alphabet()
1372 TEMP const TaEventSet<EventAttr>& THIS::Alphabet(void) const {
1373  return *pAlphabet;
1374 }
1375 
1376 // States()
1377 TEMP const TaStateSet<StateAttr>& THIS::States(void) const {
1378  return *pStates;
1379 }
1380 
1381 // TransRel()
1382 TEMP const typename THIS::ATransSet& THIS::TransRel(void) const {
1383  return *pTransRel;
1384 }
1385 
1386 // TransRel(res)
1387 TEMP void THIS::TransRel(TransSetX1EvX2& res) const { mpTransRel->ReSort(res); }
1388 TEMP void THIS::TransRel(TransSetEvX1X2& res) const { mpTransRel->ReSort(res); }
1389 TEMP void THIS::TransRel(TransSetEvX2X1& res) const { mpTransRel->ReSort(res); }
1390 TEMP void THIS::TransRel(TransSetX2EvX1& res) const { mpTransRel->ReSort(res); }
1391 TEMP void THIS::TransRel(TransSetX2X1Ev& res) const { mpTransRel->ReSort(res); }
1392 TEMP void THIS::TransRel(TransSetX1X2Ev& res) const { mpTransRel->ReSort(res); }
1393 
1394 
1395 #undef THIS
1396 #undef TEMP
1397 #undef BASE
1398 
1399 
1400 
1401 } // namespace faudes
1402 
1403 #endif
1404 

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