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

libFAUDES 2.18b --- 2010-12-17 --- c++ source docu by doxygen 1.6.3