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

libFAUDES 2.24g --- 2014.09.15 --- c++ api documentaion by doxygen