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 
34 namespace faudes {
35 
36 /** @addtogroup Container Classes */
37 /** @{ */
38 
39 // Forward declaration for the attributed version of nameset
40 template<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 
70 class FAUDES_API NameSet : public TBaseSet<Idx> {
71 
73 
74 public:
75 
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  */
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  std::string Str(const Idx& rIndex) const;
428 
429 
430  protected:
431 
432  /** Pointer to local SymbolTable */
434 
435  /**
436  * Assign from other name set. Performs a fake copy, see TBaseSet.
437  *
438  * @param rSourceSet
439  * Source to copy from
440  */
441  void DoAssign(const NameSet& rSourceSet);
442 
443 
444  /**
445  * Test equality of configuration data.
446  * Ignore name of the set, insist in matching symboltables.
447  *
448  * @param rOtherSet
449  * Other object to compare with.
450  * @return
451  * True on match.
452  */
453  bool DoEqual(const NameSet& rOtherSet) const;
454 
455  /**
456  * Write to TokenWriter, see Type::Write for public wrappers
457  * This function will also do the token IO of attributes in derived classes.
458  *
459  * @param tw
460  * Reference to TokenWriter
461  * @param rLabel
462  * Label of the section to write, defaults to name of set or "NameSet"
463  * @param pContext
464  * Write context to provide contextual information
465  *
466  * @exception Exception
467  * - IO errors (id 2)
468  */
469  virtual void DoWrite(TokenWriter& tw, const std::string& rLabel="", const Type* pContext=0) const;
470 
471  /** Write debug info to TokenWriter, see Type::DWrite for public wrapper.
472  * The debug version writes a format that includes symbolic names and indices.
473  *
474  * @param tw
475  * Reference to TokenWriter
476  * @param rLabel
477  * Label of the section to write, defaults to name of set or "NameSet"
478  * @param pContext
479  * Write context to provide contextual information
480  *
481  * @exception Exception
482  * - IO errors (id 2)
483  */
484  virtual void DoDWrite(TokenWriter& tw, const std::string& rLabel="", const Type* pContext=0) const;
485 
486  /**
487  * Write to TokenWriter XML format, see Type::XWrite for public wrappers
488  * This function will also do the token IO of attributes in derived classes.
489  *
490  * @param tw
491  * Reference to TokenWriter
492  * @param rLabel
493  * Label of the section to write, defaults to name of set or "NameSet"
494  * @param pContext
495  * Write context to provide contextual information
496  *
497  * @exception Exception
498  * - IO errors (id 2)
499  */
500  virtual void DoXWrite(TokenWriter& tw, const std::string& rLabel="", const Type* pContext=0) const;
501 
502  /**
503  * Read from TokenReader, see Type::Read for public wrappers.
504  * It is an error if the file contains a plain index (id 52).
505  * The method invokes TokenReader::ReadBegin() to seek the specified
506  * section, reads subsequent symbols, and calls matching TokenReader::ReadEnd().
507  * If no section is specified, the section is assumed to start at the current position
508  * of the token stream. If the current position is no begin token,
509  * the section "NameSet" is read.
510  * When used by a derived class with attributes, attributes are read, too.
511  *
512  * @param tr
513  * Reference to TokenReader
514  * @param rLabel
515  * Label to read, defaults to current begin label or else "NameSet"
516  * @param pContext
517  * Write context to provide contextual information
518  *
519  * @exception Exception
520  * - IO errors (id 1)
521  * - token mismatch (id 50, 51, 52)
522  */
523  virtual void DoRead(TokenReader& tr, const std::string& rLabel = "", const Type* pContext=0);
524 
525 
526 };
527 
528 
529 /**
530  * Convenience typedef for plain event sets
531  *
532  * @ingroup ContainerClasses
533  */
534 typedef NameSet EventSet;
535 
536 /* convenience typedef for eventset vectors*/
538 
539 /* RTI convenience function */
540 extern FAUDES_API void SetIntersection(const EventSetVector& rSetVector, EventSet& rRes);
541 extern FAUDES_API void SetUnion(const EventSetVector& rSetVector, EventSet& rRes);
542 
543 
544 
545 /**
546  * Set of indices with symbolic names and attributes.
547  *
548  * This class is derived from NameSet and the interface TAttrMap.
549  *
550  * The file format is demonstrated by the following example
551  * of a set "Alphabet" consisting of events "alpha", "beta" and "gamma"
552  * with "gamma" having some attribute (see eg AtributeFlags)
553  * \code
554  * <Alphabet>
555  * "alpha"
556  * "beta"
557  * "gamma" 0x0f
558  * <\Alphabet>
559  * \endcode
560  * As with TBaseSet, reading a file silently ignores unknown attributes. Thus, the above example
561  * may also be read as NameSet.
562  */
563 
564 
565 
566 template<class Attr>
567 class FAUDES_TAPI TaNameSet : public NameSet, public TAttrMap<Idx,Attr> {
568 
570 
571  /**
572  * We implement "protected privacy for template classes" by friendship.
573  * This is used for the pragmatic implemention conversion constructors.
574  */
575  friend class NameSet;
576 
577 
578  public:
579 
580 
581  /* YS in 2024 for MSys2 -- see comment in cfl_types implementation macros*/
582  using NameSet::operator=;
583  using NameSet::operator==;
584  using NameSet::operator!=;
585 
586 
587  /**
588  * Constructor for NameSet referring to the static SymbolTable.
589  */
590  TaNameSet(void);
591 
592  /**
593  * Copy-constructor from other TaNameSet (incl attributes and symboltable)
594  *
595  * @param rOtherSet
596  * Set to copy
597  */
598  TaNameSet(const TaNameSet& rOtherSet);
599 
600  /**
601  * Constructor from NameSet (sets default attributes, same symboltable)
602  *
603  * @param rOtherSet
604  * Set to copy
605  */
606  TaNameSet(const NameSet& rOtherSet);
607 
608  /**
609  * Constructor from file.
610  * This constructor reads a NameSet from a file using the DoRead(TokenReader&, const std::String&)
611  * function. The section is specified by rLabel and the static SymbolTable is used.
612  *
613  * @param rFilename
614  * Name of File
615  * @param rLabel
616  * Section for the set in the file;
617  */
618  TaNameSet(const std::string& rFilename, const std::string& rLabel = "");
619 
620  /**
621  * Virtual destructor
622  */
623  virtual ~TaNameSet(void) {};
624 
625  /** Relaxed assignment method (uses base class to maintain attributes)
626  *
627  * Runtimetype check for TransSet, maintains attributes provided they can be casted.
628  *
629  * @param rSrc
630  * Source from which to assign
631  * @return
632  * Ref to this set
633  */
634  virtual TaNameSet& Assign(const TBaseSet<Idx>& rSrc);
635 
636  /** Relaxed assignment operator (uses base class to maintain attributes)
637  *
638  * @param rSrc
639  * Source from which to assign
640  * @return
641  * Ref to this set
642  */
643  /*virtual*/ TaNameSet& operator=(const NameSet& rSrc) { return Assign(rSrc); };
644 
645  /**
646  * Iterators on nameset.
647  */
648  using NameSet::Iterator;
649 
650  /**
651  * Add an element by index.
652  * Index must be already known to the global SymbolTable. If the element already
653  * exists in the set, the attribute is maintained. Otherwise, the element
654  * is inserted with default attribute.
655  *
656  * @param rIndex
657  * Index to add
658  * @return
659  * True, if element was new to set
660  * @exception Exception
661  * - no symbolic name for index (id 65)
662  */
663  virtual bool Insert(const Idx& rIndex);
664 
665 
666  /**
667  * Add an element by index incl. attribute
668  *
669  * @param rIndex
670  * Index to add
671  * @param rAttr
672  * Attribute to add
673  * @return
674  * True, if index was new to set
675  * @exception Exception
676  * - no symbolic name for index (id 65)
677  *
678  */
679  virtual bool Insert(const Idx& rIndex, const Attr& rAttr);
680 
681  /**
682  * Add an element by its symbolic name. If the name is unknown,
683  * a new index will be generated and recorded in the symboltable.
684  * If the name is known, the corresponding index will be added to the set.
685  * If the element already exists in the set, the attribute is maintained.
686  * Otherwise, the element is inserted with default attribute.
687  *
688  * @param rName
689  * symbolic name of element to add
690  *
691  * @return
692  * Index of (new) element
693  */
694  virtual Idx Insert(const std::string& rName);
695 
696  /**
697  * Add an element by its symbolic name.
698  * If the name is unknown,
699  * a new index will be generated and recorded in the symboltable.
700  * If the name is known, the corresponding index will be added to the set.
701  *
702  * @param rName
703  * symbolic name of element to add
704  * @param rAttr
705  * Attribute
706  *
707  * @return
708  * Index of (new) element
709  */
710  virtual Idx Insert(const std::string& rName, const Attr& rAttr);
711 
712  /**
713  * Inserts elements of rOtherSet.
714  *
715  * Attributes of this set are maintained, newly inserted elements obtain the attribute
716  * from rOtherSet provided they can be casted appropriately.
717  *
718  * @param rOtherSet
719  * Other StateSet
720  * @exception Exception
721  * - symboltable mismatch (id 67)
722  */
723  virtual void InsertSet(const NameSet& rOtherSet);
724 
725  /**
726  * Inserts all elements of rOtherSet.
727  *
728  * This variant requires a runtime cast to access the synboltable.
729  * An expection is thrown if the cast fails.
730  *
731  * @param rOtherSet
732  * Other NameSet
733  * @exception Exception
734  * - symboltable mismatch (id 67)
735  * - cast to nameset failed (id 67)
736  */
737  virtual void InsertSet(const TBaseSet<Idx>& rOtherSet);
738 
739  /**
740  * Delete element by index. Symbolic name is not removed from SymbolTable.
741  *
742  * @param rIndex
743  * Index to delete
744  * @return
745  * True if element did exist
746  *
747  */
748  virtual bool Erase(const Idx& rIndex);
749 
750  /**
751  * Delete element by symbolic name. Symbolic name is not removed from SymbolTable
752  *
753  * @param rName
754  * Symbolic name of element to dlete
755  * @return
756  * True if element did exist
757  * @exception Exception
758  * - name not found in Symboltable (id 66)
759  */
760  virtual bool Erase(const std::string& rName);
761 
762  /**
763  * Delete element by iterator. Symbolic name is not removed from SymbolTable.
764  *
765  * @param pos
766  * TaNameSet::iterator
767  * @return
768  * Iterator to next element
769  * @exception Exception
770  * - invalid iterator (id 62)
771  */
772  virtual typename NameSet::Iterator Erase(const Iterator& pos);
773 
774  /**
775  * Erase elements indicated by rOtherSet
776  *
777  * @exception Exception
778  * - symboltable mismatch (id 67)
779  *
780  * @param rOtherSet
781  * Other StateSet
782  */
783  virtual void EraseSet(const NameSet& rOtherSet);
784 
785  /**
786  * Erase elements specified by rOtherSet
787  *
788  * This function requires a runtime cast to access the synboltable.
789  * An expection is thrown if the cast fails.
790  *
791  * @param rOtherSet
792  * Other NameSet
793  * @exception Exception
794  * - symboltable mismatch (id 67)
795  * - cast to nameset failed (id 67)
796  */
797  virtual void EraseSet(const TBaseSet<Idx>& rOtherSet);
798 
799  /**
800  * Restrict elements indicated by rOtherSet
801  *
802  * @exception Exception
803  * - symboltable mismatch (id 67)
804  *
805  * @param rOtherSet
806  * Other EventSet
807  */
808  virtual void RestrictSet(const NameSet& rOtherSet);
809 
810  /**
811  * Restrict to elements specified by rOtherSet
812  *
813  * This function requires a runtime cast to access the synboltable.
814  * An expection is thrown if the cast fails.
815  *
816  * @param rOtherSet
817  * Other NameSet
818  * @exception Exception
819  * - symboltable mismatch (id 67)
820  * - cast to nameset failed (id 67)
821  */
822  virtual void RestrictSet(const TBaseSet<Idx>& rOtherSet);
823 
824  /**
825  * Set attributes. Provided that rOtherSet has attributes that can be
826  * casted to the appropriate type, attributes are copied per element from rOtherSet.
827  * Elements of this set which are not in rOtherSet maintain their attribute.
828  *
829  * @param rOtherSet
830  * Other IndexSet
831  * @exception Exception
832  * - Element does not exist (63)
833  * - Cannot cast attribute type (63)
834  * - Cannot cast to NameSet (63)
835  */
836  virtual void Attributes(const TBaseSet<Idx>& rOtherSet);
837 
838 
839  /**
840  * Return pretty printable symbolic name for index.
841  * Primary meant for debugging messages.
842  *
843  * @param rIndex
844  * Index to print
845  *
846  * @return
847  * String
848  */
849  std::string Str(const Idx& rIndex) const;
850 
851  /** resolve ambiguities from attribute interface ("using" wont do the job)*/
852  const Attr* AttributeType(void) const { return TAttrMap<Idx,Attr>::AttributeType(); };
853  Attr* Attributep(const Idx& rElem) { return TAttrMap<Idx,Attr>::Attributep(rElem); };
854  const Attr& Attribute(const Idx& rElem) const { return TAttrMap<Idx,Attr>::Attribute(rElem); };
855  void Attribute(const Idx& rElem, const Attr& rAttr) { TAttrMap<Idx,Attr>::Attribute(rElem,rAttr); };
856  void Attribute(const Idx& rElem, const Type& rAttr) { TAttrMap<Idx,Attr>::Attribute(rElem,rAttr); };
857  void AttributeTry(const Idx& rElem, const Type& rAttr) { TAttrMap<Idx,Attr>::AttributeTry(rElem,rAttr); };
858 
859  // convenience attribute interface using symbolic names
860  const Attr& Attribute(const std::string& rName) const {
861  return TAttrMap<Idx,Attr>::Attribute(Index(rName));
862  };
863  Attr* Attributep(const std::string& rName) {
864  return TAttrMap<Idx,Attr>::Attributep(Index(rName));
865  };
866  void Attribute(const std::string& rName, const Attr& rAttr) {
867  TAttrMap<Idx,Attr>::Attribute(Index(rName),rAttr);
868  };
869  void Attribute(const std::string& rName, const Type& rAttr) {
870  TAttrMap<Idx,Attr>::Attribute(Index(rName),rAttr);
871  };
872 
873  protected:
874 
875  /**
876  * Assign to other name set. Performs a fake copy, see TBaseSet.
877  * This function maintains attributes.
878  *
879  * @param rSourceSet
880  * Destination to copy from
881  * @return
882  * ref to this set
883  */
884  void DoAssign(const TaNameSet& rSourceSet);
885 
886  /**
887  * Test equality of configuration data, ignore attributes
888  * Ignore name of the set, insist in matching symboltables.
889  *
890  * @param rOtherSet
891  * Other object to compare with.
892  * @return
893  * True on match.
894  */
895  bool DoEqual(const NameSet& rOtherSet) const;
896 
897 
898 };
899 
900 
901 /** Convenience Macro */
902 #define TaEventSet TaNameSet
903 
904 /** @} doxygen group */
905 
906 /*
907 *************************************************************************************
908 *************************************************************************************
909  Implementation
910 *************************************************************************************
911 *************************************************************************************
912 */
913 
914 
915 // std faudes type (cannot do New() with macro)
916 FAUDES_TYPE_TIMPLEMENTATION_COPY(Void,TaNameSet<Attr>,NameSet,template<class Attr>)
917 FAUDES_TYPE_TIMPLEMENTATION_CAST(Void,TaNameSet<Attr>,NameSet,template<class Attr>)
918 FAUDES_TYPE_TIMPLEMENTATION_ASSIGN(Void,TaNameSet<Attr>,NameSet,template<class Attr>)
919 FAUDES_TYPE_TIMPLEMENTATION_EQUAL(Void,TaNameSet<Attr>,NameSet,template<class Attr>)
920 
921 // empty constructor
922 template<class Attr>
924  NameSet(),
925  TAttrMap<Idx,Attr>(this)
926 {
927  FD_DC("TaNameSet(" << this << ")::TaNameSet()");
928  //mpSymbolTable = SymbolTable::GlobalEventSymbolTablep();
929  this->Name("NameSet");
930 }
931 
932 // constructor form other nameset
933 template<class Attr>
935  NameSet(),
936  TAttrMap<Idx,Attr>(this)
937 {
938  FD_DC("TaNameSet(" << this << ")::TaNameSet(rOtherSet " << &rOtherSet << ")");
939  DoAssign(rOtherSet);
940 }
941 
942 // constructor form other nameset
943 template<class Attr>
945  NameSet(),
946  TAttrMap<Idx,Attr>(this)
947 {
948  FD_DC("TaNameSet(" << this << ")::TaNameSet(rOtherSet " << &rOtherSet << ")");
949  Assign(rOtherSet);
950 }
951 
952 
953 // read file constructor
954 template<class Attr>
955 TaNameSet<Attr>::TaNameSet(const std::string& rFilename, const std::string& rLabel) :
956  NameSet(),
957  TAttrMap<Idx,Attr>(this)
958 {
959  FD_DC("TaNameSet(" << this << ")::TaNameSet(" << rFilename << ")");
961  Read(rFilename, rLabel);
962 }
963 
964 // New() (std faudes type, cannot use macro because we need to fix symboltable)
965 template<class Attr>
967  TaNameSet* res = new TaNameSet();
968  res->mpSymbolTable=mpSymbolTable;
969  return res;
970 }
971 
972 // DoAssign()
973 template<class Attr>
975  FD_DC("TaNameSet(" << this << ")::DoAssign( [a] " << &rSourceSet << ")");
976  // base does the job
977  NameSet::DoAssign(rSourceSet);
978 }
979 
980 // DoEqual()
981 template<class Attr>
982 bool TaNameSet<Attr>::DoEqual(const NameSet& rOtherSet) const {
983  FD_DC("TaNameESet::DoEqual()");
984  // base does the job, equality does not refer to attributes
985  return NameSet::DoEqual(rOtherSet);
986 }
987 
988 
989 // Relaxed Assign()
990 template<class Attr>
992  FD_DC("TaNameSet(" << this << ")::Assign( [v] " << &rSourceSet << ")");
993  const NameSet* nset = dynamic_cast<const NameSet*>(&rSourceSet);
994 #ifdef FAUDES_CHECKED
995  if(!nset) {
996  std::stringstream errstr;
997  errstr << "cannot cast to nameset" << std::endl;
998  throw Exception("TaNameSet::Assign", errstr.str(), 67);
999  }
1000 #endif
1001  // name set specific data
1002  mpSymbolTable=nset->mpSymbolTable;
1003  // attribute interface does relaxed assignment
1005  // done
1006  return *this;
1007 }
1008 
1009 // Insert(index)
1010 template<class Attr>
1011 bool TaNameSet<Attr>::Insert(const Idx& rIndex) {
1012 #ifdef FAUDES_CHECKED
1013  if(!mpSymbolTable->Exists(rIndex)) {
1014  std::stringstream errstr;
1015  errstr << "index " << rIndex << " has no symbolic name" << std::endl;
1016  throw Exception("TaNameSet::Insert", errstr.str(), 65);
1017  }
1018 #endif
1019  return TAttrMap<Idx,Attr>::Insert(rIndex);
1020 }
1021 
1022 
1023 // Insert(index,attr)
1024 template<class Attr>
1025 bool TaNameSet<Attr>::Insert(const Idx& rIndex, const Attr& attr) {
1026 #ifdef FAUDES_CHECKED
1027  if(!mpSymbolTable->Exists(rIndex)) {
1028  std::stringstream errstr;
1029  errstr << "index " << rIndex << " has no symbolic name" << std::endl;
1030  throw Exception("TaNameSet::Insert", errstr.str(), 65);
1031  }
1032 #endif
1033  return TAttrMap<Idx,Attr>::Insert(rIndex,attr);
1034 }
1035 
1036 
1037 // Insert(rName)
1038 template<class Attr>
1039 Idx TaNameSet<Attr>::Insert(const std::string& rName) {
1040  FD_DC("TaNameSet(" << this << ")::Insert(" << rName <<")");
1041  Idx index= NameSet::Insert(rName); // automatic: keep attribute if exists
1042  return index;
1043 }
1044 
1045 // Insert(rName, attr)
1046 template<class Attr>
1047 Idx TaNameSet<Attr>::Insert(const std::string& rName, const Attr& attr) {
1048  FD_DC("TaNameSet(" << this << ")::Insert(" << rName <<")");
1049  Idx index= NameSet::Insert(rName);
1050  TAttrMap<Idx,Attr>::Attribute(index,attr);
1051  return index;
1052 }
1053 
1054 // InsertSet(set)
1055 template<class Attr>
1056 void TaNameSet<Attr>::InsertSet(const NameSet& rOtherSet) {
1057  FD_DC("TaNameSet(" << this << ")::InsertSet(" << &rOtherSet << ")");
1058 #ifdef FAUDES_CHECKED
1059  if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
1060  std::stringstream errstr;
1061  errstr << "symboltable mismach aka not implemented" << std::endl;
1062  throw Exception("TaNameSet::InsertSet", errstr.str(), 67);
1063  }
1064 #endif
1065  TAttrMap<Idx,Attr>::InsertSet(rOtherSet);
1066 }
1067 
1068 // InsertSet(set)
1069 template<class Attr>
1071  FD_DC("TaNameSet(" << this << ")::InsertSet(" << &rOtherSet << "):: downcast");
1072 #ifdef FAUDES_CHECKED
1073  const NameSet* nset = dynamic_cast<const NameSet*>(&rOtherSet);
1074  if(!nset) {
1075  std::stringstream errstr;
1076  errstr << "cannot cast to nameset" << std::endl;
1077  throw Exception("TaNameSet::InsertSet", errstr.str(), 67);
1078  }
1079  if(nset->mpSymbolTable!=mpSymbolTable) {
1080  std::stringstream errstr;
1081  errstr << "symboltable mismatch aka not implemented" << std::endl;
1082  throw Exception("TaNameSet::InsertSet", errstr.str(), 67);
1083  }
1084 #endif
1085  TAttrMap<Idx,Attr>::InsertSet(rOtherSet);
1086 }
1087 
1088 // Erase(index)
1089 template<class Attr>
1090 bool TaNameSet<Attr>::Erase(const Idx& rIndex) {
1091  FD_DC("TaNameSet(" << this << ")::Erase(" << rIndex <<")");
1092  return TAttrMap<Idx,Attr>::Erase(rIndex);
1093 }
1094 
1095 // Erase(rName)
1096 template<class Attr>
1097 bool TaNameSet<Attr>::Erase(const std::string& rName) {
1098  FD_DC("TaNameSet(" << this << ")::Erase(" << rName <<")");
1099  Idx index = mpSymbolTable->Index(rName);
1100 #ifdef FAUDES_CHECKED
1101  if (index == 0) {
1102  std::stringstream errstr;
1103  errstr << "name \"" << rName << "\" not found in TaNameSet" << std::endl;
1104  throw Exception("TaNameSet::Erase", errstr.str(), 60);
1105  }
1106 #endif
1107  return TAttrMap<Idx,Attr>::Erase(index);
1108 }
1109 
1110 // Erase(pos)
1111 template<class Attr>
1112 typename NameSet::Iterator TaNameSet<Attr>::Erase(const Iterator& pos) {
1113  return TAttrMap<Idx,Attr>::Erase(pos);
1114 }
1115 
1116 // EraseSet(set)
1117 template<class Attr>
1118 void TaNameSet<Attr>::EraseSet(const NameSet& rOtherSet) {
1119  FD_DC("TaNameSet(" << this << ")::EraseSet(" << rOtherSet.ToString() << ")");
1120 #ifdef FAUDES_CHECKED
1121  if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
1122  std::stringstream errstr;
1123  errstr << "symboltable mismach aka not implemented" << std::endl;
1124  throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1125  }
1126 #endif
1127  TAttrMap<Idx,Attr>::EraseSet(rOtherSet);
1128 }
1129 
1130 
1131 // EraseSet(set)
1132 template<class Attr>
1134 #ifdef FAUDES_CHECKED
1135  const NameSet* nset = dynamic_cast<const NameSet*>(&rOtherSet);
1136  if(!nset) {
1137  std::stringstream errstr;
1138  errstr << "cannot cast to nameset" << std::endl;
1139  throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1140  }
1141  if(nset->mpSymbolTable!=mpSymbolTable) {
1142  std::stringstream errstr;
1143  errstr << "symboltable mismatch aka not implemented" << std::endl;
1144  throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1145  }
1146 #endif
1147  TAttrMap<Idx,Attr>::EraseSet(rOtherSet);
1148 }
1149 
1150 
1151 // RestrictSet(set)
1152 template<class Attr>
1153 void TaNameSet<Attr>::RestrictSet(const NameSet& rOtherSet) {
1154  FD_DC("TaNameSet(" << this << ")::RestrictSet(" << rOtherSet.ToString() << ")");
1155 #ifdef FAUDES_CHECKED
1156  if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
1157  std::stringstream errstr;
1158  errstr << "symboltable mismach aka not implemented" << std::endl;
1159  throw Exception("TaNameSet::RestrictSet", errstr.str(), 67);
1160  }
1161 #endif
1163 }
1164 
1165 // RestrictSet(set)
1166 template<class Attr>
1168 #ifdef FAUDES_CHECKED
1169  const NameSet* nset = dynamic_cast<const NameSet*>(&rOtherSet);
1170  if(!nset) {
1171  std::stringstream errstr;
1172  errstr << "cannot cast to nameset" << std::endl;
1173  throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1174  }
1175  if(nset->mpSymbolTable!=mpSymbolTable) {
1176  std::stringstream errstr;
1177  errstr << "symboltable mismatch aka not implemented" << std::endl;
1178  throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1179  }
1180 #endif
1182 }
1183 
1184 
1185 // Attributes(set)
1186 template<class Attr>
1188  FD_DC("TaNameSet(" << this << ")::Attributes(otherset) with type " << typeid(rOtherSet.AttributeType()).name());
1189 #ifdef FAUDES_CHECKED
1190  const NameSet* nset = dynamic_cast<const NameSet*>(&rOtherSet);
1191  if(!nset) {
1192  std::stringstream errstr;
1193  errstr << "cannot cast to nameset" << std::endl;
1194  throw Exception("TaNameSet::Attributes(otherset)", errstr.str(), 67);
1195  }
1196  if(nset->mpSymbolTable!=mpSymbolTable) {
1197  std::stringstream errstr;
1198  errstr << "symboltable mismatch aka not implemented" << std::endl;
1199  throw Exception("TaNameSet::Attributes(otherset)", errstr.str(), 67);
1200  }
1201 #endif
1202  TBaseSet<Idx>::Attributes(rOtherSet);
1203 }
1204 
1205 
1206 // Str()
1207 template<class Attr>
1208 std::string TaNameSet<Attr>::Str(const Idx& rIndex) const {
1209  return NameSet::Str(rIndex);
1210 }
1211 
1212 
1213 
1214 } // namespace faudes
1215 
1216 #endif
1217 
Class TAttrMap.
Class TBaseVector.
#define FD_DC(message)
#define FAUDES_API
Definition: cfl_platform.h:80
#define FAUDES_TAPI
Definition: cfl_platform.h:83
Class SymbolTable.
#define FAUDES_TYPE_TIMPLEMENTATION_CAST(ftype, ctype, cbase, ctemp)
Definition: cfl_types.h:935
#define FAUDES_TYPE_TIMPLEMENTATION_EQUAL(ftype, ctype, cbase, ctemp)
Definition: cfl_types.h:946
#define FAUDES_TYPE_TDECLARATION(ftype, ctype, cbase)
Definition: cfl_types.h:891
#define FAUDES_TYPE_TIMPLEMENTATION_ASSIGN(ftype, ctype, cbase, ctemp)
Definition: cfl_types.h:938
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
Definition: cfl_types.h:880
#define FAUDES_TYPE_TIMPLEMENTATION_COPY(ftype, ctype, cbase, ctemp)
Definition: cfl_types.h:932
const std::string & Name(void) const
Definition: cfl_types.cpp:422
std::string Str(const Idx &rIndex) const
bool DoEqual(const NameSet &rOtherSet) const
Definition: cfl_nameset.cpp:97
bool Insert(const Idx &rIndex)
SymbolTable * mpSymbolTable
Definition: cfl_nameset.h:433
void DoAssign(const NameSet &rSourceSet)
Definition: cfl_nameset.cpp:88
static SymbolTable * GlobalEventSymbolTablep(void)
const Attr & Attribute(const T &rElem) const
Definition: cfl_attrmap.h:463
Attr * Attributep(const T &rElem)
Definition: cfl_attrmap.h:445
void AttributeTry(const T &rElem, const Type &attr)
Definition: cfl_attrmap.h:498
bool Erase(const T &rElem)
Definition: cfl_attrmap.h:369
void EraseSet(const TBaseSet< T, Cmp > &rOtherSet)
Definition: cfl_attrmap.h:386
void InsertSet(const TBaseSet< T, Cmp > &rOtherSet)
Definition: cfl_attrmap.h:340
void RestrictSet(const TBaseSet< T, Cmp > &rOtherSet)
Definition: cfl_attrmap.h:409
void AssignWithAttributes(const TBaseSet< T, Cmp > &rSourceSet)
Definition: cfl_attrmap.h:292
bool Insert(const T &rElem)
Definition: cfl_attrmap.h:323
const Attr * AttributeType(void) const
Definition: cfl_attrmap.h:437
virtual void InsertSet(const TBaseSet< Idx > &rOtherSet)
Definition: cfl_nameset.h:1070
void Attribute(const std::string &rName, const Attr &rAttr)
Definition: cfl_nameset.h:866
const Attr & Attribute(const std::string &rName) const
Definition: cfl_nameset.h:860
virtual bool Insert(const Idx &rIndex)
Definition: cfl_nameset.h:1011
void AttributeTry(const Idx &rElem, const Type &rAttr)
Definition: cfl_nameset.h:857
virtual void Attributes(const TBaseSet< Idx > &rOtherSet)
Definition: cfl_nameset.h:1187
bool DoEqual(const NameSet &rOtherSet) const
Definition: cfl_nameset.h:982
virtual void EraseSet(const NameSet &rOtherSet)
Definition: cfl_nameset.h:1118
std::string Str(const Idx &rIndex) const
Definition: cfl_nameset.h:1208
virtual bool Insert(const Idx &rIndex, const Attr &rAttr)
Definition: cfl_nameset.h:1025
virtual void EraseSet(const TBaseSet< Idx > &rOtherSet)
Definition: cfl_nameset.h:1133
void Attribute(const std::string &rName, const Type &rAttr)
Definition: cfl_nameset.h:869
void DoAssign(const TaNameSet &rSourceSet)
Definition: cfl_nameset.h:974
virtual Idx Insert(const std::string &rName)
Definition: cfl_nameset.h:1039
TaNameSet & operator=(const NameSet &rSrc)
Definition: cfl_nameset.h:643
Attr * Attributep(const Idx &rElem)
Definition: cfl_nameset.h:853
virtual void RestrictSet(const NameSet &rOtherSet)
Definition: cfl_nameset.h:1153
void Attribute(const Idx &rElem, const Attr &rAttr)
Definition: cfl_nameset.h:855
virtual bool Erase(const Idx &rIndex)
Definition: cfl_nameset.h:1090
virtual Idx Insert(const std::string &rName, const Attr &rAttr)
Definition: cfl_nameset.h:1047
virtual void InsertSet(const NameSet &rOtherSet)
Definition: cfl_nameset.h:1056
const Attr & Attribute(const Idx &rElem) const
Definition: cfl_nameset.h:854
virtual TaNameSet & Assign(const TBaseSet< Idx > &rSrc)
Definition: cfl_nameset.h:991
void Attribute(const Idx &rElem, const Type &rAttr)
Definition: cfl_nameset.h:856
virtual NameSet::Iterator Erase(const Iterator &pos)
Definition: cfl_nameset.h:1112
const Attr * AttributeType(void) const
Definition: cfl_nameset.h:852
Attr * Attributep(const std::string &rName)
Definition: cfl_nameset.h:863
virtual void RestrictSet(const TBaseSet< Idx > &rOtherSet)
Definition: cfl_nameset.h:1167
virtual bool Erase(const std::string &rName)
Definition: cfl_nameset.h:1097
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
Definition: cfl_types.cpp:267
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
Definition: cfl_types.cpp:175
virtual Type * New(void) const
Definition: cfl_types.cpp:54
virtual const AttributeVoid * AttributeType(void) const
Definition: cfl_baseset.h:2236
virtual void Attributes(const TBaseSet &rOtherSet)
Definition: cfl_baseset.h:2311
NameSet EventSet
Definition: cfl_nameset.h:534
void SetUnion(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB, TBaseSet< T, Cmp > &rRes)
Definition: cfl_baseset.h:1037
void SetIntersection(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB, TBaseSet< T, Cmp > &rRes)
Definition: cfl_baseset.h:1067
TBaseVector< EventSet > EventSetVector
Definition: cfl_nameset.h:537
uint32_t Idx

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