pd_merge.cpp

Go to the documentation of this file.
00001 /** @file pd_merge.cpp  Attributes for pushdown automata states */
00002 
00003 
00004 /* Pushdown plugin for FAU Discrete Event Systems Library (libfaudes)
00005 
00006    Copyright (C) 2013  Stefan Jacobi, Sven Schneider, Anne-Kathrin Hess
00007 
00008 */
00009 
00010 #include "pd_merge.h"
00011 
00012 namespace faudes {
00013 
00014 /*******************************
00015 * 
00016 * Implementation of MergeStates
00017 *
00018 */ 
00019   
00020 MergeStates::MergeStates(const std::vector<Idx>& states) : mStates(states){
00021 //MergeStates::MergeStates(std::vector<Idx> states, PushdownGenerator* gen){
00022   if(states.size() == 0){
00023     std::stringstream errstr;
00024     errstr << "MergeStates contains no states" << std::endl;
00025     throw Exception("MergeStates::MergeStates()", errstr.str(), 1001);
00026   }
00027   //mpGen = gen;
00028 }
00029 
00030 
00031 void MergeStates::Write(TokenWriter& rTw, const std::string& rLabel){
00032   std::string label=rLabel;
00033   if(label=="") label="MergeStates";
00034   FD_DC("MergeStates(" << this << ")::DoWrite(tr): to section " << label);
00035   
00036   std::vector<Idx>::iterator it;
00037   std::string s = "MergeStates: ";
00038   for(it=mStates.begin();it < mStates.end();it++){
00039     if(it == mStates.begin())
00040       s += static_cast<std::ostringstream*>( &(std::ostringstream() << *it) )->str();
00041     else
00042       s += ", " + static_cast<std::ostringstream*>( &(std::ostringstream() << *it) )->str();
00043   }
00044   
00045   rTw.WriteXmlComment(s);
00046   
00047 //   Token token;
00048 //   int oldcolumns = rTw.Columns();
00049 //   //rTw.Columns(3);
00050   
00051 //   rTw.WriteBegin(label);
00052 //   
00053 //   //write contained state
00054 //   std::vector<Idx>::iterator it;
00055 //   std::string s;
00056 //   for(it=mStates.begin();it < mStates.end();it++){
00057 //     if(it == mStates.begin())
00058 //       s = static_cast<std::ostringstream*>( &(std::ostringstream() << *it) )->str();
00059 //     else
00060 //       s += ", " + static_cast<std::ostringstream*>( &(std::ostringstream() << *it) )->str();
00061 //   }
00062 //   token.SetOption(s);
00063 //   rTw << token;
00064 //   
00065 //   //recursively write contained states of contained states
00066 //   MergeAbstract* m;
00067 //   for(it=mStates.begin();it < mStates.end();it++){
00068 //     //mpGen->pStates;//doesn't compile
00069 //     //m = mpGen->pStates->Attributep(*it)->mpMerge;
00070 //     if(m != NULL){    
00071 //       m->Write(rTw,"");
00072 //     }
00073 //   }
00074 //   rTw.WriteEnd(label);
00075 //   rTw.Columns(oldcolumns);
00076   
00077 }
00078 
00079 // void MergeStates::Set(std::vector<Idx> states){
00080 //   if(states.size() == 0){
00081 //     std::stringstream errstr;
00082 //     errstr << "MergeStates contains no states" << std::endl;
00083 //     throw Exception("MergeStates::Set()", errstr.str(), 1001);
00084 //   }
00085 //   mStates = states;
00086 // }
00087 
00088 /*******************************
00089 * 
00090 * Implementation of MergeStateAnnotation
00091 *
00092 */ 
00093 
00094 MergeStateAnnotation::MergeStateAnnotation(const Idx state, const std::string& annotation) : mState(state), mAnnotation(annotation){
00095   if(state < 1){
00096     std::stringstream errstr;
00097     errstr << "MergeStateAnnotation contains no state" << std::endl;
00098     throw Exception("MergeStateAnnotation::MergeStateAnnotation()", errstr.str(), 1001);
00099   }
00100 }
00101 
00102 void MergeStateAnnotation::Write(TokenWriter& rTw, const std::string& rLabel){
00103   std::string label=rLabel;
00104   if(label=="") label="MergeStateAnnotation";
00105   FD_DC("MergeStateAnnotation(" << this << ")::DoWrite(tr): to section " << label);
00106   
00107   
00108   rTw.WriteXmlComment("MergeStateAnnotation: " + mAnnotation + ", " + static_cast<std::ostringstream*>( &(std::ostringstream() << mState) )->str());
00109 //   Token t1, t2;
00110 //   int oldcolumns = rTw.Columns();
00111 //   //rTw.Columns(3);
00112 //   
00113 //   rTw.WriteBegin(label);
00114 //   
00115 //   //write contained state
00116 //   std::string s = mAnnotation + ", ";
00117 //   s = static_cast<std::ostringstream*>( &(std::ostringstream() << mState) )->str();
00118 // 
00119 //   token.SetOption(s);
00120 //   rTw << token;
00121 //   
00122 //   rTw.WriteEnd(label);
00123 //   rTw.Columns(oldcolumns);
00124 //   
00125 }
00126 
00127 /*******************************
00128 * 
00129 * Implementation of MergeStateEvent
00130 *
00131 */ 
00132 
00133 MergeStateEvent::MergeStateEvent(const Idx state, const Idx event) : mState(state), mEvent(event){
00134   if(state < 1){
00135     std::stringstream errstr;
00136     errstr << "MergeStateEvent contains no state (state argument was " << state << ")"<< std::endl;
00137     throw Exception("MergeStateEvent::MergeStateEvent()", errstr.str(), 1001);
00138   }
00139 }
00140 
00141 void MergeStateEvent::Write(TokenWriter& rTw, const std::string& rLabel){
00142   std::string label=rLabel;
00143   if(label=="") label="MergeStateEvent";
00144   FD_DC("MergeStateEvent(" << this << ")::DoWrite(tr): to section " << label);
00145   
00146   std::stringstream s;
00147   s << "MergeStateEvent: state " << mState << ", event " << vGenerator::GlobalEventSymbolTablep()->Symbol(mEvent);
00148   rTw.WriteXmlComment(s.str());
00149 //   Token t1, t2;
00150 //   int oldcolumns = rTw.Columns();
00151 //   //rTw.Columns(3);
00152 //   
00153 //   rTw.WriteBegin(label);
00154 //   
00155 //   //write contained state
00156 //   std::string s = mAnnotation + ", ";
00157 //   s = static_cast<std::ostringstream*>( &(std::ostringstream() << mState) )->str();
00158 // 
00159 //   token.SetOption(s);
00160 //   rTw << token;
00161 //   
00162 //   rTw.WriteEnd(label);
00163 //   rTw.Columns(oldcolumns);
00164 //   
00165 }
00166 
00167 /*******************************
00168 * 
00169 * Implementation of MergeStateSplit
00170 *
00171 */ 
00172 
00173 MergeStateSplit::MergeStateSplit(const Idx state) : mState(state), mSymbol(0), mIsHead(true){
00174   if(state < 1){
00175     std::stringstream errstr;
00176     errstr << "MergeStateSplit contains no state" << std::endl;
00177     throw Exception("MergeStateSplit::MergeStateSplit()", errstr.str(), 1001);
00178   }
00179 }
00180 
00181 MergeStateSplit::MergeStateSplit(const Idx state, const Idx symbol) : mState(state), mSymbol(symbol), mIsHead(false){
00182   if(state < 1){
00183     std::stringstream errstr;
00184     errstr << "MergeStateSplit contains no state" << std::endl;
00185     throw Exception("MergeStateSplit::MergeStateSplit()", errstr.str(), 1001);
00186   }
00187 }
00188 
00189 void MergeStateSplit::Write(TokenWriter& rTw, const std::string& rLabel){
00190   std::string label=rLabel;
00191   if(label=="") label="MergeStateSplit";
00192   FD_DC("MergeStateSplit(" << this << ")::DoWrite(tr): to section " << label);
00193   
00194   std::string annotation;
00195   if(mIsHead){
00196     annotation = "MergeStateSplit: head, " + static_cast<std::ostringstream*>( &(std::ostringstream() << mState) )->str();
00197   }
00198   else{
00199     annotation = "MergeStateSplit: ear, " + static_cast<std::ostringstream*>( &(std::ostringstream() << mState) )->str() + ", " +  StackSymbolSet::StaticSymbolTablep()->Symbol(mSymbol);
00200   }
00201   
00202   rTw.WriteXmlComment(annotation);
00203 //   Token t1, t2;
00204 //   int oldcolumns = rTw.Columns();
00205 //   //rTw.Columns(3);
00206 //   
00207 //   rTw.WriteBegin(label);
00208 //   
00209 //   //write contained state
00210 //   std::string s = mAnnotation + ", ";
00211 //   s = static_cast<std::ostringstream*>( &(std::ostringstream() << mState) )->str();
00212 // 
00213 //   token.SetOption(s);
00214 //   rTw << token;
00215 //   
00216 //   rTw.WriteEnd(label);
00217 //   rTw.Columns(oldcolumns);
00218 //   
00219 }
00220 
00221 /*******************************
00222 * 
00223 * Implementation of MergeTransition
00224 *
00225 */ 
00226 
00227 MergeTransition::MergeTransition(Idx x1, Idx ev, Idx x2, const std::vector<Idx>& pop, const std::vector<Idx>& push) : mX1(x1), mEv(ev), mX2(x2), mPop(pop), mPush(push){
00228   
00229 }
00230 
00231 void MergeTransition::Write(TokenWriter& rTw, const std::string& rLabel){
00232   std::string label=rLabel;
00233   if(label=="") label="MergeTransition";
00234   FD_DC("MergeTransition(" << this << ")::DoWrite(tr): to section " << label);
00235   
00236   std::stringstream annotation;
00237   std::vector<Idx>::const_iterator ssit;
00238   annotation << "MergeTransition: (" << mX1 << ", " << mEv << ", " << mX2 << ",";
00239   for(ssit = mPop.begin(); ssit != mPop.end(); ssit++){
00240     annotation << " " << StackSymbolSet::StaticSymbolTablep()->Symbol(*ssit);
00241   }
00242   annotation << ",";
00243   for(ssit = mPush.begin(); ssit != mPush.end(); ssit++){
00244     annotation << " " << StackSymbolSet::StaticSymbolTablep()->Symbol(*ssit);
00245   }
00246   annotation << std::endl;
00247   
00248   rTw.WriteXmlComment(annotation.str());
00249 //   Token t1, t2;
00250 //   int oldcolumns = rTw.Columns();
00251 //   //rTw.Columns(3);
00252 //   
00253 //   rTw.WriteBegin(label);
00254 //   
00255 //   //write contained state
00256 //   std::string s = mAnnotation + ", ";
00257 //   s = static_cast<std::ostringstream*>( &(std::ostringstream() << mState) )->str();
00258 // 
00259 //   token.SetOption(s);
00260 //   rTw << token;
00261 //   
00262 //   rTw.WriteEnd(label);
00263 //   rTw.Columns(oldcolumns);
00264 //   
00265 }
00266 
00267 
00268 } // namespace faudes
00269 

libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen