00001
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "nameset.h"
00024
00025 namespace faudes {
00026
00027
00028 NameSet::NameSet(void) {
00029 mpSymbolTable = SymbolTable::GlobalEventSymbolTablep();
00030 IndexSet::Name("NameSet");
00031 FD_DC("NameSet("<<this<<")::NameSet() with symtab "<< mpSymbolTable);
00032 }
00033
00034
00035 NameSet::NameSet(const NameSet& rOtherSet) {
00036 FD_DC("NameSet(" << this << ")::NameSet(rOtherSet " << &rOtherSet << ")");
00037 Assign(rOtherSet);
00038 mpSymbolTable = rOtherSet.mpSymbolTable;
00039 }
00040
00041
00042
00043 NameSet::NameSet(const std::string& rFilename, const std::string& rLabel) {
00044 FD_DC("NameSet(" << this << ")::NameSet(" << rFilename << ")");
00045 mpSymbolTable = SymbolTable::GlobalEventSymbolTablep();
00046 Read(rFilename, rLabel);
00047 }
00048
00049
00050 NameSet* NameSet::NewP(void) const {
00051 NameSet* res = new NameSet();
00052 res->mpSymbolTable=mpSymbolTable;
00053 return res;
00054 }
00055
00056
00057 NameSet NameSet::NewN(void) const {
00058 NameSet res;
00059 res.mpSymbolTable=mpSymbolTable;
00060 return res;
00061 }
00062
00063
00064 SymbolTable* NameSet::SymbolTablep(void) const {
00065 return mpSymbolTable;
00066 }
00067
00068
00069 void NameSet::SymbolTablep(SymbolTable* pSymTab) {
00070 FD_DC("NameSet(" << this << ")::SymbolTablep(" << pSymTab << ")");
00071 if(!Empty()) {
00072 Clear();
00073 }
00074 mpSymbolTable=pSymTab;
00075 }
00076
00077
00078 void NameSet::DoWrite(TokenWriter& tw, const std::string& rLabel, const Type* pContext) const {
00079 TaNameSet<AttributeVoid> vcopy= *this;
00080 vcopy.Write(tw,rLabel,pContext);
00081 }
00082
00083
00084 void NameSet::DoDWrite(TokenWriter& tw, const std::string& rLabel, const Type* pContext) const {
00085 TaNameSet<AttributeVoid> vcopy= *this;
00086 vcopy.DWrite(tw,rLabel,pContext);
00087 }
00088
00089
00090 void NameSet::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
00091 FD_DC("NameSet(" << this << ")::DoRead(tr," << rLabel << ", " << pContext <<
00092 ") with symtab " << mpSymbolTable);
00093 TaNameSet<AttributeVoid> vcopy;
00094 vcopy.SymbolTablep(mpSymbolTable);
00095 vcopy.DoRead(rTr,rLabel,pContext);
00096 *this=vcopy;
00097 }
00098
00099
00100
00101 bool NameSet::Insert(Idx index) {
00102 #ifdef FAUDES_CHECKED
00103 if(!mpSymbolTable->Exists(index)) {
00104 std::stringstream errstr;
00105 errstr << "index " << index << " not known to symboltable" << std::endl;
00106 throw Exception("NameSet::Insert", errstr.str(), 65);
00107 }
00108 #endif
00109 return IndexSet::Insert(index);
00110 }
00111
00112
00113 Idx NameSet::Insert(const std::string& rName) {
00114 FD_DC("NameSet(" << this << ")::Insert(" << rName <<")");
00115 Idx index = mpSymbolTable->InsEntry(rName);
00116 IndexSet::Insert(index);
00117 return index;
00118 }
00119
00120
00121 void NameSet::InsertSet(const NameSet& rOtherSet) {
00122 FD_DC("NameSet(" << this << ")::InsertSet(" << rOtherSet.ToString() << ")");
00123 #ifdef FAUDES_CHECKED
00124 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
00125 std::stringstream errstr;
00126 errstr << "symboltable mismatch aka not implemented" << std::endl;
00127 throw Exception("NameSet::InsertSet", errstr.str(), 67);
00128 }
00129 #endif
00130 IndexSet::InsertSet(rOtherSet);
00131 }
00132
00133
00134 bool NameSet::Erase(Idx index) {
00135 FD_DC("NameSet(" << this << ")::Erase(" << index <<")");
00136 return IndexSet::Erase(index);
00137 }
00138
00139
00140 bool NameSet::Erase(const std::string& rName) {
00141 FD_DC("NameSet(" << this << ")::Erase(" << rName <<")");
00142 Idx index = mpSymbolTable->Index(rName);
00143 #ifdef FAUDES_CHECKED
00144 if (index == 0) {
00145 std::stringstream errstr;
00146 errstr << "name \"" << rName << "\" not found in NameSet" << std::endl;
00147 throw Exception("NameSet::Erase", errstr.str(), 66);
00148 }
00149 #endif
00150 return IndexSet::Erase(index);
00151 }
00152
00153
00154 NameSet::Iterator NameSet::Erase(const Iterator& pos) {
00155 return IndexSet::Erase(pos);
00156 }
00157
00158
00159 void NameSet::EraseSet(const NameSet& rOtherSet) {
00160 #ifdef FAUDES_CHECKED
00161 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
00162 std::stringstream errstr;
00163 errstr << "symboltable mismatch aka not implemented" << std::endl;
00164 throw Exception("NameSet::EraseSet", errstr.str(), 67);
00165 }
00166 #endif
00167 IndexSet::EraseSet(rOtherSet);
00168 }
00169
00170
00171 std::string NameSet::SymbolicName(Idx index) const {
00172 return mpSymbolTable->Symbol(index);
00173 }
00174
00175
00176 void NameSet::SymbolicName(Idx index, const std::string& rName) {
00177 FD_DC("NameSet(" << this << ")::SymbolicName(" << index << ", " << rName <<")");
00178 #ifdef FAUDES_CHECKED
00179 if (! Exists(index)) {
00180 std::stringstream errstr;
00181 errstr << "index " << index << " not in this set" << std::endl;
00182 throw Exception("NameSet::SymbolicName", errstr.str(), 60);
00183 }
00184 #endif
00185 mpSymbolTable->SetEntry(index, rName);
00186 }
00187
00188
00189 void NameSet::SymbolicName(const std::string& rName,
00190 const std::string& rNewName) {
00191 FD_DC("NameSet(" << this << ")::SymbolicName(" << rName << ", "
00192 << rNewName <<")");
00193 #ifdef FAUDES_CHECKED
00194 if (! Exists(rName)) {
00195 std::stringstream errstr;
00196 errstr << "name \"" << rName << "\" not found in NameSet" << std::endl;
00197 throw Exception("NameSet::Symbolic", errstr.str(), 66);
00198 }
00199 #endif
00200 mpSymbolTable->SetEntry(Index(rName), rNewName);
00201 }
00202
00203
00204 Idx NameSet::Index(const std::string& rName) const {
00205 return mpSymbolTable->Index(rName);
00206 }
00207
00208
00209 bool NameSet::Exists(Idx index) const {
00210 return IndexSet::Exists(index);
00211 }
00212
00213
00214 bool NameSet::Exists(const std::string& rName) const {
00215 return IndexSet::Exists(mpSymbolTable->Index(rName)) ;
00216 }
00217
00218
00219 NameSet::Iterator NameSet::Find(Idx index) const {
00220 return IndexSet::Find(index);
00221 }
00222
00223
00224 NameSet::Iterator NameSet::Find(const std::string& rName) const {
00225 return IndexSet::Find(mpSymbolTable->Index(rName));
00226 }
00227
00228
00229
00230 NameSet NameSet::operator + (const NameSet& rOtherSet) const {
00231 FD_DC("NameSet(" << this << ")::operator + (" << &rOtherSet << ")");
00232 #ifdef FAUDES_CHECKED
00233 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
00234 std::stringstream errstr;
00235 errstr << "symboltable mismazch aka not implemented" << std::endl;
00236 throw Exception("NameSet::Operator+", errstr.str(), 67);
00237 }
00238 #endif
00239 NameSet res= NewN();
00240 res.Assign( IndexSet::operator + (rOtherSet) );
00241 return res;
00242 }
00243
00244
00245 NameSet NameSet::operator - (const NameSet& rOtherSet) const {
00246 FD_DC("NameSet(" << this << ")::operator - (" << &rOtherSet << ")");
00247 #ifdef FAUDES_CHECKED
00248 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
00249 std::stringstream errstr;
00250 errstr << "symboltable mismazch aka not implemented" << std::endl;
00251 throw Exception("NameSet::Operator-", errstr.str(), 67);
00252 }
00253 #endif
00254 NameSet res= NewN();
00255 res.Assign( IndexSet::operator - (rOtherSet) );
00256 return res;
00257 }
00258
00259
00260 NameSet NameSet::operator * (const NameSet& rOtherSet) const {
00261 FD_DC("NameSet(" << this << ")::operator * (" << &rOtherSet << ")");
00262 #ifdef FAUDES_CHECKED
00263 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
00264 std::stringstream errstr;
00265 errstr << "symboltable mismazch aka not implemented" << std::endl;
00266 throw Exception("NameSet::Operator*", errstr.str(), 67);
00267 }
00268 #endif
00269 NameSet res= NewN();
00270 res.Assign( IndexSet::operator * (rOtherSet) );
00271 return res;
00272 }
00273
00274
00275
00276 bool NameSet::operator == (const NameSet& rOtherSet) const {
00277 #ifdef FAUDES_CHECKED
00278 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
00279 std::stringstream errstr;
00280 errstr << "symboltable mismazch aka not implemented" << std::endl;
00281 throw Exception("NameSet::Operator==", errstr.str(), 67);
00282 }
00283 #endif
00284 return IndexSet::operator == (rOtherSet);
00285 }
00286
00287
00288 bool NameSet::operator != (const NameSet& rOtherSet) const {
00289 #ifdef FAUDES_CHECKED
00290 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
00291 std::stringstream errstr;
00292 errstr << "symboltable mismazch aka not implemented" << std::endl;
00293 throw Exception("NameSet::Operator!=", errstr.str(), 67);
00294 }
00295 #endif
00296 return IndexSet::operator != (rOtherSet);
00297 }
00298
00299
00300 bool NameSet::operator <= (const NameSet& rOtherSet) const {
00301 #ifdef FAUDES_CHECKED
00302 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
00303 std::stringstream errstr;
00304 errstr << "symboltable mismazch aka not implemented" << std::endl;
00305 throw Exception("NameSet::Operator<=", errstr.str(), 67);
00306 }
00307 #endif
00308 return IndexSet::operator <= (rOtherSet);
00309 }
00310
00311
00312 bool NameSet::operator >= (const NameSet& rOtherSet) const {
00313 #ifdef FAUDES_CHECKED
00314 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
00315 std::stringstream errstr;
00316 errstr << "symboltable mismazch aka not implemented" << std::endl;
00317 throw Exception("NameSet::Operator>=", errstr.str(), 67);
00318 }
00319 #endif
00320 return IndexSet::operator >= (rOtherSet);
00321 }
00322
00323
00324 std::string NameSet::Str(Idx index) const {
00325 return mpSymbolTable->Symbol(index)+"["+faudes::ToStringInteger(index)+"]";
00326 }
00327
00328
00329
00330 }
00331
00332