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

libFAUDES 2.34e --- 2026.03.16 --- c++ api documentaion by doxygen