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

libFAUDES 2.34d --- 2026.03.10 --- c++ api documentaion by doxygen