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

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen