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 * Assign from other name set. Performs a fake copy, see TBaseSet.
449 *
450 * @param rSourceSet
451 * Source to copy from
452 */
453 void DoAssign(const NameSet& rSourceSet);
454
455
456 /**
457 * Test equality of configuration data.
458 * Ignore name of the set, insist in matching symboltables.
459 *
460 * @param rOtherSet
461 * Other object to compare with.
462 * @return
463 * True on match.
464 */
465 bool DoEqual(const NameSet& rOtherSet) const;
466
467 /**
468 * Write to TokenWriter, see Type::Write for public wrappers
469 * This function will also do the token IO of attributes in derived classes.
470 *
471 * @param tw
472 * Reference to TokenWriter
473 * @param rLabel
474 * Label of the section to write, defaults to name of set or "NameSet"
475 * @param pContext
476 * Write context to provide contextual information
477 *
478 * @exception Exception
479 * - IO errors (id 2)
480 */
481 virtual void DoWrite(TokenWriter& tw, const std::string& rLabel="", const Type* pContext=0) const;
482
483 /** Write debug info to TokenWriter, see Type::DWrite for public wrapper.
484 * The debug version writes a format that includes symbolic names and indices.
485 *
486 * @param tw
487 * Reference to TokenWriter
488 * @param rLabel
489 * Label of the section to write, defaults to name of set or "NameSet"
490 * @param pContext
491 * Write context to provide contextual information
492 *
493 * @exception Exception
494 * - IO errors (id 2)
495 */
496 virtual void DoDWrite(TokenWriter& tw, const std::string& rLabel="", const Type* pContext=0) const;
497
498 /**
499 * Write to TokenWriter XML format, see Type::XWrite for public wrappers
500 * This function will also do the token IO of attributes in derived classes.
501 *
502 * @param tw
503 * Reference to TokenWriter
504 * @param rLabel
505 * Label of the section to write, defaults to name of set or "NameSet"
506 * @param pContext
507 * Write context to provide contextual information
508 *
509 * @exception Exception
510 * - IO errors (id 2)
511 */
512 virtual void DoXWrite(TokenWriter& tw, const std::string& rLabel="", const Type* pContext=0) const;
513
514 /**
515 * Read from TokenReader, see Type::Read for public wrappers.
516 * It is an error if the file contains a plain index (id 52).
517 * The method invokes TokenReader::ReadBegin() to seek the specified
518 * section, reads subsequent symbols, and calls matching TokenReader::ReadEnd().
519 * If no section is specified, the section is assumed to start at the current position
520 * of the token stream. If the current position is no begin token,
521 * the section "NameSet" is read.
522 * When used by a derived class with attributes, attributes are read, too.
523 *
524 * @param tr
525 * Reference to TokenReader
526 * @param rLabel
527 * Label to read, defaults to current begin label or else "NameSet"
528 * @param pContext
529 * Write context to provide contextual information
530 *
531 * @exception Exception
532 * - IO errors (id 1)
533 * - token mismatch (id 50, 51, 52)
534 */
535 virtual void DoRead(TokenReader& tr, const std::string& rLabel = "", const Type* pContext=0);
536
537
538};
539
540
541/**
542 * Convenience typedef for plain event sets
543 *
544 * @ingroup ContainerClasses
545 */
547
548/* convenience typedef for eventset vectors*/
550
551/* RTI convenience function */
552extern FAUDES_API void SetIntersection(const EventSetVector& rSetVector, EventSet& rRes);
553extern FAUDES_API void SetUnion(const EventSetVector& rSetVector, EventSet& rRes);
554
555
556
557/**
558 * Set of indices with symbolic names and attributes.
559 *
560 * This class is derived from NameSet and the interface TAttrMap.
561 *
562 * The file format is demonstrated by the following example
563 * of a set "Alphabet" consisting of events "alpha", "beta" and "gamma"
564 * with "gamma" having some attribute (see eg AtributeFlags)
565 * \code
566 * <Alphabet>
567 * "alpha"
568 * "beta"
569 * "gamma" 0x0f
570 * <\Alphabet>
571 * \endcode
572 * As with TBaseSet, reading a file silently ignores unknown attributes. Thus, the above example
573 * may also be read as NameSet.
574 */
575
576
577
578template<class Attr>
579class FAUDES_TAPI TaNameSet : public NameSet, public TAttrMap<Idx,Attr> {
580
582
583 /**
584 * We implement "protected privacy for template classes" by friendship.
585 * This is used for the pragmatic implemention conversion constructors.
586 */
587 friend class NameSet;
588
589
590 public:
591
592
593 /* YS in 2024 for MSys2 -- See comment in cfl_types implementation macros*/
594 using NameSet::operator=;
595 using NameSet::operator==;
596 using NameSet::operator!=;
597
598
599 /**
600 * Constructor for NameSet referring to the static SymbolTable.
601 */
603
604 /**
605 * Copy-constructor from other TaNameSet (incl attributes and symboltable)
606 *
607 * @param rOtherSet
608 * Set to copy
609 */
610 TaNameSet(const TaNameSet& rOtherSet);
611
612 /**
613 * Constructor from NameSet (sets default attributes, same symboltable)
614 *
615 * @param rOtherSet
616 * Set to copy
617 */
618 TaNameSet(const NameSet& rOtherSet);
619
620 /**
621 * Constructor from file.
622 * This constructor reads a NameSet from a file using the DoRead(TokenReader&, const std::String&)
623 * function. The section is specified by rLabel and the static SymbolTable is used.
624 *
625 * @param rFilename
626 * Name of File
627 * @param rLabel
628 * Section for the set in the file;
629 */
630 TaNameSet(const std::string& rFilename, const std::string& rLabel = "");
631
632 /**
633 * Virtual destructor
634 */
635 virtual ~TaNameSet(void) {};
636
637 /** Relaxed assignment method (uses base class to maintain attributes)
638 *
639 * Runtimetype check for TransSet, maintains attributes provided they can be casted.
640 *
641 * @param rSrc
642 * Source from which to assign
643 * @return
644 * Ref to this set
645 */
646 virtual TaNameSet& Assign(const TBaseSet<Idx>& rSrc);
647
648 /** Relaxed assignment operator (uses base class to maintain attributes)
649 *
650 * @param rSrc
651 * Source from which to assign
652 * @return
653 * Ref to this set
654 */
655 TaNameSet& operator=(const NameSet& rSrc) { return Assign(rSrc); };
656
657 /**
658 * Iterators on nameset.
659 */
660 using NameSet::Iterator;
661
662 /**
663 * Add an element by index.
664 * Index must be already known to the global SymbolTable. If the element already
665 * exists in the set, the attribute is maintained. Otherwise, the element
666 * is inserted with default attribute.
667 *
668 * @param rIndex
669 * Index to add
670 * @return
671 * True, if element was new to set
672 * @exception Exception
673 * - no symbolic name for index (id 65)
674 */
675 virtual bool Insert(const Idx& rIndex);
676
677
678 /**
679 * Add an element by index incl. attribute
680 *
681 * @param rIndex
682 * Index to add
683 * @param rAttr
684 * Attribute to add
685 * @return
686 * True, if index was new to set
687 * @exception Exception
688 * - no symbolic name for index (id 65)
689 *
690 */
691 virtual bool Insert(const Idx& rIndex, const Attr& rAttr);
692
693 /**
694 * Add an element by its symbolic name. If the name is unknown,
695 * a new index will be generated and recorded in the symboltable.
696 * If the name is known, the corresponding index will be added to the set.
697 * If the element already exists in the set, the attribute is maintained.
698 * Otherwise, the element is inserted with default attribute.
699 *
700 * @param rName
701 * symbolic name of element to add
702 *
703 * @return
704 * Index of (new) element
705 */
706 virtual Idx Insert(const std::string& rName);
707
708 /**
709 * Add an element by its symbolic name.
710 * If the name is unknown,
711 * a new index will be generated and recorded in the symboltable.
712 * If the name is known, the corresponding index will be added to the set.
713 *
714 * @param rName
715 * symbolic name of element to add
716 * @param rAttr
717 * Attribute
718 *
719 * @return
720 * Index of (new) element
721 */
722 virtual Idx Insert(const std::string& rName, const Attr& rAttr);
723
724 /**
725 * Inserts elements of rOtherSet.
726 *
727 * Attributes of this set are maintained, newly inserted elements obtain the attribute
728 * from rOtherSet provided they can be casted appropriately.
729 *
730 * @param rOtherSet
731 * Other StateSet
732 * @exception Exception
733 * - symboltable mismatch (id 67)
734 */
735 virtual void InsertSet(const NameSet& rOtherSet);
736
737 /**
738 * Inserts all elements of rOtherSet.
739 *
740 * This variant requires a runtime cast to access the synboltable.
741 * An expection is thrown if the cast fails.
742 *
743 * @param rOtherSet
744 * Other NameSet
745 * @exception Exception
746 * - symboltable mismatch (id 67)
747 * - cast to nameset failed (id 67)
748 */
749 virtual void InsertSet(const TBaseSet<Idx>& rOtherSet);
750
751 /**
752 * Delete element by index. Symbolic name is not removed from SymbolTable.
753 *
754 * @param rIndex
755 * Index to delete
756 * @return
757 * True if element did exist
758 *
759 */
760 virtual bool Erase(const Idx& rIndex);
761
762 /**
763 * Delete element by symbolic name. Symbolic name is not removed from SymbolTable
764 *
765 * @param rName
766 * Symbolic name of element to dlete
767 * @return
768 * True if element did exist
769 * @exception Exception
770 * - name not found in Symboltable (id 66)
771 */
772 virtual bool Erase(const std::string& rName);
773
774 /**
775 * Delete element by iterator. Symbolic name is not removed from SymbolTable.
776 *
777 * @param pos
778 * TaNameSet::iterator
779 * @return
780 * Iterator to next element
781 * @exception Exception
782 * - invalid iterator (id 62)
783 */
784 virtual typename NameSet::Iterator Erase(const Iterator& pos);
785
786 /**
787 * Erase elements indicated by rOtherSet
788 *
789 * @exception Exception
790 * - symboltable mismatch (id 67)
791 *
792 * @param rOtherSet
793 * Other StateSet
794 */
795 virtual void EraseSet(const NameSet& rOtherSet);
796
797 /**
798 * Erase elements specified by rOtherSet
799 *
800 * This function requires a runtime cast to access the synboltable.
801 * An expection is thrown if the cast fails.
802 *
803 * @param rOtherSet
804 * Other NameSet
805 * @exception Exception
806 * - symboltable mismatch (id 67)
807 * - cast to nameset failed (id 67)
808 */
809 virtual void EraseSet(const TBaseSet<Idx>& rOtherSet);
810
811 /**
812 * Restrict elements indicated by rOtherSet
813 *
814 * @exception Exception
815 * - symboltable mismatch (id 67)
816 *
817 * @param rOtherSet
818 * Other EventSet
819 */
820 virtual void RestrictSet(const NameSet& rOtherSet);
821
822 /**
823 * Restrict to elements specified by rOtherSet
824 *
825 * This function requires a runtime cast to access the synboltable.
826 * An expection is thrown if the cast fails.
827 *
828 * @param rOtherSet
829 * Other NameSet
830 * @exception Exception
831 * - symboltable mismatch (id 67)
832 * - cast to nameset failed (id 67)
833 */
834 virtual void RestrictSet(const TBaseSet<Idx>& rOtherSet);
835
836 /**
837 * Set attributes. Provided that rOtherSet has attributes that can be
838 * casted to the appropriate type, attributes are copied per element from rOtherSet.
839 * Elements of this set which are not in rOtherSet maintain their attribute.
840 *
841 * @param rOtherSet
842 * Other IndexSet
843 * @exception Exception
844 * - Element does not exist (63)
845 * - Cannot cast attribute type (63)
846 * - Cannot cast to NameSet (63)
847 */
848 virtual void Attributes(const TBaseSet<Idx>& rOtherSet);
849
850
851 /**
852 * Return pretty printable symbolic name for index.
853 * Primary meant for debugging messages.
854 *
855 * @param rIndex
856 * Index to print
857 *
858 * @return
859 * String
860 */
861 virtual std::string Str(const Idx& rIndex) const;
862
863 /**
864 * Return pretty printable string for entire set
865 * Primary meant for debugging messages.
866 *
867 * @param rIndex
868 * Index to print
869 *
870 * @return
871 * String
872 */
873 virtual std::string Str(void) const;
874
875
876 /** resolve ambiguities from attribute interface ("using" wont do the job)*/
877 const Attr* AttributeType(void) const { return TAttrMap<Idx,Attr>::AttributeType(); };
878 Attr* Attributep(const Idx& rElem) { return TAttrMap<Idx,Attr>::Attributep(rElem); };
879 const Attr& Attribute(const Idx& rElem) const { return TAttrMap<Idx,Attr>::Attribute(rElem); };
880 void Attribute(const Idx& rElem, const Attr& rAttr) { TAttrMap<Idx,Attr>::Attribute(rElem,rAttr); };
881 void Attribute(const Idx& rElem, const Type& rAttr) { TAttrMap<Idx,Attr>::Attribute(rElem,rAttr); };
882 void AttributeTry(const Idx& rElem, const Type& rAttr) { TAttrMap<Idx,Attr>::AttributeTry(rElem,rAttr); };
883
884 // convenience attribute interface using symbolic names
885 const Attr& Attribute(const std::string& rName) const {
886 return TAttrMap<Idx,Attr>::Attribute(Index(rName));
887 };
888 Attr* Attributep(const std::string& rName) {
889 return TAttrMap<Idx,Attr>::Attributep(Index(rName));
890 };
891 void Attribute(const std::string& rName, const Attr& rAttr) {
892 TAttrMap<Idx,Attr>::Attribute(Index(rName),rAttr);
893 };
894 void Attribute(const std::string& rName, const Type& rAttr) {
895 TAttrMap<Idx,Attr>::Attribute(Index(rName),rAttr);
896 };
897
898 protected:
899
900 /**
901 * Assign to other name set. Performs a fake copy, see TBaseSet.
902 * This function maintains attributes.
903 *
904 * @param rSourceSet
905 * Destination to copy from
906 * @return
907 * ref to this set
908 */
909 void DoAssign(const TaNameSet& rSourceSet);
910
911 /**
912 * Test equality of configuration data, ignore attributes
913 * Ignore name of the set, insist in matching symboltables.
914 *
915 * @param rOtherSet
916 * Other object to compare with.
917 * @return
918 * True on match.
919 */
920 bool DoEqual(const NameSet& rOtherSet) const;
921
922
923};
924
925
926/** Convenience Macro */
927#define TaEventSet TaNameSet
928
929
930
931/**
932 * Relabeling map.
933 *
934 * Set-valued map to relabeling re-labeling schemes.
935 * Technically, this clase is a TaNameSet<TaNameSet>, i.e., a set with a set attribute.
936 * The interface provides some extra convenience accessors, e.g. reading from and writing
937 * to plain STL map<set<Idx>>
938 *
939 */
940class FAUDES_API RelabelMap : public TaNameSet<NameSet> {
942
943public:
944
945 // methods we refine/extend
946 using TaNameSet<NameSet>::Insert;
947 using TaNameSet<NameSet>::Str;
948
949 /**
950 * Constructor for RelabelMap referring to the static SymbolTable.
951 */
952 RelabelMap(void);
953
954 /**
955 * Copy-constructor from other RelabelMap.
956 * This also copies the SymbolTable reference, hence the new RelabelMap
957 * will use the same SymbolTable as rOtherMap.
958 *
959 * @param rOtherMap
960 * Map to copy
961 */
962 RelabelMap(const RelabelMap& rOtherMap);
963
964
965 /**
966 * Constructor from file.
967 * This constructor reads a RelabelMap from a file using the DoRead(TokenReader&, const std::string&)
968 * function. The section is specified by rLabel and the static SymbolTable is used.
969 *
970 * @param rFilename
971 * Name of file
972 * @param rLabel
973 * Section for the set in the file;
974 */
975 RelabelMap(const std::string& rFilename, const std::string& rLabel = "");
976
977 /**
978 * Virtual destructor
979 */
980 virtual ~RelabelMap(void);
981
982 /**
983 * Get Target set (read only))
984 *
985 * @param rSrc
986 * Original by index
987 * @return
988 * Reference to targe set
989 *
990 */
991 const NameSet& Target(const Idx& rSrc) const;
992
993 /**
994 * Get Target set (writable)
995 *
996 * @param rSrc
997 * Original by index
998 * @return
999 * Reference to targe set
1000 *
1001 */
1002 NameSet& Target(const Idx& rSrc);
1003
1004 /**
1005 * Get Target set (read only)
1006 *
1007 * @param rSrc
1008 * Original by name
1009 * @return
1010 * Reference to targe set
1011 *
1012 */
1013 const NameSet& Target(const std::string& rSrc) const;
1014
1015 /**
1016 * Get Target set (writable)
1017 *
1018 * @param rSrc
1019 * Original by name
1020 * @return
1021 * Reference to targe set
1022 *
1023 */
1024 NameSet& Target(const std::string& rSrc);
1025
1026 /**
1027 * Set Target set
1028 *
1029 * @param rSrc
1030 * Original by name
1031 * @param Target
1032 * Target to set
1033 * @return
1034 * Reference to targe set
1035 *
1036 */
1037 void Target(const std::string& rSrc, const NameSet& rTarget);
1038
1039 /**
1040 * Set Target set
1041 *
1042 * @param rSrc
1043 * Original by index
1044 * @param Target
1045 * Target to set
1046 * @return
1047 * Reference to targe set
1048 *
1049 */
1050 void Target(const Idx& rSrc, const NameSet& rTarget);
1051
1052 /**
1053 * Extend map by one target element
1054 *
1055 * @param rSrc
1056 * Original index
1057 * @param rDst
1058 * Target index to add
1059 * @return
1060 * True, if the original index was new to set
1061 * @exception Exception
1062 * - no symbolic name for index (id 65)
1063 *
1064 */
1065 virtual bool Insert(const Idx& rSrc, const Idx& rDst);
1066
1067 /**
1068 * Extend map by one target element
1069 *
1070 * @param rSrc
1071 * Original by name
1072 * @param rDst
1073 * Target to add by name
1074 * @return
1075 * True, if the original index was new to set
1076 *
1077 */
1078 virtual bool Insert(const std::string& rSrc, const std::string& rDst);
1079
1080 /**
1081 * Create a copy as plain STL map
1082 *
1083 * @param
1084 * STL map to read from
1085 */
1086 void FromStlMap(const std::map<Idx, std::set<Idx> >& rMap);
1087
1088 /**
1089 * Copy data to a plain STL map
1090 *
1091 * @param rMap
1092 * STL map to read from
1093 *
1094 */
1095 void ToStlMap(std::map<Idx, std::set<Idx> >& rMap) const;
1096
1097 /**
1098 * Pretty String
1099 *
1100 * @return
1101 * a pretty string
1102 *
1103 */
1104 virtual std::string Str(void) const;
1105
1106};
1107
1108
1109/**
1110 * Apply relable map to nameset
1111 *
1112 * This implementation tries to keep the atributes from the
1113 * domain elements.
1114 *
1115 * @param rMap
1116 * map to apply
1117 * @param rSet
1118 * set to apply the map to
1119 * @param rRes
1120 * relabled set
1121 * @exceptions
1122 * - symboltable must match
1123 */
1124extern FAUDES_API void ApplyRelabelMap(const RelabelMap& rMap, const NameSet& rSet, NameSet& rRes);
1125
1126
1127/** @} doxygen group */
1128
1129
1130/*
1131*************************************************************************************
1132*************************************************************************************
1133 Implementation TaNmeSet
1134*************************************************************************************
1135*************************************************************************************
1136*/
1137
1138
1139// std faudes type (cannot do New() with macro)
1144
1145// empty constructor
1146template<class Attr>
1148 NameSet(),
1149 TAttrMap<Idx,Attr>(this)
1150{
1151 FD_DC("TaNameSet(" << this << ")::TaNameSet()");
1152 //mpSymbolTable = SymbolTable::GlobalEventSymbolTablep();
1153 this->Name("NameSet");
1154}
1155
1156// constructor form other nameset
1157template<class Attr>
1159 NameSet(),
1160 TAttrMap<Idx,Attr>(this)
1161{
1162 FD_DC("TaNameSet(" << this << ")::TaNameSet(rOtherSet " << &rOtherSet << ")");
1163 DoAssign(rOtherSet);
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 Assign(rOtherSet);
1174}
1175
1176
1177// read file constructor
1178template<class Attr>
1179TaNameSet<Attr>::TaNameSet(const std::string& rFilename, const std::string& rLabel) :
1180 NameSet(),
1181 TAttrMap<Idx,Attr>(this)
1182{
1183 FD_DC("TaNameSet(" << this << ")::TaNameSet(" << rFilename << ")");
1185 Read(rFilename, rLabel);
1186}
1187
1188// New() (std faudes type, cannot use macro because we need to fix symboltable)
1189template<class Attr>
1191 TaNameSet* res = new TaNameSet();
1192 res->mpSymbolTable=mpSymbolTable;
1193 return res;
1194}
1195
1196// DoAssign()
1197template<class Attr>
1199 FD_DC("TaNameSet(" << this << ")::DoAssign( [a] " << &rSourceSet << ")");
1200 // base does the job
1201 NameSet::DoAssign(rSourceSet);
1202}
1203
1204// DoEqual()
1205template<class Attr>
1206bool TaNameSet<Attr>::DoEqual(const NameSet& rOtherSet) const {
1207 FD_DC("TaNameESet::DoEqual()");
1208 // base does the job, equality does not refer to attributes
1209 return NameSet::DoEqual(rOtherSet);
1210}
1211
1212
1213// Relaxed Assign()
1214template<class Attr>
1216 FD_DC("TaNameSet(" << this << ")::Assign( [v] " << &rSourceSet << ")");
1217 const NameSet* nset = dynamic_cast<const NameSet*>(&rSourceSet);
1218#ifdef FAUDES_CHECKED
1219 if(!nset) {
1220 std::stringstream errstr;
1221 errstr << "cannot cast to nameset" << std::endl;
1222 throw Exception("TaNameSet::Assign", errstr.str(), 67);
1223 }
1224#endif
1225 // name set specific data
1226 mpSymbolTable=nset->mpSymbolTable;
1227 // attribute interface does relaxed assignment
1229 // done
1230 return *this;
1231}
1232
1233// Insert(index)
1234template<class Attr>
1235bool TaNameSet<Attr>::Insert(const Idx& rIndex) {
1236#ifdef FAUDES_CHECKED
1237 if(!mpSymbolTable->Exists(rIndex)) {
1238 std::stringstream errstr;
1239 errstr << "index " << rIndex << " has no symbolic name" << std::endl;
1240 throw Exception("TaNameSet::Insert", errstr.str(), 65);
1241 }
1242#endif
1243 return TAttrMap<Idx,Attr>::Insert(rIndex);
1244}
1245
1246
1247// Insert(index,attr)
1248template<class Attr>
1249bool TaNameSet<Attr>::Insert(const Idx& rIndex, const Attr& attr) {
1250#ifdef FAUDES_CHECKED
1251 if(!mpSymbolTable->Exists(rIndex)) {
1252 std::stringstream errstr;
1253 errstr << "index " << rIndex << " has no symbolic name" << std::endl;
1254 throw Exception("TaNameSet::Insert", errstr.str(), 65);
1255 }
1256#endif
1257 return TAttrMap<Idx,Attr>::Insert(rIndex,attr);
1258}
1259
1260
1261// Insert(rName)
1262template<class Attr>
1263Idx TaNameSet<Attr>::Insert(const std::string& rName) {
1264 FD_DC("TaNameSet(" << this << ")::Insert(" << rName <<")");
1265 Idx index= NameSet::Insert(rName); // automatic: keep attribute if exists
1266 return index;
1267}
1268
1269// Insert(rName, attr)
1270template<class Attr>
1271Idx TaNameSet<Attr>::Insert(const std::string& rName, const Attr& attr) {
1272 FD_DC("TaNameSet(" << this << ")::Insert(" << rName <<")");
1273 Idx index= NameSet::Insert(rName);
1275 return index;
1276}
1277
1278// InsertSet(set)
1279template<class Attr>
1280void TaNameSet<Attr>::InsertSet(const NameSet& rOtherSet) {
1281 FD_DC("TaNameSet(" << this << ")::InsertSet(" << &rOtherSet << ")");
1282#ifdef FAUDES_CHECKED
1283 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
1284 std::stringstream errstr;
1285 errstr << "symboltable mismach aka not implemented" << std::endl;
1286 throw Exception("TaNameSet::InsertSet", errstr.str(), 67);
1287 }
1288#endif
1290}
1291
1292// InsertSet(set)
1293template<class Attr>
1295 FD_DC("TaNameSet(" << this << ")::InsertSet(" << &rOtherSet << "):: downcast");
1296#ifdef FAUDES_CHECKED
1297 const NameSet* nset = dynamic_cast<const NameSet*>(&rOtherSet);
1298 if(!nset) {
1299 std::stringstream errstr;
1300 errstr << "cannot cast to nameset" << std::endl;
1301 throw Exception("TaNameSet::InsertSet", errstr.str(), 67);
1302 }
1303 if(nset->mpSymbolTable!=mpSymbolTable) {
1304 std::stringstream errstr;
1305 errstr << "symboltable mismatch aka not implemented" << std::endl;
1306 throw Exception("TaNameSet::InsertSet", errstr.str(), 67);
1307 }
1308#endif
1310}
1311
1312// Erase(index)
1313template<class Attr>
1314bool TaNameSet<Attr>::Erase(const Idx& rIndex) {
1315 FD_DC("TaNameSet(" << this << ")::Erase(" << rIndex <<")");
1316 return TAttrMap<Idx,Attr>::Erase(rIndex);
1317}
1318
1319// Erase(rName)
1320template<class Attr>
1321bool TaNameSet<Attr>::Erase(const std::string& rName) {
1322 FD_DC("TaNameSet(" << this << ")::Erase(" << rName <<")");
1323 Idx index = mpSymbolTable->Index(rName);
1324#ifdef FAUDES_CHECKED
1325 if (index == 0) {
1326 std::stringstream errstr;
1327 errstr << "name \"" << rName << "\" not found in TaNameSet" << std::endl;
1328 throw Exception("TaNameSet::Erase", errstr.str(), 60);
1329 }
1330#endif
1331 return TAttrMap<Idx,Attr>::Erase(index);
1332}
1333
1334// Erase(pos)
1335template<class Attr>
1336typename NameSet::Iterator TaNameSet<Attr>::Erase(const Iterator& pos) {
1337 return TAttrMap<Idx,Attr>::Erase(pos);
1338}
1339
1340// EraseSet(set)
1341template<class Attr>
1342void TaNameSet<Attr>::EraseSet(const NameSet& rOtherSet) {
1343 FD_DC("TaNameSet(" << this << ")::EraseSet(" << rOtherSet.ToString() << ")");
1344#ifdef FAUDES_CHECKED
1345 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
1346 std::stringstream errstr;
1347 errstr << "symboltable mismach aka not implemented" << std::endl;
1348 throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1349 }
1350#endif
1352}
1353
1354
1355// EraseSet(set)
1356template<class Attr>
1358#ifdef FAUDES_CHECKED
1359 const NameSet* nset = dynamic_cast<const NameSet*>(&rOtherSet);
1360 if(!nset) {
1361 std::stringstream errstr;
1362 errstr << "cannot cast to nameset" << std::endl;
1363 throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1364 }
1365 if(nset->mpSymbolTable!=mpSymbolTable) {
1366 std::stringstream errstr;
1367 errstr << "symboltable mismatch aka not implemented" << std::endl;
1368 throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1369 }
1370#endif
1372}
1373
1374
1375// RestrictSet(set)
1376template<class Attr>
1378 FD_DC("TaNameSet(" << this << ")::RestrictSet(" << rOtherSet.ToString() << ")");
1379#ifdef FAUDES_CHECKED
1380 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
1381 std::stringstream errstr;
1382 errstr << "symboltable mismach aka not implemented" << std::endl;
1383 throw Exception("TaNameSet::RestrictSet", errstr.str(), 67);
1384 }
1385#endif
1387}
1388
1389// RestrictSet(set)
1390template<class Attr>
1392#ifdef FAUDES_CHECKED
1393 const NameSet* nset = dynamic_cast<const NameSet*>(&rOtherSet);
1394 if(!nset) {
1395 std::stringstream errstr;
1396 errstr << "cannot cast to nameset" << std::endl;
1397 throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1398 }
1399 if(nset->mpSymbolTable!=mpSymbolTable) {
1400 std::stringstream errstr;
1401 errstr << "symboltable mismatch aka not implemented" << std::endl;
1402 throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1403 }
1404#endif
1406}
1407
1408
1409// Attributes(set)
1410template<class Attr>
1412 FD_DC("TaNameSet(" << this << ")::Attributes(otherset) with type " << typeid(rOtherSet.AttributeType()).name());
1413#ifdef FAUDES_CHECKED
1414 const NameSet* nset = dynamic_cast<const NameSet*>(&rOtherSet);
1415 if(!nset) {
1416 std::stringstream errstr;
1417 errstr << "cannot cast to nameset" << std::endl;
1418 throw Exception("TaNameSet::Attributes(otherset)", errstr.str(), 67);
1419 }
1420 if(nset->mpSymbolTable!=mpSymbolTable) {
1421 std::stringstream errstr;
1422 errstr << "symboltable mismatch aka not implemented" << std::endl;
1423 throw Exception("TaNameSet::Attributes(otherset)", errstr.str(), 67);
1424 }
1425#endif
1426 TBaseSet<Idx>::Attributes(rOtherSet);
1427}
1428
1429
1430// Str()
1431template<class Attr>
1432std::string TaNameSet<Attr>::Str(const Idx& rIndex) const {
1433 return NameSet::Str(rIndex);
1434}
1435
1436// Str()
1437template<class Attr>
1438std::string TaNameSet<Attr>::Str(void) const {
1439 return NameSet::Str();
1440}
1441
1442
1443
1444} // namespace faudes
1445
1446#endif
1447
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:934
#define FAUDES_TYPE_TIMPLEMENTATION_EQUAL(ftype, ctype, cbase, ctemp)
Definition cfl_types.h:945
#define FAUDES_TYPE_TDECLARATION(ftype, ctype, cbase)
Definition cfl_types.h:890
#define FAUDES_TYPE_TIMPLEMENTATION_ASSIGN(ftype, ctype, cbase, ctemp)
Definition cfl_types.h:937
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
Definition cfl_types.h:879
#define FAUDES_TYPE_TIMPLEMENTATION_COPY(ftype, ctype, cbase, ctemp)
Definition cfl_types.h:931
const std::string & Name(void) const
bool DoEqual(const NameSet &rOtherSet) const
bool Insert(const Idx &rIndex)
virtual std::string Str(void) const
SymbolTable * mpSymbolTable
void DoAssign(const NameSet &rSourceSet)
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 AssignWithAttributes(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
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)
void DoAssign(const TaNameSet &rSourceSet)
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)
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)
virtual TaNameSet & Assign(const TBaseSet< Idx > &rSrc)
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.33k --- 2025.09.16 --- c++ api documentaion by doxygen