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 faudes Type (try to cast to agenerator or pass to base)
177  *
178  * @param rSrc
179  * Source for copy operation.
180  */
181  virtual TaGenerator& Assign(const Type& rSrc);
182 
183  /**
184  * Assignment operator (uses Assign(Generator&) )
185  *
186  * @param rOtherGen
187  * Other generator
188  */
189  virtual TaGenerator& operator= (const TaGenerator& rOtherGen);
190 
191  /**
192  * Destructive copy to other TaGenerator
193  * Copy method with increased performance at the cost of invalidating
194  * the source data. This version will copy attributes 1:1.
195  *
196  *
197  * @param rGen
198  * Destination for copy operation.
199  */
200  virtual void Move(TaGenerator& rGen);
201 
202  /**
203  * Destructive copy to other Generator.
204  * Copy method with increased performance at the cost of invalidating
205  * the source data. Convert attributes if possible.
206  *
207  *
208  * @param rGen
209  * Destination for copy operation.
210  */
211  virtual void Move(Generator& rGen);
212 
213 
214  /** @} doxygen group */
215 
216  /*****************************************
217  *****************************************
218  *****************************************
219  *****************************************/
220 
221  /** @name Basic Maintenance */
222  /** @{ doxygen group */
223 
224  /**
225  * Check if generator is valid
226  *
227  * @return
228  * Success
229  */
230  bool Valid(void) const;
231 
232 
233  /**
234  * Clear generator data.
235  * Clears state set, alphabet and transitionrealtion. Behavioural flags
236  * eg StateNamesEnabled are maintained.
237  */
238  virtual void Clear(void);
239 
240 
241 
242  /** @} doxygen group */
243 
244 
245 
246  /*****************************************
247  *****************************************
248  *****************************************
249  *****************************************/
250 
251  /** @name Read Access to Core Members */
252  /** @{ doxygen group */
253 
254  /**
255  * Return const reference to alphabet
256  *
257  * @return EventSet
258  * Reference to mpAlphabet
259  */
260  const TaEventSet<EventAttr>& Alphabet(void) const;
261 
262  /**
263  * Return reference to state set
264  *
265  * @return
266  * StateSet reference incl actual attribute type
267  */
268  const TaStateSet<StateAttr>& States(void) const;
269 
270  /**
271  * Return reference to transition relation
272  *
273  * @return TransRel
274  */
275  const ATransSet& TransRel(void) const;
276 
277  /**
278  * Get copy of trantision relation sorted by other compare
279  * operator, e.g. "x2,ev,x1"
280  *
281  * @param res
282  * resulting transition relation
283  */
284  void TransRel(TransSetX1EvX2& res) const;
285  void TransRel(TransSetEvX1X2& res) const;
286  void TransRel(TransSetEvX2X1& res) const;
287  void TransRel(TransSetX2EvX1& res) const;
288  void TransRel(TransSetX2X1Ev& res) const;
289  void TransRel(TransSetX1X2Ev& res) const;
290 
291  /** @} doxygen group */
292 
293 
294 
295  /*****************************************
296  *****************************************
297  *****************************************
298  *****************************************/
299 
300  /** @name Write Access to Core Members */
301  /** @{ doxygen group */
302 
303 
304  /**
305  * Add an existing event to alphabet by index. It is an error to insert
306  * an event index that is not known to the mpEventSymbolTable.
307  *
308  * @param index
309  * Event index
310  * @return
311  * True, if event was new to alphabet
312  */
313  bool InsEvent(Idx index);
314 
315  /**
316  * Add named event to generator. An entry in the mpEventSymbolTable will
317  * be made if event name is not known so far.
318  *
319  * @param rName
320  * Name of the event to add
321  *
322  * @return
323  * New unique index
324  */
325  Idx InsEvent(const std::string& rName);
326 
327  /**
328  * Add an existing event to alphabet by index, incl. attribute
329  * If the index allready exists, the attribute is overwritten by rAttr.
330  *
331  * @param rAttr
332  * Attribute of event
333  * @param index
334  * Event index
335  * @return
336  * True, if event was new to alphabet
337  */
338  bool InsEvent(Idx index, const EventAttr& rAttr);
339 
340  /**
341  * Add named event with attribute to generator. An entry in the
342  * mpEventSymbolTable will be made if event is not kown so far.
343  * If the event allready exits in the generator, the attribute will be
344  * overwritten by rAttr.
345  *
346  * @param rName
347  * Name of the event to add
348  * @param rAttr
349  * Attribute of event
350  *
351  * @return
352  * New unique index
353  */
354  Idx InsEvent(const std::string& rName, const EventAttr& rAttr);
355 
356  /**
357  * Set mpAlphabet without consistency check.
358  * Attributes will be casted if possible or silently ignored.
359  *
360  * @param rNewalphabet
361  * EventSet with new alphabet
362  */
363  void InjectAlphabet(const EventSet& rNewalphabet);
364 
365  /**
366  * Set mpAlphabet without consistency check.
367  *
368  * @param rNewalphabet
369  * EventSet with new alphabet
370  */
371  void InjectAlphabet(const TaEventSet<EventAttr>& rNewalphabet);
372 
373  /**
374  * Add new anonymous state to generator
375  *
376  * @return
377  * Index of new unique state
378  */
379  Idx InsState(void);
380 
381  /**
382  * Add new anonymous state with attribute to generator
383  *
384  * @param attr
385  * attribute of new state
386  *
387  * @return
388  * Index of new unique state
389  */
390  Idx InsState(const StateAttr& attr);
391 
392  /**
393  * Add (perhaps new) state to generator
394  *
395  * @return
396  * true to indicate that state was new to generator
397  */
398  bool InsState(Idx index);
399 
400  /**
401  * Add new named state to generator.
402  *
403  * @param rName
404  * Name of the state to add
405  *
406  * @return
407  * Index of new unique state
408  *
409  * @exception Exception
410  * Name already exists (id 44)
411  */
412  Idx InsState(const std::string& rName);
413 
414  /**
415  * Add new named state with attribute to generator.
416  *
417  * @param rName
418  * Name of the state to add
419  * @param attr
420  * attribute of new state
421  *
422  * @return
423  * Index of new unique state
424  * @exception Exception
425  * Name already exists (id 44)
426  */
427  Idx InsState(const std::string& rName, const StateAttr& attr);
428 
429  /**
430  * Add (perhaps new) state with attribute to generator.
431  *
432  * @param index
433  * Index of state to add
434  * @param attr
435  * Attribute of new state
436  *
437  * @return
438  * True, if event was new to alphabet
439  *
440  */
441  bool InsState(Idx index, const StateAttr& attr);
442 
443  /**
444  * Inject a complete state set without consistency checks.
445  * Attributes will be casted if possible or silently ignored.
446  *
447  * @param rNewStates
448  * StateSet
449  */
450  void InjectStates(const StateSet& rNewStates);
451 
452 
453  /**
454  * Inject a complete state set without consistency checks.
455  *
456  * @param rNewStates
457  * StateSet
458  */
459  void InjectStates(const TaStateSet<StateAttr>& rNewStates);
460 
461 
462  /**
463  * Add a transition to generator by indices. States and event
464  * must already exist!
465  *
466  * Define FAUDES_CHECKED for consistency checks.
467  *
468  * @param x1
469  * Predecessor state index
470  * @param ev
471  * Event index
472  * @param x2
473  * Successor state index
474  *
475  * @return
476  * True, if the transition was new the generator
477  *
478  * @exception Exception
479  * - state or event not in generator (id 95)
480  */
481  bool SetTransition(Idx x1, Idx ev, Idx x2);
482 
483  /**
484  * Add a transition to generator by names. Statename and eventname
485  * must already exist!
486  *
487  * @param rX1
488  * Predecessor state name
489  * @param rEv
490  * Event name
491  * @param rX2
492  * Successor state name
493  *
494  * @return
495  * True, if the transition was new the generator
496  *
497  * @exception Exception
498  * - state or event not in generator (id 95)
499  * - state name not known (id 90)
500  * - event name not known (id 66)
501  */
502  bool SetTransition(const std::string& rX1, const std::string& rEv,
503  const std::string& rX2);
504 
505  /**
506  * Add a transition to generator. States and event
507  * must already exist!
508  *
509  *
510  * @param rTransition
511  * Transition
512  *
513  * @return
514  * True, if the transition was new the generator
515  * @exception Exception
516  * - state or event not in generator (id 95)
517  */
518  bool SetTransition(const Transition& rTransition);
519 
520  /**
521  * Add a transition with attribute to generator. States and event
522  * must already exist!
523  *
524  *
525  * @param rTransition
526  * transition
527  * @param rAttr
528  * attribute
529  * @return
530  * True, if the transition was new the generator
531  * @exception Exception
532  * - state or event not in generator (id 95)
533  *
534  */
535  bool SetTransition(const Transition& rTransition, const TransAttr& rAttr);
536 
537  /**
538  * Set transition relation without consistency check.
539  * Attributes will be casted if possible or silently ignored.
540  *
541  * @param rNewtransrel
542  * TransRel to insert
543  */
544  void InjectTransRel(const TransSet& rNewtransrel);
545 
546  /**
547  * Set transition relation without consistency check.
548  *
549  * @param rNewtransrel
550  * TransRel to insert
551  */
552  void InjectTransRel(const ATransSet& rNewtransrel);
553 
554  /** @} doxygen group */
555 
556 
557 
558  /*****************************************
559  *****************************************
560  *****************************************
561  *****************************************/
562 
563  /** @name Attributes */
564  /** @{ doxygen group */
565 
566 
567  /**
568  * Set attribute for existing event
569  *
570  * @param index
571  * Event index
572  * @param rAttr
573  * New attribute
574  *
575  * @exception Exception
576  * Index not found in alphabet (id 60)
577  */
578  void EventAttribute(Idx index, const EventAttr& rAttr);
579 
580  /**
581  * Set attribute for existing event.
582  * This version uses a dynamic cast
583  * to test the actual type of the provided attribute. An exception is
584  * thrown for an invalid attribute type.
585  *
586  * @param index
587  * Event index
588  * @param rAttr
589  * New attribute
590  *
591  * @exception Exception
592  * - Index not found in alphabet (id 60)
593  * - Cannot cast attribute (id 63)
594  */
595  void EventAttribute(Idx index, const Type& rAttr);
596 
597  /**
598  * Event attribute lookup
599  *
600  * @param index
601  *
602  * @return
603  * reference to attribute
604  */
605  const EventAttr& EventAttribute(Idx index) const;
606 
607  /**
608  * Event attribute lookup
609  *
610  * @param rName
611  *
612  * @return
613  * reference to attribute
614  */
615  const EventAttr& EventAttribute(const std::string& rName) const;
616 
617  /**
618  * Event attribute pointer (to access Attribute methods)
619  * note: may insert explicit default attribute
620  *
621  * @param index
622  *
623  * @return
624  * pointer to attribute
625  */
626  EventAttr* EventAttributep(Idx index);
627 
628  /**
629  * Event attribute pointer (to access Attribute methods)
630  * note: may insert explicit default attribute
631  *
632  * @param rName
633  *
634  * @return
635  * pointer to attribute
636  */
637  EventAttr* EventAttributep(const std::string& rName);
638 
639 
640  /**
641  * Set attribute for existing state
642  *
643  * @param index
644  * Index
645  * @param rAttr
646  * attriute
647  *
648  * @exception Exception
649  * Name already associated with another index (id 44)
650  */
651  void StateAttribute(Idx index, const StateAttr& rAttr);
652 
653  /**
654  * Set attribute for existing state.
655  * This version uses a dynamic cast
656  * to test the actual type of the provided attribute. An exception is
657  * thrown for an invalid attribute type.
658  *
659  * @param index
660  * State index
661  * @param rAttr
662  * New attribute
663  *
664  * @exception Exception
665  * - Index not found in Stateset (id 60)
666  * - Cannot cast attribute (id 63)
667  */
668  void StateAttribute(Idx index, const Type& rAttr);
669 
670  /**
671  * State attribute lookup
672  *
673  * @param index
674  *
675  * @return ref to attribute of state
676  */
677  const StateAttr& StateAttribute(Idx index) const;
678 
679  /**
680  * State attribute pointer (to access Attribute methods)
681  * note: may insert explicit default attribute
682  *
683  * @param index
684  *
685  * @return pointer to attribute of state
686  */
687  StateAttr* StateAttributep(Idx index);
688 
689  /**
690  * Set attribute for existing transition
691  *
692  * @param rTrans
693  * transition
694  * @param rAttr
695  * New attribute
696  *
697  */
698  void TransAttribute(const Transition& rTrans, const TransAttr& rAttr);
699 
700  /**
701  * Set attribute for existing transition.
702  * This version uses a dynamic cast
703  * to test the actual type of the provided attribute. An exception is
704  * thrown for an invalid attribute type.
705  *
706  * @param rTrans
707  * transition
708  * @param rAttr
709  * New attribute
710  *
711  * @exception Exception
712  * - Transition not found in transition relation(id 60)
713  * - Cannot cast attribute (id 63)
714  */
715  void TransAttribute(const Transition& rTrans, const Type& rAttr);
716 
717 
718  /**
719  * Get attribute for existing transition
720  *
721  * @return
722  * attribute
723  *
724  */
725  const TransAttr& TransAttribute(const Transition& rTrans) const;
726 
727  /**
728  * Get attribute pointer for existing transition
729  * note: may insert explicit default attribute
730  *
731  * @return
732  * attribute pointer
733  *
734  */
735  TransAttr* TransAttributep(const Transition& rTrans);
736 
737  /**
738  * Set global attribute
739  *
740  * @param rAttr
741  * attribute
742  */
743  void GlobalAttribute(const GlobalAttr& rAttr) {*pGlobalAttribute=rAttr;};
744  void GlobalAttribute(const Type& rAttr) { const GlobalAttr* ap= dynamic_cast<const GlobalAttr*>(&rAttr); if(ap) *pGlobalAttribute=*ap;};
745 
746  /**
747  * Get global attribute ref
748  */
749  const GlobalAttr& GlobalAttribute(void) const {return *pGlobalAttribute;};
750 
751 
752  /**
753  * Get global attribute pointer
754  */
755  GlobalAttr* GlobalAttributep(void) {return pGlobalAttribute;};
756 
757 
758  /** @} doxygen group */
759 
760 
761 
762 
763  protected:
764 
765  /** Alphabet, pointer with actual attribute type */
767 
768  /** State set, pointer with actual attribute type */
770 
771  /** Transition relation, pointer with actual attribute type */
773 
774  /** Global attribute, pointer with actual attribute type */
775  GlobalAttr* pGlobalAttribute;
776 
777  /** Static default alphabet prototype (incl. attribute type) */
778  static const TaNameSet<EventAttr>& AlphabetTaGen(void);
779 
780  /** Static default state set prototype (incl. attribute type) */
781  static const TaIndexSet<StateAttr>& StatesTaGen(void);
782 
783  /** Static default transition relation prototype (incl. attribute type) */
784  static const ATransSet& TransRelTaGen(void);
785 
786  /** Static default global attribute prototype (configures global attribute type) */
787  static const GlobalAttr& GlobalTaGen(void);
788 
789  /** Allocate my heap members (attribute dependent types) */
790  virtual void NewCore(void);
791 
792  /** Update my secondary pointers for new core */
793  virtual void UpdateCore(void);
794 
795  /** Assignment */
796  void DoAssign(const TaGenerator& rGen);
797 
798 
799 };
800 
801 
802 
803 /* convenience access to relevant scopes */
804 #define THIS TaGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
805 #define TEMP template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
806 #define BASE vGenerator
807 
808 // static default prototypes (construct on first use design pattern)
809 TEMP const TaNameSet<EventAttr>& THIS::AlphabetTaGen(void) {
810  static TaNameSet<EventAttr> fls;
811  return fls;
812 }
813 TEMP const TaIndexSet<StateAttr>& THIS::StatesTaGen(void) {
814  static TaIndexSet<StateAttr> fls;
815  return fls;
816 }
817 TEMP const TaTransSet<TransAttr>& THIS::TransRelTaGen(void) {
818  static TaTransSet<TransAttr> fls;
819  return fls;
820 }
821 TEMP const GlobalAttr& THIS::GlobalTaGen(void) {
822  static GlobalAttr fls;;
823  return fls;
824 }
825 
826 
827 // TaGenerator::Generator(void)
828 TEMP THIS::TaGenerator(void) :
829  // init base
830  vGenerator()
831 {
832  FD_DG("TaGenerator(" << this << ")::TaGenerator()");
833  // re-allocate core members with nontrivial attribute types
835  NewCore();
836  FD_DG("TaGenerator(" << this << ")::TaGenerator(): done");
837 }
838 
839 // TaGenerator::Generator(rOtherGen)
840 TEMP THIS::TaGenerator(const TaGenerator& rOtherGen) :
841  // init base
842  vGenerator()
843 {
844  FD_DG("TaGenerator(" << this << ")::TaGenerator(" << &rOtherGen << ")");
845  // re-allocate core members with nontrivial attribute types
847  NewCore();
848  // have a 1:1 copy (incl sym tables)
849  DoAssign(rOtherGen);
850 }
851 
852 
853 // TaGenerator::Generator(rOtherGen)
854 TEMP THIS::TaGenerator(const vGenerator& rOtherGen) :
855  // init base
856  vGenerator()
857 {
858  FD_DG("TaGenerator(" << this << ")::TaGenerator([v]" << &rOtherGen << ")");
859  // re-allocate core members with nontrivial attribute types
861  NewCore();
862  // have a 1:1 copy (incl sym tables)
863  Assign(rOtherGen);
864  FD_DG("TaGenerator(" << this << ")::TaGenerator([v]" << &rOtherGen << "): ok");
865 }
866 
867 // TaGenerator::Generator(rFileName)
868 TEMP THIS::TaGenerator(const std::string& rFileName) :
869  // init base
870  vGenerator()
871 {
872  FD_DG("TaGenerator(" << this << ")::TaGenerator(" << rFileName << ")");
873  // re-allocate core members with nontrivial attribute types
875  NewCore();
876  // set some defaults
877  mStateNamesEnabled=true;
878  // do read
879  Read(rFileName);
880  // get original statenames default
882 }
883 
884 // allocate core on heap
885 TEMP void THIS::NewCore(void) {
886  FD_DG("TaGenerator(" << this << ")::NewCore()");
887 
888  // MS Compilers did somehow mess up upcast with diamond inheritance of TaNameSet-member New()
889  // call base, incl virtual call back of UpdateCore
890  //BASE::NewCore();
891 
892  DeleteCore();
893  // allocate by our typed prototypes
894  mpAlphabet= AlphabetTaGen().New();
895  mpStates=StatesTaGen().New();
896  mpTransRel=TransRelTaGen().New();
897  mpGlobalAttribute=GlobalTaGen().New();
898  // update callback
899  UpdateCore();
900 }
901 
902 // indicate new core
903 TEMP void THIS::UpdateCore(void) {
904  // let base do an update (fixes names)
905  BASE::UpdateCore();
906  // have pointer with my attribute
907  pGlobalAttribute = dynamic_cast< GlobalAttr* >(mpGlobalAttribute);
908  pAlphabet = dynamic_cast< TaNameSet<EventAttr>* >(mpAlphabet);
909  pStates = dynamic_cast< TaIndexSet<StateAttr>* >(mpStates);
910  pTransRel = dynamic_cast< ATransSet* >(mpTransRel);
911  // check for type mismatch
912  bool tmm=false;
913  if(pGlobalAttribute==0 && mpGlobalAttribute!=0) tmm=true;
914  if(pAlphabet==0 && mpAlphabet!=0) tmm=true;
915  if(pStates==0 && mpStates!=0) tmm=true;
916  if(pTransRel==0 && mpTransRel!=0) tmm=true;
917  if(tmm) {
918  std::stringstream errstr;
919  errstr << "cannot cast attributes for generator " << Name();
920  throw Exception("Generator::UpdateCore", errstr.str(), 63);
921  }
922 }
923 
924 
925 // Copy(gen) from identical type
926 TEMP void THIS::DoAssign(const TaGenerator& rGen) {
927  FD_DG("TaGenerator(" << this << ")::DoAssign(" << &rGen << ")");
928  FD_DG("TaGenerator(" << this << ")::DoAssign(..): types " << typeid(*this).name() << " <= " << typeid(rGen).name());
929  // prepare result (call clear for virtual stuff)
930  Clear();
931  // have same event symboltable
932  EventSymbolTablep(rGen.mpEventSymbolTable);
933  // copy state symboltable
934  StateSymbolTable(rGen.mStateSymbolTable);
935  // set other members
936  Name(rGen.Name());
937  *pGlobalAttribute=*rGen.pGlobalAttribute;
938  *pStates= *rGen.pStates;
939  *pAlphabet = *rGen.pAlphabet;
940  *pTransRel= *rGen.pTransRel;
941  mInitStates = rGen.mInitStates;
942  mMarkedStates = rGen.mMarkedStates;
943  mStateNamesEnabled=rGen.mStateNamesEnabled;
944  mReindexOnWrite=rGen.mReindexOnWrite;
945  // copy add on stuff
946  mMinStateIndexMap=rGen.mMinStateIndexMap;
947 #ifdef FAUDES_DEBUG_CODE
948  if(!Valid()) {
949  FD_DG("TaGenerator()::DoAssign(): invalid generator");
950  DWrite();
951  abort();
952  }
953 #endif
954  FD_DG("TaGenerator(" << this << ")::DoAssign(" << &rGen << "): done");
955 }
956 
957 // copy from other faudes type
958 TEMP THIS& THIS::Assign(const Type& rSrc) {
959  FD_DG("TaGenerator(" << this << ")::Assign([type] " << &rSrc << ")");
960  // cast to this class
961  const TaGenerator* agen=dynamic_cast<const THIS*>(&rSrc);
962  // bail out on object match
963  if(this==agen) return *this;
964  // assign on type match
965  if(agen) {
966  DoAssign(*agen);
967  return *this;
968  }
969  // pass on to base
970  BASE::Assign(rSrc);
971  return *this;
972 }
973 
974 
975 // Move(gen) destructive copy
976 TEMP void THIS::Move(TaGenerator& rGen) {
977  FD_DG("TaGenerator(" << this << ")::Move(" << &rGen << ")");
978  // call base
979  BASE::Move(rGen);
980 }
981 
982 
983 // Move(gen) destructive copy
984 TEMP void THIS::Move(Generator& rGen) {
985  FD_DG("TaGenerator(" << this << ")::Move([v]" << &rGen << ")");
986  // call base
987  BASE::Move(rGen);
988 }
989 
990 // TaGenerator::~Generator
991 TEMP THIS::~TaGenerator(void) {
992  FD_DG("TaGenerator(" << this << ")::~TaGenerator()");
993 }
994 
995 // New
996 TEMP THIS* THIS::New(void) const {
997  // allocate
998  THIS* res = new THIS;
999  // fix base data
1000  res->EventSymbolTablep(BASE::mpEventSymbolTable);
1001  res->mStateNamesEnabled=BASE::mStateNamesEnabled;
1002  res->mReindexOnWrite=BASE::mReindexOnWrite;
1003  return res;
1004 }
1005 
1006 // Copy
1007 TEMP THIS* THIS::Copy(void) const {
1008  // allocate
1009  THIS* res = new THIS(*this);
1010  // done
1011  return res;
1012 }
1013 
1014 // NewAGen()
1015 TEMP THIS THIS::NewAGen(void) const {
1016  THIS res;
1017  // fix base data
1018  res.EventSymbolTablep(BASE::mpEventSymbolTable);
1019  res.mStateNamesEnabled=BASE::mStateNamesEnabled;
1020  res.mReindexOnWrite=BASE::mReindexOnWrite;
1021  return res;
1022 }
1023 
1024 
1025 // CAST
1026 TEMP const Type* THIS::Cast(const Type* pOther) const {
1027  return dynamic_cast< const THIS* > (pOther);
1028 }
1029 
1030 
1031 // operator=
1033  FD_DG("TaGenerator(" << this << ")::operator = [v]" << &rOtherGen);
1034  return Assign(rOtherGen);
1035 }
1036 
1037 // Valid()
1038 TEMP bool THIS::Valid(void) const {
1039  FD_DG("TaGenerator(" << this << ")::Valid()");
1040  if(!BASE::Valid()) return false;
1041  // test types
1042  bool tmm=false;
1043  if(typeid(Alphabet().AttributeType())!=typeid(const EventAttr*)) tmm=true;
1044  if(typeid(States().AttributeType())!=typeid(const StateAttr*)) tmm=true;
1045  if(typeid(TransRel().AttributeType())!=typeid(const TransAttr*)) tmm=true;
1046  if(typeid(GlobalAttribute())!=typeid(const GlobalAttr&)) tmm=true;
1047  if(tmm) {
1048  return false;
1049  //std::stringstream errstr;
1050  //errstr << "attribute type mismatch in generator " << Name();
1051  //throw Exception("Generator::Valid", errstr.str(), 63);
1052  }
1053  return true;
1054 }
1055 
1056 // Clear()
1057 TEMP void THIS::Clear(void) {
1058  FD_DG("TaGenerator(" << this << ")::Clear()");
1059  BASE::Clear();
1060 }
1061 
1062 
1063 // InjectAlphabet(newalphabet)
1064 TEMP void THIS::InjectAlphabet(const EventSet& rNewAlphabet) {
1065  FD_DG("TaGenerator::InjectAlphabet() " << rNewAlphabet.ToString());
1066  BASE::InjectAlphabet(rNewAlphabet);
1067 }
1068 
1069 // InjectAlphabet(newalphabet)
1070 TEMP void THIS::InjectAlphabet(const TaEventSet<EventAttr>& rNewAlphabet) {
1071  FD_DG("TaGenerator::InjectAlphabet(TaEventSet<EventAttr>) " << rNewAlphabet.ToString());
1072 #ifdef FAUDES_CHECKED
1073  if(rNewAlphabet.SymbolTablep()!=mpEventSymbolTable) {
1074  std::stringstream errstr;
1075  errstr << "symboltable mismatch aka not implemented" << std::endl;
1076  throw Exception("TaGenerator::InjectAlphabet", errstr.str(), 88);
1077  }
1078 #endif
1079  *pAlphabet=rNewAlphabet;
1080  mpAlphabet->Name("Alphabet");
1081 }
1082 
1083 // InsEvent(index)
1084 TEMP bool THIS::InsEvent(Idx index) {
1085  FD_DG("TaGenerator(" << this << ")::InsEvent(" << index << ")");
1086  return pAlphabet->Insert(index);
1087 }
1088 
1089 // InsEvent(rName)
1090 TEMP Idx THIS::InsEvent(const std::string& rName) {
1091  FD_DG("TaGenerator(" << this << ")::InsEvent(\"" << rName << "\")");
1092  return pAlphabet->Insert(rName);
1093 }
1094 
1095 // InsEvent(index, attr)
1096 TEMP bool THIS::InsEvent(Idx index, const EventAttr& attr) {
1097  FD_DG("TaGenerator(" << this << ")::InsEvent(" << index << " " << attr.ToString() << ")");
1098  return pAlphabet->Insert(index, attr);
1099 }
1100 
1101 // InsEvent(rName)
1102 TEMP Idx THIS::InsEvent(const std::string& rName, const EventAttr& attr) {
1103  FD_DG("TaGenerator(" << this << ")::InsEvent(\"" << rName << attr.ToString() << "\")");
1104  return pAlphabet->Insert(rName, attr);
1105 }
1106 
1107 // InsState()
1108 TEMP Idx THIS::InsState(void) {
1109  FD_DG("TaGenerator(" << this << ")::InsState()");
1110  return pStates->Insert();
1111 }
1112 
1113 // InsState(attr)
1114 TEMP Idx THIS::InsState(const StateAttr& attr) {
1115  FD_DG("TaGenerator(" << this << ")::InsState(attr)");
1116  return pStates->Insert(attr);
1117 }
1118 
1119 // InsState(index)
1120 TEMP bool THIS::InsState(Idx index) {
1121  FD_DG("TaGenerator(" << this << ")::InsState(" << index << ")");
1122  return pStates->Insert(index);
1123 }
1124 
1125 // InsState(index, attr)
1126 TEMP bool THIS::InsState(Idx index, const StateAttr& rAttr) {
1127  FD_DG("TaGenerator(" << this << ")::InsState(" << index << ",rAttr)");
1128  return pStates->Insert(index,rAttr);
1129 }
1130 
1131 // InsState(rName)
1132 TEMP Idx THIS::InsState(const std::string& rName) {
1133  FD_DG("TaGenerator(" << this << ")::InsState(\"" << rName << "\")");
1134  Idx index=pStates->Insert();
1135  StateName(index,rName);
1136  return index;
1137 }
1138 
1139 // InsState(rName, attr)
1140 TEMP Idx THIS::InsState(const std::string& rName, const StateAttr& attr) {
1141  FD_DG("TaGenerator(" << this << ")::InsState(\"" << rName << "\", attr)");
1142  Idx index=pStates->Insert();
1143  StateName(index,rName);
1144  StateAttribute(index,attr);
1145  return index;
1146 }
1147 
1148 
1149 // InjectStates(rNewStates)
1150 TEMP void THIS::InjectStates(const StateSet& rNewStates) {
1151  FD_DG("TaGenerator(" << this << ")::InjectStates("
1152  << rNewStates.ToString() << ")");
1153  BASE::InjectStates(rNewStates);
1154 }
1155 
1156 // InjectStates(rNewStates)
1157 TEMP void THIS::InjectStates(const TaStateSet<StateAttr>& rNewStates) {
1158  FD_DG("TaGenerator(" << this << ")::InjectStates("
1159  << rNewStates.ToString() << ")");
1160  *pStates=rNewStates;
1161  pStates->Name("States");
1162  mpStateSymbolTable->RestrictDomain(*mpStates);
1163 }
1164 
1165 
1166 
1167 // InjectTransRel(rNewtransrel)
1168 TEMP void THIS::InjectTransRel(const TransSet& rNewTransRel) {
1169  FD_DG("TaGenerator::InjectTransRel(...)");
1170  *pTransRel=rNewTransRel;
1171 }
1172 
1173 // InjectTransRel(rNewtransrel)
1174 TEMP void THIS::InjectTransRel(const ATransSet& rNewTransRel) {
1175  FD_DG("TaGenerator::InjectTransRel(...)");
1176  *pTransRel=rNewTransRel;
1177 }
1178 
1179 
1180 // SetTransition(rX1, rEv, rX2)
1181 TEMP bool THIS::SetTransition(const std::string& rX1, const std::string& rEv, const std::string& rX2) {
1182  return BASE::SetTransition(rX1,rEv,rX2);
1183 }
1184 
1185 
1186 // SetTransition(x1, ev, x2)
1187 TEMP bool THIS::SetTransition(Idx x1, Idx ev, Idx x2) {
1188  return SetTransition(Transition(x1,ev,x2));
1189 }
1190 
1191 // SetTransition(rTransition)
1192 TEMP bool THIS::SetTransition(const Transition& rTransition) {
1193  FD_DG("TaGenerator(" << this << ")::SetTransition(" << rTransition.X1 << ","
1194  << rTransition.Ev << "," << rTransition.X2 << ")");
1195 #ifdef FAUDES_CHECKED
1196  if (! mpStates->Exists(rTransition.X1)) {
1197  std::stringstream errstr;
1198  errstr << "TaGenerator::SetTransition: state " << rTransition.X1
1199  << " not in stateset";
1200  throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
1201  }
1202  if (! mpAlphabet->Exists(rTransition.Ev)) {
1203  std::stringstream errstr;
1204  errstr << "TaGenerator::SetTransition: event " << rTransition.Ev
1205  << " not in alphabet ";
1206  throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
1207  }
1208  if (! mpStates->Exists(rTransition.X2)) {
1209  std::stringstream errstr;
1210  errstr << "TaGenerator::SetTransition: state " << rTransition.X2
1211  << " not in stateset";
1212  throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
1213  }
1214 #endif
1215  return pTransRel->Insert(rTransition);
1216 }
1217 
1218 // SetTransition(rTransition, rAttr)
1219 TEMP bool THIS::SetTransition(const Transition& rTransition, const TransAttr& rAttr) {
1220  FD_DG("TaGenerator(" << this << ")::SetTransition(" << rTransition.X1 << ","
1221  << rTransition.Ev << "," << rTransition.X2 << ", [attr:]" << rAttr.ToString() << ")");
1222 #ifdef FAUDES_CHECKED
1223  if (! mpStates->Exists(rTransition.X1)) {
1224  std::stringstream errstr;
1225  errstr << "TaGenerator::SetTransition: state " << rTransition.X1
1226  << " not in stateset";
1227  throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
1228  }
1229  if (! mpAlphabet->Exists(rTransition.Ev)) {
1230  std::stringstream errstr;
1231  errstr << "TaGenerator::SetTransition: event " << rTransition.Ev
1232  << " not in alphabet ";
1233  throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
1234  }
1235  if (! mpStates->Exists(rTransition.X2)) {
1236  std::stringstream errstr;
1237  errstr << "TaGenerator::SetTransition: state " << rTransition.X2
1238  << " not in stateset";
1239  throw Exception("TaGenerator::SetTransition(..)", errstr.str(), 95);
1240  }
1241 #endif
1242  return pTransRel->Insert(rTransition,rAttr);
1243 }
1244 
1245 // TransAttribute(trans, attr)
1246 TEMP void THIS::TransAttribute(const Transition& rTrans, const TransAttr& rAttr) {
1247  FD_DG("TaGenerator(" << this << ")::TransAttribute("
1248  << TStr(rTrans) << ",\"" << rAttr.ToString() << "\")");
1249  pTransRel->Attribute(rTrans, rAttr);
1250 }
1251 
1252 // TransAttribute(index, attr)
1253 TEMP void THIS::TransAttribute(const Transition& rTrans, const Type& rAttr) {
1254  FD_DG("TaGenerator(" << this << ")::TransAttribute("
1255  << TStr(rTrans) << ",\"" << rAttr.ToString() << "\")");
1256  const TransAttr* attrp = dynamic_cast<const TransAttr*>(&rAttr);
1257  if(!attrp) {
1258  std::stringstream errstr;
1259  errstr << "cannot cast event attribute " << rAttr.ToString() << " for generator " << Name();
1260  throw Exception("TaGenerator::TransAttribute", errstr.str(), 63);
1261  }
1262  pTransRel->Attribute(rTrans, *attrp);
1263 }
1264 
1265 // TransAttributep(trans)
1266 TEMP TransAttr* THIS::TransAttributep(const Transition& rTrans) {
1267  return pTransRel->Attributep(rTrans);
1268 }
1269 
1270 
1271 // TransAttribute(trans)
1272 TEMP const TransAttr& THIS::TransAttribute(const Transition& rTrans) const {
1273  return pTransRel->Attribute(rTrans);
1274 }
1275 
1276 // EventAttribute(index, attr)
1277 TEMP void THIS::EventAttribute(Idx index, const EventAttr& rAttr) {
1278  FD_DG("TaGenerator(" << this << ")::EventAttribute("
1279  << EStr(index) << ",\"" << rAttr.ToString() << "\")");
1280  pAlphabet->Attribute(index, rAttr);
1281 }
1282 
1283 // EventAttribute(index, attr)
1284 TEMP void THIS::EventAttribute(Idx index, const Type& rAttr) {
1285  FD_DG("TaGenerator(" << this << ")::EventAttribute("
1286  << EStr(index) << ",\"" << rAttr.ToString() << "\")");
1287  const EventAttr* attrp = dynamic_cast<const EventAttr*>(&rAttr);
1288  if(!attrp) {
1289  std::stringstream errstr;
1290  errstr << "cannot cast event attribute " << rAttr.ToString() << " for generator " << Name();
1291  throw Exception("TaGenerator::EventAttribute", errstr.str(), 63);
1292  }
1293  pAlphabet->Attribute(index, *attrp);
1294 }
1295 
1296 // EventAttribute(index)
1297 TEMP const EventAttr& THIS::EventAttribute(Idx index) const {
1298  return pAlphabet->Attribute(index);
1299 }
1300 
1301 // EventAttributep(index)
1302 TEMP EventAttr* THIS::EventAttributep(Idx index) {
1303  return pAlphabet->Attributep(index);
1304 }
1305 
1306 // EventAttribute(rName)
1307 TEMP const EventAttr& THIS::EventAttribute(const std::string& rName) const {
1308  return EventAttribute(EventIndex(rName));
1309 }
1310 
1311 // EventAttributep(rName)
1312 TEMP EventAttr* THIS::EventAttributep(const std::string& rName) {
1313  return EventAttributep(EventIndex(rName));
1314 }
1315 
1316 // StateAttribute(index, attr)
1317 TEMP void THIS::StateAttribute(Idx index, const StateAttr& rAttr) {
1318  FD_DG("TaGenerator(" << this << ")::StateAttribute("
1319  << index << ",\"" << rAttr.ToString() << "\")");
1320  pStates->Attribute(index, rAttr);
1321 }
1322 
1323 // StateAttribute(index, attr)
1324 TEMP void THIS::StateAttribute(Idx index, const Type& rAttr) {
1325  FD_DG("TaGenerator(" << this << ")::StateAttribute("
1326  << SStr(index) << ",\"" << rAttr.ToString() << "\")");
1327  const StateAttr* attrp = dynamic_cast<const StateAttr*>(&rAttr);
1328  if(!attrp) {
1329  std::stringstream errstr;
1330  errstr << "cannot cast event attribute " << rAttr.ToString() << " for generator " << Name();
1331  throw Exception("TaGenerator::StateAttribute", errstr.str(), 63);
1332  }
1333  pStates->Attribute(index, *attrp);
1334 }
1335 
1336 
1337 // StateAttribute(index)
1338 TEMP const StateAttr& THIS::StateAttribute(Idx index) const {
1339  return pStates->Attribute(index);
1340 }
1341 
1342 // StateAttributep(index)
1343 TEMP StateAttr* THIS::StateAttributep(Idx index) {
1344  return pStates->Attributep(index);
1345 }
1346 
1347 // Alphabet()
1348 TEMP const TaEventSet<EventAttr>& THIS::Alphabet(void) const {
1349  return *pAlphabet;
1350 }
1351 
1352 // States()
1353 TEMP const TaStateSet<StateAttr>& THIS::States(void) const {
1354  return *pStates;
1355 }
1356 
1357 // TransRel()
1358 TEMP const typename THIS::ATransSet& THIS::TransRel(void) const {
1359  return *pTransRel;
1360 }
1361 
1362 // TransRel(res)
1363 TEMP void THIS::TransRel(TransSetX1EvX2& res) const { mpTransRel->ReSort(res); }
1364 TEMP void THIS::TransRel(TransSetEvX1X2& res) const { mpTransRel->ReSort(res); }
1365 TEMP void THIS::TransRel(TransSetEvX2X1& res) const { mpTransRel->ReSort(res); }
1366 TEMP void THIS::TransRel(TransSetX2EvX1& res) const { mpTransRel->ReSort(res); }
1367 TEMP void THIS::TransRel(TransSetX2X1Ev& res) const { mpTransRel->ReSort(res); }
1368 TEMP void THIS::TransRel(TransSetX1X2Ev& res) const { mpTransRel->ReSort(res); }
1369 
1370 
1371 #undef THIS
1372 #undef TEMP
1373 #undef BASE
1374 
1375 
1376 
1377 } // namespace faudes
1378 
1379 #endif
1380 

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