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  using NameSet::operator=;
580  using NameSet::operator==;
581  using NameSet::operator!=;
582  /**
583  * Constructor for NameSet referring to the static SymbolTable.
584  */
585  TaNameSet(void);
586 
587  /**
588  * Copy-constructor from other TaNameSet (incl attributes and symboltable)
589  *
590  * @param rOtherSet
591  * Set to copy
592  */
593  TaNameSet(const TaNameSet& rOtherSet);
594 
595  /**
596  * Constructor from NameSet (sets default attributes, same symboltable)
597  *
598  * @param rOtherSet
599  * Set to copy
600  */
601  TaNameSet(const NameSet& rOtherSet);
602 
603  /**
604  * Constructor from file.
605  * This constructor reads a NameSet from a file using the DoRead(TokenReader&, const std::String&)
606  * function. The section is specified by rLabel and the static SymbolTable is used.
607  *
608  * @param rFilename
609  * Name of File
610  * @param rLabel
611  * Section for the set in the file;
612  */
613  TaNameSet(const std::string& rFilename, const std::string& rLabel = "");
614 
615  /**
616  * Virtual destructor
617  */
618  virtual ~TaNameSet(void) {};
619 
620  /** Relaxed assignment method (uses base class to maintain attributes)
621  *
622  * Runtimetype check for TransSet, maintains attributes provided they can be casted.
623  *
624  * @param rSrc
625  * Source from which to assign
626  * @return
627  * Ref to this set
628  */
629  virtual TaNameSet& Assign(const TBaseSet<Idx>& rSrc);
630 
631  /** Relaxed assignment operator (uses base class to maintain attributes)
632  *
633  * @param rSrc
634  * Source from which to assign
635  * @return
636  * Ref to this set
637  */
638  /*virtual*/ TaNameSet& operator=(const NameSet& rSrc) { return Assign(rSrc); };
639 
640  /**
641  * Iterators on nameset.
642  */
643  using NameSet::Iterator;
644 
645  /**
646  * Add an element by index.
647  * Index must be already known to the global SymbolTable. If the element already
648  * exists in the set, the attribute is maintained. Otherwise, the element
649  * is inserted with default attribute.
650  *
651  * @param rIndex
652  * Index to add
653  * @return
654  * True, if element was new to set
655  * @exception Exception
656  * - no symbolic name for index (id 65)
657  */
658  virtual bool Insert(const Idx& rIndex);
659 
660 
661  /**
662  * Add an element by index incl. attribute
663  *
664  * @param rIndex
665  * Index to add
666  * @param rAttr
667  * Attribute to add
668  * @return
669  * True, if index was new to set
670  * @exception Exception
671  * - no symbolic name for index (id 65)
672  *
673  */
674  virtual bool Insert(const Idx& rIndex, const Attr& rAttr);
675 
676  /**
677  * Add an element by its symbolic name. If the name is unknown,
678  * a new index will be generated and recorded in the symboltable.
679  * If the name is known, the corresponding index will be added to the set.
680  * If the element already exists in the set, the attribute is maintained.
681  * Otherwise, the element is inserted with default attribute.
682  *
683  * @param rName
684  * symbolic name of element to add
685  *
686  * @return
687  * Index of (new) element
688  */
689  virtual Idx Insert(const std::string& rName);
690 
691  /**
692  * Add an element by its symbolic name.
693  * If the name is unknown,
694  * a new index will be generated and recorded in the symboltable.
695  * If the name is known, the corresponding index will be added to the set.
696  *
697  * @param rName
698  * symbolic name of element to add
699  * @param rAttr
700  * Attribute
701  *
702  * @return
703  * Index of (new) element
704  */
705  virtual Idx Insert(const std::string& rName, const Attr& rAttr);
706 
707  /**
708  * Inserts elements of rOtherSet.
709  *
710  * Attributes of this set are maintained, newly inserted elements obtain the attribute
711  * from rOtherSet provided they can be casted appropriately.
712  *
713  * @param rOtherSet
714  * Other StateSet
715  * @exception Exception
716  * - symboltable mismatch (id 67)
717  */
718  virtual void InsertSet(const NameSet& rOtherSet);
719 
720  /**
721  * Inserts all elements of rOtherSet.
722  *
723  * This variant requires a runtime cast to access the synboltable.
724  * An expection is thrown if the cast fails.
725  *
726  * @param rOtherSet
727  * Other NameSet
728  * @exception Exception
729  * - symboltable mismatch (id 67)
730  * - cast to nameset failed (id 67)
731  */
732  virtual void InsertSet(const TBaseSet<Idx>& rOtherSet);
733 
734  /**
735  * Delete element by index. Symbolic name is not removed from SymbolTable.
736  *
737  * @param rIndex
738  * Index to delete
739  * @return
740  * True if element did exist
741  *
742  */
743  virtual bool Erase(const Idx& rIndex);
744 
745  /**
746  * Delete element by symbolic name. Symbolic name is not removed from SymbolTable
747  *
748  * @param rName
749  * Symbolic name of element to dlete
750  * @return
751  * True if element did exist
752  * @exception Exception
753  * - name not found in Symboltable (id 66)
754  */
755  virtual bool Erase(const std::string& rName);
756 
757  /**
758  * Delete element by iterator. Symbolic name is not removed from SymbolTable.
759  *
760  * @param pos
761  * TaNameSet::iterator
762  * @return
763  * Iterator to next element
764  * @exception Exception
765  * - invalid iterator (id 62)
766  */
767  virtual typename NameSet::Iterator Erase(const Iterator& pos);
768 
769  /**
770  * Erase elements indicated by rOtherSet
771  *
772  * @exception Exception
773  * - symboltable mismatch (id 67)
774  *
775  * @param rOtherSet
776  * Other StateSet
777  */
778  virtual void EraseSet(const NameSet& rOtherSet);
779 
780  /**
781  * Erase elements specified by rOtherSet
782  *
783  * This function requires a runtime cast to access the synboltable.
784  * An expection is thrown if the cast fails.
785  *
786  * @param rOtherSet
787  * Other NameSet
788  * @exception Exception
789  * - symboltable mismatch (id 67)
790  * - cast to nameset failed (id 67)
791  */
792  virtual void EraseSet(const TBaseSet<Idx>& rOtherSet);
793 
794  /**
795  * Restrict elements indicated by rOtherSet
796  *
797  * @exception Exception
798  * - symboltable mismatch (id 67)
799  *
800  * @param rOtherSet
801  * Other EventSet
802  */
803  virtual void RestrictSet(const NameSet& rOtherSet);
804 
805  /**
806  * Restrict to elements specified by rOtherSet
807  *
808  * This function requires a runtime cast to access the synboltable.
809  * An expection is thrown if the cast fails.
810  *
811  * @param rOtherSet
812  * Other NameSet
813  * @exception Exception
814  * - symboltable mismatch (id 67)
815  * - cast to nameset failed (id 67)
816  */
817  virtual void RestrictSet(const TBaseSet<Idx>& rOtherSet);
818 
819  /**
820  * Set attributes. Provided that rOtherSet has attributes that can be
821  * casted to the appropriate type, attributes are copied per element from rOtherSet.
822  * Elements of this set which are not in rOtherSet maintain their attribute.
823  *
824  * @param rOtherSet
825  * Other IndexSet
826  * @exception Exception
827  * - Element does not exist (63)
828  * - Cannot cast attribute type (63)
829  * - Cannot cast to NameSet (63)
830  */
831  virtual void Attributes(const TBaseSet<Idx>& rOtherSet);
832 
833 
834  /**
835  * Return pretty printable symbolic name for index.
836  * Primary meant for debugging messages.
837  *
838  * @param rIndex
839  * Index to print
840  *
841  * @return
842  * String
843  */
844  std::string Str(const Idx& rIndex) const;
845 
846  /** resolve ambiguities from attribute interface ("using" wont do the job)*/
847  const Attr* AttributeType(void) const { return TAttrMap<Idx,Attr>::AttributeType(); };
848  Attr* Attributep(const Idx& rElem) { return TAttrMap<Idx,Attr>::Attributep(rElem); };
849  const Attr& Attribute(const Idx& rElem) const { return TAttrMap<Idx,Attr>::Attribute(rElem); };
850  void Attribute(const Idx& rElem, const Attr& rAttr) { return TAttrMap<Idx,Attr>::Attribute(rElem,rAttr); };
851  void Attribute(const Idx& rElem, const Type& rAttr) { return TAttrMap<Idx,Attr>::Attribute(rElem,rAttr); };
852  void AttributeTry(const Idx& rElem, const Type& rAttr) { return TAttrMap<Idx,Attr>::AttributeTry(rElem,rAttr); };
853 
854 
855  protected:
856 
857  /**
858  * Assign to other name set. Performs a fake copy, see TBaseSet.
859  * This function maintains attributes.
860  *
861  * @param rSourceSet
862  * Destination to copy from
863  * @return
864  * ref to this set
865  */
866  void DoAssign(const TaNameSet& rSourceSet);
867 
868  /**
869  * Test equality of configuration data, ignore attributes
870  * Ignore name of the set, insist in matching symboltables.
871  *
872  * @param rOtherSet
873  * Other object to compare with.
874  * @return
875  * True on match.
876  */
877  bool DoEqual(const NameSet& rOtherSet) const;
878 
879 
880 
881 };
882 
883 
884 /** Convenience Macro */
885 #define TaEventSet TaNameSet
886 
887 /** @} doxygen group */
888 
889 /*
890 *************************************************************************************
891 *************************************************************************************
892  Implementation
893 *************************************************************************************
894 *************************************************************************************
895 */
896 
897 
898 // std faudes type (cannot do New() with macro)
899 FAUDES_TYPE_TIMPLEMENTATION_COPY(Void,TaNameSet<Attr>,NameSet,template<class Attr>)
900 FAUDES_TYPE_TIMPLEMENTATION_CAST(Void,TaNameSet<Attr>,NameSet,template<class Attr>)
901 FAUDES_TYPE_TIMPLEMENTATION_ASSIGN(Void,TaNameSet<Attr>,NameSet,template<class Attr>)
902 FAUDES_TYPE_TIMPLEMENTATION_EQUAL(Void,TaNameSet<Attr>,NameSet,template<class Attr>)
903 
904 // empty constructor
905 template<class Attr>
907  NameSet(),
908  TAttrMap<Idx,Attr>(this)
909 {
910  FD_DC("TaNameSet(" << this << ")::TaNameSet()");
911  //mpSymbolTable = SymbolTable::GlobalEventSymbolTablep();
912  this->Name("NameSet");
913 }
914 
915 // constructor form other nameset
916 template<class Attr>
918  NameSet(),
919  TAttrMap<Idx,Attr>(this)
920 {
921  FD_DC("TaNameSet(" << this << ")::TaNameSet(rOtherSet " << &rOtherSet << ")");
922  DoAssign(rOtherSet);
923 }
924 
925 // constructor form other nameset
926 template<class Attr>
928  NameSet(),
929  TAttrMap<Idx,Attr>(this)
930 {
931  FD_DC("TaNameSet(" << this << ")::TaNameSet(rOtherSet " << &rOtherSet << ")");
932  Assign(rOtherSet);
933 }
934 
935 
936 // read file constructor
937 template<class Attr>
938 TaNameSet<Attr>::TaNameSet(const std::string& rFilename, const std::string& rLabel) :
939  NameSet(),
940  TAttrMap<Idx,Attr>(this)
941 {
942  FD_DC("TaNameSet(" << this << ")::TaNameSet(" << rFilename << ")");
944  Read(rFilename, rLabel);
945 }
946 
947 // New() (std faudes type, cannot use macro because we need to fix symboltable)
948 template<class Attr>
950  TaNameSet* res = new TaNameSet();
951  res->mpSymbolTable=mpSymbolTable;
952  return res;
953 }
954 
955 // DoAssign()
956 template<class Attr>
958  FD_DC("TaNameSet(" << this << ")::DoAssign( [a] " << &rSourceSet << ")");
959  // base does the job
960  NameSet::DoAssign(rSourceSet);
961 }
962 
963 // DoEqual()
964 template<class Attr>
965 bool TaNameSet<Attr>::DoEqual(const NameSet& rOtherSet) const {
966  FD_DC("TaNAMESet::DoEqual()");
967  // base does the job, equality does not refer to attributes
968  return NameSet::DoEqual(rOtherSet);
969 }
970 
971 // Relaxed Assign()
972 template<class Attr>
974  FD_DC("TaNameSet(" << this << ")::Assign( [v] " << &rSourceSet << ")");
975  const NameSet* nset = dynamic_cast<const NameSet*>(&rSourceSet);
976 #ifdef FAUDES_CHECKED
977  if(!nset) {
978  std::stringstream errstr;
979  errstr << "cannot cast to nameset" << std::endl;
980  throw Exception("TaNameSet::Assign", errstr.str(), 67);
981  }
982 #endif
983  // name set specific data
984  mpSymbolTable=nset->mpSymbolTable;
985  // attribute interface does relaxed assignment
987  // done
988  return *this;
989 }
990 
991 // Insert(index)
992 template<class Attr>
993 bool TaNameSet<Attr>::Insert(const Idx& rIndex) {
994 #ifdef FAUDES_CHECKED
995  if(!mpSymbolTable->Exists(rIndex)) {
996  std::stringstream errstr;
997  errstr << "index " << rIndex << " has no symbolic name" << std::endl;
998  throw Exception("TaNameSet::Insert", errstr.str(), 65);
999  }
1000 #endif
1001  return TAttrMap<Idx,Attr>::Insert(rIndex);
1002 }
1003 
1004 
1005 // Insert(index,attr)
1006 template<class Attr>
1007 bool TaNameSet<Attr>::Insert(const Idx& rIndex, const Attr& attr) {
1008 #ifdef FAUDES_CHECKED
1009  if(!mpSymbolTable->Exists(rIndex)) {
1010  std::stringstream errstr;
1011  errstr << "index " << rIndex << " has no symbolic name" << std::endl;
1012  throw Exception("TaNameSet::Insert", errstr.str(), 65);
1013  }
1014 #endif
1015  return TAttrMap<Idx,Attr>::Insert(rIndex,attr);
1016 }
1017 
1018 
1019 // Insert(rName)
1020 template<class Attr>
1021 Idx TaNameSet<Attr>::Insert(const std::string& rName) {
1022  FD_DC("TaNameSet(" << this << ")::Insert(" << rName <<")");
1023  Idx index= NameSet::Insert(rName); // automatic: keep attribute if exists
1024  return index;
1025 }
1026 
1027 // Insert(rName, attr)
1028 template<class Attr>
1029 Idx TaNameSet<Attr>::Insert(const std::string& rName, const Attr& attr) {
1030  FD_DC("TaNameSet(" << this << ")::Insert(" << rName <<")");
1031  Idx index= NameSet::Insert(rName);
1032  TAttrMap<Idx,Attr>::Attribute(index,attr);
1033  return index;
1034 }
1035 
1036 // InsertSet(set)
1037 template<class Attr>
1038 void TaNameSet<Attr>::InsertSet(const NameSet& rOtherSet) {
1039  FD_DC("TaNameSet(" << this << ")::InsertSet(" << &rOtherSet << ")");
1040 #ifdef FAUDES_CHECKED
1041  if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
1042  std::stringstream errstr;
1043  errstr << "symboltable mismach aka not implemented" << std::endl;
1044  throw Exception("TaNameSet::InsertSet", errstr.str(), 67);
1045  }
1046 #endif
1047  TAttrMap<Idx,Attr>::InsertSet(rOtherSet);
1048 }
1049 
1050 // InsertSet(set)
1051 template<class Attr>
1053  FD_DC("TaNameSet(" << this << ")::InsertSet(" << &rOtherSet << "):: downcast");
1054 #ifdef FAUDES_CHECKED
1055  const NameSet* nset = dynamic_cast<const NameSet*>(&rOtherSet);
1056  if(!nset) {
1057  std::stringstream errstr;
1058  errstr << "cannot cast to nameset" << std::endl;
1059  throw Exception("TaNameSet::InsertSet", errstr.str(), 67);
1060  }
1061  if(nset->mpSymbolTable!=mpSymbolTable) {
1062  std::stringstream errstr;
1063  errstr << "symboltable mismatch aka not implemented" << std::endl;
1064  throw Exception("TaNameSet::InsertSet", errstr.str(), 67);
1065  }
1066 #endif
1067  TAttrMap<Idx,Attr>::InsertSet(rOtherSet);
1068 }
1069 
1070 // Erase(index)
1071 template<class Attr>
1072 bool TaNameSet<Attr>::Erase(const Idx& rIndex) {
1073  FD_DC("TaNameSet(" << this << ")::Erase(" << rIndex <<")");
1074  return TAttrMap<Idx,Attr>::Erase(rIndex);
1075 }
1076 
1077 // Erase(rName)
1078 template<class Attr>
1079 bool TaNameSet<Attr>::Erase(const std::string& rName) {
1080  FD_DC("TaNameSet(" << this << ")::Erase(" << rName <<")");
1081  Idx index = mpSymbolTable->Index(rName);
1082 #ifdef FAUDES_CHECKED
1083  if (index == 0) {
1084  std::stringstream errstr;
1085  errstr << "name \"" << rName << "\" not found in TaNameSet" << std::endl;
1086  throw Exception("TaNameSet::Erase", errstr.str(), 60);
1087  }
1088 #endif
1089  return TAttrMap<Idx,Attr>::Erase(index);
1090 }
1091 
1092 // Erase(pos)
1093 template<class Attr>
1094 typename NameSet::Iterator TaNameSet<Attr>::Erase(const Iterator& pos) {
1095  return TAttrMap<Idx,Attr>::Erase(pos);
1096 }
1097 
1098 // EraseSet(set)
1099 template<class Attr>
1100 void TaNameSet<Attr>::EraseSet(const NameSet& rOtherSet) {
1101  FD_DC("TaNameSet(" << this << ")::EraseSet(" << rOtherSet.ToString() << ")");
1102 #ifdef FAUDES_CHECKED
1103  if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
1104  std::stringstream errstr;
1105  errstr << "symboltable mismach aka not implemented" << std::endl;
1106  throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1107  }
1108 #endif
1109  TAttrMap<Idx,Attr>::EraseSet(rOtherSet);
1110 }
1111 
1112 
1113 // EraseSet(set)
1114 template<class Attr>
1116 #ifdef FAUDES_CHECKED
1117  const NameSet* nset = dynamic_cast<const NameSet*>(&rOtherSet);
1118  if(!nset) {
1119  std::stringstream errstr;
1120  errstr << "cannot cast to nameset" << std::endl;
1121  throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1122  }
1123  if(nset->mpSymbolTable!=mpSymbolTable) {
1124  std::stringstream errstr;
1125  errstr << "symboltable mismatch aka not implemented" << std::endl;
1126  throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1127  }
1128 #endif
1129  TAttrMap<Idx,Attr>::EraseSet(rOtherSet);
1130 }
1131 
1132 
1133 // RestrictSet(set)
1134 template<class Attr>
1135 void TaNameSet<Attr>::RestrictSet(const NameSet& rOtherSet) {
1136  FD_DC("TaNameSet(" << this << ")::RestrictSet(" << rOtherSet.ToString() << ")");
1137 #ifdef FAUDES_CHECKED
1138  if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
1139  std::stringstream errstr;
1140  errstr << "symboltable mismach aka not implemented" << std::endl;
1141  throw Exception("TaNameSet::RestrictSet", errstr.str(), 67);
1142  }
1143 #endif
1145 }
1146 
1147 // RestrictSet(set)
1148 template<class Attr>
1150 #ifdef FAUDES_CHECKED
1151  const NameSet* nset = dynamic_cast<const NameSet*>(&rOtherSet);
1152  if(!nset) {
1153  std::stringstream errstr;
1154  errstr << "cannot cast to nameset" << std::endl;
1155  throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1156  }
1157  if(nset->mpSymbolTable!=mpSymbolTable) {
1158  std::stringstream errstr;
1159  errstr << "symboltable mismatch aka not implemented" << std::endl;
1160  throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
1161  }
1162 #endif
1164 }
1165 
1166 
1167 // Attributes(set)
1168 template<class Attr>
1170  FD_DC("TaNameSet(" << this << ")::Attributes(otherset) with type " << typeid(*rOtherSet.AttributeType()).name());
1171 #ifdef FAUDES_CHECKED
1172  const NameSet* nset = dynamic_cast<const NameSet*>(&rOtherSet);
1173  if(!nset) {
1174  std::stringstream errstr;
1175  errstr << "cannot cast to nameset" << std::endl;
1176  throw Exception("TaNameSet::Attributes(otherset)", errstr.str(), 67);
1177  }
1178  if(nset->mpSymbolTable!=mpSymbolTable) {
1179  std::stringstream errstr;
1180  errstr << "symboltable mismatch aka not implemented" << std::endl;
1181  throw Exception("TaNameSet::Attributes(otherset)", errstr.str(), 67);
1182  }
1183 #endif
1184  TBaseSet<Idx>::Attributes(rOtherSet);
1185 }
1186 
1187 
1188 // Str()
1189 template<class Attr>
1190 std::string TaNameSet<Attr>::Str(const Idx& rIndex) const {
1191  return NameSet::Str(rIndex);
1192 }
1193 
1194 
1195 
1196 } // namespace faudes
1197 
1198 #endif
1199 
Class TAttrMap.
Class TBaseVector.
Compiletime options.
#define FD_DC(message)
Debug: optional report on container operations.
Class Exception.
#define FAUDES_API
Interface export/import symbols: windows.
Definition: cfl_platform.h:80
#define FAUDES_TAPI
Definition: cfl_platform.h:83
Runtime interface, registry for faudes-types and functions.
Class SymbolTable.
#define FAUDES_TYPE_TIMPLEMENTATION_CAST(ftype, ctype, cbase, ctemp)
Definition: cfl_types.h:922
#define FAUDES_TYPE_TIMPLEMENTATION_EQUAL(ftype, ctype, cbase, ctemp)
Definition: cfl_types.h:933
#define FAUDES_TYPE_TDECLARATION(ftype, ctype, cbase)
faudes type declaration macro, template version
Definition: cfl_types.h:878
#define FAUDES_TYPE_TIMPLEMENTATION_ASSIGN(ftype, ctype, cbase, ctemp)
Definition: cfl_types.h:925
#define FAUDES_TYPE_DECLARATION(ftype, ctype, cbase)
faudes type declaration macro
Definition: cfl_types.h:867
#define FAUDES_TYPE_TIMPLEMENTATION_COPY(ftype, ctype, cbase, ctemp)
Definition: cfl_types.h:919
Faudes exception class.
Set of indices with symbolic names.
Definition: cfl_nameset.h:69
std::string Str(const Idx &rIndex) const
Return pretty printable symbolic name for index.
bool DoEqual(const NameSet &rOtherSet) const
Test equality of configuration data.
Definition: cfl_nameset.cpp:92
bool Insert(const Idx &rIndex)
Add an element by index.
SymbolTable * mpSymbolTable
Pointer to local SymbolTable.
Definition: cfl_nameset.h:432
void DoAssign(const NameSet &rSourceSet)
Assign from other name set.
Definition: cfl_nameset.cpp:83
A SymbolTable associates sybolic names with indices.
static SymbolTable * GlobalEventSymbolTablep(void)
Get Static Symboltable ref (initialize on first use pattern)
Attribute interface for TBaseSet.
Definition: cfl_attrmap.h:52
const Attr & Attribute(const T &rElem) const
Get attribute by element.
Definition: cfl_attrmap.h:464
Attr * Attributep(const T &rElem)
Get attribute reference by element.
Definition: cfl_attrmap.h:446
void AttributeTry(const T &rElem, const Type &attr)
Set attribute.
Definition: cfl_attrmap.h:499
bool Erase(const T &rElem)
Erase Element (incl its attribute)
Definition: cfl_attrmap.h:369
void EraseSet(const TBaseSet< T, Cmp > &rOtherSet)
Erase elements given by other set.
Definition: cfl_attrmap.h:386
void InsertSet(const TBaseSet< T, Cmp > &rOtherSet)
Inserts elements from rOtherSet.
Definition: cfl_attrmap.h:340
void RestrictSet(const TBaseSet< T, Cmp > &rOtherSet)
Restrict to specified subset.
Definition: cfl_attrmap.h:409
void AssignWithAttributes(const TBaseSet< T, Cmp > &rSourceSet)
Copy from a TBaseSet to the associated TBaseSet, with attributes, provided that they can be casted ac...
Definition: cfl_attrmap.h:292
bool Insert(const T &rElem)
Insert element.
Definition: cfl_attrmap.h:323
const Attr * AttributeType(void) const
Attribute typeinfo.
Definition: cfl_attrmap.h:438
STL style set template.
Definition: cfl_baseset.h:98
Vector template.
Set of indices with symbolic names and attributes.
Definition: cfl_nameset.h:566
virtual void InsertSet(const TBaseSet< Idx > &rOtherSet)
Inserts all elements of rOtherSet.
Definition: cfl_nameset.h:1052
virtual bool Insert(const Idx &rIndex)
Add an element by index.
Definition: cfl_nameset.h:993
void AttributeTry(const Idx &rElem, const Type &rAttr)
Attribute access.
Definition: cfl_nameset.h:852
virtual void Attributes(const TBaseSet< Idx > &rOtherSet)
Set attributes.
Definition: cfl_nameset.h:1169
bool DoEqual(const NameSet &rOtherSet) const
Test equality of configuration data, ignore attributes Ignore name of the set, insist in matching sym...
Definition: cfl_nameset.h:965
virtual void EraseSet(const NameSet &rOtherSet)
Erase elements indicated by rOtherSet.
Definition: cfl_nameset.h:1100
std::string Str(const Idx &rIndex) const
Return pretty printable symbolic name for index.
Definition: cfl_nameset.h:1190
virtual bool Insert(const Idx &rIndex, const Attr &rAttr)
Add an element by index incl.
Definition: cfl_nameset.h:1007
virtual void EraseSet(const TBaseSet< Idx > &rOtherSet)
Erase elements specified by rOtherSet.
Definition: cfl_nameset.h:1115
void DoAssign(const TaNameSet &rSourceSet)
Assign to other name set.
Definition: cfl_nameset.h:957
virtual Idx Insert(const std::string &rName)
Add an element by its symbolic name.
Definition: cfl_nameset.h:1021
TaNameSet & operator=(const NameSet &rSrc)
Relaxed assignment operator (uses base class to maintain attributes)
Definition: cfl_nameset.h:638
Attr * Attributep(const Idx &rElem)
Definition: cfl_nameset.h:848
virtual void RestrictSet(const NameSet &rOtherSet)
Restrict elements indicated by rOtherSet.
Definition: cfl_nameset.h:1135
TaNameSet(void)
Constructor for NameSet referring to the static SymbolTable.
Definition: cfl_nameset.h:906
void Attribute(const Idx &rElem, const Attr &rAttr)
Definition: cfl_nameset.h:850
virtual bool Erase(const Idx &rIndex)
Delete element by index.
Definition: cfl_nameset.h:1072
virtual Idx Insert(const std::string &rName, const Attr &rAttr)
Add an element by its symbolic name.
Definition: cfl_nameset.h:1029
virtual void InsertSet(const NameSet &rOtherSet)
Inserts elements of rOtherSet.
Definition: cfl_nameset.h:1038
const Attr & Attribute(const Idx &rElem) const
Definition: cfl_nameset.h:849
virtual TaNameSet & Assign(const TBaseSet< Idx > &rSrc)
Relaxed assignment method (uses base class to maintain attributes)
Definition: cfl_nameset.h:973
void Attribute(const Idx &rElem, const Type &rAttr)
Definition: cfl_nameset.h:851
virtual NameSet::Iterator Erase(const Iterator &pos)
Delete element by iterator.
Definition: cfl_nameset.h:1094
const Attr * AttributeType(void) const
resolve ambiguities from attribute interface ("using" wont do the job)
Definition: cfl_nameset.h:847
virtual void RestrictSet(const TBaseSet< Idx > &rOtherSet)
Restrict to elements specified by rOtherSet.
Definition: cfl_nameset.h:1149
virtual bool Erase(const std::string &rName)
Delete element by symbolic name.
Definition: cfl_nameset.h:1079
A TokenReader reads sequential tokens from a file or string.
A TokenWriter writes sequential tokens to a file, a string or stdout.
Base class of all libFAUDES objects that participate in the run-time interface.
Definition: cfl_types.h:239
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
Read configuration data from file with label specified.
Definition: cfl_types.cpp:261
std::string ToString(const std::string &rLabel="", const Type *pContext=0) const
Write configuration data to a string.
Definition: cfl_types.cpp:169
virtual Type * New(void) const
Construct on heap.
Definition: cfl_types.cpp:54
virtual const AttributeVoid * AttributeType(void) const
Attribute typeinfo.
Definition: cfl_baseset.h:2180
virtual void Attributes(const TBaseSet &rOtherSet)
Attributes access.
Definition: cfl_baseset.h:2255
NameSet EventSet
Convenience typedef for plain event sets.
Definition: cfl_nameset.h:533
const std::string & Name(void) const
Return name of TBaseSet.
Definition: cfl_baseset.h:1764
void SetUnion(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB, TBaseSet< T, Cmp > &rRes)
Definition: cfl_baseset.h:1028
void SetIntersection(const TBaseSet< T, Cmp > &rSetA, const TBaseSet< T, Cmp > &rSetB, TBaseSet< T, Cmp > &rRes)
Definition: cfl_baseset.h:1058
TBaseVector< EventSet > EventSetVector
Definition: cfl_nameset.h:536
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)

libFAUDES 2.32f --- 2024.12.22 --- c++ api documentaion by doxygen