libFAUDES
Sections
Index
|
cfl_symboltable.hGo to the documentation of this file.00001 /** @file cfl_symboltable.h @brief Class SymbolTable */ 00002 00003 /* FAU Discrete Event Systems Library (libfaudes) 00004 00005 Copyright (C) 2006 Bernd Opitz 00006 Copywrite (C) 2007 Thomas Moor 00007 Exclusive copyright is granted to Klaus Schmidt 00008 00009 This library is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU Lesser General Public 00011 License as published by the Free Software Foundation; either 00012 version 2.1 of the License, or (at your option) any later version. 00013 00014 This library is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public 00020 License along with this library; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 00022 00023 00024 #ifndef FAUDES_SYMBOLTABLE_H 00025 #define FAUDES_SYMBOLTABLE_H 00026 00027 #include "cfl_definitions.h" 00028 #include "cfl_types.h" 00029 #include "cfl_exception.h" 00030 #include "cfl_helper.h" 00031 #include "cfl_indexset.h" 00032 00033 #include <algorithm> 00034 #include <map> 00035 #include <set> 00036 #include <limits> 00037 #include <iostream> 00038 #include <sstream> 00039 00040 00041 00042 namespace faudes { 00043 00044 // forward 00045 class IndexSet; 00046 00047 /** 00048 * A SymbolTable associates sybolic names with indices. 00049 * 00050 * Symbolic names are restricted to printable ascii, no quoatation ("), 00051 * and no blanks. Indices are of type faudes Idx aka (long unsigned) 00052 * integer and must be positive. Both, indices and symbolic names must 00053 * be unique within each SymbolTable. Consistency checks on input data 00054 * are preformed, regardless of the FAUDES_CHECKED compiletime option. 00055 * 00056 * Generators refer to a global symboltable for event names and hold a local 00057 * symboltable for state names. 00058 * 00059 * 00060 */ 00061 class SymbolTable : public Type { 00062 public: 00063 00064 /** Creates a new SymbolTable */ 00065 SymbolTable(void); 00066 00067 /** Copy constructor */ 00068 SymbolTable(const SymbolTable& rSrc); 00069 00070 /** Return name of SymbolTable */ 00071 const std::string& Name(void) const; 00072 00073 /** Set name of SymbolTable */ 00074 void Name(const std::string& rName); 00075 00076 /** Size of symboltabel */ 00077 Idx Size(void) const; 00078 00079 /** Clear all entries */ 00080 void Clear(void); 00081 00082 00083 /** Get maximum index which this SymbolTable accepts */ 00084 Idx MaxIndex(void) const; 00085 00086 /** 00087 * Set maximum index which this SymbolTable accapts 00088 * 00089 * @param index 00090 * New maximum index 00091 * @exception Exception 00092 * - symboltable overflow (id 40) 00093 */ 00094 void MaxIndex(Idx index); 00095 00096 /** Get the largest index in use */ 00097 Idx LastIndex(void) const; 00098 00099 /** 00100 * Symbolic name lookup 00101 * 00102 * @param index 00103 * Index to lookup 00104 * @return 00105 * Symbolic name of index, or empty string "" for non-existent index 00106 */ 00107 std::string Symbol(Idx index) const; 00108 00109 /** 00110 * Index lookup 00111 * 00112 * @param rName 00113 * Symbolic name to lookup 00114 * 00115 * @return 00116 * Index of symbolic name, or 0 for non-existent name 00117 */ 00118 Idx Index(const std::string& rName) const; 00119 00120 /** 00121 * Test existence of index 00122 * 00123 * @param index 00124 * Index to test 00125 * @return 00126 * True, if index exists 00127 */ 00128 bool Exists(Idx index) const; 00129 00130 /** 00131 * Test existence of symbol 00132 * 00133 * @param rName 00134 * Symbolic name to test 00135 * @return 00136 * True, if name exists 00137 */ 00138 bool Exists(const std::string& rName) const; 00139 00140 00141 /** 00142 * Test validiy of candidate symbol. 00143 * The current implementation insists in printable ascii, 00144 * no quotes (") and no blanks. The no-quotes-restriction 00145 * simplifies file io (see tokenreader.h), other restrictions 00146 * are cosmetic. 00147 * 00148 * @param rName 00149 * Symbolic name to test 00150 * @return 00151 * True, if name is a valid symbol 00152 */ 00153 static bool ValidSymbol(const std::string& rName); 00154 00155 /** 00156 * Create unique symbolic name by adding an underscore and extra digits. 00157 * The current implementation tries to be smart and overwrites 00158 * any previously added digits. It is also slow. 00159 * 00160 * @param rName 00161 * Candidate symbolic name 00162 * @return 00163 * Unique symbolic name 00164 */ 00165 std::string UniqueSymbol(const std::string& rName) const; 00166 00167 /** 00168 * Add new entry (aka symbolic name and index) to symboltable, 00169 * 00170 * @param index 00171 * New index 00172 * @param rName 00173 * New symbolic name 00174 * @return 00175 * New index 00176 * @exception Exception 00177 * - name already associated with another index (id 41) 00178 * - index already associated with another name (id 42) 00179 * - invalid name (id 43) 00180 */ 00181 Idx InsEntry(Idx index, const std::string& rName); 00182 00183 00184 /** 00185 * Merge a symbolic name with symboltable. 00186 * If the symbol does not exist, find a new index and add the new entry. 00187 * If the symbol does exist, lookup its index. 00188 * 00189 * @param rName 00190 * Symbolic name to merge 00191 * @return 00192 * Index of rName 00193 * @exception Exception 00194 * - invalid name (id 43) 00195 */ 00196 Idx InsEntry(const std::string& rName); 00197 00198 00199 /** 00200 * Set symbolic name for existing entry. 00201 * If the name is the emptystring, an existing entry is cleared. 00202 * All other invalid names throw an exception. 00203 * 00204 * @param index 00205 * Index to specify entry 00206 * @param rName 00207 * New esymbolic name for index 00208 * 00209 * @exception Exception 00210 * - name already associated with another index (id 41) 00211 * - invalid name (id 43) 00212 */ 00213 void SetEntry(Idx index, const std::string& rName); 00214 00215 /** 00216 * Set default names ("1", "2", "3", ...) for index. 00217 * 00218 * @param index 00219 * Index for which to set the default name 00220 */ 00221 void SetDefaultSymbol(Idx index); 00222 00223 /** 00224 * Delete entry by index 00225 * 00226 * @param index 00227 * Index to delete 00228 * 00229 */ 00230 void ClrEntry(Idx index); 00231 00232 /** 00233 * Delete entry by symbol 00234 * 00235 * @param rName 00236 * Symbolic name to delete 00237 * 00238 */ 00239 void ClrEntry(const std::string& rName); 00240 00241 /** 00242 * Restrict to specified indicees. 00243 * 00244 * @param rDomain 00245 * Indicees to keep. 00246 * 00247 */ 00248 void RestrictDomain(const IndexSet& rDomain); 00249 00250 /** 00251 * Get Static Symboltable ref 00252 */ 00253 static SymbolTable* GlobalEventSymbolTablep(void); 00254 00255 protected: 00256 00257 /** assign my members */ 00258 virtual void DoAssign(const SymbolTable& rSrc); 00259 00260 private: 00261 00262 /** Name of the SymbolTable */ 00263 std::string mMyName; 00264 00265 /** Index lookup map */ 00266 std::map<std::string,Idx> mIndexMap; 00267 00268 /** Name lookup map */ 00269 std::map<Idx,std::string> mNameMap; 00270 00271 /** Upper limit (incl) */ 00272 Idx mMaxIndex; 00273 00274 /** Largest used index + 1 */ 00275 Idx mNextIndex; 00276 00277 /** static event symbol table (should go to faudes::Generator, or faudes) */ 00278 static SymbolTable msEventSymbolTable; 00279 00280 /** Symboltable token io */ 00281 void DoRead(TokenReader& rTr, const std::string& rLabel = "", const Type* pContext=0); 00282 00283 /** Symboltable token io */ 00284 void DoWrite(TokenWriter& rTw, const std::string& rLabel="",const Type* pContext=0) const; 00285 }; 00286 00287 00288 } // namespace faudes 00289 00290 #endif |
libFAUDES 2.20d --- 2011.04.26 --- c++ source docu by doxygen