pd_merge.cpp
Go to the documentation of this file.
1 /** @file pd_merge.cpp Attributes for pushdown automata states */
2 
3 
4 /* Pushdown plugin for FAU Discrete Event Systems Library (libfaudes)
5 
6  Copyright (C) 2013 Stefan Jacobi, Sven Schneider, Anne-Kathrin Hess
7 
8 */
9 
10 #include "pd_merge.h"
11 
12 namespace faudes {
13 
14 /*******************************
15 *
16 * Implementation of MergeStates
17 *
18 */
19 
20 MergeStates::MergeStates(const std::vector<Idx>& states) : mStates(states){
21 //MergeStates::MergeStates(std::vector<Idx> states, PushdownGenerator* gen){
22  if(states.size() == 0){
23  std::stringstream errstr;
24  errstr << "MergeStates contains no states" << std::endl;
25  throw Exception("MergeStates::MergeStates()", errstr.str(), 1001);
26  }
27  //mpGen = gen;
28 }
29 
30 
31 void MergeStates::Write(TokenWriter& rTw, const std::string& rLabel){
32  std::string label=rLabel;
33  if(label=="") label="MergeStates";
34  FD_DC("MergeStates(" << this << ")::DoWrite(tr): to section " << label);
35 
36  std::vector<Idx>::iterator it;
37  std::string s = "MergeStates: ";
38  for(it=mStates.begin();it < mStates.end();it++){
39  if(it == mStates.begin())
40  s += static_cast<std::ostringstream*>( &(std::ostringstream() << *it) )->str();
41  else
42  s += ", " + static_cast<std::ostringstream*>( &(std::ostringstream() << *it) )->str();
43  }
44 
45  rTw.WriteXmlComment(s);
46 
47 // Token token;
48 // int oldcolumns = rTw.Columns();
49 // //rTw.Columns(3);
50 
51 // rTw.WriteBegin(label);
52 //
53 // //write contained state
54 // std::vector<Idx>::iterator it;
55 // std::string s;
56 // for(it=mStates.begin();it < mStates.end();it++){
57 // if(it == mStates.begin())
58 // s = static_cast<std::ostringstream*>( &(std::ostringstream() << *it) )->str();
59 // else
60 // s += ", " + static_cast<std::ostringstream*>( &(std::ostringstream() << *it) )->str();
61 // }
62 // token.SetOption(s);
63 // rTw << token;
64 //
65 // //recursively write contained states of contained states
66 // MergeAbstract* m;
67 // for(it=mStates.begin();it < mStates.end();it++){
68 // //mpGen->pStates;//doesn't compile
69 // //m = mpGen->pStates->Attributep(*it)->mpMerge;
70 // if(m != NULL){
71 // m->Write(rTw,"");
72 // }
73 // }
74 // rTw.WriteEnd(label);
75 // rTw.Columns(oldcolumns);
76 
77 }
78 
79 // void MergeStates::Set(std::vector<Idx> states){
80 // if(states.size() == 0){
81 // std::stringstream errstr;
82 // errstr << "MergeStates contains no states" << std::endl;
83 // throw Exception("MergeStates::Set()", errstr.str(), 1001);
84 // }
85 // mStates = states;
86 // }
87 
88 /*******************************
89 *
90 * Implementation of MergeStateAnnotation
91 *
92 */
93 
94 MergeStateAnnotation::MergeStateAnnotation(const Idx state, const std::string& annotation) : mState(state), mAnnotation(annotation){
95  if(state < 1){
96  std::stringstream errstr;
97  errstr << "MergeStateAnnotation contains no state" << std::endl;
98  throw Exception("MergeStateAnnotation::MergeStateAnnotation()", errstr.str(), 1001);
99  }
100 }
101 
102 void MergeStateAnnotation::Write(TokenWriter& rTw, const std::string& rLabel){
103  std::string label=rLabel;
104  if(label=="") label="MergeStateAnnotation";
105  FD_DC("MergeStateAnnotation(" << this << ")::DoWrite(tr): to section " << label);
106 
107 
108  rTw.WriteXmlComment("MergeStateAnnotation: " + mAnnotation + ", " + static_cast<std::ostringstream*>( &(std::ostringstream() << mState) )->str());
109 // Token t1, t2;
110 // int oldcolumns = rTw.Columns();
111 // //rTw.Columns(3);
112 //
113 // rTw.WriteBegin(label);
114 //
115 // //write contained state
116 // std::string s = mAnnotation + ", ";
117 // s = static_cast<std::ostringstream*>( &(std::ostringstream() << mState) )->str();
118 //
119 // token.SetOption(s);
120 // rTw << token;
121 //
122 // rTw.WriteEnd(label);
123 // rTw.Columns(oldcolumns);
124 //
125 }
126 
127 /*******************************
128 *
129 * Implementation of MergeStateEvent
130 *
131 */
132 
133 MergeStateEvent::MergeStateEvent(const Idx state, const Idx event) : mState(state), mEvent(event){
134  if(state < 1){
135  std::stringstream errstr;
136  errstr << "MergeStateEvent contains no state (state argument was " << state << ")"<< std::endl;
137  throw Exception("MergeStateEvent::MergeStateEvent()", errstr.str(), 1001);
138  }
139 }
140 
141 void MergeStateEvent::Write(TokenWriter& rTw, const std::string& rLabel){
142  std::string label=rLabel;
143  if(label=="") label="MergeStateEvent";
144  FD_DC("MergeStateEvent(" << this << ")::DoWrite(tr): to section " << label);
145 
146  std::stringstream s;
147  s << "MergeStateEvent: state " << mState << ", event " << vGenerator::GlobalEventSymbolTablep()->Symbol(mEvent);
148  rTw.WriteXmlComment(s.str());
149 // Token t1, t2;
150 // int oldcolumns = rTw.Columns();
151 // //rTw.Columns(3);
152 //
153 // rTw.WriteBegin(label);
154 //
155 // //write contained state
156 // std::string s = mAnnotation + ", ";
157 // s = static_cast<std::ostringstream*>( &(std::ostringstream() << mState) )->str();
158 //
159 // token.SetOption(s);
160 // rTw << token;
161 //
162 // rTw.WriteEnd(label);
163 // rTw.Columns(oldcolumns);
164 //
165 }
166 
167 /*******************************
168 *
169 * Implementation of MergeStateSplit
170 *
171 */
172 
173 MergeStateSplit::MergeStateSplit(const Idx state) : mState(state), mSymbol(0), mIsHead(true){
174  if(state < 1){
175  std::stringstream errstr;
176  errstr << "MergeStateSplit contains no state" << std::endl;
177  throw Exception("MergeStateSplit::MergeStateSplit()", errstr.str(), 1001);
178  }
179 }
180 
181 MergeStateSplit::MergeStateSplit(const Idx state, const Idx symbol) : mState(state), mSymbol(symbol), mIsHead(false){
182  if(state < 1){
183  std::stringstream errstr;
184  errstr << "MergeStateSplit contains no state" << std::endl;
185  throw Exception("MergeStateSplit::MergeStateSplit()", errstr.str(), 1001);
186  }
187 }
188 
189 void MergeStateSplit::Write(TokenWriter& rTw, const std::string& rLabel){
190  std::string label=rLabel;
191  if(label=="") label="MergeStateSplit";
192  FD_DC("MergeStateSplit(" << this << ")::DoWrite(tr): to section " << label);
193 
194  std::string annotation;
195  if(mIsHead){
196  annotation = "MergeStateSplit: head, " + static_cast<std::ostringstream*>( &(std::ostringstream() << mState) )->str();
197  }
198  else{
199  annotation = "MergeStateSplit: ear, " + static_cast<std::ostringstream*>( &(std::ostringstream() << mState) )->str() + ", " + StackSymbolSet::StaticSymbolTablep()->Symbol(mSymbol);
200  }
201 
202  rTw.WriteXmlComment(annotation);
203 // Token t1, t2;
204 // int oldcolumns = rTw.Columns();
205 // //rTw.Columns(3);
206 //
207 // rTw.WriteBegin(label);
208 //
209 // //write contained state
210 // std::string s = mAnnotation + ", ";
211 // s = static_cast<std::ostringstream*>( &(std::ostringstream() << mState) )->str();
212 //
213 // token.SetOption(s);
214 // rTw << token;
215 //
216 // rTw.WriteEnd(label);
217 // rTw.Columns(oldcolumns);
218 //
219 }
220 
221 /*******************************
222 *
223 * Implementation of MergeTransition
224 *
225 */
226 
228  const std::vector<Idx>& pop, const std::vector<Idx>& push) : mX1(x1), mEv(ev), mX2(x2), mPop(pop), mPush(push)
229 {}
230 
232  const std::vector<Idx>& pop, const std::vector<Idx>& push) : mX1(trans.X1), mEv(trans.Ev), mX2(trans.X2), mPop(pop), mPush(push)
233 {}
234 
235 void MergeTransition::Write(TokenWriter& rTw, const std::string& rLabel){
236  std::string label=rLabel;
237  if(label=="") label="MergeTransition";
238  FD_DC("MergeTransition(" << this << ")::DoWrite(tr): to section " << label);
239 
240  std::stringstream annotation;
241  std::vector<Idx>::const_iterator ssit;
242  annotation << "MergeTransition: (" << mX1 << ", " << mEv << ", " << mX2 << ",";
243  for(ssit = mPop.begin(); ssit != mPop.end(); ssit++){
244  annotation << " " << StackSymbolSet::StaticSymbolTablep()->Symbol(*ssit);
245  }
246  annotation << ",";
247  for(ssit = mPush.begin(); ssit != mPush.end(); ssit++){
248  annotation << " " << StackSymbolSet::StaticSymbolTablep()->Symbol(*ssit);
249  }
250  annotation << std::endl;
251 
252  rTw.WriteXmlComment(annotation.str());
253 // Token t1, t2;
254 // int oldcolumns = rTw.Columns();
255 // //rTw.Columns(3);
256 //
257 // rTw.WriteBegin(label);
258 //
259 // //write contained state
260 // std::string s = mAnnotation + ", ";
261 // s = static_cast<std::ostringstream*>( &(std::ostringstream() << mState) )->str();
262 //
263 // token.SetOption(s);
264 // rTw << token;
265 //
266 // rTw.WriteEnd(label);
267 // rTw.Columns(oldcolumns);
268 //
269 }
270 
271 
272 } // namespace faudes
273 

libFAUDES 2.26g --- 2015.08.17 --- c++ api documentaion by doxygen