pev_pgenerator.h
Go to the documentation of this file.
1 /** @file pev_pgenerator.h Classes pGenerator */
2 
3 
4 /* FAU Discrete Event Systems Library (libfaudes)
5 
6  Copyright (C) 2025 Yiheng Tang, Thomas Moor
7  Exclusive copyright is granted to Klaus Schmidt
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef FAUDES_PEV_PGENERATOR_H
24 #define FAUDES_PEV_PGENERATOR_H
25 
26 #include "corefaudes.h"
27 #include "pev_priorities.h"
28 
29 namespace faudes {
30 
31 
32 /*!
33  * \brief The AttributePGenGl class
34  * Class wrapping various global attributes of a FPGen
35  */
36 
38 
40 
41 public:
42  /**
43  * Default constructor
44  */
45  AttributePGenGl(void);
46 
47  /** Destructor */
48  virtual ~AttributePGenGl(void) {}
49 
50  /** Access members */
51  void Fairness(const FairnessConstraints& rFair) { mFairCons = rFair; }
52  const FairnessConstraints& Fairness(void) const { return mFairCons; }
53 
54  /**
55  * Clear (mandatory for serialisation)
56  */
57  void Clear(void) { mFairCons.Clear();}
58 
59  /**
60  * Test for default value
61  */
62  bool IsDefault(void) const {return mFairCons.Empty();};
63 
64 protected:
65  /**
66  * Assignment method.
67  *
68  * @param rSrcAttr
69  * Source to assign from
70  */
71  void DoAssign(const AttributePGenGl& rSrcAttr) {mFairCons = rSrcAttr.mFairCons;}
72 
73  /**
74  * Test equality of configuration data.
75  *
76  * @param rOther
77  * Other attribute to compare with.
78  * @return
79  * True on match.
80  */
81  bool DoEqual(const AttributePGenGl& rOther) const {return (mFairCons == rOther.mFairCons);}
82 
83  /**
84  * Reads attribute from TokenReader, see AttributeVoid for public wrappers.
85  * Label and Context argument are ignored.
86  *
87  * @param rTr
88  * TokenReader to read from
89  * @param rLabel
90  * Section to read
91  * @param pContext
92  * Read context to provide contextual information
93  *
94  * @exception Exception
95  * - IO error (id 1)
96  */
97  virtual void DoRead(TokenReader& rTr, const std::string& rLabel="", const Type* pContext=nullptr);
98 
99  /**
100  * Writes attribute to TokenWriter, see AttributeVoid for public wrappers.
101  * Label and Context argument are ignored.
102  *
103  * @param rTw
104  * TokenWriter to write to
105  * @param rLabel
106  * Section to write
107  * @param pContext
108  * Write context to provide contextual information
109  *
110  * @exception Exception
111  * - IO error (id 2)
112  */
113  virtual void DoWrite(TokenWriter& rTw,const std::string& rLabel="", const Type* pContext=nullptr) const;
114 
115  /**
116  * Writes attribute to TokenWriter, see AttributeVoid for public wrappers.
117  * Label and Context argument are ignored.
118  *
119  * @param rTw
120  * TokenWriter to write to
121  * @param rLabel
122  * Section to write
123  * @param pContext
124  * Write context to provide contextual information
125  *
126  * @exception Exception
127  * - IO error (id 2)
128  */
129  virtual void DoXWrite(TokenWriter& rTw,const std::string& rLabel="", const Type* pContext=nullptr) const;
130 
131  /*!
132  * \brief mFairConst
133  * fairness constraints
134  */
136 
137 };
138 
139 
140 /**
141  * Generator with priositised events.
142  *
143  * @section PGeneratorOverview Overview
144  *
145  * The TpGenerator is a variant of the TcGenerator to add an interface for priositised events and fairness
146  *
147  * Technically, the construct is based on the specialized attribute class faudes::AttributePriority
148  * derived from faudes::AttributeCFlags. The TpGenerator expects an event attribute template parameter
149  * with the minimum interface defined in AttribuePriority and AttributeCFlags..
150  * For convenience, the configuration with the minimum attributes is been typedef-ed as PriositisedSystem.
151  *
152  * @ingroup GeneratorClasses
153  */
154 
155 template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
156  class FAUDES_TAPI TpGenerator : public TcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr> {
157  public:
158 
159 
160  /**
161  * Creates an emtpy PrioritisedSystem object
162  */
163  TpGenerator(void);
164 
165  /**
166  * PrioritisedSystem from a std Generator. Copy constructor
167  *
168  * @param rOtherGen
169  */
170  TpGenerator(const vGenerator& rOtherGen);
171 
172  /**
173  * PriositisedSystem from a PriositisedSystem. Copy constructor
174  *
175  * @param rOtherGen
176  */
177  TpGenerator(const TpGenerator& rOtherGen);
178 
179  /**
180  * Construct from file
181  *
182  * @param rFileName
183  * Filename
184  *
185  * @exception Exception
186  * If opening/reading fails an Exception object is thrown (id 1, 50, 51)
187  */
188  TpGenerator(const std::string& rFileName);
189 
190  /**
191  * Construct on heap
192  *
193  * @return
194  * new Generator
195  */
196  TpGenerator* New(void) const;
197 
198  /**
199  * Construct copy on heap
200  *
201  * @return
202  * new Generator
203  */
204  TpGenerator* Copy(void) const;
205 
206  /**
207  * Type test.
208  * Uses C++ dynamic cast to test whether the specified object
209  * casts to a Priositised System.
210  *
211  * @param pOther
212  * poinetr to object to test
213  *
214  * @return
215  * TpGenerator reference if dynamic cast succeeds, else NULL
216  */
217  virtual const Type* Cast(const Type* pOther) const {
218  return dynamic_cast< const TpGenerator* > (pOther); };
219 
220 
221  /**
222  * Construct on stack
223  *
224  * @return
225  * new Generator
226  */
227  TpGenerator NewPGen(void) const;
228 
229  /**
230  * Assignment operator (uses Assign)
231  *
232  * Note: you must reimplement this operator in derived
233  * classes in order to handle internal pointers correctly
234  *
235  * @param rOtherGen
236  * Other generator
237  */
238  TpGenerator& operator= (const TpGenerator& rOtherGen);
239 
240  /**
241  * Assignment method
242  *
243  * Note: you must reimplement this method in derived
244  * classes in order to handle internal pointers correctly
245  *
246  * @param rSource
247  * Other generator
248  */
249  virtual TpGenerator& Assign(const Type& rSource);
250 
251  /**
252  * Clear (mandatory for serialisation)
253  */
254  void Clear(void);
255  /**
256  * Get priority by event index
257  *
258  * @param index
259  * Event index
260  * @return
261  * Priority of specified event
262  */
263  Idx Priority(const Idx index) const;
264 
265  /**
266  * Get priority by event name
267  *
268  * @param rName
269  * Event name
270  * @return
271  * Priority of specified event
272  */
273  Idx Priority(const std::string& rName) const;
274 
275  /**
276  * Set priority by event index
277  *
278  * @param index
279  * Specify event
280  * @param prio
281  * Specify priority
282  */
283  void Priority(const Idx index, const Idx prio);
284 
285  /**
286  * Set priority by event name
287  *
288  * @param rName
289  * Specify event
290  * @param prio
291  * Specify priority
292  */
293  void Priority(const std::string& rName, const Idx prio);
294 
295  /**
296  * Set Priorities from other prioritised event set
297  *
298  * @param rOtherSet
299  * set to get priorities from
300  *
301  */
302  void Priorities(const TpEventSet<EventAttr>& rOtherSet);
303 
304  /**
305  * Get Priorities
306  *
307  */
308  EventPriorities Priorities(void) const;
309 
310  /**
311  * Get lowest priority
312  * Note: this is a dumb member -- you need to set it programatically
313  *
314  * @return
315  * lowest priority
316  *
317  */
318  Idx LowestPriority(void) const;
319 
320  /**
321  * Set lowest priority
322  * Note: this is a dumb member -- you need to set it programatically
323  *
324  * @param
325  * lowest priority
326  *
327  */
328  void LowestPriority(const Idx rPriority);
329 
330  /**
331  * Get highest priority
332  * Note: this is a dumb member -- you need to set it programatically
333  *
334  * @return
335  * highest priority
336  *
337  */
338  void HighestPriority(const Idx rPriority);
339 
340  /**
341  * Set highest priority
342  * Note: this is a dumb member -- you need to set it programatically
343  *
344  * @param
345  * highest priority
346  *
347  */
348  Idx HighestPriority(void) const;
349 
350  /**
351  * Get fairness constraints
352  *
353  * @return
354  * vector of fainess eventsets
355  *
356  */
357  FairnessConstraints Fairness(void) const;
358 
359  /**
360  * Set fairness constraints
361  *
362  * @param
363  * fairness constraints
364  *
365  */
366  void Fairness(const FairnessConstraints& rFair);
367 
368 
369 protected:
370 
371  /** need to reimplement to care about additional members */
372  void DoAssign(const TpGenerator& rSrc);
373 
374  /** need to reimplement to care about additional members */
375  bool DoEqual(const TpGenerator& rOther) const;
376 
377  /**
378  * lowest priority value of globally all events (not only my alphabet).
379  */
380  Idx mPLowest = 0;
381 
382  /**
383  * highest priority value of globally all events (not only my alphabet).
384  */
385  Idx mPHighest = 0;
386 
387 
388 }; // end class TpGenerator
389 
390 
391 /**
392  * Convenience typedef for std prioritised generator
393  */
395 
396 
397 /**
398  * Convenience typedef for vectors of priositised systems
399  * @ingroup GeneratorClasses
400  */
402 
403 
404 // Tyoedef for compatibility with YT's original code / internal use
406 
407 
408 /*
409 ***************************************************************************
410 ***************************************************************************
411 ***************************************************************************
412 
413 Implementation pGenerator
414 
415 ***************************************************************************
416 ***************************************************************************
417 ***************************************************************************
418 */
419 
420 /* convenience access to relevant scopes */
421 #define THIS TpGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
422 #define BASE TcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
423 #define TEMP template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
424 
425 
426 // TpGenerator(void)
427 TEMP THIS::TpGenerator(void) : BASE() {
428  FD_DG("TpGenerator(" << this << ")::TpGenerator()");
429  // my members
430  mPLowest = 0;
431  mPHighest = 0;
432 }
433 
434 // TpGenerator(rOtherGen)
435 TEMP THIS::TpGenerator(const TpGenerator& rOtherGen) : BASE() {
436  FD_DG("TpGenerator(" << this << ")::TpGenerator(rOtherGen)");
437  // my members
438  mPLowest = 0;
439  mPHighest = 0;
440  // full assign
441  DoAssign(rOtherGen);
442 }
443 
444 // TpGenerator(rOtherGen)
445 TEMP THIS::TpGenerator(const vGenerator& rOtherGen) : BASE() {
446  FD_DG("TpGenerator(" << this << ")::TpGenerator(rOtherGen)");
447  // my members
448  mPLowest = 0;
449  mPHighest = 0;
450  // try best
451  Assign(rOtherGen);
452 }
453 
454 // TpGenerator(rFilename)
455 TEMP THIS::TpGenerator(const std::string& rFileName) : BASE() {
456  FD_DG("TpGenerator(" << this << ")::TpGenerator(rFilename)");
457  this->Read(rFileName);
458  // my members
459  mPLowest = 0;
460  mPHighest = 0;
461 }
462 
463 // full assign of matching type (not virtual)
464 TEMP void THIS::DoAssign(const TpGenerator& rSrc) {
465  FD_DG("TpGenerator(" << this << ")::operator = [v]" << &rOtherGen);
466  // recursive call base, incl virtual clear
467  BASE::DoAssign(rSrc);
468  // my members
469  mPLowest = rSrc.mPLowest;
470  mPHighest = rSrc.mPHighest;
471 }
472 
473 // operator=
474 TEMP THIS& THIS::operator= (const TpGenerator& rOtherGen) {
475  FD_DG("TpGenerator(" << this << ")::operator = [v]" << &rOtherGen);
476  DoAssign(rOtherGen);
477  return *this;
478 }
479 
480 // copy from other faudes type
481 TEMP THIS& THIS::Assign(const Type& rSrc) {
482  FD_DG("TpGenerator(" << this << ")::Assign([type] " << &rSrc << ")");
483  // bail out on match
484  if(&rSrc==static_cast<const Type*>(this))
485  return *this;
486  // dot if we can
487  const THIS* pgen=dynamic_cast<const THIS*>(&rSrc);
488  if(pgen!=nullptr) {
489  DoAssign(*pgen);
490  return *this;
491  }
492  // pass on to base
493  FD_DG("TpGenerator(" << this << ")::Assign([type] " << &rSrc << "): call base");
494  BASE::Assign(rSrc);
495  return *this;
496 }
497 
498 // New
499 TEMP THIS* THIS::New(void) const {
500  // allocate
501  THIS* res = new THIS;
502  // fix base data
503  res->EventSymbolTablep(BASE::mpEventSymbolTable);
504  res->mStateNamesEnabled=BASE::mStateNamesEnabled;
505  res->mReindexOnWrite=BASE::mReindexOnWrite;
506  return res;
507 }
508 
509 // Copy
510 TEMP THIS* THIS::Copy(void) const {
511  // allocate
512  THIS* res = new THIS(*this);
513  // done
514  return res;
515 }
516 
517 // virtual
518 TEMP void THIS::Clear(void) {
519  // base mmbers
520  BASE::Clear();
521  // my menbers
522  mPLowest = 0;
523  mPHighest = 0;
524 }
525 
526 
527 // CAST
528 //TEMP const Type* THIS::Cast(const Type* pOther) const {
529 // return dynamic_cast< const THIS* > (pOther);
530 //}
531 
532 
533 // Priority(index)
534 TEMP Idx THIS::Priority(const Idx index) const {
535  return this->EventAttribute(index).Priority();
536 }
537 
538 // Priority(name)
539 TEMP Idx THIS::Priority(const std::string& rName) const {
540  return this->EventAttribute(rName).Priority();
541 }
542 
543 // Priority(index,prio)
544 TEMP void THIS::Priority(const Idx index, const Idx prio) {
545  this->EventAttributep(index)->Priority(prio);
546 }
547 
548 // Priority(name,prio)
549 TEMP void THIS::Priority(const std::string& rName, Idx prio) {
550  this->EventAttributep(rName)->Priority(prio);
551 }
552 
553 // Priorities(otherset)
554 TEMP void THIS::Priorities(const TpEventSet<EventAttr>& rOtherSet) {
555  FD_DG("TpGenerator(" << this << ")::Priorities(src)");
556  NameSet::Iterator eit=this->AlphabetBegin();
557  NameSet::Iterator eit_end=this->AlphabetEnd();
558  for(;eit!=eit_end;++eit) {
559  if(rOtherSet.Exists(*eit))
560  Priority(*eit,rOtherSet.Priority(*eit));
561  }
562  FD_DG("TpGenerator(" << this << ")::Priorities(src): done");
563 }
564 
565 // Priorities()
566 TEMP EventPriorities THIS::Priorities(void) const {
567  FD_DG("TpGenerator(" << this << ")::Priorities()");
568  EventPriorities res;
569  NameSet::Iterator eit=this->AlphabetBegin();
570  NameSet::Iterator eit_end=this->AlphabetEnd();
571  for(;eit!=eit_end;++eit) {
572  res.InsPriority(*eit,this->Priority(*eit));
573  }
574  FD_DG("TpGenerator(" << this << ")::Priorities():done");
575  return res;
576 }
577 // LowestPriority
578 TEMP Idx THIS::LowestPriority(void) const {
579  return mPLowest;
580 }
581 
582 // LowestPriority
583 TEMP void THIS::LowestPriority(Idx prio) {
584  mPLowest=prio;
585 }
586 
587 // HighestPriority
588 TEMP Idx THIS::HighestPriority(void) const {
589  return mPHighest;
590 }
591 
592 // HighestPriority
593 TEMP void THIS::HighestPriority(Idx prio) {
594  mPHighest=prio;
595 }
596 
597 // Fairness
598 TEMP FairnessConstraints THIS::Fairness(void) const {
599  return this->GlobalAttribute().Fairness();
600 }
601 
602 // Fairness
603 TEMP void THIS::Fairness(const FairnessConstraints& rFair) {
604  this->GlobalAttributep()->Fairness(rFair);
605 }
606 
607 //todo
608 //bool DoEqual(const AttributePGenGl& rOther) const {return (mFairConsts == rOther.mFairConsts);}
609 
610 
611 
612 #undef TEMP
613 #undef BASE
614 #undef THIS
615 
616 
617 
618 } // namespace faudes
619 #endif // PEV_GENERATOR_H
#define FD_DG(message)
#define FAUDES_API
Definition: cfl_platform.h:85
#define FAUDES_TAPI
Definition: cfl_platform.h:88
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
Definition: cfl_types.h:879
The AttributePGenGl class Class wrapping various global attributes of a FPGen.
virtual ~AttributePGenGl(void)
const FairnessConstraints & Fairness(void) const
void Fairness(const FairnessConstraints &rFair)
bool DoEqual(const AttributePGenGl &rOther) const
FairnessConstraints mFairCons
mFairConst fairness constraints
bool IsDefault(void) const
void DoAssign(const AttributePGenGl &rSrcAttr)
Idx Priority(const std::string &rName) const
void InsPriority(const Idx idx, const Idx prio)
TpGenerator NewPGen(void) const
void DoAssign(const TpGenerator &rSrc)
virtual TpGenerator & Assign(const Type &rSource)
bool DoEqual(const TpGenerator &rOther) const
virtual const Type * Cast(const Type *pOther) const
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
Definition: cfl_types.cpp:267
TBaseVector< FairGenerator > FairGeneratorVector
uint32_t Idx
TpGenerator< AttributePGenGl, AttributeVoid, AttributePriority, AttributeVoid > pGenerator
TpGenerator< AttributePGenGl, AttributeVoid, AttributePriority, AttributeVoid > FairGenerator
#define TEMP
#define BASE
#define THIS

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