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 wraping various global attributes of a FPGen including
35  * Fairness and lowest event priority.
36  * Note: this is not yet a propper faudes Attribute, it misses out on
37  * serialisation.
38  */
39 
41 
43 
44 public:
45  /**
46  * Default constructor
47  */
49 
50  /** Destructor */
51  virtual ~AttributePGenGl(void) {}
52 
53  /** Access members */
54  void LowestPriority(const Idx rPriority) { mPLowest = rPriority; }
55  Idx LowestPriority(void) const { return mPLowest; }
56  void HighestPriority(const Idx rPriority) { mPHighest = rPriority; }
57  Idx HighestPriority(void) const { return mPHighest; }
58  void Fairness(const FairnessConstraints& rFair) { mFairConsts = rFair; }
59  const FairnessConstraints& Fairness(void) const { return mFairConsts; }
60 
61  /**
62  * Clear (mandatory for serialisation)
63  */
64  void Clear(void) { mPLowest = 0; mPHighest=0; mFairConsts.Clear();}
65 
66 protected:
67  /**
68  * Assignment method.
69  *
70  * @param rSrcAttr
71  * Source to assign from
72  */
73  void DoAssign(const AttributePGenGl& rSrcAttr){mPLowest = rSrcAttr.mPLowest; mPHighest = rSrcAttr.mPHighest; mFairConsts = rSrcAttr.mFairConsts;}
74 
75  /**
76  * Test equality of configuration data.
77  *
78  * @param rOther
79  * Other attribute to compare with.
80  * @return
81  * True on match.
82  */
83  bool DoEqual(const AttributePGenGl& rOther) const {return (mPLowest == rOther.mPLowest && mPHighest == rOther.mPHighest && mFairConsts == rOther.mFairConsts);}
84 
85  /**
86  * Reads attribute from TokenReader, see AttributeVoid for public wrappers.
87  * Label and Context argument are ignored.
88  *
89  * @param rTr
90  * TokenReader to read from
91  * @param rLabel
92  * Section to read
93  * @param pContext
94  * Read context to provide contextual information
95  *
96  * @exception Exception
97  * - IO error (id 1)
98  */
99  virtual void DoRead(TokenReader& rTr, const std::string& rLabel="", const Type* pContext=nullptr){}
100 
101  /**
102  * Writes attribute to TokenWriter, see AttributeVoid for public wrappers.
103  * Label and Context argument are ignored.
104  *
105  * @param rTw
106  * TokenWriter to write to
107  * @param rLabel
108  * Section to write
109  * @param pContext
110  * Write context to provide contextual information
111  *
112  * @exception Exception
113  * - IO error (id 2)
114  */
115  virtual void DoWrite(TokenWriter& rTw,const std::string& rLabel="", const Type* pContext=nullptr) const {}
116 
117  /*!
118  * \brief mFairConst
119  * fairness constraints
120  */
122 
123  /**
124  * lowest priority value of globally all events (not only my alphabet).
125  */
126  Idx mPLowest = 0;
127 
128  /**
129  * highest priority value of globally all events (not only my alphabet).
130  */
131  Idx mPHighest = 0;
132 };
133 
134 
135 /**
136  * Generator with priositised events.
137  *
138  * @section PGeneratorOverview Overview
139  *
140  * The TpGenerator is a variant of the TcGenerator to add an interface for priositised events and fairness
141  *
142  * Technically, the construct is based on the specialized attribute class faudes::AttributePriority
143  * derived from faudes::AttributeCFlags. The TpGenerator expects an event attribute template parameter
144  * with the minimum interface defined in AttribuePriority and AttributeCFlags..
145  * For convenience, the configuration with the minimum attributes is been typedef-ed as PriositisedSystem.
146  *
147  * @ingroup GeneratorClasses
148  */
149 
150 template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
151  class FAUDES_TAPI TpGenerator : public TcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr> {
152  public:
153 
154 
155  /**
156  * Creates an emtpy PrioritisedSystem object
157  */
158  TpGenerator(void);
159 
160  /**
161  * PrioritisedSystem from a std Generator. Copy constructor
162  *
163  * @param rOtherGen
164  */
165  TpGenerator(const vGenerator& rOtherGen);
166 
167  /**
168  * PriositisedSystem from a PriositisedSystem. Copy constructor
169  *
170  * @param rOtherGen
171  */
172  TpGenerator(const TpGenerator& rOtherGen);
173 
174  /**
175  * Construct from file
176  *
177  * @param rFileName
178  * Filename
179  *
180  * @exception Exception
181  * If opening/reading fails an Exception object is thrown (id 1, 50, 51)
182  */
183  TpGenerator(const std::string& rFileName);
184 
185  /**
186  * Construct on heap
187  *
188  * @return
189  * new Generator
190  */
191  TpGenerator* New(void) const;
192 
193  /**
194  * Construct copy on heap
195  *
196  * @return
197  * new Generator
198  */
199  TpGenerator* Copy(void) const;
200 
201  /**
202  * Type test.
203  * Uses C++ dynamic cast to test whether the specified object
204  * casts to a Priositised System.
205  *
206  * @param pOther
207  * poinetr to object to test
208  *
209  * @return
210  * TpGenerator reference if dynamic cast succeeds, else NULL
211  */
212  virtual const Type* Cast(const Type* pOther) const {
213  return dynamic_cast< const TpGenerator* > (pOther); };
214 
215 
216  /**
217  * Construct on stack
218  *
219  * @return
220  * new Generator
221  */
222  TpGenerator NewPGen(void) const;
223 
224  /**
225  * Assignment operator (uses Assign)
226  *
227  * Note: you must reimplement this operator in derived
228  * classes in order to handle internal pointers correctly
229  *
230  * @param rOtherGen
231  * Other generator
232  */
233  /*virtual*/ TpGenerator& operator= (const TpGenerator& rOtherGen);
234 
235  /**
236  * Assignment method
237  *
238  * Note: you must reimplement this method in derived
239  * classes in order to handle internal pointers correctly
240  *
241  * @param rSource
242  * Other generator
243  */
244  virtual TpGenerator& Assign(const Type& rSource);
245 
246  /**
247  * Get priority by event index
248  *
249  * @param index
250  * Event index
251  * @return
252  * Priority of specified event
253  */
254  Idx Priority(const Idx index) const;
255 
256  /**
257  * Get priority by event name
258  *
259  * @param rName
260  * Event name
261  * @return
262  * Priority of specified event
263  */
264  Idx Priority(const std::string& rName) const;
265 
266  /**
267  * Set priority by event index
268  *
269  * @param index
270  * Specify event
271  * @param prio
272  * Specify priority
273  */
274  void Priority(const Idx index, const Idx prio);
275 
276  /**
277  * Set priority by event name
278  *
279  * @param rName
280  * Specify event
281  * @param prio
282  * Specify priority
283  */
284  void Priority(const std::string& rName, const Idx prio);
285 
286  /**
287  * Set Priorities from other prioritised event set
288  *
289  * @param rOtherSet
290  * set to get priorities from
291  *
292  */
293  void Priorities(const TpEventSet<EventAttr>& rOtherSet);
294 
295  /**
296  * Get Priorities
297  *
298  *
299  */
300  EventPriorities Priorities(void) const;
301 
302  /**
303  * Get lowest priority
304  * Note: this is a dumb member -- you need to set it programatically
305  *
306  * @return
307  * lowest priority
308  *
309  */
310  Idx LowestPriority(void) const;
311 
312  /**
313  * Set lowest priority
314  * Note: this is a dumb member -- you need to set it programatically
315  *
316  * @param
317  * lowest priority
318  *
319  */
320  void LowestPriority(Idx prio);
321 
322  /**
323  * Get highest priority
324  * Note: this is a dumb member -- you need to set it programatically
325  *
326  * @return
327  * highest priority
328  *
329  */
330  Idx HighestPriority(void) const;
331 
332  /**
333  * Set highest priority
334  * Note: this is a dumb member -- you need to set it programatically
335  *
336  * @param
337  * highest priority
338  *
339  */
340  void HighestPriority(Idx prio);
341 
342  /**
343  * Get fairness constraints
344  *
345  * @return
346  * vector of fainess eventsets
347  *
348  */
349  FairnessConstraints Fairness(void) const;
350 
351  /**
352  * Set fairness constraints
353  *
354  * @param
355  * fairness constraints
356  *
357  */
358  void Fairness(const FairnessConstraints& rFair);
359 
360 
361 
362 }; // end class TpGenerator
363 
364 
365 /**
366  * Convenience typedef for std prioritised generator
367  */
369 
370 
371 // Tyoedef for compatibility with YT's original code / internal use
373 
374 /**
375  * Convenience typedef for vectors of priositised systems
376  * \ingroup GeneratorClasses
377  */
378  //typedef TBaseVector<PriositisedSystem> PrioritisedSystemVector;
379 
380 
381 
382 
383 /*
384 ***************************************************************************
385 ***************************************************************************
386 ***************************************************************************
387 
388 Implementation pGenerator
389 
390 ***************************************************************************
391 ***************************************************************************
392 ***************************************************************************
393 */
394 
395 /* convenience access to relevant scopes */
396 #define THIS TpGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
397 #define BASE TcGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
398 #define TEMP template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
399 
400 
401 // TpGenerator(void)
402 TEMP THIS::TpGenerator(void) : BASE() {
403  FD_DG("TpGenerator(" << this << ")::TpGenerator()");
404 }
405 
406 // TpGenerator(rOtherGen)
407 TEMP THIS::TpGenerator(const TpGenerator& rOtherGen) : BASE(rOtherGen) {
408  FD_DG("TpGenerator(" << this << ")::TpGenerator(rOtherGen)");
409 }
410 
411 // TpGenerator(rOtherGen)
412 TEMP THIS::TpGenerator(const vGenerator& rOtherGen) : BASE(rOtherGen) {
413  FD_DG("TpGenerator(" << this << ")::TpGenerator(rOtherGen)");
414 }
415 
416 // TpGenerator(rFilename)
417 TEMP THIS::TpGenerator(const std::string& rFileName) : BASE(rFileName) {
418  FD_DG("TpGenerator(" << this << ")::TpGenerator(rFilename) : done");
419 }
420 
421 // operator=
422 TEMP THIS& THIS::operator= (const TpGenerator& rOtherGen) {
423  FD_DG("TpGenerator(" << this << ")::operator = [v]" << &rOtherGen);
424  return Assign(rOtherGen);
425 }
426 
427 // copy from other faudes type
428 TEMP THIS& THIS::Assign(const Type& rSrc) {
429  FD_DG("TpGenerator(" << this << ")::Assign([type] " << &rSrc << ")");
430  // bail out on match
431  if(&rSrc==static_cast<const Type*>(this)) return *this;
432  // pass on to base
433  FD_DG("TpGenerator(" << this << ")::Assign([type] " << &rSrc << "): call base");
434  BASE::Assign(rSrc);
435  return *this;
436 }
437 
438 // New
439 TEMP THIS* THIS::New(void) const {
440  // allocate
441  THIS* res = new THIS;
442  // fix base data
443  res->EventSymbolTablep(BASE::mpEventSymbolTable);
444  res->mStateNamesEnabled=BASE::mStateNamesEnabled;
445  res->mReindexOnWrite=BASE::mReindexOnWrite;
446  return res;
447 }
448 
449 // Copy
450 TEMP THIS* THIS::Copy(void) const {
451  // allocate
452  THIS* res = new THIS(*this);
453  // done
454  return res;
455 }
456 
457 // NewPGen
458 TEMP THIS THIS::NewPGen(void) const {
459  // call base (fixes by assignment constructor)
460  THIS res= BASE::NewCGen();
461  return res;
462 }
463 
464 
465 // CAST
466 //TEMP const Type* THIS::Cast(const Type* pOther) const {
467 // return dynamic_cast< const THIS* > (pOther);
468 //}
469 
470 
471 // Priority(index)
472 TEMP Idx THIS::Priority(const Idx index) const {
473  return this->EventAttribute(index).Priority();
474 }
475 
476 // Priority(name)
477 TEMP Idx THIS::Priority(const std::string& rName) const {
478  return this->EventAttribute(rName).Priority();
479 }
480 
481 // Priority(index,prio)
482 TEMP void THIS::Priority(const Idx index, const Idx prio) {
483  this->EventAttributep(index)->Priority(prio);
484 }
485 
486 // Priority(name,prio)
487 TEMP void THIS::Priority(const std::string& rName, Idx prio) {
488  this->EventAttributep(rName)->Priority(prio);
489 }
490 
491 // Priorities(otherset)
492 TEMP void THIS::Priorities(const TpEventSet<EventAttr>& rOtherSet) {
493  NameSet::Iterator eit=this->AlphabetBegin();
494  NameSet::Iterator eit_end=this->AlphabetEnd();
495  for(;eit!=eit_end;++eit) {
496  if(rOtherSet.Exists(*eit))
497  Priority(*eit,rOtherSet.Priority(*eit));
498  }
499 }
500 
501 // Priorities()
502 TEMP EventPriorities THIS::Priorities(void) const {
503  EventPriorities res;
504  NameSet::Iterator eit=this->AlphabetBegin();
505  NameSet::Iterator eit_end=this->AlphabetEnd();
506  for(;eit!=eit_end;++eit) {
507  res.InsPriority(*eit,this->Priority(*eit));
508  }
509  return res;
510 }
511 // LowestPriority
512 TEMP Idx THIS::LowestPriority(void) const {
513  return this->GlobalAttribute().LowestPriority();
514 }
515 
516 // LowestPriority
517 TEMP void THIS::LowestPriority(Idx prio) {
518  this->GlobalAttributep()->LowestPriority(prio);
519 }
520 
521 // HighestPriority
522 TEMP Idx THIS::HighestPriority(void) const {
523  return this->GlobalAttribute().HighestPriority();
524 }
525 
526 // HighestPriority
527 TEMP void THIS::HighestPriority(Idx prio) {
528  this->GlobalAttributep()->HighestPriority(prio);
529 }
530 
531 // Fairness
532 TEMP FairnessConstraints THIS::Fairness(void) const {
533  return this->GlobalAttribute().Fairness();
534 }
535 
536 // Fairness
537 TEMP void THIS::Fairness(const FairnessConstraints& rFair) {
538  this->GlobalAttributep()->Fairness(rFair);
539 }
540 
541 
542 
543 
544 #undef TEMP
545 #undef BASE
546 #undef THIS
547 
548 
549 
550 } // namespace faudes
551 #endif // PEV_GENERATOR_H
#define FD_DG(message)
#define FAUDES_API
Definition: cfl_platform.h:80
#define FAUDES_TAPI
Definition: cfl_platform.h:83
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
Definition: cfl_types.h:872
The AttributePGenGl class Class wraping various global attributes of a FPGen including Fairness and l...
FairnessConstraints mFairConsts
mFairConst fairness constraints
virtual ~AttributePGenGl(void)
void LowestPriority(const Idx rPriority)
Idx LowestPriority(void) const
const FairnessConstraints & Fairness(void) const
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=nullptr)
void Fairness(const FairnessConstraints &rFair)
void HighestPriority(const Idx rPriority)
bool DoEqual(const AttributePGenGl &rOther) const
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=nullptr) const
Idx HighestPriority(void) const
void DoAssign(const AttributePGenGl &rSrcAttr)
Idx Priority(const std::string &rName) const
void InsPriority(const Idx idx, const Idx prio)
virtual const Type * Cast(const Type *pOther) const
#define THIS
uint32_t Idx
TpGenerator< AttributePGenGl, AttributeVoid, AttributePriority, AttributeVoid > PrioritisedGenerator
TpGenerator< AttributePGenGl, AttributeVoid, AttributePriority, AttributeVoid > pGenerator
#define TEMP
#define BASE

libFAUDES 2.33b --- 2025.05.07 --- c++ api documentaion by doxygen