cfl_symbolset.h

Go to the documentation of this file.
00001 /** @file cfl_symbolset.h @brief Class SymbolSet, TaSymbolSet */
00002 
00003 
00004 /* FAU Discrete Event Systems Library (libfaudes)
00005 
00006    Copyright (C) 2006  Bernd Opitz
00007    Copyright (C) 2007  Thomas Moor
00008    Exclusive copyright is granted to Klaus Schmidt
00009 
00010    This library is free software; you can redistribute it and/or
00011    modify it under the terms of the GNU Lesser General Public
00012    License as published by the Free Software Foundation; either
00013    version 2.1 of the License, or (at your option) any later version.
00014 
00015    This library is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018    Lesser General Public License for more details.
00019 
00020    You should have received a copy of the GNU Lesser General Public
00021    License along with this library; if not, write to the Free Software
00022    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
00023 
00024 
00025 
00026 #ifndef FAUDES_SYMBOLSET_H
00027 
00028 #include "cfl_definitions.h"
00029 #include "cfl_attributes.h"
00030 #include "cfl_symboltable.h"
00031 #include "cfl_baseset.h"
00032 #include <set>
00033 #include <map>
00034 #include <algorithm>
00035 
00036 namespace faudes {
00037 
00038 /** @addtogroup ContainerClasses */
00039 /** @{  */
00040 
00041 /**
00042  * Set of symbols. 
00043  * 
00044  * The class is built on top of the faudes version
00045  * TBaseSet of STL sets. It provides the essentials of the STL interface and 
00046  * plus token based file IO.
00047  * Invalid iterators throw an exception (id 62) when used as an argument to a SymbolSet function. 
00048  * If the macro FAUDES_CHECKED is defined, the attempt to insert an invalid symbol
00049  * an exception (id 61). 
00050  *
00051  * Note that a symbol set holds a plain set of valid faudes symbols with no indices
00052  * or symboltable associated. If you are looking for a set of items with 
00053  * mandatory symbolic names you most likely are better of with a NameSet or  a 
00054  * TaNameSet. Currently, there is no attributed version of a SymbolSet.
00055  *
00056  * The token IO format is demonstrated by the following example
00057  * of a set with name "MySymbols" 
00058  * \code
00059  * <MySymbols> 
00060  * "ASymbol"
00061  * "AnotherSymbol" 
00062  * </MySymbols> 
00063  * \endcode
00064  * Note that you can read SymbolSet files to NameSets and vice versa.
00065  *
00066  */
00067 
00068 class SymbolSet : public TBaseSet<std::string> {
00069 
00070 FAUDES_TYPE_DECLARATION(SymbolSet,SymbolSet,TBaseSet<std::string>)
00071 
00072 public:
00073 
00074   /**
00075    * Constructor. 
00076    */
00077   SymbolSet(void);
00078 
00079   /**
00080    * Copy-constructor. 
00081    */
00082   SymbolSet(const TBaseSet<std::string>& rOtherSet);
00083 
00084   /**
00085    * Construct from file. Uses the Read(TokenReader&, const std::string&) function to read.
00086    * a SymbolSet from section rLabel in file rFilename.
00087    *
00088    * @param rFilename
00089    *   Name of file to read
00090    * @param rLabel
00091    *   Section to read
00092    *
00093    * @exception Exception
00094    *   - IO Errors (id 1)
00095    *   - token musmatch (id 50, 51, 52)
00096    */
00097   SymbolSet(const std::string& rFilename, const std::string& rLabel = "SymbolSet");
00098 
00099   /**
00100    * Virtual destructor
00101    */
00102   virtual ~SymbolSet(void) {};
00103 
00104   /**
00105    * Test whether the given string is a valid faudes symbol
00106    * @param symbol
00107    *    Symbol to test
00108    * @return
00109    *    True if valid
00110    */
00111    bool Valid(const std::string& symbol) const;
00112    
00113   /** 
00114    * Iterators on indexset. 
00115    */
00116   typedef TBaseSet<std::string>::Iterator Iterator;
00117 
00118   /** 
00119    * Insert specified symbol
00120    *
00121    * @param symbol
00122    *    Symbol to insert
00123    * @return
00124    *   True if symbol was new to set 
00125    */
00126   bool Insert(const std::string& symbol);
00127 
00128   /**
00129    * Compute an Idx type signature for a Set. This method
00130    * is currently not implemented.
00131    *
00132    * @return
00133    *   Idx type set signature
00134    */
00135   Idx Signature(void) const {return 0;};
00136 
00137   /**
00138    * Return pretty printable symbol. 
00139    *
00140    * @param symbol
00141    *   Symbol to print
00142    *
00143    * @return
00144    *   String
00145    */
00146   std::string Str(const std::string& symbol) const {return symbol; };
00147 
00148  protected:
00149 
00150 
00151 
00152   /**
00153    * Assign my members. This method calls the base class to assign its members.
00154    *
00155    * @param rSource 
00156    *    Source to copy from
00157    * @return
00158    *    Ref to this set
00159    */
00160   virtual void DoAssign(const SymbolSet& rSource);
00161 
00162   /** 
00163    * Write to TokenWriter, see TBaseSet for public wrappers.
00164    *
00165    * @param tw
00166    *   Reference to TokenWriter
00167    * @param rLabel
00168    *   Label of section to write, defaults to name of set
00169    * @param pContext
00170    *   Write context for contextual information
00171    *
00172    * @exception Exception
00173    *   - IO errors (id 2)
00174    */
00175   void DoWrite(TokenWriter& tw, const std::string& rLabel="", const Type* pContext=0) const;
00176 
00177   /**
00178    * Read from TokenReader, see TBaseSet for public wrappers. 
00179    *
00180    * @param rTr
00181    *   Reference to tokenreader
00182    * @param rLabel
00183    *   Section to read
00184    * @param pContext
00185    *   Read context for contextual information
00186    *
00187    * @exception Exception
00188    *   - IO errors (id 1)
00189    *   - token mismatch (id 50, 51, 52)
00190    */
00191   void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0);
00192 
00193 
00194 };
00195 
00196 
00197 /** @} doxygen group */
00198 
00199 
00200 } // namespace faudes
00201 
00202 #define FAUDES_SYMBOLSET_H
00203 #endif 

libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen