vgenerator.cpp

Go to the documentation of this file.
00001 
00003 /* FAU Discrete Event Systems Library (libfaudes)
00004 
00005    Copyright (C) 2006  Bernd Opitz
00006    Copyright (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 FITNES 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 #include "vgenerator.h"
00025 
00026 
00027 namespace faudes {
00028 
00029 // msObjectCount (static) 
00030 Idx vGenerator::msObjectCount = 0;
00031 
00032 // constructor
00033 vGenerator::vGenerator(void) : 
00034     // my name
00035     mMyName("Generator"),
00036     // std symboltables
00037     mpStateSymbolTable(&mStateSymbolTable),
00038     mpEventSymbolTable(GlobalEventSymbolTablep()),
00039     // other members
00040     mStateNamesEnabled(true)  
00041 {
00042   FD_DG("vGenerator(" << this << ")::vGenerator()");
00043   // track generator objects
00044   msObjectCount++; 
00045   mId = msObjectCount;
00046 }
00047 
00048 // copy constructor
00049 vGenerator::vGenerator(const vGenerator& rOtherGen) :
00050     // copy name
00051     mMyName(rOtherGen.mMyName),
00052     // copy symboltables
00053     mStateSymbolTable(rOtherGen.mStateSymbolTable),
00054     mpStateSymbolTable(&mStateSymbolTable),
00055     mpEventSymbolTable(rOtherGen.mpEventSymbolTable),
00056     // other members
00057     mStateNamesEnabled(rOtherGen.mStateNamesEnabled)  
00058 {
00059   FD_DG("vGenerator(" << this << ")::vGenerator(" << &rOtherGen << ")");
00060   // track generator objects
00061   msObjectCount++; 
00062   mId = msObjectCount;
00063 }
00064 
00065 
00066 // Id()
00067 Idx vGenerator::Id(void) const {
00068   return mId;
00069 }
00070 
00071 // Name(rName)
00072 void vGenerator::Name(const std::string& rName) {
00073   FD_DV("vGenerator(" << this << ")::Name(\"" << rName << "\")");
00074   mMyName = rName;
00075 }
00076 
00077 // Name()
00078 std::string vGenerator::Name(void) const {
00079   return mMyName;
00080 }
00081 
00082 // EventSymbolTablep() const
00083 SymbolTable* vGenerator::EventSymbolTablep(void) const {
00084   return mpEventSymbolTable;
00085 }
00086 
00087 // GlobalEventSymbolTablep() const
00088 SymbolTable* vGenerator::GlobalEventSymbolTablep(void) {
00089   return SymbolTable::GlobalEventSymbolTablep();
00090 }
00091 
00092 // EventSymbolTablep(pSymTab) 
00093 void vGenerator::EventSymbolTablep(SymbolTable* pSymTab) {
00094   mpEventSymbolTable=pSymTab;
00095 }
00096 
00097 // EventSymbolTablep(rOtherGen) 
00098 void vGenerator::EventSymbolTablep(const vGenerator& rOtherGen) {
00099   EventSymbolTablep(rOtherGen.EventSymbolTablep());
00100 }
00101 
00102 // EventIndex(rName)
00103 Idx vGenerator::EventIndex(const std::string& rName) const {
00104   return mpEventSymbolTable->Index(rName);
00105 }
00106 
00107 // EventName(index)
00108 std::string vGenerator::EventName(Idx index) const {
00109   return mpEventSymbolTable->Symbol(index);
00110 }
00111 
00112 // EventName(index, name)
00113 void vGenerator::EventName(Idx index, const std::string& rName) {
00114   FD_DG("vGenerator(" << this << ")::EventName(" 
00115       << index << ",\"" << rName << "\")");
00116 #ifdef FAUDES_CHECKED
00117   if (! ExistsEvent(index)) {
00118     std::stringstream errstr;
00119     errstr << "event \"" << index << "\" not found in generator \""
00120      << Name() << "\"";
00121     throw Exception("vGenerator::EventName(name)", errstr.str(), 89);
00122   }
00123 #endif
00124   mpEventSymbolTable->SetEntry(index, rName);
00125 }
00126 
00127 // UniqueEventName(rName)
00128 std::string vGenerator::UniqueEventName(const std::string& rName) const {
00129   std::string name=rName;
00130   if(name=="") name="ev";
00131   return mpEventSymbolTable->UniqueSymbol(name) ;
00132 }
00133 
00134 // NewEventSet()
00135 EventSet vGenerator::NewEventSet(void) const {
00136   EventSet res;
00137   res.SymbolTablep(mpEventSymbolTable);
00138   return res;
00139 }
00140 
00141 // NewEventSetp()
00142 EventSet* vGenerator::NewEventSetp(void) const {
00143   EventSet* res = new EventSet();
00144   res->SymbolTablep(mpEventSymbolTable);
00145   return res;
00146 }
00147 
00148 
00149 // StateSymbolTable() const
00150 const SymbolTable& vGenerator::StateSymbolTable(void) const {
00151   return mStateSymbolTable;
00152 }
00153 
00154 // StateSymbolTable(rSymTab) 
00155 void vGenerator::StateSymbolTable(const SymbolTable& rSymTab) {
00156   mStateSymbolTable=rSymTab;
00157   mpStateSymbolTable=&mStateSymbolTable;
00158 }
00159 
00160 // StateIndex(rName)
00161 Idx vGenerator::StateIndex(const std::string& rName) const {
00162    return mpStateSymbolTable->Index(rName);
00163 }
00164 
00165 // StateName(index)
00166 std::string vGenerator::StateName(Idx index) const {
00167   return mpStateSymbolTable->Symbol(index);
00168 }
00169 
00170 // StateName(index, name)
00171 void vGenerator::StateName(Idx index, const std::string& rName) {
00172   FD_DG("vGenerator(" << this << ")::StateName(" 
00173       << index << ",\"" << rName << "\")");
00174 #ifdef FAUDES_CHECKED
00175   if (! ExistsState(index)) {
00176     std::stringstream errstr;
00177     errstr << "state name \"" << rName << "\" not found in generator \""
00178      << Name() << "\"";
00179     throw Exception("vGenerator::StateName(name)", errstr.str(), 90);
00180   }
00181 #endif
00182   mpStateSymbolTable->SetEntry(index, rName);
00183 }
00184 
00185 
00186 // ClearStateNames()
00187 void vGenerator::ClearStateNames(void) {
00188   FD_DG("vGenerator(" << this << ")::ClearStateNames()");
00189   mpStateSymbolTable->Clear();
00190   mStateNamesEnabled = false;
00191 }
00192 
00193 
00194 // ClrStateName(index)
00195 void vGenerator::ClrStateName(Idx index) {
00196   FD_DG("Generator(" << this << ")::ClrStateName(\"" << index << "\")");
00197 #ifdef FAUDES_CHECKED
00198   if (! ExistsState(index)) {
00199     std::stringstream errstr;
00200     errstr << "state \"" << index << "\" not found in generator \""
00201      << Name() << "\"";
00202     throw Exception("vGenerator::ClrStateName(name)", errstr.str(), 90);
00203   }
00204 #endif
00205   mpStateSymbolTable->ClrEntry(index);
00206 }
00207 
00208 // ClrStateName(rName)
00209 void vGenerator::ClrStateName(const std::string& rName) {
00210   FD_DG("vGenerator(" << this << ")::ClrStateName(\"" << rName << "\")");
00211   Idx index = StateIndex(rName);
00212   ClrStateName(index);
00213 }
00214 
00215 
00216 // StateNamesEnabled()
00217 bool vGenerator::StateNamesEnabled(void) const {
00218   return mStateNamesEnabled;
00219 }
00220 
00221 // StateNamesEnabled(flag)
00222 void vGenerator::StateNamesEnabled(bool flag) {
00223   mStateNamesEnabled = flag;
00224 }
00225 
00226 // SetDefaultStateNames()
00227 void vGenerator::SetDefaultStateNames(void) {
00228   FD_DG("vGenerator(" << this << ")::SetDefaultStateNames()");
00229   StateSet::Iterator it;
00230   for (it = StatesBegin(); it != StatesEnd(); ++it) {
00231     mpStateSymbolTable->SetDefaultSymbol(*it);
00232   }
00233 }
00234 
00235 // EnforceStateNames(rTemplate)
00236 void vGenerator::EnforceStateNames(const std::string& rTemplate) {
00237   FD_DG("vGenerator(" << this << ")::EnforceStateNames(temp)");
00238   StateSet::Iterator it;
00239   for (it = StatesBegin(); it != StatesEnd(); ++it) {
00240     if(StateName(*it)=="") {
00241       std::string name=UniqueStateName(rTemplate + "_1");
00242       StateName(*it,name);
00243     }
00244   }
00245 }
00246 
00247 // UniqueStateName(rName)
00248 std::string vGenerator::UniqueStateName(const std::string& rName) const {
00249   std::string name=rName;
00250   if(name=="") name="st";
00251   return mpStateSymbolTable->UniqueSymbol(name) ;
00252 }
00253 
00254 // EStr(index)
00255 std::string vGenerator::EStr(Idx index) const {
00256   return EventName(index);
00257 }
00258 
00259 // SStr(index)
00260 std::string vGenerator::SStr(Idx index) const {
00261   std::string name = StateName(index);
00262   if(name == "") name=ToStringInteger(index);
00263   return name+"["+faudes::ToStringInteger(index)+"]";
00264 }
00265 
00266 // TStr(index)
00267 std::string vGenerator::TStr(const Transition& trans) const {
00268   return SStr(trans.X1) + "--(" + EStr(trans.Ev) + ")-->" + SStr(trans.X2);
00269 }
00270 
00271 
00272 
00273 // GraphWrite(rFileName,rOutFormat)
00274 void vGenerator::GraphWrite(const std::string& rFileName, const std::string& rOutFormat,
00275    const std::string& rDotExec) {
00276   FD_DG("vGenerator::GraohWrite(...)");
00277   // generate temp dot ibput file
00278   std::string dotin = CreateTempFile();
00279   if(dotin == "") {
00280     std::stringstream errstr;
00281     errstr << "Exception opening temp file";
00282     throw Exception("vGenerator::GraphWrite", errstr.str(), 2);
00283   }
00284   try{
00285     DotWrite(dotin);
00286   } 
00287   catch (faudes::Exception& exception) {  
00288     RemoveFile(dotin);
00289     std::stringstream errstr;
00290     errstr << "Exception writing dot input file";
00291     throw Exception("vGenerator::GraphWrite", errstr.str(), 2);
00292   }
00293   try{
00294     faudes::ProcessDot(dotin,rFileName,rOutFormat,rDotExec);
00295   } 
00296   catch (faudes::Exception& exception) {  
00297     RemoveFile(dotin);
00298     std::stringstream errstr;
00299     errstr << "Exception processing dot file";
00300     throw Exception("vGenerator::GraphWrite", errstr.str(), 3);
00301   }
00302   RemoveFile(dotin);
00303 }
00304 
00305 
00306 } // name space
00307 
00308 

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