nameset.cpp

Go to the documentation of this file.
00001 
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 #include "nameset.h"
00024 
00025 namespace faudes {
00026 
00027 // empty constructor
00028 NameSet::NameSet(void) {
00029   mpSymbolTable = SymbolTable::GlobalEventSymbolTablep();
00030   IndexSet::Name("NameSet");
00031   FD_DC("NameSet("<<this<<")::NameSet() with symtab "<< mpSymbolTable); 
00032 }
00033 
00034 // constructor from nameset
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 // read file constructor
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 // NewP()
00050 NameSet* NameSet::NewP(void) const {
00051   NameSet* res = new NameSet();
00052   res->mpSymbolTable=mpSymbolTable;
00053   return res;
00054 }
00055 
00056 // NewN()
00057 NameSet NameSet::NewN(void) const {
00058   NameSet res;
00059   res.mpSymbolTable=mpSymbolTable;
00060   return res;
00061 }
00062 
00063 // SymbolTablep()
00064 SymbolTable* NameSet::SymbolTablep(void) const {
00065   return mpSymbolTable;
00066 }
00067 
00068 // SymbolTablep(pSymTab)
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 // DoWrite(tw, rLabel)
00078 void NameSet::DoWrite(TokenWriter& tw, const std::string& rLabel) const {
00079   TaNameSet<AttributeVoid> vcopy= *this;
00080   vcopy.Write(tw,rLabel);
00081 }
00082 
00083 // DoDWrite()
00084 void NameSet::DoDWrite(TokenWriter& tw) const {
00085   TaNameSet<AttributeVoid> vcopy= *this;
00086   vcopy.DWrite(tw);
00087 }
00088 
00089 // DoRead(rTr, rLabel)
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 // Insert(index)
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 // Insert(rName)
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 // InsertSet(set)
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 // Erase(index)
00133 bool NameSet::Erase(Idx index) {
00134   FD_DC("NameSet(" << this << ")::Erase(" << index <<")");
00135   return IndexSet::Erase(index);
00136 }
00137 
00138 // Erase(rName)
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 // Erase(pos)
00153 NameSet::Iterator NameSet::Erase(const Iterator& pos) {
00154   return IndexSet::Erase(pos);
00155 }
00156 
00157 // EraseSet(set)
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 // SymbolicName(index)
00170 std::string NameSet::SymbolicName(Idx index) const {
00171   return mpSymbolTable->Symbol(index);
00172 }
00173 
00174 // SymbolicName(index, name)
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 // SymbolicName(name, name)
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 // Index(rName)
00203 Idx NameSet::Index(const std::string& rName) const {
00204   return mpSymbolTable->Index(rName);
00205 }
00206 
00207 // Exists(index)
00208 bool NameSet::Exists(Idx index) const {
00209   return IndexSet::Exists(index);
00210 }
00211 
00212 // Exists(rName)
00213 bool NameSet::Exists(const std::string& rName) const {
00214   return IndexSet::Exists(mpSymbolTable->Index(rName)) ;
00215 }
00216 
00217 // Find(index) const
00218 NameSet::Iterator NameSet::Find(Idx index) const {
00219   return IndexSet::Find(index);
00220 }
00221 
00222 // Find(rName) const
00223 NameSet::Iterator NameSet::Find(const std::string& rName) const {
00224   return IndexSet::Find(mpSymbolTable->Index(rName));
00225 }
00226 
00227 
00228 // operator +
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 // operator -
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 // operator *
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 // operator ==
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 // operator !=
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 // operator <=
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 // operator >=
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 // Str(index)
00323 std::string NameSet::Str(Idx index) const {
00324   return mpSymbolTable->Symbol(index)+"["+faudes::ToStringInteger(index)+"]";
00325 }
00326 
00327 
00328 
00329 } // namespace faudes
00330 
00331 

Generated on Fri May 9 11:26:47 2008 for libFAUDES 2.09b by  doxygen 1.4.4