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

libFAUDES 2.33h --- 2025.06.18 --- c++ api documentaion by doxygen