tp_tgenerator.h
Go to the documentation of this file.
1/** @file tp_tgenerator.h Timed generator class TtGenerator */
2
3/*
4 Timeplugin for FAU Discrete Event Systems Library (libfaudes)
5
6 Copyright (C) 2007 Thomas Moor
7 Exclusive copyright is granted to Klaus Schmidt
8
9*/
10
11
12#ifndef FAUDES_TP_TGENERATOR_H
13#define FAUDES_TP_TGENERATOR_H
14
15#include "corefaudes.h"
16#include "tp_attributes.h"
17
18namespace faudes {
19
20
21
22/**
23 * Generator with timing extensions.
24 *
25 * \section SecTimedAlur Alur's Timed Automata
26 *
27 * The TtGenerator implements a timed automaton as
28 * introduced by Alur et al. Thus, a TtGenerator is equipped with a number of clock
29 * variables to express conditions on timing, so called time constraints. Each state has a
30 * TimeConstraint called the invariant, which must be satisfied while the generator
31 * resides in the respective state. Similarly, each transition has a timeconstraint called the
32 * guard, which must be satisfied at the moment in which the transition is executed. Transitions
33 * may also reset clock variables.
34 *
35 *
36 * \section SecTimedAlusImplement Implementation
37 *
38 * The TimedGenerator is derived from the System and requires
39 * adequate attribute parameters that implement the timing constraints. Suitable
40 * attribute classes are provided by AttributeTimedState, AttributeTimedTrans and AttributeTimedGlobal
41 * which may be used either directly or as base classes for further derivatives.
42 * For the event attribute, the TimedGenerator assumes the AttributeCFlags interface. A convenience
43 * definition faudes::TimedGenerator is used for a minimal version with the above mentioned attribute parameters.
44 *
45 *
46 * \section TimedGeneratorFileFormat File IO
47 *
48 * The TtGenerator calsses use the TaGenerator file IO, i.e. the file format is the
49 * same up to timing related requirements from the attribute parameters. The below
50 * example is from the basic version TimedGenerator and represents a simplemachine with a
51 * busy cycle of at least 5 and at most 10 time units.
52 * @code
53 * <Generator name="tc simple machine">
54 *
55 * <Alphabet>
56 * "alpha" +C+ "beta" "mue" "lambda" +C+
57 * </Alphabet>
58 *
59 * <States>
60 * "idle"
61 * "busy" <Invariant> "cBusy" "LT" 10 </Invariant>
62 * "down"
63 * </States>
64 *
65 * <TransRel>
66 *
67 * "idle" "alpha" "busy"
68 * <Timing>
69 * <Resets>
70 * "cBusy"
71 * </Resets>
72 * </Timing>
73 *
74 * "busy" "beta" "idle"
75 * <Timing>
76 * <Guard>
77 * "cBusy" "GT" 5
78 * </Guard>
79 * </Timing>
80 *
81 * "busy" "mue" "down"
82 *
83 * "down" "lambda" "idle"
84 *
85 * </TransRel>
86 *
87 * <InitStates> "idle" </InitStates>
88 * <MarkedStates> "idle" </MarkedStates>
89 *
90 * <Clocks> "cBusy" </Clocks>
91 *
92 * </Generator>
93 * @endcode
94 *
95 *
96 * @ingroup TimedPlugin
97 */
98
99template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
100class FAUDES_TAPI TtGenerator : public TcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr> {
101 public:
102 /**
103 * Constructor
104 */
105 TtGenerator(void);
106
107 /**
108 * Copy constructor
109 *
110 * @param rOtherGen
111 */
112 TtGenerator(const TtGenerator& rOtherGen);
113
114 /**
115 * Copy constructor (no attributes)
116 *
117 * @param rOtherGen
118 */
119 TtGenerator(const vGenerator& rOtherGen);
120
121 /**
122 * Assignment operator (uses Assign)
123 * Note: you must reimplement this operator in derived
124 * classes in order to handle internal pointers correctly
125 *
126 * @param rOtherGen
127 * Other generator
128 */
129 TtGenerator& operator= (const TtGenerator& rOtherGen) {this->Assign(rOtherGen); return *this;};
130
131
132 /**
133 * Construct from file
134 *
135 * @param rFileName
136 * Name of file
137 *
138 * @exception Exception
139 * - file format errors (id 1, 50, 51, 52)
140 */
141 TtGenerator(const std::string& rFileName);
142
143 /**
144 * Construct on heap.
145 * Constructs a TtGenerator on heap with the same attribute types and the same event- and clock-symboltable.
146 *
147 * @return
148 * new Generator
149 */
150 TtGenerator* New(void) const;
151
152 /**
153 * Construct copy on heap.
154 * Constructs a TtGenerator on heap with the same attribute types and the same event- and clock-symboltable.
155 *
156 * @return
157 * new Generator
158 */
159 TtGenerator* Copy(void) const;
160
161 /**
162 * Type test.
163 * Uses C++ dynamic cast to test whether the specified object
164 * casts to a TimedGenerator.
165 *
166 * @return
167 * TtGenerator reference if dynamic cast succeeds, else NULL
168 */
169 virtual const Type* Cast(const Type* pOther) const {
170 return dynamic_cast< const TtGenerator* > (pOther); };
171
172
173 /**
174 * Construct on stack.
175 * Constructs a TtGenerator on stack with the same attribute types and the same event- and clock-symboltable.
176 *
177 * @return
178 * new Generator
179 */
180 TtGenerator NewTGen(void) const;
181
182
183 /**
184 * Get Pointer to mpClockSymbolTable.
185 *
186 * @return Pointer mpClockSymbolTable
187 */
188 SymbolTable* ClockSymbolTablep(void) const;
189
190 /**
191 * Set ClockSymbolTable.
192 *
193 * @param pClockSymTab
194 * Pointer SymbolTable
195 */
196 void ClockSymbolTablep(SymbolTable* pClockSymTab);
197
198
199 /**
200 * Number of clocks in mClocks
201 *
202 * @return Number of clocks in mClocks
203 */
204 Idx ClocksSize(void) const;
205
206 /**
207 * Get clockset as const reference
208 *
209 * @return mClocks
210 */
211 const ClockSet& Clocks(void) const;
212
213
214 /**
215 * Get clockset as pointer
216 *
217 * @return mClocks
218 */
219 ClockSet* Clocksp(void);
220
221 /**
222 * Overwrites mClocks with newclocks without consistency check
223 *
224 * @param newclocks
225 * New clocks that are written to mClocks
226 */
227 void InjectClocks(const ClockSet& newclocks);
228
229 /**
230 * Looks up clock name for given index
231 *
232 * @param index
233 * Clock index
234 *
235 * @return Clock name
236 */
237 std::string ClockName(Idx index) const;
238
239 /**
240 * Looks up clock index for given name
241 *
242 * @param rName
243 * Clock name
244 *
245 * @return Clock index or 0 for nonexistent
246 */
247 Idx ClockIndex(const std::string& rName) const;
248
249 /**
250 * Add an existing clock to mClcoks by index
251 *
252 * @param index
253 * Clock index
254 * @return
255 * True if clock was new to clockset
256 */
257 bool InsClock(Idx index);
258
259 /**
260 * Add named clock to generator. An entry in the mpClockSymbolTable will
261 * be made if clock is new.
262 *
263 * @param rName
264 * Name of the clock to add
265 *
266 * @return
267 * New unique index
268 */
269 Idx InsClock(const std::string& rName);
270
271 /**
272 * Add new named clocks to generator.
273 *
274 * @param rClockSet
275 * ClockSet
276 */
277 void InsClocks(const ClockSet& rClockSet);
278
279 /**
280 * Delete clock from generator by index. This also removes
281 * any constraints and resets that refer to that clock.
282 *
283 * @param index
284 * Index of clock
285 * @return
286 * True if clock did exist
287 *
288 */
289 bool DelClock(Idx index);
290
291 /**
292 * Delete clock from generator by name. mpClockSymbolTable stays untouched.
293 * Also removes constraints and resets that refer to this clock
294 *
295 * @param rName
296 * Name of clock
297 * @return
298 * True if clock did exist
299 */
300 bool DelClock(const std::string& rName);
301
302 /**
303 * Delete a set of clocks from generator.
304 *
305 * @param rClocks
306 * ClockSet containing clocks to remove
307 */
308 void DelClocks(const ClockSet& rClocks);
309
310 /**
311 * Test existence of clock in mClocks
312 *
313 * @param index
314 * Clock index
315 *
316 * @return
317 * true / false
318 */
319 bool ExistsClock(Idx index) const;
320
321 /**
322 * Test existence of clock in mClock
323 *
324 * @param rName
325 * Clock name
326 *
327 * @return
328 * True if clock exists
329 */
330 bool ExistsClock(const std::string& rName) const;
331
332 /**
333 * Returns a niterator to clock index in mClock
334 *
335 * @param index
336 * Index to find
337 *
338 * @return
339 * ClockSet::Iterator to clock index
340 */
341 ClockSet::Iterator FindClock(Idx index) const;
342
343 /**
344 * Returns an iterator to clock index in mClock
345 *
346 * @param rName
347 * Clock name of index to find
348 *
349 * @return
350 * ClockSet::Iterator to clock index
351 */
352 ClockSet::Iterator FindClock(const std::string& rName) const;
353
354 /**
355 * Returns all clocks used by all TimeConstraints and Resets.
356 * Should be a subset of Clocks()
357 *
358 * @return
359 * ClockSet containing all clocks
360 */
361 ClockSet ActiveClocks(void) const;
362
363 /**
364 * Returns all clocks not used by any TimeConstraints or Reset.
365 *
366 * @return
367 * ClockSet containing all unused clocks
368 */
369 ClockSet InactiveClocks(void) const;
370
371 /**
372 * Update Clocks to include all active clocks
373 *
374 */
375 void InsActiveClocks(void);
376
377 /**
378 * Update Clocks not to include any inactive clocks
379 *
380 */
381 void DelInactiveClocks(void);
382
383 /**
384 * Iterator to Begin() of mClocks
385 *
386 * @return iterator to begin of mClocks
387 */
388 ClockSet::Iterator ClocksBegin(void) const;
389
390 /**
391 * Iterator to End() of mClocks
392 *
393 * @return iterator to end of mClocks
394 */
395 ClockSet::Iterator ClocksEnd(void) const;
396
397 /**
398 * Throw exception if timeconstraint refers to clocks not
399 * in clockset or symboltable mismatch
400 *
401 * @exception Exception
402 * - invalid cock (id 200)
403 */
404 void ConsistentTimeConstraint(const TimeConstraint& rTimeConstr) const;
405
406 /**
407 * Throw exception if clocksset contains clocks not
408 * in generators clockset or symboltable mismatch
409 *
410 * @exception Exception
411 * - invalid cock (id 200)
412 */
413 void ConsistentClocks(const ClockSet& rClocks) const;
414
415
416 /**
417 * Get invariant of state by index
418 *
419 * @param idx
420 * State index
421 * @return
422 * Const ref to invariant
423 */
424 const TimeConstraint& Invariant(Idx idx) const;
425
426 /**
427 * Get invariant of state by index
428 *
429 * @param idx
430 * State index
431 * @return
432 * Pointer to invariant
433 */
434 TimeConstraint* Invariantp(Idx idx);
435
436 /**
437 * Get invariant of state by name
438 *
439 * @param name
440 * State name
441 * @return
442 * Const ref to invariant
443 */
444 const TimeConstraint& Invariant(const std::string& name) const;
445
446
447 /**
448 * Get invariant of state by name
449 *
450 * @param name
451 * State index
452 * @return
453 * Pointer to invariant
454 */
455 TimeConstraint* Invariantp(const std::string& name);
456
457 /**
458 * Set invariant of state by index
459 *
460 * @param index
461 * State index
462 * @param rConstraints
463 * New constraints
464 */
465 void Invariant(Idx index, const TimeConstraint& rConstraints);
466
467
468 /**
469 * Set invariant of state by name
470 *
471 * @param name
472 * State name
473 * @param rConstraints
474 * New constraints
475 */
476 void Invariant(const std::string& name, const TimeConstraint& rConstraints);
477
478
479 /**
480 * Ins invariant of state by name
481 *
482 * @param name
483 * State name
484 * @param rConstraints
485 * New constraints
486 */
487 void InsInvariant(const std::string& name, const TimeConstraint& rConstraints);
488
489
490 /**
491 * Ins invariant of state by name
492 *
493 * @param index
494 * State index
495 * @param rConstraints
496 * New constraints
497 */
498 void InsInvariant(Idx index, const TimeConstraint& rConstraints);
499
500
501 /**
502 * Clear invariant of state by index
503 *
504 * @param idx
505 * State index
506 */
507 void ClrInvariant(Idx idx);
508
509 /**
510 * Clear invariant of state by name
511 *
512 * @param name
513 * State name
514 */
515 void ClrInvariant(const std::string& name);
516
517 /**
518 * Clear all invariants
519 *
520 */
521 void ClearInvariants(void);
522
523 /**
524 * Add a transition to generator by indices. States and event
525 * must already exist!
526 *
527 * Define FAUDES_CHECKED for consistency checks.
528 *
529 * @param x1
530 * Predecessor state index
531 * @param ev
532 * Event index
533 * @param x2
534 * Successor state index
535 *
536 * @return
537 * True, if the transition was new the generator
538 *
539 * @exception Exception
540 * - state or event not in generator (id 95)
541 */
542 bool SetTransition(Idx x1, Idx ev, Idx x2);
543
544 /**
545 * Add a transition to generator by names. Statename and eventname
546 * must already exist!
547 *
548 * @param rX1
549 * Predecessor state name
550 * @param rEv
551 * Event name
552 * @param rX2
553 * Successor state name
554 *
555 * @return
556 * True, if the transition was new the generator
557 *
558 * @exception Exception
559 * - state or event not in generator (id 95)
560 * - state name not known (id 90)
561 * - event name not known (id 66)
562 */
563 bool SetTransition(const std::string& rX1, const std::string& rEv,
564 const std::string& rX2);
565
566 /**
567 * Add a transition with attribute to generator. States and event
568 * must already exist!
569 *
570 * Define FAUDES_CHECKED for consistency checks.
571 *
572 * @param rTransition
573 * transition
574 * @param rAttr
575 * attribute
576 *
577 * @return
578 * True, if the transition was new the generator
579 *
580 */
581 bool SetTransition(const Transition& rTransition, const TransAttr& rAttr);
582
583 /**
584 * Inserts new TimedTransition constructed from parameters.
585 * Performs consistency checks for x1, x2, ev and all clocks in rguard and rResetClocks.
586 *
587 * @param rTrans
588 * new transition
589 * @param rGuard
590 * Guard of new TimedTransition.
591 * @param rResets
592 * Reset clocks of new TimedTransition.
593 * @return
594 * True, if the transition was new the generator
595 */
596 bool SetTransition(const Transition& rTrans,
597 const TimeConstraint& rGuard = TimeConstraint(), const ClockSet& rResets = ClockSet());
598
599 /**
600 * Inserts new TimedTransition constructed from parameters.
601 * Performs consistency checks for x1, x2, ev and all clocks in rguard and rResetClocks.
602 *
603 * @param x1
604 * Start state of new TimedTransition.
605 * @param ev
606 * Event of new TimedTransition.
607 * @param x2
608 * Goal state of new TimedTransition.
609 * @param rguard
610 * Guard of new TimedTransition.
611 * @param rResetClocks
612 * Reset clocks of new TimedTransition.
613 */
614 bool SetTransition(Idx x1, Idx ev, Idx x2,
615 const TimeConstraint& rguard, const ClockSet& rResetClocks = ClockSet());
616
617 /**
618 * Inserts new TimedTransition constructed from parameters.
619 * Performs consistency checks for x1, x2, ev and all clocks in rguard and rResetClocks.
620 *
621 * @param rX1
622 * Start state of new TimedTransition.
623 * @param rEv
624 * Event of new TimedTransition.
625 * @param rX2
626 * Goal state of new TimedTransition.
627 * @param rGuard
628 * Guard of new TimedTransition.
629 * @param rResets
630 * Reset clocks of new TimedTransition.
631 *
632 * @return
633 * True, if the transition was new the generator
634 */
635 bool SetTransition(const std::string& rX1, const std::string& rEv, const std::string& rX2,
636 const TimeConstraint& rGuard = TimeConstraint(), const ClockSet& rResets = ClockSet());
637
638
639 /**
640 * Sets Guard of a transition
641 *
642 * @param rTrans
643 * transition to manupilate
644 * @param rGuard
645 * new Guard of transition.
646 */
647 void Guard(const Transition& rTrans, const TimeConstraint& rGuard);
648
649 /**
650 * adds constraints to Guard of a transition
651 *
652 * @param rTrans
653 * transition to manupilate
654 * @param rConstraints
655 * new constraints for Guard
656 */
657 void InsGuard(const Transition& rTrans, const TimeConstraint& rConstraints);
658
659 /**
660 * Gets Guard refernce of a transition
661 *
662 * @param rTrans
663 * transition to inspect
664 *
665 * @return
666 * Guard of transition.
667 */
668 const TimeConstraint& Guard(const Transition& rTrans) const;
669
670 /**
671 * Gets Guard pointer of ransition
672 *
673 * @param rTrans
674 * transition to inspect
675 *
676 * @return
677 * Guard of transition.
678 */
679 TimeConstraint* Guardp(const Transition& rTrans);
680
681
682 /**
683 * Clears Guard of a transition
684 *
685 * @param rTrans
686 * transition to manupilate
687 */
688 void ClrGuard(const Transition& rTrans);
689
690 /**
691 * Sets Resets of a transition
692 *
693 * @param rTrans
694 * transition to manupilate
695 * @param rResets
696 * new Resets of transition.
697 */
698 void Resets(const Transition& rTrans, const ClockSet& rResets);
699
700 /**
701 * adds Resets of a transition
702 *
703 * @param rTrans
704 * transition to manupilate
705 * @param rMoreResets
706 * new Resets of transition.
707 */
708 void InsResets(const Transition& rTrans, const ClockSet& rMoreResets);
709
710 /**
711 * Gets Resets refernce of a transition
712 *
713 * @param rTrans
714 * transition to inspect
715 *
716 * @return
717 * Resets of transition.
718 */
719 const ClockSet& Resets(const Transition& rTrans) const;
720
721 /**
722 * Gets Resets pointer of ransition
723 *
724 * @param rTrans
725 * transition to inspect
726 *
727 * @return
728 * Resets of transition.
729 */
730 ClockSet* Resetsp(const Transition& rTrans);
731
732 /**
733 * Clears Resets of a transition
734 *
735 * @param rTrans
736 * transition to manupilate
737 */
738 void ClrResets(const Transition& rTrans);
739
740 /**
741 * Return pretty printable clock name for index.
742 * Primary meant for debugging messages
743 *
744 * @param index
745 * Event index
746 *
747 * @return
748 * std::string
749 */
750 std::string CStr(Idx index) const;
751
752 /**
753 * Check if generator is valid
754 *
755 * @return
756 * Success
757 */
758 virtual bool Valid(void) const;
759
760
761 /**
762 * Updates internal attributes. As a demo, we set
763 * state flag 0x20000000 for blocking states.
764 * Reimplement to your needs.
765 *
766 * @return true if value changed
767 */
768 virtual bool UpdateAttributes(void);
769
770
771
772}; // end class TtGeneraator
773
774
775/** Convenience typedef for std TimedGenerator */
776typedef TtGenerator<AttributeTimedGlobal, AttributeTimedState, AttributeCFlags,AttributeTimedTrans>
778
779/** Compatibility: pre 2.20b used tGenerator as C++ class name*/
780#ifdef FAUDES_COMPATIBILITY
783#endif
784
785
786
787// convenient scope macors
788#define THIS TtGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
789#define BASE TcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
790#define TEMP template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
791
792
793// TtGenerator(void)
794TEMP THIS::TtGenerator(void) : BASE() {
795 // set basic members (cosmetic)
796 BASE::pGlobalAttribute->mClocks.Name("Clocks");
797 BASE::pGlobalAttribute->mpClockSymbolTable=ClockSet::GlobalClockSymbolTablep();
798 FD_DG("TimedGenerator(" << this << ")::TimedGenerator() with csymtab "
799 << (BASE::pGlobalAttribute->mpClockSymbolTable ));
800}
801
802// TtGenerator(rOtherGen)
803TEMP THIS::TtGenerator(const TtGenerator& rOtherGen) : BASE(rOtherGen) {
804 FD_DG("TimedGenerator(" << this << ")::TimedGenerator(rOtherGen) with csymtab"
805 << (BASE::pGlobalAttribute->mpClockSymbolTable) );
806}
807
808// TtGenerator(rOtherGen)
809TEMP THIS::TtGenerator(const vGenerator& rOtherGen) : BASE(rOtherGen) {
810 // set basic members (cosmetic)
811 BASE::pGlobalAttribute->mClocks.Name("Clocks");
812 BASE::pGlobalAttribute->mpClockSymbolTable=ClockSet::GlobalClockSymbolTablep();
813 FD_DG("TimedGenerator(" << this << ")::TimedGenerator(rOtherGen) with csymtab"
814 << (BASE::pGlobalAttribute->mpClockSymbolTable) );
815}
816
817// TtGenerator(rFilename)
818TEMP THIS::TtGenerator(const std::string& rFileName) : BASE(rFileName) {
819 FD_DG("TimedGenerator(" << this << ")::TimedGenerator(" << rFileName << ") with csymtab"
820 << (BASE::pGlobalAttribute->mpClockSymbolTable) );
821}
822
823
824// ClockSymbolTablep()
825TEMP SymbolTable* THIS::ClockSymbolTablep(void) const {
826 return BASE::pGlobalAttribute->mpClockSymbolTable;
827}
828
829// ClockSymbolTablep(pSymTab)
830TEMP void THIS::ClockSymbolTablep(SymbolTable* pSymTab) {
831 BASE::Clear(); // TODO: relax this
832 BASE::pGlobalAttribute->mpClockSymbolTable=pSymTab;
833}
834
835
836// New
837TEMP THIS* THIS::New(void) const {
838 // allocate
839 THIS* res = new THIS;
840 // fix base data
841 res->EventSymbolTablep(BASE::mpEventSymbolTable);
842 res->mStateNamesEnabled=BASE::mStateNamesEnabled;
843 res->mReindexOnWrite=BASE::mReindexOnWrite;
844 // fix my data
845 res->ClockSymbolTablep(ClockSymbolTablep());
846 return res;
847}
848
849// Copy
850TEMP THIS* THIS::Copy(void) const {
851 // allocate
852 THIS* res = new THIS(*this);
853 // done
854 return res;
855}
856
857// NewTGen
858TEMP THIS THIS::NewTGen(void) const {
859 // call base (fixes by assignment constructor)
860 THIS res= BASE::NewCGen();
861 // fix my data
862 res.ClockSymbolTablep(ClockSymbolTablep());
863 return res;
864}
865
866// ClockSize() const
867TEMP Idx THIS::ClocksSize(void) const {
868 return BASE::pGlobalAttribute->mClocks.Size();
869}
870
871// Clocks()
872TEMP const ClockSet& THIS::Clocks(void) const {
873 return BASE::pGlobalAttribute->mClocks;
874}
875
876// Clocksp()
877TEMP ClockSet* THIS::Clocksp(void) {
878 return &BASE::pGlobalAttribute->mClocks;
879}
880
881// InjectClocks(set)
882TEMP void THIS::InjectClocks(const ClockSet& clockset) {
883 BASE::pGlobalAttribute->mClocks=clockset;
884 BASE::pGlobalAttribute->mClocks.Name("Clocks");
885}
886
887// InsClock(index)
888TEMP bool THIS::InsClock(Idx clockindex) {
889 return BASE::pGlobalAttribute->mClocks.Insert(clockindex);
890}
891
892// InsClock(name)
893TEMP Idx THIS::InsClock(const std::string& clockname) {
894 return BASE::pGlobalAttribute->mClocks.Insert(clockname);
895}
896
897// InsClocks(set)
898TEMP void THIS::InsClocks(const ClockSet& clockset) {
899 BASE::pGlobalAttribute->mClocks.InsertSet(clockset);
900}
901
902
903// DelClock(index)
904TEMP bool THIS::DelClock(Idx clockindex) {
905 FD_DG("TimedGenerator(" << this << ")::DelClock(" << clockindex << ")");
907 for(tit=BASE::TransRelBegin(); tit!=BASE::TransRelEnd(); tit++) {
908 if(!BASE::pTransRel->Attribute(*tit).IsDefault()) {
909 BASE::pTransRel->Attributep(*tit)->mGuard.EraseByClock(clockindex);
910 BASE::pTransRel->Attributep(*tit)->mResets.Erase(clockindex);
911 }
912 }
913 StateSet::Iterator it;
914 for(it=BASE::StatesBegin(); it!=BASE::StatesEnd(); it++) {
915 if(!BASE::pStates->Attribute(*it).IsDefault()) {
916 BASE::pStates->Attributep(*it)->mInvariant.EraseByClock(clockindex);
917 }
918 }
919 return BASE::pGlobalAttribute->mClocks.Erase(clockindex);
920}
921
922// DelClock(name)
923TEMP bool THIS::DelClock(const std::string& clockname) {
924 Idx index=BASE::pGlobalAttribute->mClocks.Index(clockname);
925 return DelClock(index);
926}
927
928// DelClocks(set)
929TEMP void THIS::DelClocks(const ClockSet& clockset) {
930 ClockSet::Iterator it, tmpit;
931 for(it=clockset.Begin(); it!=clockset.End(); ) {
932 tmpit=it;
933 it++;
934 DelClock(*tmpit);
935 }
936}
937
938// ExistsClock(index)
939TEMP bool THIS::ExistsClock(Idx clockindex) const {
940 return BASE::pGlobalAttribute->mClocks.Exists(clockindex);
941}
942
943// ExistsClock(name)
944TEMP bool THIS::ExistsClock(
945 const std::string& clockname) const {
946 return BASE::pGlobalAttribute->mClocks.Exists(clockname);
947}
948
949// FindClock(index)
950TEMP ClockSet::Iterator THIS::FindClock(Idx clockindex) const {
951 return BASE::pGlobalAttribute->mClocks.Find(clockindex);
952}
953
954// FindClock(name)
955TEMP ClockSet::Iterator THIS::FindClock(const std::string& clockname) const {
956 return BASE::pGlobalAttribute->mClocks.Find(clockname);
957}
958
959// ClockName(index)
960TEMP std::string THIS::ClockName(Idx clockindex) const {
961 return BASE::pGlobalAttribute->mClocks.SymbolicName(clockindex);
962}
963
964// ClockIndex(name)
965TEMP Idx THIS::ClockIndex(const std::string& clockname) const {
966 return BASE::pGlobalAttribute->mClocks.Index(clockname);
967}
968
969// ActiveClocks() const
970TEMP ClockSet THIS::ActiveClocks(void) const {
971 FD_DG("TimedGenerator(" << this << ")::ActiveClocks() const");
972 ClockSet res;
974 for(tit=BASE::TransRelBegin(); tit!=BASE::TransRelEnd(); tit++) {
975 res.InsertSet(Guard(*tit).ActiveClocks());
976 res.InsertSet(Resets(*tit));
977 }
978 StateSet::Iterator it;
979 for(it=BASE::StatesBegin(); it!=BASE::StatesEnd(); it++) {
980 res.InsertSet(Invariant(*it).ActiveClocks());
981 }
982 res.Name("AcitiveClocks");
983 return res;
984}
985
986// InactiveClocks() const
987TEMP ClockSet THIS::InactiveClocks(void) const {
988 FD_DG("TtaGenerator(" << this << ")::InactiveClocks() const");
989 ClockSet res = BASE::pGlobalAttribute->mClocks;
990 res.EraseSet(ActiveClocks());
991 res.Name("InactiveClocks");
992 return res;
993}
994
995// InsActiveClocks()
996TEMP void THIS::InsActiveClocks(void) {
997 FD_DG("TimedGenerator(" << this << ")::InsActiveClocks()");
998 ClockSet aclocks=ActiveClocks();
999 InsClocks(aclocks);
1000}
1001
1002// DelInactiveClocks()
1003TEMP void THIS::DelInactiveClocks(void) {
1004 FD_DG("TimedGenerator(" << this << ")::InsActiveClocks()");
1005 ClockSet iaclocks=InactiveClocks();
1006 BASE::pGlobalAttribute->mClocks.EraseSet(iaclocks);
1007}
1008
1009// iterator ClocksBegin() const
1010TEMP ClockSet::Iterator THIS::ClocksBegin(void) const {
1011 return BASE::pGlobalAttribute->mClocks.Begin();
1012}
1013
1014// iterator ClocksEnd() const
1015TEMP ClockSet::Iterator THIS::ClocksEnd(void) const {
1016 return BASE::pGlobalAttribute->mClocks.End();
1017}
1018
1019// ConsistentTimeConstraint(constraint)
1020TEMP void THIS::ConsistentTimeConstraint(const TimeConstraint& rTimeConstr) const {
1021 FD_DG("TimedGenerator(" << this << ")::ConsistentTimeConstraint(constr)");
1022 if( rTimeConstr.ClockSymbolTablep() != ClockSymbolTablep()) {
1023 std::stringstream errstr;
1024 errstr << "clocksymboltable mismatch" << std::endl;
1025 throw Exception("TimedGenerator::ConsistentTimeConstraint)", errstr.str(), 200);
1026 }
1027 if(!( rTimeConstr.ActiveClocks() <= Clocks() )) {
1028 std::stringstream errstr;
1029 errstr << "time constraint refers to clocks not in clockset: " <<
1030 rTimeConstr.ActiveClocks().ToString() << " versus " << Clocks().ToString() << std::endl;
1031 throw Exception("TimedGenerator::ConsistentTimeConstraint)", errstr.str(), 200);
1032 }
1033 FD_DG("TimedGenerator(" << this << ")::ConsistentTimeConstraint(constr): ok");
1034}
1035
1036// ConsistentClocks(clocks)
1037TEMP void THIS::ConsistentClocks(const ClockSet& rClocks) const {
1038 if(!( rClocks <= Clocks() )) {
1039 std::stringstream errstr;
1040 errstr << "clocksset contains clocks not in clockset" << std::endl;
1041 throw Exception("TimedGenerator::ConsistentClocks)", errstr.str(), 200);
1042 }
1043 if( rClocks.SymbolTablep() != ClockSymbolTablep()) {
1044 std::stringstream errstr;
1045 errstr << "clocksymboltable mismatch" << std::endl;
1046 throw Exception("TimedGenerator::ConsistentClocks)", errstr.str(), 200);
1047 }
1048}
1049
1050
1051// Invariant(index)
1052TEMP const TimeConstraint& THIS::Invariant(Idx stateindex) const {
1053 if(!BASE::ExistsState(stateindex)) {
1054 std::stringstream errstr;
1055 errstr << "state index " << stateindex << " not found in StateSet" << std::endl;
1056 throw Exception("TimedGenerator::Invariant", errstr.str(), 200);
1057 }
1058 return BASE::pStates->Attribute(stateindex).mInvariant;
1059}
1060
1061// Invariantp(index)
1062TEMP TimeConstraint* THIS::Invariantp(Idx stateindex) {
1063 if(!BASE::ExistsState(stateindex)) {
1064 std::stringstream errstr;
1065 errstr << "state index " << stateindex << " not found in StateSet" << std::endl;
1066 throw Exception("TimedGenerator::Invariant", errstr.str(), 200);
1067 }
1068 return &BASE::pStates->Attributep(stateindex)->mInvariant;
1069}
1070
1071// Invariant(name)
1072TEMP const TimeConstraint& THIS::Invariant(const std::string& statename) const {
1073 Idx idx=BASE::StateIndex(statename);
1074 return Invariant(idx);
1075}
1076
1077// Invariantp(name)
1078TEMP TimeConstraint* THIS::Invariantp(const std::string& statename) {
1079 Idx idx=BASE::StateIndex(statename);
1080 return Invariantp(idx);
1081}
1082
1083// Invariant(index,invariant)
1084TEMP void THIS::Invariant(Idx stateindex, const TimeConstraint& rInv) {
1085 FD_DG("TimedGenerator(" << this << ")::Invariant("<<stateindex<<",inv)");
1086#ifdef FAUDES_CHECKED
1087 ConsistentTimeConstraint(rInv);
1088 if(!BASE::ExistsState(stateindex)) {
1089 std::stringstream errstr;
1090 errstr << "state index " << stateindex << " not found in StateSet" << std::endl;
1091 throw Exception("TimedGenerator::Invariant", errstr.str(), 200);
1092 }
1093#endif
1094 BASE::pStates->Attributep(stateindex)->mInvariant=rInv;
1095 BASE::pStates->Attributep(stateindex)->mInvariant.Name("Invariant");
1096}
1097
1098// Invariant(name,invariant)
1099TEMP void THIS::Invariant(const std::string& statename, const TimeConstraint& rInv) {
1100 FD_DG("TimedGenerator(" << this << ")::Invariant("<<statename<<",inv)");
1101 Idx idx=BASE::StateIndex(statename);
1102 Invariant(idx,rInv);
1103}
1104
1105// InsInvariant(index,invariant)
1106TEMP void THIS::InsInvariant(Idx stateindex, const TimeConstraint& rInv) {
1107 FD_DG("TimedGenerator(" << this << ")::InsInvariant("<<stateindex<<",inv)");
1108#ifdef FAUDES_CHECKED
1109 ConsistentTimeConstraint(rInv);
1110 if(!BASE::ExistsState(stateindex)) {
1111 std::stringstream errstr;
1112 errstr << "state index " << stateindex << " not found in StateSet" << std::endl;
1113 throw Exception("TimedGenerator::InsInvariant", errstr.str(), 200);
1114 }
1115#endif
1116 if(!rInv.Empty()) {
1117 BASE::pStates->Attributep(stateindex)->mInvariant.Insert(rInv);
1118 }
1119}
1120
1121// InsInvariant(name,invariant)
1122TEMP void THIS::InsInvariant(const std::string& statename, const TimeConstraint& rInv) {
1123 FD_DG("TimedGenerator(" << this << ")::InsInvariant("<<statename<<",inv)");
1124 Idx idx=BASE::StateIndex(statename);
1125 InsInvariant(idx,rInv);
1126}
1127
1128// ClrInvariant(index)
1129TEMP void THIS::ClrInvariant(Idx stateindex) {
1130 if(!BASE::pStates->Attribute(stateindex).IsDefault())
1131 BASE::pStates->Attributep(stateindex)->mInvariant.Clear();
1132}
1133
1134// ClrInvariant(name)
1135TEMP void THIS::ClrInvariant(const std::string& statename) {
1136 Idx idx=BASE::StateIndex(statename);
1137 ClrInvariant(idx);
1138}
1139
1140// ClearInvariants()
1141TEMP void THIS::ClearInvariants(void) {
1142 // FIXME: should iterate, there could be other attributes
1143 BASE::pStates->ClearAttributes();
1144}
1145
1146
1147// SetTransition(rX1, rEv, rX2)
1148TEMP bool THIS::SetTransition(const std::string& rX1, const std::string& rEv, const std::string& rX2) {
1149 return BASE::SetTransition(rX1,rEv,rX2);
1150}
1151
1152
1153// SetTransition(x1, ev, x2)
1154TEMP bool THIS::SetTransition(Idx x1, Idx ev, Idx x2) {
1155 return BASE::SetTransition(Transition(x1,ev,x2));
1156}
1157
1158// SetTransition(rTransition, rAttr)
1159TEMP bool THIS::SetTransition(const Transition& rTransition, const TransAttr& rAttr) {
1160 return BASE::SetTransition(rTransition,rAttr);
1161}
1162
1163// SetTransition(trans,....)
1164TEMP bool THIS::SetTransition(const Transition& rTrans,
1165 const TimeConstraint& rGuard, const ClockSet& rResets) {
1166 FD_DG("TimedGenerator(" << this << ")::SetTransition(" << (BASE::TStr(rTrans)) <<", " <<
1167 rGuard.ToString() << ", " << rResets.ToString() << ") const");
1168 if(rResets.Empty() && rGuard.Empty()) {
1169 return BASE::SetTransition(rTrans);
1170 }
1171 TransAttr attr;
1172 attr.mGuard=rGuard;
1173 attr.mResets=rResets;
1174 attr.mGuard.Name("Guard");
1175 attr.mResets.Name("Resets");
1176#ifdef FAUDES_CHECKED
1177 ConsistentTimeConstraint(rGuard);
1178 ConsistentClocks(rResets);
1179#endif
1180 return BASE::SetTransition(rTrans,attr);
1181}
1182
1183// SetTransition(x1,ev,x2, ...)
1184TEMP bool THIS::SetTransition(Idx x1, Idx ev, Idx x2,
1185 const TimeConstraint& rGuard, const ClockSet& rResets) {
1186 return SetTransition(Transition(x1,ev,x2),rGuard,rResets);
1187}
1188
1189// SetTransition(X1,Ev,X2, ...)
1190TEMP bool THIS::SetTransition(
1191 const std::string& rX1, const std::string& rEv, const std::string& rX2,
1192 const TimeConstraint& rGuard, const ClockSet& rResets) {
1193 FD_DG("TimedGenerator(" << this << ")::SetTransition(" << rX1 << " " << rEv <<" " << rX2 <<
1194 rGuard.ToString() << ", " << rResets.ToString() << ") const");
1195 Idx x1=this->StateIndex(rX1);
1196 Idx ev=this->EventIndex(rEv);
1197 Idx x2=this->StateIndex(rX2);
1198 bool res=BASE::SetTransition(x1,ev,x2);
1199 if(rResets.Empty() && rGuard.Empty()) {
1200 return res;
1201 }
1202 TransAttr attr;
1203 attr.mResets=rResets;
1204 attr.mGuard=rGuard;
1205 attr.mGuard.Name("Guard");
1206 attr.mResets.Name("Resets");
1207#ifdef FAUDES_CHECKED
1208 ConsistentTimeConstraint(rGuard);
1209 ConsistentClocks(rResets);
1210#endif
1211 BASE::TransAttribute(Transition(x1,ev,x2),attr);
1212 return res;
1213}
1214
1215// Guard(trans)
1216TEMP const TimeConstraint& THIS::Guard(const Transition& rTrans) const {
1217#ifdef FAUDES_CHECKED
1218 if(!BASE::ExistsTransition(rTrans)) {
1219 std::stringstream errstr;
1220 errstr << "transition " << BASE::TStr(rTrans) << " not found " << std::endl;
1221 throw Exception("TimedGenerator::Guard(trans)", errstr.str(), 200);
1222 }
1223#endif
1224 return BASE::pTransRel->Attribute(rTrans).mGuard;
1225}
1226
1227
1228// Guardp(trans)
1229TEMP TimeConstraint* THIS::Guardp(const Transition& rTrans) {
1230#ifdef FAUDES_CHECKED
1231 if(!BASE::ExistsTransition(rTrans)) {
1232 std::stringstream errstr;
1233 errstr << "transition " << BASE::TStr(rTrans) << " not found " << std::endl;
1234 throw Exception("TimedGenerator::Guardp(trans)", errstr.str(), 200);
1235 }
1236#endif
1237 return &BASE::pTransRel->Attributep(rTrans)->mGuard;
1238}
1239
1240
1241// Guard(trans,guard)
1242TEMP void THIS::Guard(const Transition& rTrans, const TimeConstraint& rGuard) {
1243#ifdef FAUDES_CHECKED
1244 ConsistentTimeConstraint(rGuard);
1245 if(!BASE::ExistsTransition(rTrans)) {
1246 std::stringstream errstr;
1247 errstr << "transition " << BASE::TStr(rTrans) << " not found " << std::endl;
1248 throw Exception("TimedGenerator::Guard(trans,guard)", errstr.str(), 200);
1249 }
1250#endif
1251 BASE::pTransRel->Attributep(rTrans)->mGuard=rGuard;
1252 BASE::pTransRel->Attributep(rTrans)->mGuard.Name("Guard");
1253}
1254
1255// InsGuard(trans,guard)
1256TEMP void THIS::InsGuard(const Transition& rTrans, const TimeConstraint& rGuard) {
1257#ifdef FAUDES_CHECKED
1258 ConsistentTimeConstraint(rGuard);
1259 if(!BASE::ExistsTransition(rTrans)) {
1260 std::stringstream errstr;
1261 errstr << "transition " << BASE::TStr(rTrans) << " not found " << std::endl;
1262 throw Exception("TimedGenerator::InsGuard(trans,guard)", errstr.str(), 200);
1263 }
1264#endif
1265 if(!rGuard.Empty()) {
1266 BASE::pTransRel->Attributep(rTrans)->mGuard.Insert(rGuard);
1267 }
1268}
1269
1270// ClrGuard(trans)
1271TEMP void THIS::ClrGuard(const Transition& rTrans) {
1272#ifdef FAUDES_CHECKED
1273 if(!BASE::ExistsTransition(rTrans)) {
1274 std::stringstream errstr;
1275 errstr << "transition " << BASE::TStr(rTrans) << " not found " << std::endl;
1276 throw Exception("TimedGenerator::ClrGuard(trans)", errstr.str(), 200);
1277 }
1278#endif
1279 if(!BASE::pTransRel->Attribute(rTrans).IsDefault())
1280 BASE::pTransRel->Attributep(rTrans)->mGuard.Clear();
1281}
1282
1283
1284// Resets(trans)
1285TEMP const ClockSet& THIS::Resets(const Transition& rTrans) const {
1286#ifdef FAUDES_CHECKED
1287 if(!BASE::ExistsTransition(rTrans)) {
1288 std::stringstream errstr;
1289 errstr << "transition " << BASE::TStr(rTrans) << " not found " << std::endl;
1290 throw Exception("TimedGenerator::Resets(trans)", errstr.str(), 200);
1291 }
1292#endif
1293 return BASE::pTransRel->Attribute(rTrans).mResets;
1294}
1295
1296
1297// Resetsp(trans)
1298TEMP ClockSet* THIS::Resetsp(const Transition& rTrans) {
1299#ifdef FAUDES_CHECKED
1300 if(!BASE::ExistsTransition(rTrans)) {
1301 std::stringstream errstr;
1302 errstr << "transition " << BASE::TStr(rTrans) << " not found " << std::endl;
1303 throw Exception("TimedGenerator::Resetsp(trans)", errstr.str(), 200);
1304 }
1305#endif
1306 return &BASE::pTransRel->Attributep(rTrans)->mResets;
1307}
1308
1309
1310// Resets(trans,guard)
1311TEMP void THIS::Resets(const Transition& rTrans, const ClockSet& rResets) {
1312#ifdef FAUDES_CHECKED
1313 ConsistentClocks(rResets);
1314 if(!BASE::ExistsTransition(rTrans)) {
1315 std::stringstream errstr;
1316 errstr << "transition " << BASE::TStr(rTrans) << " not found " << std::endl;
1317 throw Exception("TimedGenerator::Resets(trans,guard)", errstr.str(), 200);
1318 }
1319#endif
1320 BASE::pTransRel->Attributep(rTrans)->mResets=rResets;
1321 BASE::pTransRel->Attributep(rTrans)->mResets.Name("Resets");
1322}
1323
1324// InsResets(trans,guard)
1325TEMP void THIS::InsResets(const Transition& rTrans, const ClockSet& rResets) {
1326#ifdef FAUDES_CHECKED
1327 ConsistentClocks(rResets);
1328 if(!BASE::ExistsTransition(rTrans)) {
1329 std::stringstream errstr;
1330 errstr << "transition " << BASE::TStr(rTrans) << " not found " << std::endl;
1331 throw Exception("TimedGenerator::InsResets(trans,guard)", errstr.str(), 200);
1332 }
1333#endif
1334 if(!rResets.Empty()) {
1335 BASE::pTransRel->Attributep(rTrans)->mResets.InsertSet(rResets);
1336 }
1337}
1338
1339
1340// ClrResets(trans)
1341TEMP void THIS::ClrResets(const Transition& rTrans) {
1342#ifdef FAUDES_CHECKED
1343 if(!BASE::ExistsTransition(rTrans)) {
1344 std::stringstream errstr;
1345 errstr << "transition " << BASE::TStr(rTrans) << " not found " << std::endl;
1346 throw Exception("TimedGenerator::ClrResets(trans)", errstr.str(), 200);
1347 }
1348#endif
1349 if(!BASE::pTransRel->Attribute(rTrans).IsDefault())
1350 BASE::pTransRel->Attributep(rTrans)->mGuard.Clear();
1351}
1352
1353
1354// Valid()
1355TEMP bool THIS::Valid(void) const {
1356 FD_DV("TimedGenerator(" << this << ")::Valid()");
1357 //call base
1358 if(!BASE::Valid()) return false;
1359 // check my names
1361 StateSet::Iterator sit;
1362 for(sit = BASE::StatesBegin(); sit!= BASE::StatesEnd(); ++sit) {
1363 if(Invariant(*sit).Name()!="Invariant") return false;
1364 }
1365 for(tit = BASE::TransRelBegin(); tit!= BASE::TransRelEnd(); ++tit) {
1366 if(Guard(*tit).Name()!="Guard") return false;
1367 if(Resets(*tit).Name()!="Resets") return false;
1368 }
1369 if(Clocks().Name()!="Clocks") return false;
1370 // check my clockset
1371 ClockSet aclocks=ActiveClocks();
1372 if(!(aclocks <= Clocks())) return false;
1373 // check all clocksymboltables
1374 for(sit = BASE::StatesBegin(); sit!= BASE::StatesEnd(); ++sit) {
1375 if(Invariant(*sit).ClockSymbolTablep()!=ClockSymbolTablep()) return false;
1376 }
1377 for(tit = BASE::TransRelBegin(); tit!= BASE::TransRelEnd(); ++tit) {
1378 if(Guard(*tit).ClockSymbolTablep()!=ClockSymbolTablep()) return false;
1379 if(Resets(*tit).SymbolTablep()!=ClockSymbolTablep()) return false;
1380 }
1381 if(Clocks().SymbolTablep()!=ClockSymbolTablep()) return false;
1382
1383 return true;
1384}
1385
1386
1387// UpdateAttributes()
1388TEMP bool THIS::UpdateAttributes(void) {
1389 FD_DG("TimedGenerator(" << this << ")::UpdateAttributes()");
1390
1391 // debugging example: flag blocking states
1392 // btw: need efficient methods to set/clr flags by sets
1393 StateSet blockstates=BASE::BlockingStates();
1394 StateSet::Iterator sit;
1395 for(sit=BASE::StatesBegin(); sit!= BASE::StatesEnd(); sit++) {
1396 StateAttr attr=BASE::StateAttribute(*sit);
1397 if(blockstates.Exists(*sit)) {
1398 attr.Set(0x20000000);
1399 } else {
1400 attr.Clr(0x20000000);
1401 }
1402 BASE::StateAttribute(*sit,attr);
1403 };
1404
1405 return true;
1406}
1407
1408
1409
1410// CStr(index)
1411TEMP std::string THIS::CStr(Idx index) const {
1412 return BASE::pGlobalAttribute->mClocks.Str(index);
1413}
1414
1415
1416
1417#undef BASE
1418#undef THIS
1419#undef TEMP
1420
1421
1422
1423} // namespace faudes
1424
1425
1426#endif
1427
#define TEMP
#define BASE
#define THIS
#define FD_DG(message)
#define FD_DV(message)
#define FAUDES_TAPI
static SymbolTable * GlobalClockSymbolTablep(void)
const std::string & Name(void) const
virtual void InsertSet(const NameSet &rOtherSet)
SymbolTable * SymbolTablep(void) const
void EraseSet(const NameSet &rOtherSet)
std::string ToString(void) const
std::string Name(void) const
ClockSet ActiveClocks(void) const
SymbolTable * ClockSymbolTablep(void) const
virtual const Type * Cast(const Type *pOther) const
virtual void Name(const std::string &rName)
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
bool Empty(void) const
bool Exists(const T &rElem) const
Iterator End(void) const
virtual AttributeVoid * Attributep(const T &rElem)
Iterator Begin(void) const
uint32_t Idx
TtGenerator< AttributeTimedGlobal, AttributeTimedState, AttributeCFlags, AttributeTimedTrans > TimedGenerator
TtGenerator< AttributeTimedGlobal, AttributeTimedState, AttributeCFlags, AttributeTimedTrans > tGenerator

libFAUDES 2.33k --- 2025.09.16 --- c++ api documentaion by doxygen