cfl_nameset.h
Go to the documentation of this file.
1/** @file cfl_nameset.h @brief Classes NameSet, TaNameSet */
2
3/* FAU Discrete Event Systems Library (libfaudes)
4
5 Copyright (C) 2006 Bernd Opitz
6 Copyright (C) 2008-2025 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
24#ifndef FAUDES_NAMESET_H
25#define FAUDES_NAMESET_H
26
27#include "cfl_definitions.h"
28#include "cfl_exception.h"
29#include "cfl_basevector.h"
30#include "cfl_attrmap.h"
31#include "cfl_symboltable.h"
32#include "cfl_registry.h"
33
34namespace faudes {
35
36/** @addtogroup Container Classes */
37/** @{ */
38
39// Forward declaration for the attributed version of nameset
40template<class Attr> class TaNameSet;
41
42
43/**
44 * Set of indices with symbolic names.
45 * In a NameSet, symbolic names are mandatory.
46 * The class is derived from IndexSet and uses a pointer to a SymbolTable
47 * to maintain the symbolic names. The static SymbolTable is used as default,
48 * which in the context of libfaudes becomes the global event symbol table.
49 * It is an error to refer to an unknown symbolic name or to an index
50 * with no name associated. When FAUDES_CHECKED is defined, an exception will
51 * be thrown. It is also considered an error to relate two NameSets that refer to
52 * different SymbolTables (using e.g. SetUnion).
53 *
54 *
55 * Since symbolic names are mandatory, file IO uses names rather than indices.
56 * Technically, file IO is done by TaNameSet functions. This requires a copy and for
57 * that reason may be reimplemented in a future versions.
58 * The format is demonstrated by the following example
59 * of a set with name "Alphabet" consisting of events "alpha", "beta" and "gamma":
60 * \code
61 * <Alphabet>
62 * "alpha" "beta" "gamma"
63 * <\Alphabet>
64 * \endcode
65 * Note that when reading a file, indices will be associated with the symbolic names
66 * based on availability. Within one libfaudes session, each individual event will
67 * be referred to by a unique index.
68 */
69
70class FAUDES_API NameSet : public TBaseSet<Idx> {
71
73
74public:
75
76 using TBaseSet<Idx>::operator=;
77 using TBaseSet<Idx>::operator==;
78 using TBaseSet<Idx>::operator!=;
79
80 /**
81 * We implement "protected privacy for template classes" by friendship.
82 * This is used for the pragmatic implemention of conversion constructors.
83 */
84 template<class Attr> friend class TaNameSet;
85
86 /**
87 * Constructor for NameSet referring to the static SymbolTable.
88 */
89 NameSet(void);
90
91 /**
92 * Copy-constructor from other NameSet.
93 * This also copies the SymbolTable reference, hence the new NameSet
94 * will use the same SymbolTable as rOtherSet.
95 *
96 * @param rOtherSet
97 * Set to copy
98 */
99 NameSet(const NameSet& rOtherSet);
100
101
102 /**
103 * Constructor from file.
104 * This constructor reads a NameSet from a file using the DoRead(TokenReader&, const std::string&)
105 * function. The section is specified by rLabel and the static SymbolTable is used.
106 *
107 *
108 * @param rFilename
109 * Name of file
110 * @param rLabel
111 * Section for the set in the file;
112 */
113 NameSet(const std::string& rFilename, const std::string& rLabel = "");
114
115 /**
116 * Virtual destructor
117 */
118 virtual ~NameSet(void);
119
120 /**
121 * Get Pointer mpSymbolTable.
122 *
123 * @return
124 * Pointer mpSymbolTable
125 */
126 SymbolTable* SymbolTablep(void) const;
127
128 /**
129 * Set SymbolTable reference.
130 * This function sets the reference to the SymbolTable. The current implementation
131 * clears the set, future versions may implement a re-indexing.
132 *
133 * @param pSymTab
134 * Pointer to SymbolTable
135 */
136 void SymbolTablep(SymbolTable* pSymTab);
137
138 /**
139 * Iterators on nameset.
140 */
141 using TBaseSet<Idx>::Iterator;
142
143 /**
144 * Add an element by index.
145 * Index must be already known to the global SymbolTable.
146 *
147 * @param rIndex
148 * Index to add
149 * @return
150 * True, if element was new to set
151 * @exception Exception
152 * - no symbolic name for index (id 65)
153 */
154 bool Insert(const Idx& rIndex);
155
156 /**
157 * Add an element by its symbolic name. If the name is unknown,
158 * a new index will be generated and recorded in the symboltable.
159 * If the name is known, the corresponding index will be added to the set.
160 *
161 * @param rName
162 * Symbolic name of element to add
163 *
164 * @return
165 * Index of (new) element
166 */
167 Idx Insert(const std::string& rName);
168
169 /**
170 * Inserts all elements of rOtherSet.
171 *
172 * @param rOtherSet
173 * Other NameSet
174 * @exception Exception
175 * - symboltable mismatch (id 67)
176 */
177 virtual void InsertSet(const NameSet& rOtherSet);
178
179 /**
180 * Inserts all elements of rOtherSet.
181 *
182 * This variant requires a runtime cast to access the synboltable.
183 * An expection is thrown if the cast fails.
184 *
185 * @param rOtherSet
186 * Other NameSet
187 * @exception Exception
188 * - symboltable mismatch (id 67)
189 * - cast to nameset failed (id 67)
190 */
191 virtual void InsertSet(const TBaseSet<Idx>& rOtherSet);
192
193 /**
194 * Delete element by index. The symbolic name is not removed from the SymbolTable.
195 *
196 * @param rIndex
197 * Index
198 * @return
199 * True if element did exist
200 */
201 virtual bool Erase(const Idx& rIndex);
202
203 /**
204 * Delete element by symbolic name. The symbolic name is not removed from the SymbolTable
205 *
206 * @param rName
207 * symbolic name
208 * @return
209 * True if element did exist
210 * @exception Exception
211 * - unknown symbolic name (id 66)
212 */
213 virtual bool Erase(const std::string& rName);
214
215 /**
216 * Delete element by iterator. Symbolic nam is not removed from SymbolTable.
217 *
218 * @param pos
219 * NameSet::iterator
220 * @return
221 * iterator to next element
222 * @exception Exception
223 * - invalid iterator (id 62)
224 */
225 virtual NameSet::Iterator Erase(const Iterator& pos);
226
227 /**
228 * Erase elements specified by rOtherSet
229 *
230 * @param rOtherSet
231 * Other StateSet
232 * @exception Exception
233 * - symboltable mismatch (id 67)
234 */
235 void EraseSet(const NameSet& rOtherSet);
236
237 /**
238 * Erase elements specified by rOtherSet
239 *
240 * This function requires a runtime cast to access the synboltable.
241 * An expection is thrown if the cast fails.
242 *
243 * @param rOtherSet
244 * Other NameSet
245 * @exception Exception
246 * - symboltable mismatch (id 67)
247 * - cast to nameset failed (id 67)
248 */
249 virtual void EraseSet(const TBaseSet<Idx>& rOtherSet);
250
251 /**
252 * Restrict to elements specified by rOtherSet
253 *
254 * @param rOtherSet
255 * Other StateSet
256 * @exception Exception
257 * - symboltable mismatch (id 67)
258 */
259 void RestrictSet(const NameSet& rOtherSet);
260
261 /**
262 * Restrict to elements specified by rOtherSet
263 *
264 * This function requires a runtime cast to access the synboltable.
265 * An expection is thrown if the cast fails.
266 *
267 * @param rOtherSet
268 * Other NameSet
269 * @exception Exception
270 * - symboltable mismatch (id 67)
271 * - cast to nameset failed (id 67)
272 */
273 virtual void RestrictSet(const TBaseSet<Idx>& rOtherSet);
274
275 /**
276 * Set new name for existing index.
277 * FAUDES_CHECKED checks if index exists in NameSet.
278 *
279 * @param index
280 * Index to edit
281 * @param rName
282 * New name
283 *
284 * @exception Exception
285 * - index not in this set (id 60)
286 * - index not found in SymbolTable (id 42)
287 * - name already associated with another index (id 44)
288 */
289 void SymbolicName(Idx index, const std::string& rName);
290
291
292 /**
293 * Set new name for existing name
294 * FAUDES_CHECKED checks if the specified name exists in NameSet.
295 *
296 * @param rName
297 * Symbolic name to edit
298 * @param rNewName
299 * New name
300 *
301 * @exception Exception
302 * - symbolic name not in this set (id 60)
303 * - new name already associated with another index (id 44)
304 */
305 void SymbolicName(const std::string& rName, const std::string& rNewName);
306
307 /**
308 * Name lookup
309 *
310 * @param index
311 * Index to lookup
312 *
313 * @return
314 * Corresponding name or empty std::string if non-existent
315 */
316 std::string SymbolicName(Idx index) const;
317
318 /**
319 * Index lookup
320 *
321 * @param rName
322 * Symbolic name to look up
323 *
324 * @return
325 * Corresponding index or 0 for non-existent
326 */
327 Idx Index(const std::string& rName) const;
328
329 /**
330 * Test existence of index
331 *
332 * @param rIndex
333 * Index to test
334 *
335 * @return
336 * True if index is in this set
337 */
338 bool Exists(const Idx& rIndex) const;
339
340 /**
341 * Test existence of name
342 *
343 * @param rName
344 * Symbolic name to test
345 *
346 * @return
347 * True if index is in this set
348 */
349 bool Exists(const std::string& rName) const;
350
351 /**
352 * Find iterator for index. Returns either a valid iterator
353 * or End() for non-existent.
354 *
355 * @param rIndex
356 * Index to find
357 *
358 * @return
359 * NameSet::Iterator
360 */
361 NameSet::Iterator Find(const Idx& rIndex) const;
362
363 /**
364 * Find iterator for name. Returns either a valid iterator
365 * or End() for non-existent.
366 *
367 * @param rName
368 * Name to find
369 *
370 * @return
371 * NameSet::Iterator
372 */
373 NameSet::Iterator Find(const std::string& rName) const;
374
375
376 /**
377 * Set union operator
378 *
379 * @return
380 * Union Set
381 *
382 * @exception Exception
383 * - symboltable mismatch (id 67)
384 */
385 NameSet operator+ (const NameSet& rOtherSet) const;
386
387 /**
388 * Set difference operator
389 *
390 * @return
391 * Difference NameSet
392 *
393 * @exception Exception
394 * - symboltable mismatch (id 67)
395 */
396 NameSet operator- (const NameSet& rOtherSet) const;
397
398 /**
399 * Set intersection operator
400 *
401 * @return
402 * Intersection NameSet
403 *
404 * @exception Exception
405 * - symboltable mismatch (id 67)
406 */
407 NameSet operator* (const NameSet& rOtherSet) const;
408
409
410 /** Test for subset */
411 bool operator<= (const NameSet& rOtherSet) const;
412
413 /** Test for superset */
414 bool operator>= (const NameSet& rOtherSet) const;
415
416
417 /**
418 * Return pretty printable symbolic name for index.
419 * Primary meant for debugging messages.
420 *
421 * @param rIndex
422 * Index to print
423 *
424 * @return
425 * String
426 */
427 virtual std::string Str(const Idx& rIndex) const;
428
429 /**
430 * Return pretty printable string for entire set
431 * Primary meant for debugging messages.
432 *
433 * @param rIndex
434 * Index to print
435 *
436 * @return
437 * String
438 */
439 virtual std::string Str(void) const;
440
441
442 protected:
443
444 /** Pointer to local SymbolTable */
446
447 /**
448 * Copy from other name set. Performs a fake copy, see TBaseSet.
449 *
450 * @param rSourceSet
451 * Source to copy from
452 */
453 void DoCopy(const NameSet& rSourceSet);
454
455
456 /**
457 * Move from other name set. Performs a fake copy, see TBaseSet.
458 *
459 * @param rSourceSet
460 * Source to copy from
461 */
462 void DoMove(NameSet& rSourceSet);
463
464
465 /**
466 * Test equality of configuration data.
467 * Ignore name of the set, insist in matching symboltables.
468 *
469 * @param rOtherSet
470 * Other object to compare with.
471 * @return
472 * True on match.
473 */
474 bool DoEqual(const NameSet& rOtherSet) const;
475
476 /**
477 * Write to TokenWriter, see Type::Write for public wrappers
478 * This function will also do the token IO of attributes in derived classes.
479 *
480 * @param tw
481 * Reference to TokenWriter
482 * @param rLabel
483 * Label of the section to write, defaults to name of set or "NameSet"
484 * @param pContext
485 * Write context to provide contextual information
486 *
487 * @exception Exception
488 * - IO errors (id 2)
489 */
490 virtual void DoWrite(TokenWriter& tw, const std::string& rLabel="", const Type* pContext=0) const;
491
492 /** Write debug info to TokenWriter, see Type::DWrite for public wrapper.
493 * The debug version writes a format that includes symbolic names and indices.
494 *
495 * @param tw
496 * Reference to TokenWriter
497 * @param rLabel
498 * Label of the section to write, defaults to name of set or "NameSet"
499 * @param pContext
500 * Write context to provide contextual information
501 *
502 * @exception Exception
503 * - IO errors (id 2)
504 */
505 virtual void DoDWrite(TokenWriter& tw, const std::string& rLabel="", const Type* pContext=0) const;
506
507 /**
508 * Write to TokenWriter XML format, see Type::XWrite for public wrappers
509 * This function will also do the token IO of attributes in derived classes.
510 *
511 * @param tw
512 * Reference to TokenWriter
513 * @param rLabel
514 * Label of the section to write, defaults to name of set or "NameSet"
515 * @param pContext
516 * Write context to provide contextual information
517 *
518 * @exception Exception
519 * - IO errors (id 2)
520 */
521 virtual void DoXWrite(TokenWriter& tw, const std::string& rLabel="", const Type* pContext=0) const;
522
523 /**
524 * Read from TokenReader, see Type::Read for public wrappers.
525 * It is an error if the file contains a plain index (id 52).
526 * The method invokes TokenReader::ReadBegin() to seek the specified
527 * section, reads subsequent symbols, and calls matching TokenReader::ReadEnd().
528 * If no section is specified, the section is assumed to start at the current position
529 * of the token stream. If the current position is no begin token,
530 * the section "NameSet" is read.
531 * When used by a derived class with attributes, attributes are read, too.
532 *
533 * @param tr
534 * Reference to TokenReader
535 * @param rLabel
536 * Label to read, defaults to current begin label or else "NameSet"
537 * @param pContext
538 * Write context to provide contextual information
539 *
540 * @exception Exception
541 * - IO errors (id 1)
542 * - token mismatch (id 50, 51, 52)
543 */
544 virtual void DoRead(TokenReader& tr, const std::string& rLabel = "", const Type* pContext=0);
545
546
547};
548
549
550/**
551 * Convenience typedef for plain event sets
552 *
553 * @ingroup ContainerClasses
554 */
556
557/* convenience typedef for eventset vectors*/
559
560/* RTI convenience function */
561extern FAUDES_API void SetIntersection(const EventSetVector& rSetVector, EventSet& rRes);
562extern FAUDES_API void SetUnion(const EventSetVector& rSetVector, EventSet& rRes);
563
564
565
566/**
567 * Set of indices with symbolic names and attributes.
568 *
569 * This class is derived from NameSet and the interface TAttrMap.
570 *
571 * The file format is demonstrated by the following example
572 * of a set "Alphabet" consisting of events "alpha", "beta" and "gamma"
573 * with "gamma" having some attribute (see eg AtributeFlags)
574 * \code
575 * <Alphabet>
576 * "alpha"
577 * "beta"
578 * "gamma" 0x0f
579 * <\Alphabet>
580 * \endcode
581 * As with TBaseSet, reading a file silently ignores unknown attributes. Thus, the above example
582 * may also be read as NameSet.
583 */
584
585
586
587template<class Attr>
588class FAUDES_TAPI TaNameSet : public NameSet, public TAttrMap<Idx,Attr> {
589
591
592 /**
593 * We implement "protected privacy for template classes" by friendship.
594 * This is used for the pragmatic implemention conversion constructors.
595 */
596 friend class NameSet;
597
598
599 public:
600
601
602 /* YS in 2024 for MSys2 -- See comment in cfl_types implementation macros*/
603 using NameSet::operator=;
604 using NameSet::operator==;
605 using NameSet::operator!=;
606
607
608 /**
609 * Constructor for NameSet referring to the static SymbolTable.
610 */
612
613 /**
614 * Copy-constructor from other TaNameSet (incl attributes and symboltable)
615 *
616 * @param rOtherSet
617 * Set to copy
618 */
619 TaNameSet(const TaNameSet& rOtherSet);
620
621 /**
622 * Constructor from NameSet (sets default attributes, same symboltable)
623 *
624 * @param rOtherSet
625 * Set to copy
626 */
627 TaNameSet(const NameSet& rOtherSet);
628
629 /**
630 * Constructor from file.
631 * This constructor reads a NameSet from a file using the DoRead(TokenReader&, const std::String&)
632 * function. The section is specified by rLabel and the static SymbolTable is used.
633 *
634 * @param rFilename
635 * Name of File
636 * @param rLabel
637 * Section for the set in the file;
638 */
639 TaNameSet(const std::string& rFilename, const std::string& rLabel = "");
640
641 /**
642 * Virtual destructor
643 */
644 virtual ~TaNameSet(void) {};
645
646 /** Relaxed assignment method (uses base class to maintain attributes)
647 *
648 * Runtimetype check for TransSet, maintains attributes provided they can be casted.
649 *
650 * @param rSrc
651 * Source from which to assign
652 * @return
653 * Ref to this set
654 */
655 virtual TaNameSet& Copy(const TBaseSet<Idx>& rSrc);
656
657 /** Relaxed assignment operator (uses base class to maintain attributes)
658 *
659 * @param rSrc
660 * Source from which to assign
661 * @return
662 * Ref to this set
663 */
664 TaNameSet& operator=(const NameSet& rSrc) { return Copy(rSrc); };
665
666 /**
667 * Iterators on nameset.
668 */
669 using NameSet::Iterator;
670
671 /**
672 * Add an element by index.
673 * Index must be already known to the global SymbolTable. If the element already
674 * exists in the set, the attribute is maintained. Otherwise, the element
675 * is inserted with default attribute.
676 *
677 * @param rIndex
678 * Index to add
679 * @return
680 * True, if element was new to set
681 * @exception Exception
682 * - no symbolic name for index (id 65)
683 */
684 virtual bool Insert(const Idx& rIndex);
685
686
687 /**
688 * Add an element by index incl. attribute
689 *
690 * @param rIndex
691 * Index to add
692 * @param rAttr
693 * Attribute to add
694 * @return
695 * True, if index was new to set
696 * @exception Exception
697 * - no symbolic name for index (id 65)
698 *
699 */
700 virtual bool Insert(const Idx& rIndex, const Attr& rAttr);
701
702 /**
703 * Add an element by its symbolic name. If the name is unknown,
704 * a new index will be generated and recorded in the symboltable.
705 * If the name is known, the corresponding index will be added to the set.
706 * If the element already exists in the set, the attribute is maintained.
707 * Otherwise, the element is inserted with default attribute.
708 *
709 * @param rName
710 * symbolic name of element to add
711 *
712 * @return
713 * Index of (new) element
714 */
715 virtual Idx Insert(const std::string& rName);
716
717 /**
718 * Add an element by its symbolic name.
719 * If the name is unknown,
720 * a new index will be generated and recorded in the symboltable.
721 * If the name is known, the corresponding index will be added to the set.
722 *
723 * @param rName
724 * symbolic name of element to add
725 * @param rAttr
726 * Attribute
727 *
728 * @return
729 * Index of (new) element
730 */
731 virtual Idx Insert(const std::string& rName, const Attr& rAttr);
732
733 /**
734 * Inserts elements of rOtherSet.
735 *
736 * Attributes of this set are maintained, newly inserted elements obtain the attribute
737 * from rOtherSet provided they can be casted appropriately.
738 *
739 * @param rOtherSet
740 * Other StateSet
741 * @exception Exception
742 * - symboltable mismatch (id 67)
743 */
744 virtual void InsertSet(const NameSet& rOtherSet);
745
746 /**
747 * Inserts all elements of rOtherSet.
748 *
749 * This variant requires a runtime cast to access the synboltable.
750 * An expection is thrown if the cast fails.
751 *
752 * @param rOtherSet
753 * Other NameSet
754 * @exception Exception
755 * - symboltable mismatch (id 67)
756 * - cast to nameset failed (id 67)
757 */
758 virtual void InsertSet(const TBaseSet<Idx>& rOtherSet);
759
760 /**
761 * Delete element by index. Symbolic name is not removed from SymbolTable.
762 *
763 * @param rIndex
764 * Index to delete
765 * @return
766 * True if element did exist
767 *
768 */
769 virtual bool Erase(const Idx& rIndex);
770
771 /**
772 * Delete element by symbolic name. Symbolic name is not removed from SymbolTable
773 *
774 * @param rName
775 * Symbolic name of element to dlete
776 * @return
777 * True if element did exist
778 * @exception Exception
779 * - name not found in Symboltable (id 66)
780 */
781 virtual bool Erase(const std::string& rName);
782
783 /**
784 * Delete element by iterator. Symbolic name is not removed from SymbolTable.
785 *
786 * @param pos
787 * TaNameSet::iterator
788 * @return
789 * Iterator to next element
790 * @exception Exception
791 * - invalid iterator (id 62)
792 */
793 virtual typename NameSet::Iterator Erase(const Iterator& pos);
794
795 /**
796 * Erase elements indicated by rOtherSet
797 *
798 * @exception Exception
799 * - symboltable mismatch (id 67)
800 *
801 * @param rOtherSet
802 * Other StateSet
803 */
804 virtual void EraseSet(const NameSet& rOtherSet);
805
806 /**
807 * Erase elements specified by rOtherSet
808 *
809 * This function requires a runtime cast to access the synboltable.
810 * An expection is thrown if the cast fails.
811 *
812 * @param rOtherSet
813 * Other NameSet
814 * @exception Exception
815 * - symboltable mismatch (id 67)
816 * - cast to nameset failed (id 67)
817 */
818 virtual void EraseSet(const TBaseSet<Idx>& rOtherSet);
819
820 /**
821 * Restrict elements indicated by rOtherSet
822 *
823 * @exception Exception
824 * - symboltable mismatch (id 67)
825 *
826 * @param rOtherSet
827 * Other EventSet
828 */
829 virtual void RestrictSet(const NameSet& rOtherSet);
830
831 /**
832 * Restrict to elements specified by rOtherSet
833 *
834 * This function requires a runtime cast to access the synboltable.
835 * An expection is thrown if the cast fails.
836 *
837 * @param rOtherSet
838 * Other NameSet
839 * @exception Exception
840 * - symboltable mismatch (id 67)
841 * - cast to nameset failed (id 67)
842 */
843 virtual void RestrictSet(const TBaseSet<Idx>& rOtherSet);
844
845 /**
846 * Set attributes. Provided that rOtherSet has attributes that can be
847 * casted to the appropriate type, attributes are copied per element from rOtherSet.
848 * Elements of this set which are not in rOtherSet maintain their attribute.
849 *
850 * @param rOtherSet
851 * Other IndexSet
852 * @exception Exception
853 * - Element does not exist (63)
854 * - Cannot cast attribute type (63)
855 * - Cannot cast to NameSet (63)
856 */
857 virtual void Attributes(const TBaseSet<Idx>& rOtherSet);
858
859
860 /**
861 * Return pretty printable symbolic name for index.
862 * Primary meant for debugging messages.
863 *
864 * @param rIndex
865 * Index to print
866 *
867 * @return
868 * String
869 */
870 virtual std::string Str(const Idx& rIndex) const;
871
872 /**
873 * Return pretty printable string for entire set
874 * Primary meant for debugging messages.
875 *
876 * @param rIndex
877 * Index to print
878 *
879 * @return
880 * String
881 */
882 virtual std::string Str(void) const;
883
884
885 /** resolve ambiguities from attribute interface ("using" wont do the job)*/
886 const Attr* AttributeType(void) const { return TAttrMap<Idx,Attr>::AttributeType(); };
887 Attr* Attributep(const Idx& rElem) { return TAttrMap<Idx,Attr>::Attributep(rElem); };
888 const Attr& Attribute(const Idx& rElem) const { return TAttrMap<Idx,Attr>::Attribute(rElem); };
889 void Attribute(const Idx& rElem, const Attr& rAttr) { TAttrMap<Idx,Attr>::Attribute(rElem,rAttr); };
890 void Attribute(const Idx& rElem, const Type& rAttr) { TAttrMap<Idx,Attr>::Attribute(rElem,rAttr); };
891 void AttributeTry(const Idx& rElem, const Type& rAttr) { TAttrMap<Idx,Attr>::AttributeTry(rElem,rAttr); };
892
893 // convenience attribute interface using symbolic names
894 const Attr& Attribute(const std::string& rName) const {
895 return TAttrMap<Idx,Attr>::Attribute(Index(rName));
896 };
897 Attr* Attributep(const std::string& rName) {
898 return TAttrMap<Idx,Attr>::Attributep(Index(rName));
899 };
900 void Attribute(const std::string& rName, const Attr& rAttr) {
901 TAttrMap<Idx,Attr>::Attribute(Index(rName),rAttr);
902 };
903 void Attribute(const std::string& rName, const Type& rAttr) {
904 TAttrMap<Idx,Attr>::Attribute(Index(rName),rAttr);
905 };
906
907 protected:
908
909 /**
910 * Copy to other name set. Performs a fake copy, see TBaseSet.
911 * This function maintains attributes.
912 *
913 * @param rSourceSet
914 * Destination to copy from
915 * @return
916 * ref to this set
917 */
918 void DoCopy(const TaNameSet& rSourceSet);
919
920 /**
921 * Test equality of configuration data, ignore attributes
922 * Ignore name of the set, insist in matching symboltables.
923 *
924 * @param rOtherSet
925 * Other object to compare with.
926 * @return
927 * True on match.
928 */
929 bool DoEqual(const NameSet& rOtherSet) const;
930
931
932};
933
934
935/** Convenience Macro */
936#define TaEventSet TaNameSet
937
938
939
940/**
941 * Relabeling map.
942 *
943 * Set-valued map to relabeling re-labeling schemes.
944 * Technically, this clase is a TaNameSet<TaNameSet>, i.e., a set with a set attribute.
945 * The interface provides some extra convenience accessors, e.g. reading from and writing
946 * to plain STL map<set<Idx>>
947 *
948 */
949class FAUDES_API RelabelMap : public TaNameSet<NameSet> {
951
952public:
953
954 // methods we refine/extend
955 using TaNameSet<NameSet>::Insert;
956 using TaNameSet<NameSet>::Str;
957
958 /**
959 * Constructor for RelabelMap referring to the static SymbolTable.
960 */
961 RelabelMap(void);
962
963 /**
964 * Copy-constructor from other RelabelMap.
965 * This also copies the SymbolTable reference, hence the new RelabelMap
966 * will use the same SymbolTable as rOtherMap.
967 *
968 * @param rOtherMap
969 * Map to copy
970 */
971 RelabelMap(const RelabelMap& rOtherMap);
972
973
974 /**
975 * Constructor from file.
976 * This constructor reads a RelabelMap from a file using the DoRead(TokenReader&, const std::string&)
977 * function. The section is specified by rLabel and the static SymbolTable is used.
978 *
979 * @param rFilename
980 * Name of file
981 * @param rLabel
982 * Section for the set in the file;
983 */
984 RelabelMap(const std::string& rFilename, const std::string& rLabel = "");
985
986 /**
987 * Virtual destructor
988 */
989 virtual ~RelabelMap(void);
990
991 /**
992 * Get Target set (read only))
993 *
994 * @param rSrc
995 * Original by index
996 * @return
997 * Reference to targe set
998 *
999 */
1000 const NameSet& Target(const Idx& rSrc) const;
1001
1002 /**
1003 * Get Target set (writable)
1004 *
1005 * @param rSrc
1006 * Original by index
1007 * @return
1008 * Reference to targe set
1009 *
1010 */
1011 NameSet& Target(const Idx& rSrc);
1012
1013 /**
1014 * Get Target set (read only)
1015 *
1016 * @param rSrc
1017 * Original by name
1018 * @return
1019 * Reference to targe set
1020 *
1021 */
1022 const NameSet& Target(const std::string& rSrc) const;
1023
1024 /**
1025 * Get Target set (writable)
1026 *
1027 * @param rSrc
1028 * Original by name
1029 * @return
1030 * Reference to targe set
1031 *
1032 */
1033 NameSet& Target(const std::string& rSrc);
1034
1035 /**
1036 * Set Target set
1037 *
1038 * @param rSrc
1039 * Original by name
1040 * @param Target
1041 * Target to set
1042 * @return
1043 * Reference to targe set
1044 *
1045 */
1046 void Target(const std::string& rSrc, const NameSet& rTarget);
1047
1048 /**
1049 * Set Target set
1050 *
1051 * @param rSrc
1052 * Original by index
1053 * @param Target
1054 * Target to set
1055 * @return
1056 * Reference to targe set
1057 *
1058 */
1059 void Target(const Idx& rSrc, const NameSet& rTarget);
1060
1061 /**
1062 * Extend map by one target element
1063 *
1064 * @param rSrc
1065 * Original index
1066 * @param rDst
1067 * Target index to add
1068 * @return
1069 * True, if the original index was new to set
1070 * @exception Exception
1071 * - no symbolic name for index (id 65)
1072 *
1073 */
1074 virtual bool Insert(const Idx& rSrc, const Idx& rDst);
1075
1076 /**
1077 * Extend map by one target element
1078 *
1079 * @param rSrc
1080 * Original by name
1081 * @param rDst
1082 * Target to add by name
1083 * @return
1084 * True, if the original index was new to set
1085 *
1086 */
1087 virtual bool Insert(const std::string& rSrc, const std::string& rDst);
1088
1089 /**
1090 * Create a copy as plain STL map
1091 *
1092 * @param
1093 * STL map to read from
1094 */
1095 void FromStlMap(const std::map<Idx, std::set<Idx> >& rMap);
1096
1097 /**
1098 * Copy data to a plain STL map
1099 *
1100 * @param rMap
1101 * STL map to read from
1102 *
1103 */
1104 void ToStlMap(std::map<Idx, std::set<Idx> >& rMap) const;
1105
1106 /**
1107 * Pretty String
1108 *
1109 * @return
1110 * a pretty string
1111 *
1112 */
1113 virtual std::string Str(void) const;
1114
1115};
1116
1117
1118/**
1119 * Apply relable map to nameset
1120 *
1121 * This implementation tries to keep the atributes from the
1122 * domain elements.
1123 *
1124 * @param rMap
1125 * map to apply
1126 * @param rSet
1127 * set to apply the map to
1128 * @param rRes
1129 * relabled set
1130 * @exceptions
1131 * - symboltable must match
1132 */
1133extern FAUDES_API void ApplyRelabelMap(const RelabelMap& rMap, const NameSet& rSet, NameSet& rRes);
1134
1135
1136/** @} doxygen group */
1137
1138
1139/*
1140*************************************************************************************
1141*************************************************************************************
1142 Implementation TaNmeSet
1143*************************************************************************************
1144*************************************************************************************
1145*/
1146
1147
1148// std faudes type (cannot do New() with macro)
1154
1155// empty constructor
1156template<class Attr>
1158 NameSet(),
1159 TAttrMap<Idx,Attr>(this)
1160{
1161 FD_DC("TaNameSet(" << this << ")::TaNameSet()");
1162 //mpSymbolTable = SymbolTable::GlobalEventSymbolTablep();
1163 this->Name("NameSet");
1164}
1165
1166// constructor form other nameset
1167template<class Attr>
1169 NameSet(),
1170 TAttrMap<Idx,Attr>(this)
1171{
1172 FD_DC("TaNameSet(" << this << ")::TaNameSet(rOtherSet " << &rOtherSet << ")");
1173 DoCopy(rOtherSet);
1174}
1175
1176// constructor form other nameset
1177template<class Attr>
1179 NameSet(),
1180 TAttrMap<Idx,Attr>(this)
1181{
1182 FD_DC("TaNameSet(" << this << ")::TaNameSet(rOtherSet " << &rOtherSet << ")");
1183 Copy(rOtherSet);
1184}
1185
1186
1187// read file constructor
1188template<class Attr>
1189TaNameSet<Attr>::TaNameSet(const std::string& rFilename, const std::string& rLabel) :
1190 NameSet(),
1191 TAttrMap<Idx,Attr>(this)
1192{
1193 FD_DC("TaNameSet(" << this << ")::TaNameSet(" << rFilename << ")");
1195 Read(rFilename, rLabel);
1196}
1197
1198// New() (std faudes type, cannot use macro because we need to fix symboltable)
1199template<class Attr>
1201 TaNameSet* res = new TaNameSet();
1202 res->mpSymbolTable=mpSymbolTable;
1203 return res;
1204}
1205
1206// DoCopy()
1207template<class Attr>
1209 FD_DC("TaNameSet(" << this << ")::DoCopy( [a] " << &rSourceSet << ")");
1210 // base does the job
1211 NameSet::DoCopy(rSourceSet);
1212}
1213
1214// DoEqual()
1215template<class Attr>
1216bool TaNameSet<Attr>::DoEqual(const NameSet& rOtherSet) const {
1217 FD_DC("TaNameESet::DoEqual()");
1218 // base does the job, equality does not refer to attributes
1219 return NameSet::DoEqual(rOtherSet);
1220}
1221
1222
1223// Relaxed Copy()
1224template<class Attr>
1226 FD_DC("TaNameSet(" << this << ")::Copy( [v] " << &rSourceSet << ")");
1227 const NameSet* nset = dynamic_cast<const NameSet*>(&rSourceSet);
1228#ifdef FAUDES_CHECKED
1229 if(!nset) {
1230 std::stringstream errstr;
1231 errstr << "cannot cast to nameset" << std::endl;
1232 throw Exception("TaNameSet::Copy", errstr.str(), 67);
1233 }
1234#endif
1235 // name set specific data
1236 mpSymbolTable=nset->mpSymbolTable;
1237 // attribute interface does relaxed assignment
1239 // done
1240 return *this;
1241}
1242
1243// op missing?
1244//template<class Attr>
1245//TaNameSet<Attr>& TaNameSet<Attr>::operator=(TaNameSet&& rSourceSet) {
1246// FD_WARN("TaNameSet: move operator missing");
1247//}
1248
1249// Insert(index)
1250template<class Attr>
1251bool TaNameSet<Attr>::Insert(const Idx& rIndex) {
1252#ifdef FAUDES_CHECKED
1253 if(!mpSymbolTable->Exists(rIndex)) {
1254 std::stringstream errstr;
1255 errstr << "index " << rIndex << " has no symbolic name" << std::endl;
1256 throw Exception("TaNameSet::Insert", errstr.str(), 65);
1257 }
1258#endif
1259 return TAttrMap<Idx,Attr>::Insert(rIndex);
1260}
1261
1262
1263// Insert(index,attr)
1264template<class Attr>
1265bool TaNameSet<Attr>::Insert(const Idx& rIndex, const Attr& attr) {
1266#ifdef FAUDES_CHECKED
1267 if(!mpSymbolTable->Exists(rIndex)) {
1268 std::stringstream errstr;
1269 errstr << "index " << rIndex << " has no symbolic name" << std::endl;
1270 throw Exception("TaNameSet::Insert", errstr.str(), 65);
1271 }
1272#endif
1273 return TAttrMap<Idx,Attr>::Insert(rIndex,attr);
1274}
1275
1276
1277// Insert(rName)
1278template<class Attr>
1279Idx TaNameSet<Attr>::Insert(const std::string& rName) {
1280 FD_DC("TaNameSet(" << this << ")::Insert(" << rName <<")");
1281 Idx index= NameSet::Insert(rName); // automatic: keep attribute if exists
1282 return index;
1283}
1284
1285// Insert(rName, attr)
1286template<class Attr>
1287Idx TaNameSet<Attr>::Insert(const std::string& rName, const Attr& attr) {
1288 FD_DC("TaNameSet(" << this << ")::Insert(" << rName <<")");
1289 Idx index= NameSet::Insert(rName);
1291 return index;
1292}
1293
1294// InsertSet(set)
1295template<class Attr>
1296void TaNameSet<Attr>::InsertSet(const NameSet& rOtherSet) {
1297 FD_DC("TaNameSet(" << this << ")::InsertSet(" << &rOtherSet << ")");
1298#ifdef FAUDES_CHECKED
1299 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
1300 std::stringstream errstr;
1301 errstr << "symboltable mismach aka not implemented" << std::endl;
1302 throw Exception("TaNameSet::InsertSet", errstr.str(), 67);
1303 }
1304#endif
1306}
1307
1308// InsertSet(set)
1309template<class Attr>
1311 FD_DC("TaNameSet(" << this << ")::InsertSet(" << &rOtherSet << "):: downcast");
1312#ifdef FAUDES_CHECKED
1313 const NameSet* nset = dynamic_cast<const NameSet*>(&rOtherSet);
1314 if(!nset) {
1315 std::stringstream errstr;
1316 errstr << "cannot cast to nameset" << std::endl;
1317 throw Exception("TaNameSet::InsertSet", errstr.str(), 67);
1318 }
1319 if(nset->mpSymbolTable!=mpSymbolTable) {
1320 std::stringstream errstr;
1321 errstr << "symboltable mismatch aka not implemented" << std::endl;
1322 throw Exception("TaNameSet::InsertSet", errstr.str(), 67);
1323 }
1324#endif
1326}
1327
1328// Erase(index)
1329template<class Attr>
1330bool TaNameSet<Attr>::Erase(const Idx& rIndex) {
1331 FD_DC("TaNameSet(" << this << ")::Erase(" << rIndex <<")");
1332 return TAttrMap<Idx,Attr>::Erase(rIndex);
1333}
1334
1335// Erase(rName)
1336template<class Attr>
1337bool TaNameSet<Attr>::Erase(const std::string& rName) {
1338 FD_DC("TaNameSet(" << this << ")::Erase(" << rName <<")");
1339 Idx index = mpSymbolTable->Index(rName);
1340#ifdef FAUDES_CHECKED
1341 if (index == 0) {
1342 std::stringstream errstr;
1343 errstr << "name \"" << rName << "\" not found in TaNameSet" << std::endl;
1344 throw Exception("TaNameSet::Erase", errstr.str(), 60);
1345 }
1346#endif
1347 return TAttrMap<Idx,Attr>::Erase(index);
1348}
1349
1350// Erase(pos)
1351template<class Attr>
1352typename NameSet::Iterator TaNameSet<Attr>::Erase(const Iterator& pos) {
1353 return TAttrMap<Idx,Attr>::Erase(pos);
1354}
1355
1356// EraseSet(set)
1357template<class Attr>
1358void TaNameSet<Attr>::EraseSet(const NameSet& rOtherSet) {
1359 FD_DC("TaNameSet(" << this << ")::EraseSet(" << rOtherSet.ToString() << ")");
1360#ifdef FAUDES_CHECKED
1361 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
1362 std::stringstream errstr;
1363 errstr << "symboltable mismach aka not implemented" << std::endl;
1364 throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1365 }
1366#endif
1368}
1369
1370
1371// EraseSet(set)
1372template<class Attr>
1374#ifdef FAUDES_CHECKED
1375 const NameSet* nset = dynamic_cast<const NameSet*>(&rOtherSet);
1376 if(!nset) {
1377 std::stringstream errstr;
1378 errstr << "cannot cast to nameset" << std::endl;
1379 throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1380 }
1381 if(nset->mpSymbolTable!=mpSymbolTable) {
1382 std::stringstream errstr;
1383 errstr << "symboltable mismatch aka not implemented" << std::endl;
1384 throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1385 }
1386#endif
1388}
1389
1390
1391// RestrictSet(set)
1392template<class Attr>
1394 FD_DC("TaNameSet(" << this << ")::RestrictSet(" << rOtherSet.ToString() << ")");
1395#ifdef FAUDES_CHECKED
1396 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
1397 std::stringstream errstr;
1398 errstr << "symboltable mismach aka not implemented" << std::endl;
1399 throw Exception("TaNameSet::RestrictSet", errstr.str(), 67);
1400 }
1401#endif
1403}
1404
1405// RestrictSet(set)
1406template<class Attr>
1408#ifdef FAUDES_CHECKED
1409 const NameSet* nset = dynamic_cast<const NameSet*>(&rOtherSet);
1410 if(!nset) {
1411 std::stringstream errstr;
1412 errstr << "cannot cast to nameset" << std::endl;
1413 throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1414 }
1415 if(nset->mpSymbolTable!=mpSymbolTable) {
1416 std::stringstream errstr;
1417 errstr << "symboltable mismatch aka not implemented" << std::endl;
1418 throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1419 }
1420#endif
1422}
1423
1424
1425// Attributes(set)
1426template<class Attr>
1428 FD_DC("TaNameSet(" << this << ")::Attributes(otherset) with type " << typeid(rOtherSet.AttributeType()).name());
1429#ifdef FAUDES_CHECKED
1430 const NameSet* nset = dynamic_cast<const NameSet*>(&rOtherSet);
1431 if(!nset) {
1432 std::stringstream errstr;
1433 errstr << "cannot cast to nameset" << std::endl;
1434 throw Exception("TaNameSet::Attributes(otherset)", errstr.str(), 67);
1435 }
1436 if(nset->mpSymbolTable!=mpSymbolTable) {
1437 std::stringstream errstr;
1438 errstr << "symboltable mismatch aka not implemented" << std::endl;
1439 throw Exception("TaNameSet::Attributes(otherset)", errstr.str(), 67);
1440 }
1441#endif
1442 TBaseSet<Idx>::Attributes(rOtherSet);
1443}
1444
1445
1446// Str()
1447template<class Attr>
1448std::string TaNameSet<Attr>::Str(const Idx& rIndex) const {
1449 return NameSet::Str(rIndex);
1450}
1451
1452// Str()
1453template<class Attr>
1454std::string TaNameSet<Attr>::Str(void) const {
1455 return NameSet::Str();
1456}
1457
1458
1459
1460} // namespace faudes
1461
1462#endif
1463
Class TAttrMap.
Class TBaseVector.
#define FD_DC(message)
#define FAUDES_API
#define FAUDES_TAPI
Class SymbolTable.
#define FAUDES_TYPE_TIMPLEMENTATION_CAST(ftype, ctype, cbase, ctemp)
Definition cfl_types.h:985
#define FAUDES_TYPE_TIMPLEMENTATION_EQUAL(ftype, ctype, cbase, ctemp)
Definition cfl_types.h:1004
#define FAUDES_TYPE_TDECLARATION(ftype, ctype, cbase)
Definition cfl_types.h:931
#define FAUDES_TYPE_TIMPLEMENTATION_MOVE(ftype, ctype, cbase, ctemp)
Definition cfl_types.h:996
#define FAUDES_TYPE_TIMPLEMENTATION_ASSIGN(ftype, ctype, cbase, ctemp)
Definition cfl_types.h:988
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
Definition cfl_types.h:918
#define FAUDES_TYPE_TIMPLEMENTATION_NEWCOPY(ftype, ctype, cbase, ctemp)
Definition cfl_types.h:982
const std::string & Name(void) const
void DoCopy(const NameSet &rSourceSet)
bool DoEqual(const NameSet &rOtherSet) const
bool Insert(const Idx &rIndex)
virtual std::string Str(void) const
SymbolTable * mpSymbolTable
static SymbolTable * GlobalEventSymbolTablep(void)
const Attr & Attribute(const T &rElem) const
bool Erase(const T &rElem)
void EraseSet(const TBaseSet< T, Cmp > &rOtherSet)
void InsertSet(const TBaseSet< T, Cmp > &rOtherSet)
void RestrictSet(const TBaseSet< T, Cmp > &rOtherSet)
void CopyWithAttributes(const TBaseSet< T, Cmp > &rSourceSet)
bool Insert(const T &rElem)
const Attr & Attribute(const std::string &rName) const
virtual void InsertSet(const TBaseSet< Idx > &rOtherSet)
void Attribute(const std::string &rName, const Attr &rAttr)
Attr * Attributep(const std::string &rName)
virtual bool Insert(const Idx &rIndex)
void AttributeTry(const Idx &rElem, const Type &rAttr)
virtual std::string Str(void) const
virtual void Attributes(const TBaseSet< Idx > &rOtherSet)
bool DoEqual(const NameSet &rOtherSet) const
void DoCopy(const TaNameSet &rSourceSet)
Attr * Attributep(const Idx &rElem)
virtual void EraseSet(const NameSet &rOtherSet)
virtual std::string Str(const Idx &rIndex) const
virtual bool Insert(const Idx &rIndex, const Attr &rAttr)
virtual void EraseSet(const TBaseSet< Idx > &rOtherSet)
TaNameSet & operator=(const NameSet &rSrc)
void Attribute(const std::string &rName, const Type &rAttr)
virtual Idx Insert(const std::string &rName)
const Attr * AttributeType(void) const
virtual void RestrictSet(const NameSet &rOtherSet)
void Attribute(const Idx &rElem, const Attr &rAttr)
virtual TaNameSet & Copy(const TBaseSet< Idx > &rSrc)
const Attr & Attribute(const Idx &rElem) const
virtual bool Erase(const Idx &rIndex)
virtual Idx Insert(const std::string &rName, const Attr &rAttr)
virtual void InsertSet(const NameSet &rOtherSet)
void Attribute(const Idx &rElem, const Type &rAttr)
virtual NameSet::Iterator Erase(const Iterator &pos)
virtual void RestrictSet(const TBaseSet< Idx > &rOtherSet)
virtual bool Erase(const std::string &rName)
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
virtual Type * New(void) const
Definition cfl_types.cpp:54
virtual const AttributeVoid * AttributeType(void) const
virtual void Attributes(const TBaseSet &rOtherSet)
NameSet EventSet
void SetUnion(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB, TBaseSet< T, Cmp > &rRes)
void SetIntersection(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB, TBaseSet< T, Cmp > &rRes)
TBaseVector< EventSet > EventSetVector
uint32_t Idx
void ApplyRelabelMap(const RelabelMap &rMap, const vGenerator &rGen, vGenerator &rRes)

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