libFAUDES

Sections

Index

cfl_nameset.h

Go to the documentation of this file.
00001 /** @file cfl_nameset.h @brief Classes NameSet, TaNameSet */
00002 
00003 /* FAU Discrete Event Systems Library (libfaudes)
00004 
00005    Copyright (C) 2006  Bernd Opitz
00006    Exclusive copyright is granted to Klaus Schmidt
00007 
00008    This library is free software; you can redistribute it and/or
00009    modify it under the terms of the GNU Lesser General Public
00010    License as published by the Free Software Foundation; either
00011    version 2.1 of the License, or (at your option) any later version.
00012 
00013    This library is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016    Lesser General Public License for more details.
00017 
00018    You should have received a copy of the GNU Lesser General Public
00019    License along with this library; if not, write to the Free Software
00020    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00021 
00022 
00023 #ifndef FAUDES_NAMESET_H
00024 #define FAUDES_NAMESET_H
00025 
00026 #include "cfl_definitions.h"
00027 #include "cfl_exception.h"
00028 #include "cfl_basevector.h"
00029 #include "cfl_abaseset.h"
00030 #include "cfl_symboltable.h"
00031 #include "cfl_tokenreader.h"
00032 #include "cfl_tokenwriter.h"
00033 #include <fstream>
00034 #include <sstream>
00035 #include <iostream>
00036 #include <set>
00037 #include <assert.h>
00038 
00039 namespace faudes {
00040 
00041 /** @addtogroup Container Classes */
00042 /** @{ */
00043 
00044 // Forward declaration for the attributed version of nameset
00045 template<class Attr> class TaNameSet;
00046 
00047 
00048 /**
00049  * Set of indices with symbolic names. 
00050  * In a NameSet, symbolic names are mandatory.
00051  * The class is derived from IndexSet and uses a pointer to a SymbolTable 
00052  * to maintain the symbolic names. The static SymbolTable is used as default,
00053  * which in the context of libfaudes becomes the global event symbol table.
00054  * It is an error to refer to an unknown symbolic name or to an index
00055  * with no name associated. When FAUDES_CHECKED is defined, an exception will
00056  * be thrown. It is also considered an error to relate two NameSets that refer to
00057  * different SymbolTables (using e.g. SetUnion).  
00058  *
00059  *
00060  * Since symbolic names are mandatory, file IO uses names rather than indices.
00061  * Technically, file IO is done by TaNameSet functions. This requires a copy and for
00062  * that reason may be reimplemented in a future versions.
00063  * The format is demonstrated by the following example
00064  * of a set with name "Alphabet" consisting of events "alpha", "beta" and "gamma":
00065  * \code
00066  * <Alphabet> 
00067  * "alpha" "beta" "gamma"
00068  * <\Alphabet> 
00069  * \endcode
00070  * Note that when reading a file, indices will be associated with the symbolic names
00071  * based on availability. Within one libfaudes session, each individual event will
00072  * be referred to by a unique index.
00073  */
00074 
00075 class NameSet : public virtual TBaseSet<Idx> {
00076 
00077 FAUDES_TYPE_DECLARATION(NameSet,(TBaseSet<Idx>))
00078 
00079   /** 
00080    * We implement "protected privacy for template classes" by friendship.
00081    * This is used for the pragmatic implemention conversion constructors.
00082    */
00083   template<class Attr> friend class TaNameSet;
00084 
00085  public:
00086   /**
00087    * Constructor for NameSet referring to the static SymbolTable. 
00088    */
00089   NameSet(void);
00090          
00091   /**
00092    * Copy-constructor from other NameSet.
00093    * This also copies the SymbolTable reference, hence the new NameSet
00094    * will use the same SymbolTable as rOtherSet.
00095    *
00096    * @param rOtherSet
00097    *   Set to copy
00098    */
00099   NameSet(const NameSet& rOtherSet);
00100 
00101 
00102   /**
00103    * Constructor from file.
00104    * This constructor reads a NameSet from a file using the DoRead(TokenReader&, const std::string&)
00105    * function. The section is specified by rLabel and the static SymbolTable is used.
00106    *
00107    *
00108    * @param rFilename
00109    *   Name of file
00110    * @param rLabel
00111    *   Section for the set in the file; 
00112    */
00113   NameSet(const std::string& rFilename, const std::string& rLabel = "");
00114 
00115   /**
00116    * Virtual destructor
00117    */
00118   virtual ~NameSet(void);
00119 
00120   /**
00121    * Return an empty NameSet with same SymbolTable as this set.
00122    *
00123    * @return 
00124    *   New empty NameSet
00125    */
00126   NameSet NewN() const;
00127 
00128   /**
00129    * Get Pointer mpSymbolTable.
00130    *
00131    * @return
00132    *   Pointer mpSymbolTable
00133    */
00134   SymbolTable* SymbolTablep(void) const;
00135 
00136   /**
00137    * Set SymbolTable reference.
00138    * This function sets the reference to the SymbolTable. The current implementation
00139    * clears the set, future versions may implement a re-indexing.
00140    *
00141    * @param pSymTab
00142    *   Pointer to SymbolTable
00143    */
00144   void SymbolTablep(SymbolTable* pSymTab);
00145 
00146   /**
00147    * Add an element by index. 
00148    * Index must be already known to the global SymbolTable. 
00149    *
00150    * @param rIndex
00151    *   Index to add
00152    * @return 
00153    *   True, if element was new to set
00154    * @exception Exception
00155    *   - no symbolic name for index (id 65)
00156    */
00157   bool Insert(const Idx& rIndex);
00158 
00159   /** 
00160    * Add an element by its symbolic name. If the name is unknown, 
00161    * a new index will be generated and recorded in the symboltable.
00162    * If the name is known, the corresponding index will be added to the set.
00163    *
00164    * @param rName
00165    *   Symbolic name of element to add
00166    *
00167    * @return 
00168    *   Index of (new) element
00169    */
00170   Idx Insert(const std::string& rName);
00171 
00172   /**
00173    * Inserts elements of rOtherSet.
00174    *
00175    * @param rOtherSet
00176    *   Other NameSet
00177    * @exception Exception
00178    *   - symboltable mismatch (id 67) 
00179    */
00180   virtual void InsertSet(const NameSet& rOtherSet);
00181 
00182   /**
00183    * Delete element by index. The symbolic name is not removed from the SymbolTable.
00184    *
00185    * @param rIndex
00186    *   Index
00187    * @return
00188    *   True if element did exist
00189    */
00190   virtual bool Erase(const Idx& rIndex);
00191 
00192   /**
00193    * Delete element by symbolic name. The symbolic name is not removed from the SymbolTable
00194    *
00195    * @param rName
00196    *   symbolic name
00197    * @return
00198    *    True if element did exist
00199    * @exception Exception
00200    *   - unknown symbolic name (id 66)
00201    */
00202   virtual bool Erase(const std::string& rName);
00203 
00204   /**
00205    * Delete element by iterator. Symbolic nam is not removed from SymbolTable.
00206    *
00207    * @param pos
00208    *   NameSet::iterator
00209    * @return
00210    *  iterator to next element
00211    * @exception Exception
00212    *   - invalid iterator (id 62)
00213    */
00214   virtual Iterator Erase(const Iterator& pos);
00215 
00216   /**
00217    * Erase elements specified by rOtherSet
00218    *
00219    * @param rOtherSet
00220    *   Other StateSet
00221    * @exception Exception
00222    *   - symboltable mismatch (id 67) 
00223    */
00224    void EraseSet(const NameSet& rOtherSet);
00225 
00226   /**
00227    * Restrict elements specified by rOtherSet
00228    *
00229    * @param rOtherSet
00230    *   Other StateSet
00231    * @exception Exception
00232    *   - symboltable mismatch (id 67) 
00233    */
00234    void RestrictSet(const NameSet& rOtherSet);
00235 
00236   /**
00237    * Set new name for existing index.
00238    * FAUDES_CHECKED checks if index exists in NameSet. 
00239    *
00240    * @param index
00241    *   Index to edit
00242    * @param rName
00243    *   New name
00244    *
00245    * @exception Exception
00246    *   - index not in this set (id 60)
00247    *   - index not found in SymbolTable (id 42)
00248    *   - name already associated with another index (id 44)
00249    */
00250   void SymbolicName(Idx index, const std::string& rName);
00251 
00252         
00253   /**
00254    * Set new name for existing name
00255    * FAUDES_CHECKED checks if the specified name exists in NameSet. 
00256    *
00257    * @param rName
00258    *   Symbolic name to edit
00259    * @param rNewName
00260    *   New name
00261    *
00262    * @exception Exception
00263    *   - symbolic name not in this set (id 60)
00264    *   - new name already associated with another index (id 44)
00265    */
00266   void SymbolicName(const std::string& rName, const std::string& rNewName);
00267 
00268   /**
00269    * Name lookup
00270    *
00271    * @param index
00272    *   Index to lookup
00273    *
00274    * @return
00275    *   Corresponding name or empty std::string if non-existent
00276    */
00277   std::string SymbolicName(Idx index) const;
00278 
00279   /**
00280    * Index lookup
00281    *
00282    * @param rName
00283    *   Symbolic name to look up
00284    *
00285    * @return 
00286    *   Corresponding index or 0 for non-existent
00287    */
00288   Idx Index(const std::string& rName) const;
00289 
00290   /**
00291    * Test existence of index
00292    *
00293    * @param rIndex
00294    *   Index to test
00295    *
00296    * @return 
00297    *   True if index is in this set
00298    */
00299   bool Exists(const Idx& rIndex) const;
00300 
00301   /** 
00302    * Test existence of name
00303    *
00304    * @param rName
00305    *   Symbolic name to test
00306    *
00307    * @return 
00308    *   True if index is in this set
00309    */
00310   bool Exists(const std::string& rName) const;
00311 
00312   /**
00313    * Find iterator for index. Returns either a valid iterator
00314    * or End() for non-existent.
00315    *
00316    * @param rIndex
00317    *   Index to find
00318    *
00319    * @return
00320    *   NameSet::Iterator
00321    */
00322   NameSet::Iterator Find(const Idx& rIndex) const;
00323 
00324   /**
00325    * Find iterator for name. Returns either a valid iterator
00326    * or End() for non-existent.
00327    *
00328    * @param rName
00329    *   Name to find
00330    *
00331    * @return
00332    *   NameSet::Iterator
00333    */
00334   NameSet::Iterator Find(const std::string& rName) const;
00335 
00336 
00337   /**
00338    * Set attributes. This virtual interface function is overloaded by the derived class TaNameSet
00339    * to set attributes by the specified set. Since the plain NameSet has no attributes, this
00340    * function does nothing.
00341    *
00342    * @param rOtherSet
00343    *   Other NameSet
00344    * @exception Exception
00345    *   - Element does not exist (63)
00346    *   - Cannot cast attribute type (63)
00347    */
00348   virtual void Attributes(const NameSet& rOtherSet) { (void) rOtherSet; };
00349 
00350 
00351   /**
00352    * Set union operator
00353    *
00354    * @return 
00355    *   Union Set
00356    *
00357    * @exception Exception
00358    *   - symboltable mismatch (id 67) 
00359    */
00360   NameSet operator + (const NameSet& rOtherSet) const;
00361 
00362   /**
00363    * Set difference operator
00364    *
00365    * @return 
00366    *   Difference NameSet
00367    *
00368    * @exception Exception
00369    *   - symboltable mismatch (id 67) 
00370    */
00371   NameSet operator - (const NameSet& rOtherSet) const;
00372 
00373   /**
00374    * Set intersection operator
00375    *
00376    * @return 
00377    *   Intersection NameSet
00378    *
00379    * @exception Exception
00380    *   - symboltable mismatch (id 67) 
00381    */
00382   NameSet operator * (const NameSet& rOtherSet) const;
00383 
00384 
00385   /** Test for subset  */
00386   bool operator<= (const NameSet& rOtherSet) const;
00387 
00388   /** Test for superset */
00389   bool operator>= (const NameSet& rOtherSet) const;
00390 
00391 
00392   /**
00393    * Return pretty printable symbolic name for index.
00394    * Primary meant for debugging messages.
00395    *
00396    * @param rIndex
00397    *   Index to print
00398    *
00399    * @return
00400    *   String
00401    */
00402   std::string Str(const Idx& rIndex) const;
00403 
00404 
00405  protected:
00406 
00407   /** Pointer to local SymbolTable */
00408   SymbolTable* mpSymbolTable;
00409 
00410   /**
00411    * Assign from other name set. Performs a fake copy, see TBaseSet.
00412    *
00413    * @param rSourceSet
00414    *   Source to copy from
00415    * @return
00416    *   ref to this set
00417    */
00418   virtual NameSet& DoAssign(const NameSet& rSourceSet);
00419 
00420 
00421   /**
00422    * Test equality of configuration data.
00423    * Ignore name of the set, insist in matching symboltables.
00424    *
00425    * @param rOtherSet 
00426    *    Other object to compare with.
00427    * @return 
00428    *   True on match.
00429    */
00430   virtual bool DoEqual(const NameSet& rOtherSet) const;
00431 
00432   /**
00433    * Write to TokenWriter, see Type::Write for public wrappers
00434    * This function will also do the token io of attributes in derived classes.
00435    *
00436    * @param tw
00437    *   Reference to TokenWriter
00438    * @param rLabel
00439    *   Label of the section to write, defaults to name of set or "NameSet"
00440    * @param pContext
00441    *   Write context to provide contextual information
00442    *
00443    * @exception Exception
00444    *   - IO errors (id 2)
00445    */
00446   virtual void DoWrite(TokenWriter& tw, const std::string& rLabel="", const Type* pContext=0) const;
00447         
00448   /** Write debug info to TokenWriter, see Type::DWrite for public wrapper.
00449    * The debug version writes a format that includes symbolic names and indices. 
00450    *
00451    * @param tw
00452    *   Reference to TokenWriter
00453    * @param rLabel
00454    *   Label of the section to write, defaults to name of set or "NameSet"
00455    * @param pContext
00456    *   Write context to provide contextual information
00457    *
00458    * @exception Exception 
00459    *   - IO errors (id 2)
00460    */
00461   virtual void DoDWrite(TokenWriter& tw, const std::string& rLabel="", const Type* pContext=0) const;
00462 
00463   /**
00464    * Read from TokenReader, see Type::Read for public wrappers. 
00465    * It is an error if the file contains a plain index (id 52).
00466    * The method invokes TokenReader::SeekBegin() to seek the specified
00467    * section, reads subsequent symbols, and calls matching TokenReader::SeekEnd(). 
00468    * If no section is specified, the section is assumed to start at the current position
00469    * of the token stream. If the current position is no begin token, 
00470    * the section "NameSet" is read.
00471    * When used by a derived class with attributes, attributes are read, too. 
00472    *
00473    * @param tr
00474    *   Reference to TokenReader
00475    * @param rLabel
00476    *   Label to read, defaults to current begin label or else "NameSet"
00477    * @param pContext
00478    *   Write context to provide contextual information
00479    *
00480    * @exception Exception
00481    *   - IO errors (id 1)
00482    *   - token mismatch (id 50, 51, 52)
00483    */
00484   virtual void DoRead(TokenReader& tr, const std::string& rLabel = "", const Type* pContext=0);
00485 
00486 
00487 };
00488 
00489 
00490 /* convenience typedef for eventset */
00491 typedef  NameSet EventSet;  
00492 
00493 /* convenience typedef for eventset vectors*/
00494 typedef  TBaseVector<EventSet> EventSetVector;  
00495 
00496 
00497 
00498 /**
00499  * Set of indices with symbolic names and attributes. 
00500  *
00501  * This class is derived from NameSet and TaBaseSet.
00502  *
00503  * The file format is demonstrated by the following example
00504  * of a set "Alphabet" consisting of events "alpha", "beta" and "gamma"
00505  * with "gamma" having some attribute (see eg AtributeFlags)
00506  * \code
00507  * <Alphabet> 
00508  * "alpha" 
00509  * "beta" 
00510  * "gamma" 0x0f
00511  * <\Alphabet> 
00512  * \endcode
00513  * As with TaBaseSet, reading a file ignores unknown attributes. Thus, the above example
00514  * may also be read as NameSet.
00515  */
00516 
00517 
00518 
00519 template<class Attr>
00520 class TaNameSet : public virtual NameSet, public virtual TaBaseSet<Idx,Attr> {
00521 
00522 FAUDES_TYPE_DECLARATION(TaNameSet,NameSet)
00523 
00524   /** 
00525    * We implement "protected privacy for template classes" by friendship.
00526    * This is used for the pragmatic implemention conversion constructors.
00527    */
00528   friend class NameSet;
00529 
00530 
00531  public:
00532   /**
00533    * Constructor for NameSet referring to the static SymbolTable. 
00534    */
00535   TaNameSet(void);
00536          
00537   /**
00538    * Copy-constructor from other TaNameSet (incl attributes and symboltable) 
00539    *
00540    * @param rOtherSet
00541    *   Set to copy
00542    */
00543   TaNameSet(const TaNameSet& rOtherSet);
00544 
00545   /**
00546    * Constructor from NameSet (sets default attributes, same symboltable) 
00547    *
00548    * @param rOtherSet
00549    *   Set to copy
00550    */
00551   TaNameSet(const NameSet& rOtherSet);
00552 
00553   /**
00554    * Constructor from file.
00555    * This constructor reads a NameSet from a file using the DoRead(TokenReader&, const std::String&)
00556    * function. The section is specified by rLabel and the static SymbolTable is used.
00557    *
00558    * @param rFilename
00559    *   Name of File
00560    * @param rLabel
00561    *   Section for the set in the file; 
00562    */
00563   TaNameSet(const std::string& rFilename, const std::string& rLabel = "");
00564 
00565   /**
00566    * Virtual destructor
00567    */
00568   virtual ~TaNameSet(void) {};
00569 
00570   /**
00571    * Return a NameSet with same symboltable as this set.
00572    *
00573    * @return 
00574    *   New empty TaNameSet
00575    */
00576   TaNameSet NewN() const;
00577 
00578   /** Relaxed assignment method (uses base class to be maintain attributes)
00579    *
00580    * @param rSrc 
00581    *    Source from which to assign
00582    * @return
00583    *    Ref to this set
00584    */
00585   virtual TaNameSet& Assign(const NameSet& rSrc);
00586 
00587   /** Relaxed assignment operator (uses base class to be maintain attributes)
00588    *
00589    * @param rSrc 
00590    *    Source from which to assign
00591    * @return
00592    *    Ref to this set
00593    */
00594   virtual TaNameSet& operator=(const NameSet& rSrc) { return Assign(rSrc); };
00595 
00596   /**
00597    * Add an element by index. 
00598    * Index must be already known to the global SymbolTable. If the element already
00599    * exists in the set, the attribute is maintained. Otherwise, the element
00600    * is inserted with default attribute.
00601    *
00602    * @param rIndex
00603    *   Index to add
00604    * @return 
00605    *   True, if element was new to set
00606    * @exception Exception
00607    *   - no symbolic name for index (id 65)
00608    */
00609   bool Insert(const Idx& rIndex);
00610 
00611 
00612   /**
00613    * Add an element by index incl. attribute 
00614    *
00615    * @param rIndex
00616    *   Index to add
00617    * @param rAttr
00618    *   Attribute to add
00619    * @return 
00620    *   True, if index was new to set
00621    * @exception Exception
00622    *   - no symbolic name for index (id 65)
00623    *
00624    */
00625   bool Insert(const Idx& rIndex, const Attr& rAttr);
00626 
00627   /** 
00628    * Add an element by its  symbolic name. If the name is unknown, 
00629    * a new index will be generated and recorded in the symboltable.
00630    * If the name is known, the corresponding index will be added to the set.
00631    * If the element already exists in the set, the attribute is maintained. 
00632    * Otherwise, the element is inserted with default attribute.
00633    *
00634    * @param rName
00635    *   symbolic name of element to add
00636    *
00637    * @return 
00638    *   Index of (new) element
00639    */
00640   Idx Insert(const std::string& rName);
00641 
00642   /** 
00643    * Add an element by its symbolic name.
00644    * If the name is unknown, 
00645    * a new index will be generated and recorded in the symboltable.
00646    * If the name is known, the corresponding index will be added to the set.
00647    *
00648    * @param rName
00649    *   symbolic name of element to add
00650    * @param rAttr
00651    *   Attribute
00652    *
00653    * @return 
00654    *   Index of (new) element
00655    */
00656   Idx Insert(const std::string& rName, const Attr& rAttr);
00657 
00658   /**
00659    * Inserts elements of rOtherSet.
00660    * Attributes of this set are maintained, newly inserted elements have default attribute.
00661    *
00662    * @param rOtherSet
00663    *   Other StateSet
00664    * @exception Exception 
00665    *   - symboltable mismatch (id 67)
00666    */
00667    void InsertSet(const NameSet& rOtherSet);
00668 
00669   /**
00670    * Inserts elements of rOtherSet incl attributes
00671    * Attributes of this set are maintained, new elements are inserted with attribute.
00672    *
00673    * @param rOtherSet
00674    *   Other StateSet
00675    */
00676    void InsertSet(const TaNameSet& rOtherSet);
00677 
00678   /**
00679    * Delete element by index. Symbolic name is not removed from SymbolTable.
00680    *
00681    * @param rIndex
00682    *   Index to delete
00683    * @return
00684    *   True if element did exist
00685    * 
00686    */
00687   virtual bool Erase(const Idx& rIndex);
00688 
00689   /**
00690    * Delete element by symbolic name. Symbolic name is not removed from SymbolTable
00691    *
00692    * @param rName
00693    *   Symbolic name of element to dlete
00694    * @return
00695    *    True if element did exist
00696    * @exception Exception 
00697    *   - name not found in Symboltable (id 66)
00698    */
00699   virtual bool Erase(const std::string& rName);
00700 
00701   /**
00702    * Delete element by iterator. Symbolic nam is not removed from SymbolTable.
00703    *
00704    * @param pos
00705    *   TaNameSet::iterator
00706    * @return
00707    *   Iterator to next element
00708    * @exception Exception 
00709    *   - invalid iterator (id 62)
00710    */
00711   virtual Iterator Erase(const Iterator& pos);
00712 
00713   /**
00714    * Erase elements indicated by rOtherSet
00715    *
00716    * @exception Exception 
00717    *   - symboltable mismatch (id 67)
00718    *
00719    * @param rOtherSet
00720    *   Other StateSet
00721    */
00722    void EraseSet(const NameSet& rOtherSet);
00723 
00724   /**
00725    * Erase elements indicated by rOtherSet.
00726    *
00727    * @exception Exception 
00728    *   - symboltable mismatch (id 67)
00729    *
00730    * @param rOtherSet
00731    *   Other StateSet
00732    */
00733    void EraseSet(const TaNameSet& rOtherSet);
00734 
00735   /**
00736    * Restrict elements indicated by rOtherSet
00737    *
00738    * @exception Exception 
00739    *   - symboltable mismatch (id 67)
00740    *
00741    * @param rOtherSet
00742    *   Other EventSet
00743    */
00744    void RestrictSet(const NameSet& rOtherSet);
00745 
00746   /**
00747    * Restrict elements indicated by rOtherSet.
00748    *
00749    * @exception Exception 
00750    *   - symboltable mismatch (id 67)
00751    *
00752    * @param rOtherSet
00753    *   Other StateSet
00754    */
00755    void RestrictSet(const TaNameSet& rOtherSet);
00756 
00757   /**
00758    * Set attributes. Provided that rOtherSet has attributes that can be
00759    * casted to the appropriate type, attributes are copied per element from rOtherSet. 
00760    * Elements of this set which are not in rOtherSet maintain their attribute. 
00761    *
00762    * @param rOtherSet
00763    *   Other IndexSet
00764    * @exception Exception
00765    *   - Element does not exist (63)
00766    *   - Cannot cast attribute type (63)
00767    */
00768    virtual void Attributes(const NameSet& rOtherSet);
00769 
00770   /**
00771    * Set attributes. Attributes are copied per element from rOtherSet. 
00772    * Elements of this set which are not in rOtherSet maintain their attribute. 
00773    *
00774    * @param rOtherSet
00775    *   Other IndexSet
00776    */
00777    virtual void Attributes(const TaNameSet& rOtherSet);
00778 
00779   /**
00780    * Return pretty printable symbolic name for index.
00781    * Primary meant for debugging messages.
00782    *
00783    * @param rIndex
00784    *   Index to print
00785    *
00786    * @return
00787    *   String
00788    */
00789   std::string Str(const Idx& rIndex) const;
00790 
00791  protected:
00792 
00793   /**
00794    * Assign to other name set. Performs a fake copy, see TBaseSet.
00795    * This function maintains attributes.
00796    *
00797    * @param rSourceSet
00798    *   Destination to copy from
00799    * @return
00800    *   ref to this set
00801    */
00802   virtual TaNameSet& DoAssign(const TaNameSet& rSourceSet);
00803 
00804 
00805 
00806 };
00807 
00808 
00809 /** Convenience Macro */
00810 #define TaEventSet TaNameSet  
00811 
00812 /** @} doxygen group */
00813 
00814 /*
00815 *************************************************************************************
00816 *************************************************************************************
00817  Implementation
00818 *************************************************************************************
00819 *************************************************************************************
00820 */
00821 
00822 
00823 // std faudes type (cannot do New() with macro)
00824 FAUDES_TYPE_TIMPLEMENTATION_COPY(TaNameSet<Attr>,NameSet,template<class Attr>)
00825 FAUDES_TYPE_TIMPLEMENTATION_CAST(TaNameSet<Attr>,NameSet,template<class Attr>)
00826 FAUDES_TYPE_TIMPLEMENTATION_ASSIGN(TaNameSet<Attr>,NameSet,template<class Attr>)
00827 FAUDES_TYPE_TIMPLEMENTATION_EQUAL(TaNameSet<Attr>,NameSet,template<class Attr>)
00828 
00829 // empty constructor // todo: investigate base contructor/initialisation
00830 template<class Attr>
00831 TaNameSet<Attr>::TaNameSet(void) :
00832   TBaseSet<Idx>(),
00833   NameSet(),
00834   TaBaseSet<Idx,Attr>()
00835 {
00836   FD_DC("TaNameSet(" << this << ")::TaNameSet()");
00837   //mpSymbolTable = SymbolTable::GlobalEventSymbolTablep();
00838   this->Name("NameSet");
00839 }
00840 
00841 // constructor form other nameset
00842 template<class Attr>
00843 TaNameSet<Attr>::TaNameSet(const TaNameSet& rOtherSet) :
00844   TBaseSet<Idx>(),
00845   NameSet(),
00846   TaBaseSet<Idx,Attr>()
00847 {
00848   FD_DC("TaNameSet(" << this << ")::TaNameSet(rOtherSet " << &rOtherSet << ")");
00849   // TaIndexSet<Attr>::mAttributeMap=rOtherSet.mAttributeMap; 
00850   DoAssign(rOtherSet);
00851 }
00852 
00853 // constructor form other nameset
00854 template<class Attr>
00855 TaNameSet<Attr>::TaNameSet(const NameSet& rOtherSet) :
00856   TBaseSet<Idx>(),
00857   NameSet(),
00858   TaBaseSet<Idx,Attr>()
00859 {
00860   FD_DC("TaNameSet(" << this << ")::TaNameSet(rOtherSet " << &rOtherSet << ")");
00861   Assign(rOtherSet);
00862 }
00863 
00864 
00865 // read file constructor
00866 template<class Attr>
00867 TaNameSet<Attr>::TaNameSet(const std::string& rFilename, const std::string& rLabel) :
00868   TBaseSet<Idx>(),
00869   NameSet(),
00870   TaBaseSet<Idx,Attr>()
00871 {
00872   FD_DC("TaNameSet(" << this << ")::TaNameSet(" << rFilename << ")");
00873   mpSymbolTable = SymbolTable::GlobalEventSymbolTablep();
00874   Read(rFilename, rLabel);
00875 }
00876 
00877 // New() (std faudes type, cannot use macro)
00878 template<class Attr>
00879 TaNameSet<Attr>* TaNameSet<Attr>::New(void) const {
00880   TaNameSet* res = new TaNameSet();
00881   res->mpSymbolTable=mpSymbolTable;
00882   return res;
00883 }
00884 
00885 // NewN()
00886 template<class Attr>
00887 TaNameSet<Attr> TaNameSet<Attr>::NewN(void) const {
00888   TaNameSet res;
00889   res.mpSymbolTable=mpSymbolTable;
00890   return res;
00891 }
00892 
00893 // DoAssign()
00894 template<class Attr>
00895 TaNameSet<Attr>& TaNameSet<Attr>::DoAssign(const TaNameSet<Attr>& rSourceSet) {
00896   FD_DC("TaNameSet(" << this << ")::DoAssign( [a] " << &rSourceSet << ")");
00897   // fix symboltable
00898   mpSymbolTable=rSourceSet.mpSymbolTable;
00899   // call base with attributes
00900   TaBaseSet<Idx,Attr>::DoAssign(rSourceSet);
00901   // done
00902   return *this;
00903 }
00904 
00905 // Relaxed Assign()
00906 template<class Attr>
00907 TaNameSet<Attr>& TaNameSet<Attr>::Assign(const NameSet& rSourceSet) {
00908   FD_DC("TaNameSet(" << this << ")::Assign( [v] " << &rSourceSet << ")");
00909   // fix symboltable
00910   mpSymbolTable=rSourceSet.mpSymbolTable;
00911   // call base with relaxed attributes
00912   TaBaseSet<Idx,Attr>::Assign(rSourceSet);
00913   // done
00914   return *this;
00915 }
00916 
00917 // Insert(index)
00918 template<class Attr>
00919 bool TaNameSet<Attr>::Insert(const Idx& rIndex) { 
00920 #ifdef FAUDES_CHECKED
00921   if(!mpSymbolTable->Exists(rIndex)) {
00922     std::stringstream errstr;
00923     errstr << "index " << rIndex << " has no symbolic name" << std::endl;
00924     throw Exception("TaNameSet::Insert", errstr.str(), 65);
00925   }
00926 #endif
00927   return TaBaseSet<Idx,Attr>::Insert(rIndex);
00928 }
00929 
00930         
00931 // Insert(index,attr)
00932 template<class Attr>
00933 bool TaNameSet<Attr>::Insert(const Idx& rIndex, const Attr& attr) { 
00934 #ifdef FAUDES_CHECKED
00935   if(!mpSymbolTable->Exists(rIndex)) {
00936     std::stringstream errstr;
00937     errstr << "index " << rIndex << " has no symbolic name" << std::endl;
00938     throw Exception("TaNameSet::Insert", errstr.str(), 65);
00939   }
00940 #endif
00941   return TaBaseSet<Idx,Attr>::Insert(rIndex,attr);
00942 }
00943 
00944         
00945 // Insert(rName)
00946 template<class Attr>
00947 Idx TaNameSet<Attr>::Insert(const std::string& rName) {
00948   FD_DC("TaNameSet(" << this << ")::Insert(" << rName <<")");
00949   Idx index= NameSet::Insert(rName); // automatic: keep attribute if exists
00950   return index;
00951 }
00952 
00953 // Insert(rName, attr)
00954 template<class Attr>
00955 Idx TaNameSet<Attr>::Insert(const std::string& rName, const Attr& attr) {
00956   FD_DC("TaNameSet(" << this << ")::Insert(" << rName <<")");
00957   Idx index= NameSet::Insert(rName);
00958   TaBaseSet<Idx,Attr>::Attribute(index,attr);
00959   return index;
00960 }
00961 
00962 // InsertSet(set)
00963 template<class Attr>
00964 void TaNameSet<Attr>::InsertSet(const NameSet& rOtherSet) {
00965   FD_DC("TaNameSet(" << this << ")::InsertSet(" << rOtherSet.ToString() << ")");
00966 #ifdef FAUDES_CHECKED
00967   if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
00968     std::stringstream errstr;
00969     errstr << "symboltable mismach aka not implemented" << std::endl;
00970     throw Exception("TaNameSet::InsertSet", errstr.str(), 67);
00971   }
00972 #endif
00973   NameSet::InsertSet(rOtherSet);
00974 }
00975 
00976 // InsertSet(set)
00977 template<class Attr>
00978 void TaNameSet<Attr>::InsertSet(const TaNameSet& rOtherSet) {
00979   FD_DC("TaNameSet(" << this << ")::InsertSet(" << rOtherSet.ToString() << ")");
00980 #ifdef FAUDES_CHECKED
00981   if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
00982     std::stringstream errstr;
00983     errstr << "symboltable mismach aka not implemented" << std::endl;
00984     throw Exception("TaNameSet::InsertSet", errstr.str(), 200);
00985   }
00986 #endif
00987   TaBaseSet<Idx,Attr>::InsertSet(rOtherSet);
00988 }
00989     
00990 // Erase(index)
00991 template<class Attr>
00992 bool TaNameSet<Attr>::Erase(const Idx& rIndex) {
00993   FD_DC("TaNameSet(" << this << ")::Erase(" << rIndex <<")");
00994   return TaBaseSet<Idx,Attr>::Erase(rIndex);
00995 }
00996 
00997 // Erase(rName)
00998 template<class Attr>
00999 bool TaNameSet<Attr>::Erase(const std::string& rName) {
01000   FD_DC("TaNameSet(" << this << ")::Erase(" << rName <<")");
01001   Idx index = mpSymbolTable->Index(rName);
01002 #ifdef FAUDES_CHECKED
01003   if (index == 0) {
01004     std::stringstream errstr;
01005     errstr << "name \"" << rName << "\" not found in TaNameSet" << std::endl;
01006     throw Exception("TaNameSet::Erase", errstr.str(), 60);
01007   }
01008 #endif
01009   return TaBaseSet<Idx,Attr>::Erase(index);
01010 }
01011 
01012 // Erase(pos)
01013 template<class Attr>
01014 typename TaNameSet<Attr>::Iterator TaNameSet<Attr>::Erase(const Iterator& pos) {
01015   return TaBaseSet<Idx,Attr>::Erase(pos);
01016 }
01017 
01018 // EraseSet(set)
01019 template<class Attr>
01020 void TaNameSet<Attr>::EraseSet(const NameSet& rOtherSet) {
01021   FD_DC("TaNameSet(" << this << ")::EraseSet(" << rOtherSet.ToString() << ")");
01022 #ifdef FAUDES_CHECKED
01023   if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
01024     std::stringstream errstr;
01025     errstr << "symboltable mismach aka not implemented" << std::endl;
01026     throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
01027   }
01028 #endif
01029   TaBaseSet<Idx,Attr>::EraseSet(rOtherSet);
01030 }
01031 
01032 // EraseSet(set)
01033 template<class Attr>
01034 void TaNameSet<Attr>::EraseSet(const TaNameSet& rOtherSet) {
01035   FD_DC("TaNameSet(" << this << ")::EraseSet(" << rOtherSet.ToString() << ")");
01036 #ifdef FAUDES_CHECKED
01037   if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
01038     std::stringstream errstr;
01039     errstr << "symboltable mismatch aka not implemented" << std::endl;
01040     throw Exception("TaNameSet::EraseSet", errstr.str(), 67);
01041   }
01042 #endif
01043   TaBaseSet<Idx,Attr>::EraseSet(rOtherSet);
01044 }
01045     
01046 // RestrictSet(set)
01047 template<class Attr>
01048 void TaNameSet<Attr>::RestrictSet(const NameSet& rOtherSet) {
01049   FD_DC("TaNameSet(" << this << ")::RestrictSet(" << rOtherSet.ToString() << ")");
01050 #ifdef FAUDES_CHECKED
01051   if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
01052     std::stringstream errstr;
01053     errstr << "symboltable mismach aka not implemented" << std::endl;
01054     throw Exception("TaNameSet::RestrictSet", errstr.str(), 67);
01055   }
01056 #endif
01057   TaBaseSet<Idx,Attr>::RestrictSet(rOtherSet);
01058 }
01059 
01060 // RestrictSet(set)
01061 template<class Attr>
01062 void TaNameSet<Attr>::RestrictSet(const TaNameSet& rOtherSet) {
01063   FD_DC("TaNameSet(" << this << ")::RestrictSet(" << rOtherSet.ToString() << ")");
01064 #ifdef FAUDES_CHECKED
01065   if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
01066     std::stringstream errstr;
01067     errstr << "symboltable mismatch aka not implemented" << std::endl;
01068     throw Exception("TaNameSet::RestrictSet", errstr.str(), 67);
01069   }
01070 #endif
01071   TaBaseSet<Idx,Attr>::RestrictSet(rOtherSet);
01072 }
01073     
01074 // Attributes(set)
01075 template<class Attr>
01076 void TaNameSet<Attr>::Attributes(const TaNameSet& rOtherSet) {
01077   FD_DC("TaNameSet(" << this << ")::Attributes(set) with type " << typeid(rOtherSet.Attribute()).name());
01078 #ifdef FAUDES_CHECKED
01079   if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
01080     std::stringstream errstr;
01081     errstr << "symboltable mismatch aka not implemented" << std::endl;
01082     throw Exception("TaNameSet::Attributes", errstr.str(), 67);
01083   }
01084 #endif
01085   TaBaseSet<Idx,Attr>::Attributes(rOtherSet);
01086 }
01087 
01088 // Attributes(set)
01089 template<class Attr>
01090 void TaNameSet<Attr>::Attributes(const NameSet& rOtherSet) {
01091   FD_DC("TaNameSet(" << this << ")::Attributes(set) with type " << typeid(rOtherSet.Attribute()).name());
01092 #ifdef FAUDES_CHECKED
01093   if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
01094     std::stringstream errstr;
01095     errstr << "symboltable mismatch aka not implemented" << std::endl;
01096     throw Exception("TaNameSet::Attributes", errstr.str(), 67);
01097   }
01098 #endif
01099   TaBaseSet<Idx,Attr>::Attributes(rOtherSet);
01100 }
01101 
01102 
01103 // Str()
01104 template<class Attr>
01105 std::string TaNameSet<Attr>::Str(const Idx& rIndex) const {
01106   return NameSet::Str(rIndex);
01107 }
01108 
01109 
01110 
01111 } // namespace faudes
01112 
01113 #endif 
01114 

libFAUDES 2.16b --- 2010-9-8 --- c++ source docu by doxygen 1.6.3