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