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 {
00079 TaNameSet<AttributeVoid> vcopy= *this;
00080 vcopy.Write(tw,rLabel);
00081 }
00082
00083
00084 void NameSet::DoDWrite(TokenWriter& tw) const {
00085 TaNameSet<AttributeVoid> vcopy= *this;
00086 vcopy.DWrite(tw);
00087 }
00088
00089
00090 void NameSet::DoRead(TokenReader& rTr, const std::string& rLabel) {
00091 FD_DC("NameSet(" << this << ")::DoRead(tr," << rLabel << ") with symtab " << mpSymbolTable);
00092 TaNameSet<AttributeVoid> vcopy;
00093 vcopy.SymbolTablep(mpSymbolTable);
00094 vcopy.Read(rTr,rLabel);
00095 *this=vcopy;
00096 }
00097
00098
00099
00100 bool NameSet::Insert(Idx index) {
00101 #ifdef FAUDES_CHECKED
00102 if(!mpSymbolTable->Exists(index)) {
00103 std::stringstream errstr;
00104 errstr << "index " << index << " not known to symboltable" << std::endl;
00105 throw Exception("NameSet::Insert", errstr.str(), 65);
00106 }
00107 #endif
00108 return IndexSet::Insert(index);
00109 }
00110
00111
00112 Idx NameSet::Insert(const std::string& rName) {
00113 FD_DC("NameSet(" << this << ")::Insert(" << rName <<")");
00114 Idx index = mpSymbolTable->InsEntry(rName);
00115 IndexSet::Insert(index);
00116 return index;
00117 }
00118
00119
00120 void NameSet::InsertSet(const NameSet& rOtherSet) {
00121 FD_DC("NameSet(" << this << ")::InsertSet(" << rOtherSet.ToString() << ")");
00122 #ifdef FAUDES_CHECKED
00123 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
00124 std::stringstream errstr;
00125 errstr << "symboltable mismatch aka not implemented" << std::endl;
00126 throw Exception("NameSet::InsertSet", errstr.str(), 67);
00127 }
00128 #endif
00129 IndexSet::InsertSet(rOtherSet);
00130 }
00131
00132
00133 bool NameSet::Erase(Idx index) {
00134 FD_DC("NameSet(" << this << ")::Erase(" << index <<")");
00135 return IndexSet::Erase(index);
00136 }
00137
00138
00139 bool NameSet::Erase(const std::string& rName) {
00140 FD_DC("NameSet(" << this << ")::Erase(" << rName <<")");
00141 Idx index = mpSymbolTable->Index(rName);
00142 #ifdef FAUDES_CHECKED
00143 if (index == 0) {
00144 std::stringstream errstr;
00145 errstr << "name \"" << rName << "\" not found in NameSet" << std::endl;
00146 throw Exception("NameSet::Erase", errstr.str(), 66);
00147 }
00148 #endif
00149 return IndexSet::Erase(index);
00150 }
00151
00152
00153 NameSet::Iterator NameSet::Erase(const Iterator& pos) {
00154 return IndexSet::Erase(pos);
00155 }
00156
00157
00158 void NameSet::EraseSet(const NameSet& rOtherSet) {
00159 #ifdef FAUDES_CHECKED
00160 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
00161 std::stringstream errstr;
00162 errstr << "symboltable mismatch aka not implemented" << std::endl;
00163 throw Exception("NameSet::EraseSet", errstr.str(), 67);
00164 }
00165 #endif
00166 IndexSet::EraseSet(rOtherSet);
00167 }
00168
00169
00170 std::string NameSet::SymbolicName(Idx index) const {
00171 return mpSymbolTable->Symbol(index);
00172 }
00173
00174
00175 void NameSet::SymbolicName(Idx index, const std::string& rName) {
00176 FD_DC("NameSet(" << this << ")::SymbolicName(" << index << ", " << rName <<")");
00177 #ifdef FAUDES_CHECKED
00178 if (! Exists(index)) {
00179 std::stringstream errstr;
00180 errstr << "index " << index << " not in this set" << std::endl;
00181 throw Exception("NameSet::SymbolicName", errstr.str(), 60);
00182 }
00183 #endif
00184 mpSymbolTable->SetEntry(index, rName);
00185 }
00186
00187
00188 void NameSet::SymbolicName(const std::string& rName,
00189 const std::string& rNewName) {
00190 FD_DC("NameSet(" << this << ")::SymbolicName(" << rName << ", "
00191 << rNewName <<")");
00192 #ifdef FAUDES_CHECKED
00193 if (! Exists(rName)) {
00194 std::stringstream errstr;
00195 errstr << "name \"" << rName << "\" not found in NameSet" << std::endl;
00196 throw Exception("NameSet::Symbolic", errstr.str(), 66);
00197 }
00198 #endif
00199 mpSymbolTable->SetEntry(Index(rName), rNewName);
00200 }
00201
00202
00203 Idx NameSet::Index(const std::string& rName) const {
00204 return mpSymbolTable->Index(rName);
00205 }
00206
00207
00208 bool NameSet::Exists(Idx index) const {
00209 return IndexSet::Exists(index);
00210 }
00211
00212
00213 bool NameSet::Exists(const std::string& rName) const {
00214 return IndexSet::Exists(mpSymbolTable->Index(rName)) ;
00215 }
00216
00217
00218 NameSet::Iterator NameSet::Find(Idx index) const {
00219 return IndexSet::Find(index);
00220 }
00221
00222
00223 NameSet::Iterator NameSet::Find(const std::string& rName) const {
00224 return IndexSet::Find(mpSymbolTable->Index(rName));
00225 }
00226
00227
00228
00229 NameSet NameSet::operator + (const NameSet& rOtherSet) const {
00230 FD_DC("NameSet(" << this << ")::operator + (" << &rOtherSet << ")");
00231 #ifdef FAUDES_CHECKED
00232 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
00233 std::stringstream errstr;
00234 errstr << "symboltable mismazch aka not implemented" << std::endl;
00235 throw Exception("NameSet::Operator+", errstr.str(), 67);
00236 }
00237 #endif
00238 NameSet res= NewN();
00239 res.Assign( IndexSet::operator + (rOtherSet) );
00240 return res;
00241 }
00242
00243
00244 NameSet NameSet::operator - (const NameSet& rOtherSet) const {
00245 FD_DC("NameSet(" << this << ")::operator - (" << &rOtherSet << ")");
00246 #ifdef FAUDES_CHECKED
00247 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
00248 std::stringstream errstr;
00249 errstr << "symboltable mismazch aka not implemented" << std::endl;
00250 throw Exception("NameSet::Operator-", errstr.str(), 67);
00251 }
00252 #endif
00253 NameSet res= NewN();
00254 res.Assign( IndexSet::operator - (rOtherSet) );
00255 return res;
00256 }
00257
00258
00259 NameSet NameSet::operator * (const NameSet& rOtherSet) const {
00260 FD_DC("NameSet(" << this << ")::operator * (" << &rOtherSet << ")");
00261 #ifdef FAUDES_CHECKED
00262 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
00263 std::stringstream errstr;
00264 errstr << "symboltable mismazch aka not implemented" << std::endl;
00265 throw Exception("NameSet::Operator*", errstr.str(), 67);
00266 }
00267 #endif
00268 NameSet res= NewN();
00269 res.Assign( IndexSet::operator * (rOtherSet) );
00270 return res;
00271 }
00272
00273
00274
00275 bool NameSet::operator == (const NameSet& rOtherSet) const {
00276 #ifdef FAUDES_CHECKED
00277 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
00278 std::stringstream errstr;
00279 errstr << "symboltable mismazch aka not implemented" << std::endl;
00280 throw Exception("NameSet::Operator==", errstr.str(), 67);
00281 }
00282 #endif
00283 return IndexSet::operator == (rOtherSet);
00284 }
00285
00286
00287 bool NameSet::operator != (const NameSet& rOtherSet) const {
00288 #ifdef FAUDES_CHECKED
00289 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
00290 std::stringstream errstr;
00291 errstr << "symboltable mismazch aka not implemented" << std::endl;
00292 throw Exception("NameSet::Operator!=", errstr.str(), 67);
00293 }
00294 #endif
00295 return IndexSet::operator != (rOtherSet);
00296 }
00297
00298
00299 bool NameSet::operator <= (const NameSet& rOtherSet) const {
00300 #ifdef FAUDES_CHECKED
00301 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
00302 std::stringstream errstr;
00303 errstr << "symboltable mismazch aka not implemented" << std::endl;
00304 throw Exception("NameSet::Operator<=", errstr.str(), 67);
00305 }
00306 #endif
00307 return IndexSet::operator <= (rOtherSet);
00308 }
00309
00310
00311 bool NameSet::operator >= (const NameSet& rOtherSet) const {
00312 #ifdef FAUDES_CHECKED
00313 if(rOtherSet.mpSymbolTable!=mpSymbolTable) {
00314 std::stringstream errstr;
00315 errstr << "symboltable mismazch aka not implemented" << std::endl;
00316 throw Exception("NameSet::Operator>=", errstr.str(), 67);
00317 }
00318 #endif
00319 return IndexSet::operator >= (rOtherSet);
00320 }
00321
00322
00323 std::string NameSet::Str(Idx index) const {
00324 return mpSymbolTable->Symbol(index)+"["+faudes::ToStringInteger(index)+"]";
00325 }
00326
00327
00328
00329 }
00330
00331