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  Exclusive copyright is granted to Klaus Schmidt
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
21 
22 
23 #ifndef FAUDES_NAMESET_H
24 #define FAUDES_NAMESET_H
25 
26 #include "cfl_definitions.h"
27 #include "cfl_exception.h"
28 #include "cfl_basevector.h"
29 #include "cfl_attrmap.h"
30 #include "cfl_symboltable.h"
31 #include "cfl_registry.h"
32 
33 namespace faudes {
34 
35 /** @addtogroup Container Classes */
36 /** @{ */
37 
38 // Forward declaration for the attributed version of nameset
39 template<class Attr> class TaNameSet;
40 
41 
42 /**
43  * Set of indices with symbolic names.
44  * In a NameSet, symbolic names are mandatory.
45  * The class is derived from IndexSet and uses a pointer to a SymbolTable
46  * to maintain the symbolic names. The static SymbolTable is used as default,
47  * which in the context of libfaudes becomes the global event symbol table.
48  * It is an error to refer to an unknown symbolic name or to an index
49  * with no name associated. When FAUDES_CHECKED is defined, an exception will
50  * be thrown. It is also considered an error to relate two NameSets that refer to
51  * different SymbolTables (using e.g. SetUnion).
52  *
53  *
54  * Since symbolic names are mandatory, file IO uses names rather than indices.
55  * Technically, file IO is done by TaNameSet functions. This requires a copy and for
56  * that reason may be reimplemented in a future versions.
57  * The format is demonstrated by the following example
58  * of a set with name "Alphabet" consisting of events "alpha", "beta" and "gamma":
59  * \code
60  * <Alphabet>
61  * "alpha" "beta" "gamma"
62  * <\Alphabet>
63  * \endcode
64  * Note that when reading a file, indices will be associated with the symbolic names
65  * based on availability. Within one libfaudes session, each individual event will
66  * be referred to by a unique index.
67  */
68 
69 class FAUDES_API NameSet : public TBaseSet<Idx> {
70 
72 
73 public:
74 
78 
79  /**
80  * We implement "protected privacy for template classes" by friendship.
81  * This is used for the pragmatic implemention of conversion constructors.
82  */
83  template<class Attr> friend class TaNameSet;
84 
85  /**
86  * Constructor for NameSet referring to the static SymbolTable.
87  */
88  NameSet(void);
89 
90  /**
91  * Copy-constructor from other NameSet.
92  * This also copies the SymbolTable reference, hence the new NameSet
93  * will use the same SymbolTable as rOtherSet.
94  *
95  * @param rOtherSet
96  * Set to copy
97  */
98  NameSet(const NameSet& rOtherSet);
99 
100 
101  /**
102  * Constructor from file.
103  * This constructor reads a NameSet from a file using the DoRead(TokenReader&, const std::string&)
104  * function. The section is specified by rLabel and the static SymbolTable is used.
105  *
106  *
107  * @param rFilename
108  * Name of file
109  * @param rLabel
110  * Section for the set in the file;
111  */
112  NameSet(const std::string& rFilename, const std::string& rLabel = "");
113 
114  /**
115  * Virtual destructor
116  */
117  virtual ~NameSet(void);
118 
119  /**
120  * Get Pointer mpSymbolTable.
121  *
122  * @return
123  * Pointer mpSymbolTable
124  */
125  SymbolTable* SymbolTablep(void) const;
126 
127  /**
128  * Set SymbolTable reference.
129  * This function sets the reference to the SymbolTable. The current implementation
130  * clears the set, future versions may implement a re-indexing.
131  *
132  * @param pSymTab
133  * Pointer to SymbolTable
134  */
135  void SymbolTablep(SymbolTable* pSymTab);
136 
137  /**
138  * Iterators on nameset.
139  */
141 
142  /**
143  * Add an element by index.
144  * Index must be already known to the global SymbolTable.
145  *
146  * @param rIndex
147  * Index to add
148  * @return
149  * True, if element was new to set
150  * @exception Exception
151  * - no symbolic name for index (id 65)
152  */
153  bool Insert(const Idx& rIndex);
154 
155  /**
156  * Add an element by its symbolic name. If the name is unknown,
157  * a new index will be generated and recorded in the symboltable.
158  * If the name is known, the corresponding index will be added to the set.
159  *
160  * @param rName
161  * Symbolic name of element to add
162  *
163  * @return
164  * Index of (new) element
165  */
166  Idx Insert(const std::string& rName);
167 
168  /**
169  * Inserts all elements of rOtherSet.
170  *
171  * @param rOtherSet
172  * Other NameSet
173  * @exception Exception
174  * - symboltable mismatch (id 67)
175  */
176  virtual void InsertSet(const NameSet& rOtherSet);
177 
178  /**
179  * Inserts all elements of rOtherSet.
180  *
181  * This variant requires a runtime cast to access the synboltable.
182  * An expection is thrown if the cast fails.
183  *
184  * @param rOtherSet
185  * Other NameSet
186  * @exception Exception
187  * - symboltable mismatch (id 67)
188  * - cast to nameset failed (id 67)
189  */
190  virtual void InsertSet(const TBaseSet<Idx>& rOtherSet);
191 
192  /**
193  * Delete element by index. The symbolic name is not removed from the SymbolTable.
194  *
195  * @param rIndex
196  * Index
197  * @return
198  * True if element did exist
199  */
200  virtual bool Erase(const Idx& rIndex);
201 
202  /**
203  * Delete element by symbolic name. The symbolic name is not removed from the SymbolTable
204  *
205  * @param rName
206  * symbolic name
207  * @return
208  * True if element did exist
209  * @exception Exception
210  * - unknown symbolic name (id 66)
211  */
212  virtual bool Erase(const std::string& rName);
213 
214  /**
215  * Delete element by iterator. Symbolic nam is not removed from SymbolTable.
216  *
217  * @param pos
218  * NameSet::iterator
219  * @return
220  * iterator to next element
221  * @exception Exception
222  * - invalid iterator (id 62)
223  */
224  virtual NameSet::Iterator Erase(const Iterator& pos);
225 
226  /**
227  * Erase elements specified by rOtherSet
228  *
229  * @param rOtherSet
230  * Other StateSet
231  * @exception Exception
232  * - symboltable mismatch (id 67)
233  */
234  void EraseSet(const NameSet& rOtherSet);
235 
236  /**
237  * Erase elements specified by rOtherSet
238  *
239  * This function requires a runtime cast to access the synboltable.
240  * An expection is thrown if the cast fails.
241  *
242  * @param rOtherSet
243  * Other NameSet
244  * @exception Exception
245  * - symboltable mismatch (id 67)
246  * - cast to nameset failed (id 67)
247  */
248  virtual void EraseSet(const TBaseSet<Idx>& rOtherSet);
249 
250  /**
251  * Restrict to elements specified by rOtherSet
252  *
253  * @param rOtherSet
254  * Other StateSet
255  * @exception Exception
256  * - symboltable mismatch (id 67)
257  */
258  void RestrictSet(const NameSet& rOtherSet);
259 
260  /**
261  * Restrict to elements specified by rOtherSet
262  *
263  * This function requires a runtime cast to access the synboltable.
264  * An expection is thrown if the cast fails.
265  *
266  * @param rOtherSet
267  * Other NameSet
268  * @exception Exception
269  * - symboltable mismatch (id 67)
270  * - cast to nameset failed (id 67)
271  */
272  virtual void RestrictSet(const TBaseSet<Idx>& rOtherSet);
273 
274  /**
275  * Set new name for existing index.
276  * FAUDES_CHECKED checks if index exists in NameSet.
277  *
278  * @param index
279  * Index to edit
280  * @param rName
281  * New name
282  *
283  * @exception Exception
284  * - index not in this set (id 60)
285  * - index not found in SymbolTable (id 42)
286  * - name already associated with another index (id 44)
287  */
288  void SymbolicName(Idx index, const std::string& rName);
289 
290 
291  /**
292  * Set new name for existing name
293  * FAUDES_CHECKED checks if the specified name exists in NameSet.
294  *
295  * @param rName
296  * Symbolic name to edit
297  * @param rNewName
298  * New name
299  *
300  * @exception Exception
301  * - symbolic name not in this set (id 60)
302  * - new name already associated with another index (id 44)
303  */
304  void SymbolicName(const std::string& rName, const std::string& rNewName);
305 
306  /**
307  * Name lookup
308  *
309  * @param index
310  * Index to lookup
311  *
312  * @return
313  * Corresponding name or empty std::string if non-existent
314  */
315  std::string SymbolicName(Idx index) const;
316 
317  /**
318  * Index lookup
319  *
320  * @param rName
321  * Symbolic name to look up
322  *
323  * @return
324  * Corresponding index or 0 for non-existent
325  */
326  Idx Index(const std::string& rName) const;
327 
328  /**
329  * Test existence of index
330  *
331  * @param rIndex
332  * Index to test
333  *
334  * @return
335  * True if index is in this set
336  */
337  bool Exists(const Idx& rIndex) const;
338 
339  /**
340  * Test existence of name
341  *
342  * @param rName
343  * Symbolic name to test
344  *
345  * @return
346  * True if index is in this set
347  */
348  bool Exists(const std::string& rName) const;
349 
350  /**
351  * Find iterator for index. Returns either a valid iterator
352  * or End() for non-existent.
353  *
354  * @param rIndex
355  * Index to find
356  *
357  * @return
358  * NameSet::Iterator
359  */
360  NameSet::Iterator Find(const Idx& rIndex) const;
361 
362  /**
363  * Find iterator for name. Returns either a valid iterator
364  * or End() for non-existent.
365  *
366  * @param rName
367  * Name to find
368  *
369  * @return
370  * NameSet::Iterator
371  */
372  NameSet::Iterator Find(const std::string& rName) const;
373 
374 
375  /**
376  * Set union operator
377  *
378  * @return
379  * Union Set
380  *
381  * @exception Exception
382  * - symboltable mismatch (id 67)
383  */
384  NameSet operator + (const NameSet& rOtherSet) const;
385 
386  /**
387  * Set difference operator
388  *
389  * @return
390  * Difference NameSet
391  *
392  * @exception Exception
393  * - symboltable mismatch (id 67)
394  */
395  NameSet operator - (const NameSet& rOtherSet) const;
396 
397  /**
398  * Set intersection operator
399  *
400  * @return
401  * Intersection NameSet
402  *
403  * @exception Exception
404  * - symboltable mismatch (id 67)
405  */
406  NameSet operator * (const NameSet& rOtherSet) const;
407 
408 
409  /** Test for subset */
410  bool operator<= (const NameSet& rOtherSet) const;
411 
412  /** Test for superset */
413  bool operator>= (const NameSet& rOtherSet) const;
414 
415 
416  /**
417  * Return pretty printable symbolic name for index.
418  * Primary meant for debugging messages.
419  *
420  * @param rIndex
421  * Index to print
422  *
423  * @return
424  * String
425  */
426  std::string Str(const Idx& rIndex) const;
427 
428 
429  protected:
430 
431  /** Pointer to local SymbolTable */
433 
434  /**
435  * Assign from other name set. Performs a fake copy, see TBaseSet.
436  *
437  * @param rSourceSet
438  * Source to copy from
439  */
440  void DoAssign(const NameSet& rSourceSet);
441 
442 
443  /**
444  * Test equality of configuration data.
445  * Ignore name of the set, insist in matching symboltables.
446  *
447  * @param rOtherSet
448  * Other object to compare with.
449  * @return
450  * True on match.
451  */
452  bool DoEqual(const NameSet& rOtherSet) const;
453 
454  /**
455  * Write to TokenWriter, see Type::Write for public wrappers
456  * This function will also do the token IO of attributes in derived classes.
457  *
458  * @param tw
459  * Reference to TokenWriter
460  * @param rLabel
461  * Label of the section to write, defaults to name of set or "NameSet"
462  * @param pContext
463  * Write context to provide contextual information
464  *
465  * @exception Exception
466  * - IO errors (id 2)
467  */
468  virtual void DoWrite(TokenWriter& tw, const std::string& rLabel="", const Type* pContext=0) const;
469 
470  /** Write debug info to TokenWriter, see Type::DWrite for public wrapper.
471  * The debug version writes a format that includes symbolic names and indices.
472  *
473  * @param tw
474  * Reference to TokenWriter
475  * @param rLabel
476  * Label of the section to write, defaults to name of set or "NameSet"
477  * @param pContext
478  * Write context to provide contextual information
479  *
480  * @exception Exception
481  * - IO errors (id 2)
482  */
483  virtual void DoDWrite(TokenWriter& tw, const std::string& rLabel="", const Type* pContext=0) const;
484 
485  /**
486  * Write to TokenWriter XML format, see Type::XWrite for public wrappers
487  * This function will also do the token IO of attributes in derived classes.
488  *
489  * @param tw
490  * Reference to TokenWriter
491  * @param rLabel
492  * Label of the section to write, defaults to name of set or "NameSet"
493  * @param pContext
494  * Write context to provide contextual information
495  *
496  * @exception Exception
497  * - IO errors (id 2)
498  */
499  virtual void DoXWrite(TokenWriter& tw, const std::string& rLabel="", const Type* pContext=0) const;
500 
501  /**
502  * Read from TokenReader, see Type::Read for public wrappers.
503  * It is an error if the file contains a plain index (id 52).
504  * The method invokes TokenReader::ReadBegin() to seek the specified
505  * section, reads subsequent symbols, and calls matching TokenReader::ReadEnd().
506  * If no section is specified, the section is assumed to start at the current position
507  * of the token stream. If the current position is no begin token,
508  * the section "NameSet" is read.
509  * When used by a derived class with attributes, attributes are read, too.
510  *
511  * @param tr
512  * Reference to TokenReader
513  * @param rLabel
514  * Label to read, defaults to current begin label or else "NameSet"
515  * @param pContext
516  * Write context to provide contextual information
517  *
518  * @exception Exception
519  * - IO errors (id 1)
520  * - token mismatch (id 50, 51, 52)
521  */
522  virtual void DoRead(TokenReader& tr, const std::string& rLabel = "", const Type* pContext=0);
523 
524 
525 };
526 
527 
528 /**
529  * Convenience typedef for plain event sets
530  *
531  * @ingroup ContainerClasses
532  */
533 typedef NameSet EventSet;
534 
535 /* convenience typedef for eventset vectors*/
537 
538 /* RTI convenience function */
539 extern FAUDES_API void SetIntersection(const EventSetVector& rSetVector, EventSet& rRes);
540 extern FAUDES_API void SetUnion(const EventSetVector& rSetVector, EventSet& rRes);
541 
542 
543 
544 /**
545  * Set of indices with symbolic names and attributes.
546  *
547  * This class is derived from NameSet and the interface TAttrMap.
548  *
549  * The file format is demonstrated by the following example
550  * of a set "Alphabet" consisting of events "alpha", "beta" and "gamma"
551  * with "gamma" having some attribute (see eg AtributeFlags)
552  * \code
553  * <Alphabet>
554  * "alpha"
555  * "beta"
556  * "gamma" 0x0f
557  * <\Alphabet>
558  * \endcode
559  * As with TBaseSet, reading a file silently ignores unknown attributes. Thus, the above example
560  * may also be read as NameSet.
561  */
562 
563 
564 
565 template<class Attr>
566 class FAUDES_TAPI TaNameSet : public NameSet, public TAttrMap<Idx,Attr> {
567 
569 
570  /**
571  * We implement "protected privacy for template classes" by friendship.
572  * This is used for the pragmatic implemention conversion constructors.
573  */
574  friend class NameSet;
575 
576 
577  public:
578 
579 
580  /* YS in 2024 for MSys2 -- see comment in cfl_types implementation macros*/
581  using NameSet::operator=;
582  using NameSet::operator==;
583  using NameSet::operator!=;
584 
585 
586  /**
587  * Constructor for NameSet referring to the static SymbolTable.
588  */
589  TaNameSet(void);
590 
591  /**
592  * Copy-constructor from other TaNameSet (incl attributes and symboltable)
593  *
594  * @param rOtherSet
595  * Set to copy
596  */
597  TaNameSet(const TaNameSet& rOtherSet);
598 
599  /**
600  * Constructor from NameSet (sets default attributes, same symboltable)
601  *
602  * @param rOtherSet
603  * Set to copy
604  */
605  TaNameSet(const NameSet& rOtherSet);
606 
607  /**
608  * Constructor from file.
609  * This constructor reads a NameSet from a file using the DoRead(TokenReader&, const std::String&)
610  * function. The section is specified by rLabel and the static SymbolTable is used.
611  *
612  * @param rFilename
613  * Name of File
614  * @param rLabel
615  * Section for the set in the file;
616  */
617  TaNameSet(const std::string& rFilename, const std::string& rLabel = "");
618 
619  /**
620  * Virtual destructor
621  */
622  virtual ~TaNameSet(void) {};
623 
624  /** Relaxed assignment method (uses base class to maintain attributes)
625  *
626  * Runtimetype check for TransSet, maintains attributes provided they can be casted.
627  *
628  * @param rSrc
629  * Source from which to assign
630  * @return
631  * Ref to this set
632  */
633  virtual TaNameSet& Assign(const TBaseSet<Idx>& rSrc);
634 
635  /** Relaxed assignment operator (uses base class to maintain attributes)
636  *
637  * @param rSrc
638  * Source from which to assign
639  * @return
640  * Ref to this set
641  */
642  /*virtual*/ TaNameSet& operator=(const NameSet& rSrc) { return Assign(rSrc); };
643 
644  /**
645  * Iterators on nameset.
646  */
647  using NameSet::Iterator;
648 
649  /**
650  * Add an element by index.
651  * Index must be already known to the global SymbolTable. If the element already
652  * exists in the set, the attribute is maintained. Otherwise, the element
653  * is inserted with default attribute.
654  *
655  * @param rIndex
656  * Index to add
657  * @return
658  * True, if element was new to set
659  * @exception Exception
660  * - no symbolic name for index (id 65)
661  */
662  virtual bool Insert(const Idx& rIndex);
663 
664 
665  /**
666  * Add an element by index incl. attribute
667  *
668  * @param rIndex
669  * Index to add
670  * @param rAttr
671  * Attribute to add
672  * @return
673  * True, if index was new to set
674  * @exception Exception
675  * - no symbolic name for index (id 65)
676  *
677  */
678  virtual bool Insert(const Idx& rIndex, const Attr& rAttr);
679 
680  /**
681  * Add an element by its symbolic name. If the name is unknown,
682  * a new index will be generated and recorded in the symboltable.
683  * If the name is known, the corresponding index will be added to the set.
684  * If the element already exists in the set, the attribute is maintained.
685  * Otherwise, the element is inserted with default attribute.
686  *
687  * @param rName
688  * symbolic name of element to add
689  *
690  * @return
691  * Index of (new) element
692  */
693  virtual Idx Insert(const std::string& rName);
694 
695  /**
696  * Add an element by its symbolic name.
697  * If the name is unknown,
698  * a new index will be generated and recorded in the symboltable.
699  * If the name is known, the corresponding index will be added to the set.
700  *
701  * @param rName
702  * symbolic name of element to add
703  * @param rAttr
704  * Attribute
705  *
706  * @return
707  * Index of (new) element
708  */
709  virtual Idx Insert(const std::string& rName, const Attr& rAttr);
710 
711  /**
712  * Inserts elements of rOtherSet.
713  *
714  * Attributes of this set are maintained, newly inserted elements obtain the attribute
715  * from rOtherSet provided they can be casted appropriately.
716  *
717  * @param rOtherSet
718  * Other StateSet
719  * @exception Exception
720  * - symboltable mismatch (id 67)
721  */
722  virtual void InsertSet(const NameSet& rOtherSet);
723 
724  /**
725  * Inserts all elements of rOtherSet.
726  *
727  * This variant requires a runtime cast to access the synboltable.
728  * An expection is thrown if the cast fails.
729  *
730  * @param rOtherSet
731  * Other NameSet
732  * @exception Exception
733  * - symboltable mismatch (id 67)
734  * - cast to nameset failed (id 67)
735  */
736  virtual void InsertSet(const TBaseSet<Idx>& rOtherSet);
737 
738  /**
739  * Delete element by index. Symbolic name is not removed from SymbolTable.
740  *
741  * @param rIndex
742  * Index to delete
743  * @return
744  * True if element did exist
745  *
746  */
747  virtual bool Erase(const Idx& rIndex);
748 
749  /**
750  * Delete element by symbolic name. Symbolic name is not removed from SymbolTable
751  *
752  * @param rName
753  * Symbolic name of element to dlete
754  * @return
755  * True if element did exist
756  * @exception Exception
757  * - name not found in Symboltable (id 66)
758  */
759  virtual bool Erase(const std::string& rName);
760 
761  /**
762  * Delete element by iterator. Symbolic name is not removed from SymbolTable.
763  *
764  * @param pos
765  * TaNameSet::iterator
766  * @return
767  * Iterator to next element
768  * @exception Exception
769  * - invalid iterator (id 62)
770  */
771  virtual typename NameSet::Iterator Erase(const Iterator& pos);
772 
773  /**
774  * Erase elements indicated by rOtherSet
775  *
776  * @exception Exception
777  * - symboltable mismatch (id 67)
778  *
779  * @param rOtherSet
780  * Other StateSet
781  */
782  virtual void EraseSet(const NameSet& rOtherSet);
783 
784  /**
785  * Erase elements specified by rOtherSet
786  *
787  * This function requires a runtime cast to access the synboltable.
788  * An expection is thrown if the cast fails.
789  *
790  * @param rOtherSet
791  * Other NameSet
792  * @exception Exception
793  * - symboltable mismatch (id 67)
794  * - cast to nameset failed (id 67)
795  */
796  virtual void EraseSet(const TBaseSet<Idx>& rOtherSet);
797 
798  /**
799  * Restrict elements indicated by rOtherSet
800  *
801  * @exception Exception
802  * - symboltable mismatch (id 67)
803  *
804  * @param rOtherSet
805  * Other EventSet
806  */
807  virtual void RestrictSet(const NameSet& rOtherSet);
808 
809  /**
810  * Restrict to elements specified by rOtherSet
811  *
812  * This function requires a runtime cast to access the synboltable.
813  * An expection is thrown if the cast fails.
814  *
815  * @param rOtherSet
816  * Other NameSet
817  * @exception Exception
818  * - symboltable mismatch (id 67)
819  * - cast to nameset failed (id 67)
820  */
821  virtual void RestrictSet(const TBaseSet<Idx>& rOtherSet);
822 
823  /**
824  * Set attributes. Provided that rOtherSet has attributes that can be
825  * casted to the appropriate type, attributes are copied per element from rOtherSet.
826  * Elements of this set which are not in rOtherSet maintain their attribute.
827  *
828  * @param rOtherSet
829  * Other IndexSet
830  * @exception Exception
831  * - Element does not exist (63)
832  * - Cannot cast attribute type (63)
833  * - Cannot cast to NameSet (63)
834  */
835  virtual void Attributes(const TBaseSet<Idx>& rOtherSet);
836 
837 
838  /**
839  * Return pretty printable symbolic name for index.
840  * Primary meant for debugging messages.
841  *
842  * @param rIndex
843  * Index to print
844  *
845  * @return
846  * String
847  */
848  std::string Str(const Idx& rIndex) const;
849 
850  /** resolve ambiguities from attribute interface ("using" wont do the job)*/
851  const Attr* AttributeType(void) const { return TAttrMap<Idx,Attr>::AttributeType(); };
852  Attr* Attributep(const Idx& rElem) { return TAttrMap<Idx,Attr>::Attributep(rElem); };
853  const Attr& Attribute(const Idx& rElem) const { return TAttrMap<Idx,Attr>::Attribute(rElem); };
854  void Attribute(const Idx& rElem, const Attr& rAttr) { TAttrMap<Idx,Attr>::Attribute(rElem,rAttr); };
855  void Attribute(const Idx& rElem, const Type& rAttr) { TAttrMap<Idx,Attr>::Attribute(rElem,rAttr); };
856  void AttributeTry(const Idx& rElem, const Type& rAttr) { TAttrMap<Idx,Attr>::AttributeTry(rElem,rAttr); };
857 
858  // convenience attribute interface using symbolic names
859  const Attr& Attribute(const std::string& rName) const {
860  return TAttrMap<Idx,Attr>::Attribute(Index(rName));
861  };
862  Attr* Attributep(const std::string& rName) {
863  return TAttrMap<Idx,Attr>::Attributep(Index(rName));
864  };
865  void Attribute(const std::string& rName, const Attr& rAttr) {
866  TAttrMap<Idx,Attr>::Attribute(Index(rName),rAttr);
867  };
868  void Attribute(const std::string& rName, const Type& rAttr) {
869  TAttrMap<Idx,Attr>::Attribute(Index(rName),rAttr);
870  };
871 
872  protected:
873 
874  /**
875  * Assign to other name set. Performs a fake copy, see TBaseSet.
876  * This function maintains attributes.
877  *
878  * @param rSourceSet
879  * Destination to copy from
880  * @return
881  * ref to this set
882  */
883  void DoAssign(const TaNameSet& rSourceSet);
884 
885  /**
886  * Test equality of configuration data, ignore attributes
887  * Ignore name of the set, insist in matching symboltables.
888  *
889  * @param rOtherSet
890  * Other object to compare with.
891  * @return
892  * True on match.
893  */
894  bool DoEqual(const NameSet& rOtherSet) const;
895 
896 
897 };
898 
899 
900 /** Convenience Macro */
901 #define TaEventSet TaNameSet
902 
903 /** @} doxygen group */
904 
905 /*
906 *************************************************************************************
907 *************************************************************************************
908  Implementation
909 *************************************************************************************
910 *************************************************************************************
911 */
912 
913 
914 // std faudes type (cannot do New() with macro)
915 FAUDES_TYPE_TIMPLEMENTATION_COPY(Void,TaNameSet<Attr>,NameSet,template<class Attr>)
916 FAUDES_TYPE_TIMPLEMENTATION_CAST(Void,TaNameSet<Attr>,NameSet,template<class Attr>)
917 FAUDES_TYPE_TIMPLEMENTATION_ASSIGN(Void,TaNameSet<Attr>,NameSet,template<class Attr>)
918 FAUDES_TYPE_TIMPLEMENTATION_EQUAL(Void,TaNameSet<Attr>,NameSet,template<class Attr>)
919 
920 // empty constructor
921 template<class Attr>
923  NameSet(),
924  TAttrMap<Idx,Attr>(this)
925 {
926  FD_DC("TaNameSet(" << this << ")::TaNameSet()");
927  //mpSymbolTable = SymbolTable::GlobalEventSymbolTablep();
928  this->Name("NameSet");
929 }
930 
931 // constructor form other nameset
932 template<class Attr>
934  NameSet(),
935  TAttrMap<Idx,Attr>(this)
936 {
937  FD_DC("TaNameSet(" << this << ")::TaNameSet(rOtherSet " << &rOtherSet << ")");
938  DoAssign(rOtherSet);
939 }
940 
941 // constructor form other nameset
942 template<class Attr>
944  NameSet(),
945  TAttrMap<Idx,Attr>(this)
946 {
947  FD_DC("TaNameSet(" << this << ")::TaNameSet(rOtherSet " << &rOtherSet << ")");
948  Assign(rOtherSet);
949 }
950 
951 
952 // read file constructor
953 template<class Attr>
954 TaNameSet<Attr>::TaNameSet(const std::string& rFilename, const std::string& rLabel) :
955  NameSet(),
956  TAttrMap<Idx,Attr>(this)
957 {
958  FD_DC("TaNameSet(" << this << ")::TaNameSet(" << rFilename << ")");
960  Read(rFilename, rLabel);
961 }
962 
963 // New() (std faudes type, cannot use macro because we need to fix symboltable)
964 template<class Attr>
966  TaNameSet* res = new TaNameSet();
967  res->mpSymbolTable=mpSymbolTable;
968  return res;
969 }
970 
971 // DoAssign()
972 template<class Attr>
974  FD_DC("TaNameSet(" << this << ")::DoAssign( [a] " << &rSourceSet << ")");
975  // base does the job
976  NameSet::DoAssign(rSourceSet);
977 }
978 
979 // DoEqual()
980 template<class Attr>
981 bool TaNameSet<Attr>::DoEqual(const NameSet& rOtherSet) const {
982  FD_DC("TaNameESet::DoEqual()");
983  // base does the job, equality does not refer to attributes
984  return NameSet::DoEqual(rOtherSet);
985 }
986 
987 
988 // Relaxed Assign()
989 template<class Attr>
991  FD_DC("TaNameSet(" << this << ")::Assign( [v] " << &rSourceSet << ")");
992  const NameSet* nset = dynamic_cast<const NameSet*>(&rSourceSet);
993 #ifdef FAUDES_CHECKED
994  if(!nset) {
995  std::stringstream errstr;
996  errstr << "cannot cast to nameset" << std::endl;
997  throw Exception("TaNameSet::Assign", errstr.str(), 67);
998  }
999 #endif
1000  // name set specific data
1001  mpSymbolTable=nset->mpSymbolTable;
1002  // attribute interface does relaxed assignment
1004  // done
1005  return *this;
1006 }
1007 
1008 // Insert(index)
1009 template<class Attr>
1010 bool TaNameSet<Attr>::Insert(const Idx& rIndex) {
1011 #ifdef FAUDES_CHECKED
1012  if(!mpSymbolTable->Exists(rIndex)) {
1013  std::stringstream errstr;
1014  errstr << "index " << rIndex << " has no symbolic name" << std::endl;
1015  throw Exception("TaNameSet::Insert", errstr.str(), 65);
1016  }
1017 #endif
1018  return TAttrMap<Idx,Attr>::Insert(rIndex);
1019 }
1020 
1021 
1022 // Insert(index,attr)
1023 template<class Attr>
1024 bool TaNameSet<Attr>::Insert(const Idx& rIndex, const Attr& attr) {
1025 #ifdef FAUDES_CHECKED
1026  if(!mpSymbolTable->Exists(rIndex)) {
1027  std::stringstream errstr;
1028  errstr << "index " << rIndex << " has no symbolic name" << std::endl;
1029  throw Exception("TaNameSet::Insert", errstr.str(), 65);
1030  }
1031 #endif
1032  return TAttrMap<Idx,Attr>::Insert(rIndex,attr);
1033 }
1034 
1035 
1036 // Insert(rName)
1037 template<class Attr>
1038 Idx TaNameSet<Attr>::Insert(const std::string& rName) {
1039  FD_DC("TaNameSet(" << this << ")::Insert(" << rName <<")");
1040  Idx index= NameSet::Insert(rName); // automatic: keep attribute if exists
1041  return index;
1042 }
1043 
1044 // Insert(rName, attr)
1045 template<class Attr>
1046 Idx TaNameSet<Attr>::Insert(const std::string& rName, const Attr& attr) {
1047  FD_DC("TaNameSet(" << this << ")::Insert(" << rName <<")");
1048  Idx index= NameSet::Insert(rName);
1049  TAttrMap<Idx,Attr>::Attribute(index,attr);
1050  return index;
1051 }
1052 
1053 // InsertSet(set)
1054 template<class Attr>
1055 void TaNameSet<Attr>::InsertSet(const NameSet& rOtherSet) {
1056  FD_DC("TaNameSet(" << this << ")::InsertSet(" << &rOtherSet << ")");
1057 #ifdef FAUDES_CHECKED
1058  if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
1059  std::stringstream errstr;
1060  errstr << "symboltable mismach aka not implemented" << std::endl;
1061  throw Exception("TaNameSet::InsertSet", errstr.str(), 67);
1062  }
1063 #endif
1064  TAttrMap<Idx,Attr>::InsertSet(rOtherSet);
1065 }
1066 
1067 // InsertSet(set)
1068 template<class Attr>
1070  FD_DC("TaNameSet(" << this << ")::InsertSet(" << &rOtherSet << "):: downcast");
1071 #ifdef FAUDES_CHECKED
1072  const NameSet* nset = dynamic_cast<const NameSet*>(&rOtherSet);
1073  if(!nset) {
1074  std::stringstream errstr;
1075  errstr << "cannot cast to nameset" << std::endl;
1076  throw Exception("TaNameSet::InsertSet", errstr.str(), 67);
1077  }
1078  if(nset->mpSymbolTable!=mpSymbolTable) {
1079  std::stringstream errstr;
1080  errstr << "symboltable mismatch aka not implemented" << std::endl;
1081  throw Exception("TaNameSet::InsertSet", errstr.str(), 67);
1082  }
1083 #endif
1084  TAttrMap<Idx,Attr>::InsertSet(rOtherSet);
1085 }
1086 
1087 // Erase(index)
1088 template<class Attr>
1089 bool TaNameSet<Attr>::Erase(const Idx& rIndex) {
1090  FD_DC("TaNameSet(" << this << ")::Erase(" << rIndex <<")");
1091  return TAttrMap<Idx,Attr>::Erase(rIndex);
1092 }
1093 
1094 // Erase(rName)
1095 template<class Attr>
1096 bool TaNameSet<Attr>::Erase(const std::string& rName) {
1097  FD_DC("TaNameSet(" << this << ")::Erase(" << rName <<")");
1098  Idx index = mpSymbolTable->Index(rName);
1099 #ifdef FAUDES_CHECKED
1100  if (index == 0) {
1101  std::stringstream errstr;
1102  errstr << "name \"" << rName << "\" not found in TaNameSet" << std::endl;
1103  throw Exception("TaNameSet::Erase", errstr.str(), 60);
1104  }
1105 #endif
1106  return TAttrMap<Idx,Attr>::Erase(index);
1107 }
1108 
1109 // Erase(pos)
1110 template<class Attr>
1111 typename NameSet::Iterator TaNameSet<Attr>::Erase(const Iterator& pos) {
1112  return TAttrMap<Idx,Attr>::Erase(pos);
1113 }
1114 
1115 // EraseSet(set)
1116 template<class Attr>
1117 void TaNameSet<Attr>::EraseSet(const NameSet& rOtherSet) {
1118  FD_DC("TaNameSet(" << this << ")::EraseSet(" << rOtherSet.ToString() << ")");
1119 #ifdef FAUDES_CHECKED
1120  if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
1121  std::stringstream errstr;
1122  errstr << "symboltable mismach aka not implemented" << std::endl;
1123  throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1124  }
1125 #endif
1126  TAttrMap<Idx,Attr>::EraseSet(rOtherSet);
1127 }
1128 
1129 
1130 // EraseSet(set)
1131 template<class Attr>
1133 #ifdef FAUDES_CHECKED
1134  const NameSet* nset = dynamic_cast<const NameSet*>(&rOtherSet);
1135  if(!nset) {
1136  std::stringstream errstr;
1137  errstr << "cannot cast to nameset" << std::endl;
1138  throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1139  }
1140  if(nset->mpSymbolTable!=mpSymbolTable) {
1141  std::stringstream errstr;
1142  errstr << "symboltable mismatch aka not implemented" << std::endl;
1143  throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1144  }
1145 #endif
1146  TAttrMap<Idx,Attr>::EraseSet(rOtherSet);
1147 }
1148 
1149 
1150 // RestrictSet(set)
1151 template<class Attr>
1152 void TaNameSet<Attr>::RestrictSet(const NameSet& rOtherSet) {
1153  FD_DC("TaNameSet(" << this << ")::RestrictSet(" << rOtherSet.ToString() << ")");
1154 #ifdef FAUDES_CHECKED
1155  if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
1156  std::stringstream errstr;
1157  errstr << "symboltable mismach aka not implemented" << std::endl;
1158  throw Exception("TaNameSet::RestrictSet", errstr.str(), 67);
1159  }
1160 #endif
1162 }
1163 
1164 // RestrictSet(set)
1165 template<class Attr>
1167 #ifdef FAUDES_CHECKED
1168  const NameSet* nset = dynamic_cast<const NameSet*>(&rOtherSet);
1169  if(!nset) {
1170  std::stringstream errstr;
1171  errstr << "cannot cast to nameset" << std::endl;
1172  throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1173  }
1174  if(nset->mpSymbolTable!=mpSymbolTable) {
1175  std::stringstream errstr;
1176  errstr << "symboltable mismatch aka not implemented" << std::endl;
1177  throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1178  }
1179 #endif
1181 }
1182 
1183 
1184 // Attributes(set)
1185 template<class Attr>
1187  FD_DC("TaNameSet(" << this << ")::Attributes(otherset) with type " << typeid(rOtherSet.AttributeType()).name());
1188 #ifdef FAUDES_CHECKED
1189  const NameSet* nset = dynamic_cast<const NameSet*>(&rOtherSet);
1190  if(!nset) {
1191  std::stringstream errstr;
1192  errstr << "cannot cast to nameset" << std::endl;
1193  throw Exception("TaNameSet::Attributes(otherset)", errstr.str(), 67);
1194  }
1195  if(nset->mpSymbolTable!=mpSymbolTable) {
1196  std::stringstream errstr;
1197  errstr << "symboltable mismatch aka not implemented" << std::endl;
1198  throw Exception("TaNameSet::Attributes(otherset)", errstr.str(), 67);
1199  }
1200 #endif
1201  TBaseSet<Idx>::Attributes(rOtherSet);
1202 }
1203 
1204 
1205 // Str()
1206 template<class Attr>
1207 std::string TaNameSet<Attr>::Str(const Idx& rIndex) const {
1208  return NameSet::Str(rIndex);
1209 }
1210 
1211 
1212 
1213 } // namespace faudes
1214 
1215 #endif
1216 
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:927
#define FAUDES_TYPE_TIMPLEMENTATION_EQUAL(ftype, ctype, cbase, ctemp)
Definition: cfl_types.h:938
#define FAUDES_TYPE_TDECLARATION(ftype, ctype, cbase)
Definition: cfl_types.h:883
#define FAUDES_TYPE_TIMPLEMENTATION_ASSIGN(ftype, ctype, cbase, ctemp)
Definition: cfl_types.h:930
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
Definition: cfl_types.h:872
#define FAUDES_TYPE_TIMPLEMENTATION_COPY(ftype, ctype, cbase, ctemp)
Definition: cfl_types.h:924
std::string Str(const Idx &rIndex) const
bool DoEqual(const NameSet &rOtherSet) const
Definition: cfl_nameset.cpp:95
bool Insert(const Idx &rIndex)
SymbolTable * mpSymbolTable
Definition: cfl_nameset.h:432
void DoAssign(const NameSet &rSourceSet)
Definition: cfl_nameset.cpp:86
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:1069
void Attribute(const std::string &rName, const Attr &rAttr)
Definition: cfl_nameset.h:865
const Attr & Attribute(const std::string &rName) const
Definition: cfl_nameset.h:859
virtual bool Insert(const Idx &rIndex)
Definition: cfl_nameset.h:1010
void AttributeTry(const Idx &rElem, const Type &rAttr)
Definition: cfl_nameset.h:856
virtual void Attributes(const TBaseSet< Idx > &rOtherSet)
Definition: cfl_nameset.h:1186
bool DoEqual(const NameSet &rOtherSet) const
Definition: cfl_nameset.h:981
virtual void EraseSet(const NameSet &rOtherSet)
Definition: cfl_nameset.h:1117
std::string Str(const Idx &rIndex) const
Definition: cfl_nameset.h:1207
virtual bool Insert(const Idx &rIndex, const Attr &rAttr)
Definition: cfl_nameset.h:1024
virtual void EraseSet(const TBaseSet< Idx > &rOtherSet)
Definition: cfl_nameset.h:1132
void Attribute(const std::string &rName, const Type &rAttr)
Definition: cfl_nameset.h:868
void DoAssign(const TaNameSet &rSourceSet)
Definition: cfl_nameset.h:973
virtual Idx Insert(const std::string &rName)
Definition: cfl_nameset.h:1038
TaNameSet & operator=(const NameSet &rSrc)
Definition: cfl_nameset.h:642
Attr * Attributep(const Idx &rElem)
Definition: cfl_nameset.h:852
virtual void RestrictSet(const NameSet &rOtherSet)
Definition: cfl_nameset.h:1152
void Attribute(const Idx &rElem, const Attr &rAttr)
Definition: cfl_nameset.h:854
virtual bool Erase(const Idx &rIndex)
Definition: cfl_nameset.h:1089
virtual Idx Insert(const std::string &rName, const Attr &rAttr)
Definition: cfl_nameset.h:1046
virtual void InsertSet(const NameSet &rOtherSet)
Definition: cfl_nameset.h:1055
const Attr & Attribute(const Idx &rElem) const
Definition: cfl_nameset.h:853
virtual TaNameSet & Assign(const TBaseSet< Idx > &rSrc)
Definition: cfl_nameset.h:990
void Attribute(const Idx &rElem, const Type &rAttr)
Definition: cfl_nameset.h:855
virtual NameSet::Iterator Erase(const Iterator &pos)
Definition: cfl_nameset.h:1111
const Attr * AttributeType(void) const
Definition: cfl_nameset.h:851
Attr * Attributep(const std::string &rName)
Definition: cfl_nameset.h:862
virtual void RestrictSet(const TBaseSet< Idx > &rOtherSet)
Definition: cfl_nameset.h:1166
virtual bool Erase(const std::string &rName)
Definition: cfl_nameset.h:1096
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
Definition: cfl_types.cpp:262
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
Definition: cfl_types.cpp:170
virtual Type * New(void) const
Definition: cfl_types.cpp:54
virtual const AttributeVoid * AttributeType(void) const
Definition: cfl_baseset.h:2188
virtual void Attributes(const TBaseSet &rOtherSet)
Definition: cfl_baseset.h:2263
NameSet EventSet
Definition: cfl_nameset.h:533
const std::string & Name(void) const
Definition: cfl_baseset.h:1772
void SetUnion(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB, TBaseSet< T, Cmp > &rRes)
Definition: cfl_baseset.h:1033
void SetIntersection(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB, TBaseSet< T, Cmp > &rRes)
Definition: cfl_baseset.h:1063
TBaseVector< EventSet > EventSetVector
Definition: cfl_nameset.h:536
uint32_t Idx

libFAUDES 2.33c --- 2025.05.15 --- c++ api documentaion by doxygen