cfl_nameset.hGo 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 /** 00502 * Convenience typedef for plain event sets 00503 * 00504 * @ingroup ContainerClasses 00505 */ 00506 typedef NameSet EventSet; 00507 00508 /* convenience typedef for eventset vectors*/ 00509 typedef TBaseVector<EventSet> EventSetVector; 00510 00511 /* RTI convenience function */ 00512 void SetIntersection(const EventSetVector& rSetVector, EventSet& rRes); 00513 void SetUnion(const EventSetVector& rSetVector, EventSet& rRes); 00514 00515 00516 00517 /** 00518 * Set of indices with symbolic names and attributes. 00519 * 00520 * This class is derived from NameSet and TaBaseSet. 00521 * 00522 * The file format is demonstrated by the following example 00523 * of a set "Alphabet" consisting of events "alpha", "beta" and "gamma" 00524 * with "gamma" having some attribute (see eg AtributeFlags) 00525 * \code 00526 * <Alphabet> 00527 * "alpha" 00528 * "beta" 00529 * "gamma" 0x0f 00530 * <\Alphabet> 00531 * \endcode 00532 * As with TaBaseSet, reading a file ignores unknown attributes. Thus, the above example 00533 * may also be read as NameSet. 00534 */ 00535 00536 00537 00538 template<class Attr> 00539 class TaNameSet : public virtual NameSet, public virtual TaBaseSet<Idx,Attr> { 00540 00541 FAUDES_TYPE_TDECLARATION(Void,TaNameSet,NameSet) 00542 00543 /** 00544 * We implement "protected privacy for template classes" by friendship. 00545 * This is used for the pragmatic implemention conversion constructors. 00546 */ 00547 friend class NameSet; 00548 00549 00550 public: 00551 /** 00552 * Constructor for NameSet referring to the static SymbolTable. 00553 */ 00554 TaNameSet(void); 00555 00556 /** 00557 * Copy-constructor from other TaNameSet (incl attributes and symboltable) 00558 * 00559 * @param rOtherSet 00560 * Set to copy 00561 */ 00562 TaNameSet(const TaNameSet& rOtherSet); 00563 00564 /** 00565 * Constructor from NameSet (sets default attributes, same symboltable) 00566 * 00567 * @param rOtherSet 00568 * Set to copy 00569 */ 00570 TaNameSet(const NameSet& rOtherSet); 00571 00572 /** 00573 * Constructor from file. 00574 * This constructor reads a NameSet from a file using the DoRead(TokenReader&, const std::String&) 00575 * function. The section is specified by rLabel and the static SymbolTable is used. 00576 * 00577 * @param rFilename 00578 * Name of File 00579 * @param rLabel 00580 * Section for the set in the file; 00581 */ 00582 TaNameSet(const std::string& rFilename, const std::string& rLabel = ""); 00583 00584 /** 00585 * Virtual destructor 00586 */ 00587 virtual ~TaNameSet(void) {}; 00588 00589 /** 00590 * Return a NameSet with same symboltable as this set. 00591 * 00592 * @return 00593 * New empty TaNameSet 00594 */ 00595 TaNameSet NewN() const; 00596 00597 /** Relaxed assignment method (uses base class to maintain attributes) 00598 * 00599 * @param rSrc 00600 * Source from which to assign 00601 * @return 00602 * Ref to this set 00603 */ 00604 virtual TaNameSet& Assign(const NameSet& rSrc); 00605 00606 /** Relaxed assignment operator (uses base class to maintain attributes) 00607 * 00608 * @param rSrc 00609 * Source from which to assign 00610 * @return 00611 * Ref to this set 00612 */ 00613 virtual TaNameSet& operator=(const NameSet& rSrc) { return Assign(rSrc); }; 00614 00615 /** 00616 * Add an element by index. 00617 * Index must be already known to the global SymbolTable. If the element already 00618 * exists in the set, the attribute is maintained. Otherwise, the element 00619 * is inserted with default attribute. 00620 * 00621 * @param rIndex 00622 * Index to add 00623 * @return 00624 * True, if element was new to set 00625 * @exception Exception 00626 * - no symbolic name for index (id 65) 00627 */ 00628 bool Insert(const Idx& rIndex); 00629 00630 00631 /** 00632 * Add an element by index incl. attribute 00633 * 00634 * @param rIndex 00635 * Index to add 00636 * @param rAttr 00637 * Attribute to add 00638 * @return 00639 * True, if index was new to set 00640 * @exception Exception 00641 * - no symbolic name for index (id 65) 00642 * 00643 */ 00644 bool Insert(const Idx& rIndex, const Attr& rAttr); 00645 00646 /** 00647 * Add an element by its symbolic name. If the name is unknown, 00648 * a new index will be generated and recorded in the symboltable. 00649 * If the name is known, the corresponding index will be added to the set. 00650 * If the element already exists in the set, the attribute is maintained. 00651 * Otherwise, the element is inserted with default attribute. 00652 * 00653 * @param rName 00654 * symbolic name of element to add 00655 * 00656 * @return 00657 * Index of (new) element 00658 */ 00659 Idx Insert(const std::string& rName); 00660 00661 /** 00662 * Add an element by its symbolic name. 00663 * If the name is unknown, 00664 * a new index will be generated and recorded in the symboltable. 00665 * If the name is known, the corresponding index will be added to the set. 00666 * 00667 * @param rName 00668 * symbolic name of element to add 00669 * @param rAttr 00670 * Attribute 00671 * 00672 * @return 00673 * Index of (new) element 00674 */ 00675 Idx Insert(const std::string& rName, const Attr& rAttr); 00676 00677 /** 00678 * Inserts elements of rOtherSet. 00679 * Attributes of this set are maintained, newly inserted elements have default attribute. 00680 * 00681 * @param rOtherSet 00682 * Other StateSet 00683 * @exception Exception 00684 * - symboltable mismatch (id 67) 00685 */ 00686 void InsertSet(const NameSet& rOtherSet); 00687 00688 /** 00689 * Inserts elements of rOtherSet incl attributes 00690 * Attributes of this set are maintained, new elements are inserted with attribute. 00691 * 00692 * @param rOtherSet 00693 * Other StateSet 00694 */ 00695 void InsertSet(const TaNameSet& rOtherSet); 00696 00697 /** 00698 * Delete element by index. Symbolic name is not removed from SymbolTable. 00699 * 00700 * @param rIndex 00701 * Index to delete 00702 * @return 00703 * True if element did exist 00704 * 00705 */ 00706 virtual bool Erase(const Idx& rIndex); 00707 00708 /** 00709 * Delete element by symbolic name. Symbolic name is not removed from SymbolTable 00710 * 00711 * @param rName 00712 * Symbolic name of element to dlete 00713 * @return 00714 * True if element did exist 00715 * @exception Exception 00716 * - name not found in Symboltable (id 66) 00717 */ 00718 virtual bool Erase(const std::string& rName); 00719 00720 /** 00721 * Delete element by iterator. Symbolic nam is not removed from SymbolTable. 00722 * 00723 * @param pos 00724 * TaNameSet::iterator 00725 * @return 00726 * Iterator to next element 00727 * @exception Exception 00728 * - invalid iterator (id 62) 00729 */ 00730 virtual Iterator Erase(const Iterator& pos); 00731 00732 /** 00733 * Erase elements indicated by rOtherSet 00734 * 00735 * @exception Exception 00736 * - symboltable mismatch (id 67) 00737 * 00738 * @param rOtherSet 00739 * Other StateSet 00740 */ 00741 void EraseSet(const NameSet& rOtherSet); 00742 00743 /** 00744 * Erase elements indicated by rOtherSet. 00745 * 00746 * @exception Exception 00747 * - symboltable mismatch (id 67) 00748 * 00749 * @param rOtherSet 00750 * Other StateSet 00751 */ 00752 void EraseSet(const TaNameSet& rOtherSet); 00753 00754 /** 00755 * Restrict elements indicated by rOtherSet 00756 * 00757 * @exception Exception 00758 * - symboltable mismatch (id 67) 00759 * 00760 * @param rOtherSet 00761 * Other EventSet 00762 */ 00763 void RestrictSet(const NameSet& rOtherSet); 00764 00765 /** 00766 * Restrict elements indicated by rOtherSet. 00767 * 00768 * @exception Exception 00769 * - symboltable mismatch (id 67) 00770 * 00771 * @param rOtherSet 00772 * Other StateSet 00773 */ 00774 void RestrictSet(const TaNameSet& rOtherSet); 00775 00776 /** 00777 * Set attributes. Provided that rOtherSet has attributes that can be 00778 * casted to the appropriate type, attributes are copied per element from rOtherSet. 00779 * Elements of this set which are not in rOtherSet maintain their attribute. 00780 * 00781 * @param rOtherSet 00782 * Other IndexSet 00783 * @exception Exception 00784 * - Element does not exist (63) 00785 * - Cannot cast attribute type (63) 00786 */ 00787 virtual void Attributes(const NameSet& rOtherSet); 00788 00789 /** 00790 * Set attributes. Attributes are copied per element from rOtherSet. 00791 * Elements of this set which are not in rOtherSet maintain their attribute. 00792 * 00793 * @param rOtherSet 00794 * Other IndexSet 00795 */ 00796 virtual void Attributes(const TaNameSet& rOtherSet); 00797 00798 /** 00799 * Return pretty printable symbolic name for index. 00800 * Primary meant for debugging messages. 00801 * 00802 * @param rIndex 00803 * Index to print 00804 * 00805 * @return 00806 * String 00807 */ 00808 std::string Str(const Idx& rIndex) const; 00809 00810 protected: 00811 00812 /** 00813 * Assign to other name set. Performs a fake copy, see TBaseSet. 00814 * This function maintains attributes. 00815 * 00816 * @param rSourceSet 00817 * Destination to copy from 00818 * @return 00819 * ref to this set 00820 */ 00821 virtual void DoAssign(const TaNameSet& rSourceSet); 00822 00823 /** 00824 * Test equality of configuration data, ignore attributes 00825 * Ignore name of the set, insist in matching symboltables. 00826 * 00827 * @param rOtherSet 00828 * Other object to compare with. 00829 * @return 00830 * True on match. 00831 */ 00832 virtual bool DoEqual(const NameSet& rOtherSet) const; 00833 00834 00835 00836 }; 00837 00838 00839 /** Convenience Macro */ 00840 #define TaEventSet TaNameSet 00841 00842 /** @} doxygen group */ 00843 00844 /* 00845 ************************************************************************************* 00846 ************************************************************************************* 00847 Implementation 00848 ************************************************************************************* 00849 ************************************************************************************* 00850 */ 00851 00852 00853 // std faudes type (cannot do New() with macro) 00854 FAUDES_TYPE_TIMPLEMENTATION_COPY(Void,TaNameSet<Attr>,NameSet,template<class Attr>) 00855 FAUDES_TYPE_TIMPLEMENTATION_CAST(Void,TaNameSet<Attr>,NameSet,template<class Attr>) 00856 FAUDES_TYPE_TIMPLEMENTATION_ASSIGN(Void,TaNameSet<Attr>,NameSet,template<class Attr>) 00857 FAUDES_TYPE_TIMPLEMENTATION_EQUAL(Void,TaNameSet<Attr>,NameSet,template<class Attr>) 00858 00859 // empty constructor // todo: investigate base contructor/initialisation 00860 template<class Attr> 00861 TaNameSet<Attr>::TaNameSet(void) : 00862 TBaseSet<Idx>(), 00863 NameSet(), 00864 TaBaseSet<Idx,Attr>() 00865 { 00866 FD_DC("TaNameSet(" << this << ")::TaNameSet()"); 00867 //mpSymbolTable = SymbolTable::GlobalEventSymbolTablep(); 00868 this->Name("NameSet"); 00869 } 00870 00871 // constructor form other nameset 00872 template<class Attr> 00873 TaNameSet<Attr>::TaNameSet(const TaNameSet& rOtherSet) : 00874 TBaseSet<Idx>(), 00875 NameSet(), 00876 TaBaseSet<Idx,Attr>() 00877 { 00878 FD_DC("TaNameSet(" << this << ")::TaNameSet(rOtherSet " << &rOtherSet << ")"); 00879 // TaIndexSet<Attr>::mAttributeMap=rOtherSet.mAttributeMap; 00880 DoAssign(rOtherSet); 00881 } 00882 00883 // constructor form other nameset 00884 template<class Attr> 00885 TaNameSet<Attr>::TaNameSet(const NameSet& rOtherSet) : 00886 TBaseSet<Idx>(), 00887 NameSet(), 00888 TaBaseSet<Idx,Attr>() 00889 { 00890 FD_DC("TaNameSet(" << this << ")::TaNameSet(rOtherSet " << &rOtherSet << ")"); 00891 Assign(rOtherSet); 00892 } 00893 00894 00895 // read file constructor 00896 template<class Attr> 00897 TaNameSet<Attr>::TaNameSet(const std::string& rFilename, const std::string& rLabel) : 00898 TBaseSet<Idx>(), 00899 NameSet(), 00900 TaBaseSet<Idx,Attr>() 00901 { 00902 FD_DC("TaNameSet(" << this << ")::TaNameSet(" << rFilename << ")"); 00903 mpSymbolTable = SymbolTable::GlobalEventSymbolTablep(); 00904 Read(rFilename, rLabel); 00905 } 00906 00907 // New() (std faudes type, cannot use macro) 00908 template<class Attr> 00909 TaNameSet<Attr>* TaNameSet<Attr>::New(void) const { 00910 TaNameSet* res = new TaNameSet(); 00911 res->mpSymbolTable=mpSymbolTable; 00912 return res; 00913 } 00914 00915 // NewN() 00916 template<class Attr> 00917 TaNameSet<Attr> TaNameSet<Attr>::NewN(void) const { 00918 TaNameSet res; 00919 res.mpSymbolTable=mpSymbolTable; 00920 return res; 00921 } 00922 00923 // DoAssign() 00924 template<class Attr> 00925 void TaNameSet<Attr>::DoAssign(const TaNameSet<Attr>& rSourceSet) { 00926 FD_DC("TaNameSet(" << this << ")::DoAssign( [a] " << &rSourceSet << ")"); 00927 // fix symboltable 00928 mpSymbolTable=rSourceSet.mpSymbolTable; 00929 // call base with attributes 00930 TaBaseSet<Idx,Attr>::DoAssign(rSourceSet); 00931 } 00932 00933 // DoEqual() 00934 template<class Attr> 00935 bool TaNameSet<Attr>::DoEqual(const NameSet& rOtherSet) const { 00936 FD_DC("TaNAMESet::DoEqual()"); 00937 // insist in symboltable match 00938 if(mpSymbolTable!=rOtherSet.mpSymbolTable) return false; 00939 // call base 00940 return TaBaseSet<Idx,Attr>::DoEqual(rOtherSet); 00941 } 00942 00943 // Relaxed Assign() 00944 template<class Attr> 00945 TaNameSet<Attr>& TaNameSet<Attr>::Assign(const NameSet& rSourceSet) { 00946 FD_DC("TaNameSet(" << this << ")::Assign( [v] " << &rSourceSet << ")"); 00947 // fix symboltable 00948 mpSymbolTable=rSourceSet.mpSymbolTable; 00949 // call base with relaxed attributes 00950 TaBaseSet<Idx,Attr>::Assign(rSourceSet); 00951 // done 00952 return *this; 00953 } 00954 00955 // Insert(index) 00956 template<class Attr> 00957 bool TaNameSet<Attr>::Insert(const Idx& rIndex) { 00958 #ifdef FAUDES_CHECKED 00959 if(!mpSymbolTable->Exists(rIndex)) { 00960 std::stringstream errstr; 00961 errstr << "index " << rIndex << " has no symbolic name" << std::endl; 00962 throw Exception("TaNameSet::Insert", errstr.str(), 65); 00963 } 00964 #endif 00965 return TaBaseSet<Idx,Attr>::Insert(rIndex); 00966 } 00967 00968 00969 // Insert(index,attr) 00970 template<class Attr> 00971 bool TaNameSet<Attr>::Insert(const Idx& rIndex, const Attr& attr) { 00972 #ifdef FAUDES_CHECKED 00973 if(!mpSymbolTable->Exists(rIndex)) { 00974 std::stringstream errstr; 00975 errstr << "index " << rIndex << " has no symbolic name" << std::endl; 00976 throw Exception("TaNameSet::Insert", errstr.str(), 65); 00977 } 00978 #endif 00979 return TaBaseSet<Idx,Attr>::Insert(rIndex,attr); 00980 } 00981 00982 00983 // Insert(rName) 00984 template<class Attr> 00985 Idx TaNameSet<Attr>::Insert(const std::string& rName) { 00986 FD_DC("TaNameSet(" << this << ")::Insert(" << rName <<")"); 00987 Idx index= NameSet::Insert(rName); // automatic: keep attribute if exists 00988 return index; 00989 } 00990 00991 // Insert(rName, attr) 00992 template<class Attr> 00993 Idx TaNameSet<Attr>::Insert(const std::string& rName, const Attr& attr) { 00994 FD_DC("TaNameSet(" << this << ")::Insert(" << rName <<")"); 00995 Idx index= NameSet::Insert(rName); 00996 TaBaseSet<Idx,Attr>::Attribute(index,attr); 00997 return index; 00998 } 00999 01000 // InsertSet(set) 01001 template<class Attr> 01002 void TaNameSet<Attr>::InsertSet(const NameSet& rOtherSet) { 01003 FD_DC("TaNameSet(" << this << ")::InsertSet(" << rOtherSet.ToString() << ")"); 01004 #ifdef FAUDES_CHECKED 01005 if(rOtherSet.mpSymbolTable!=mpSymbolTable) { 01006 std::stringstream errstr; 01007 errstr << "symboltable mismach aka not implemented" << std::endl; 01008 throw Exception("TaNameSet::InsertSet", errstr.str(), 67); 01009 } 01010 #endif 01011 NameSet::InsertSet(rOtherSet); 01012 } 01013 01014 // InsertSet(set) 01015 template<class Attr> 01016 void TaNameSet<Attr>::InsertSet(const TaNameSet& rOtherSet) { 01017 FD_DC("TaNameSet(" << this << ")::InsertSet(" << rOtherSet.ToString() << ")"); 01018 #ifdef FAUDES_CHECKED 01019 if(rOtherSet.mpSymbolTable!=mpSymbolTable) { 01020 std::stringstream errstr; 01021 errstr << "symboltable mismach aka not implemented" << std::endl; 01022 throw Exception("TaNameSet::InsertSet", errstr.str(), 200); 01023 } 01024 #endif 01025 TaBaseSet<Idx,Attr>::InsertSet(rOtherSet); 01026 } 01027 01028 // Erase(index) 01029 template<class Attr> 01030 bool TaNameSet<Attr>::Erase(const Idx& rIndex) { 01031 FD_DC("TaNameSet(" << this << ")::Erase(" << rIndex <<")"); 01032 return TaBaseSet<Idx,Attr>::Erase(rIndex); 01033 } 01034 01035 // Erase(rName) 01036 template<class Attr> 01037 bool TaNameSet<Attr>::Erase(const std::string& rName) { 01038 FD_DC("TaNameSet(" << this << ")::Erase(" << rName <<")"); 01039 Idx index = mpSymbolTable->Index(rName); 01040 #ifdef FAUDES_CHECKED 01041 if (index == 0) { 01042 std::stringstream errstr; 01043 errstr << "name \"" << rName << "\" not found in TaNameSet" << std::endl; 01044 throw Exception("TaNameSet::Erase", errstr.str(), 60); 01045 } 01046 #endif 01047 return TaBaseSet<Idx,Attr>::Erase(index); 01048 } 01049 01050 // Erase(pos) 01051 template<class Attr> 01052 typename TaNameSet<Attr>::Iterator TaNameSet<Attr>::Erase(const Iterator& pos) { 01053 return TaBaseSet<Idx,Attr>::Erase(pos); 01054 } 01055 01056 // EraseSet(set) 01057 template<class Attr> 01058 void TaNameSet<Attr>::EraseSet(const NameSet& rOtherSet) { 01059 FD_DC("TaNameSet(" << this << ")::EraseSet(" << rOtherSet.ToString() << ")"); 01060 #ifdef FAUDES_CHECKED 01061 if(rOtherSet.mpSymbolTable!=mpSymbolTable) { 01062 std::stringstream errstr; 01063 errstr << "symboltable mismach aka not implemented" << std::endl; 01064 throw Exception("TaNameSet::EraseSet", errstr.str(), 67); 01065 } 01066 #endif 01067 TaBaseSet<Idx,Attr>::EraseSet(rOtherSet); 01068 } 01069 01070 // EraseSet(set) 01071 template<class Attr> 01072 void TaNameSet<Attr>::EraseSet(const TaNameSet& rOtherSet) { 01073 FD_DC("TaNameSet(" << this << ")::EraseSet(" << rOtherSet.ToString() << ")"); 01074 #ifdef FAUDES_CHECKED 01075 if(rOtherSet.mpSymbolTable!=mpSymbolTable) { 01076 std::stringstream errstr; 01077 errstr << "symboltable mismatch aka not implemented" << std::endl; 01078 throw Exception("TaNameSet::EraseSet", errstr.str(), 67); 01079 } 01080 #endif 01081 TaBaseSet<Idx,Attr>::EraseSet(rOtherSet); 01082 } 01083 01084 // RestrictSet(set) 01085 template<class Attr> 01086 void TaNameSet<Attr>::RestrictSet(const NameSet& rOtherSet) { 01087 FD_DC("TaNameSet(" << this << ")::RestrictSet(" << rOtherSet.ToString() << ")"); 01088 #ifdef FAUDES_CHECKED 01089 if(rOtherSet.mpSymbolTable!=mpSymbolTable) { 01090 std::stringstream errstr; 01091 errstr << "symboltable mismach aka not implemented" << std::endl; 01092 throw Exception("TaNameSet::RestrictSet", errstr.str(), 67); 01093 } 01094 #endif 01095 TaBaseSet<Idx,Attr>::RestrictSet(rOtherSet); 01096 } 01097 01098 // RestrictSet(set) 01099 template<class Attr> 01100 void TaNameSet<Attr>::RestrictSet(const TaNameSet& rOtherSet) { 01101 FD_DC("TaNameSet(" << this << ")::RestrictSet(" << rOtherSet.ToString() << ")"); 01102 #ifdef FAUDES_CHECKED 01103 if(rOtherSet.mpSymbolTable!=mpSymbolTable) { 01104 std::stringstream errstr; 01105 errstr << "symboltable mismatch aka not implemented" << std::endl; 01106 throw Exception("TaNameSet::RestrictSet", errstr.str(), 67); 01107 } 01108 #endif 01109 TaBaseSet<Idx,Attr>::RestrictSet(rOtherSet); 01110 } 01111 01112 // Attributes(set) 01113 template<class Attr> 01114 void TaNameSet<Attr>::Attributes(const TaNameSet& rOtherSet) { 01115 FD_DC("TaNameSet(" << this << ")::Attributes(set) with type " << typeid(rOtherSet.Attribute()).name()); 01116 #ifdef FAUDES_CHECKED 01117 if(rOtherSet.mpSymbolTable!=mpSymbolTable) { 01118 std::stringstream errstr; 01119 errstr << "symboltable mismatch aka not implemented" << std::endl; 01120 throw Exception("TaNameSet::Attributes", errstr.str(), 67); 01121 } 01122 #endif 01123 TaBaseSet<Idx,Attr>::Attributes(rOtherSet); 01124 } 01125 01126 // Attributes(set) 01127 template<class Attr> 01128 void TaNameSet<Attr>::Attributes(const NameSet& rOtherSet) { 01129 FD_DC("TaNameSet(" << this << ")::Attributes(set) with type " << typeid(rOtherSet.Attribute()).name()); 01130 #ifdef FAUDES_CHECKED 01131 if(rOtherSet.mpSymbolTable!=mpSymbolTable) { 01132 std::stringstream errstr; 01133 errstr << "symboltable mismatch aka not implemented" << std::endl; 01134 throw Exception("TaNameSet::Attributes", errstr.str(), 67); 01135 } 01136 #endif 01137 TaBaseSet<Idx,Attr>::Attributes(rOtherSet); 01138 } 01139 01140 01141 // Str() 01142 template<class Attr> 01143 std::string TaNameSet<Attr>::Str(const Idx& rIndex) const { 01144 return NameSet::Str(rIndex); 01145 } 01146 01147 01148 01149 } // namespace faudes 01150 01151 #endif 01152 libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen |