|
Go to the documentation of this file.
31 #ifndef FAUDES_PD_DOTPARSER_H
32 #define FAUDES_PD_DOTPARSER_H
40 extern FAUDES_API std::vector<std::string> split( const std::string& rStr, const std::string& rSep,
41 const std::string& rFilename, const int lineNr);
64 extern FAUDES_API std::string::size_type getIde(std::string::size_type& rPos,
65 const std::string& rInput, std::string& rRestString,
66 const std::string& rFilename, const int lineNr);
101 #define TEMP template <class GlobalAttr, class StateAttr, class EventAttr, class TransAttr>
105 #define THIS TpdGenerator<GlobalAttr, StateAttr, EventAttr, TransAttr>
113 rPd.InsLambdaStackSymbol();
118 for (std::vector<std::string>::const_iterator itstr = rVec.begin(); itstr != rVec.end(); ++itstr) {
119 std::string name = *itstr;
122 if(rVec.size() == 1){
125 rPd.InsLambdaStackSymbol();
131 #ifdef FAUDES_CHECKED
133 std::stringstream errstr;
134 errstr << rFileName << " L:"<< lineNr<< " pop/push lambda vector can't contain more than exactly one symbol(=lambda) ";
135 throw Exception( "pd_dotparser::ParserInsStackSymbols", errstr.str(), 200);
141 if(!rPd.ExistsStackSymbol(name))
142 rPd.InsStackSymbol(name);
153 std::string srcState, eventName, trgState, label;
154 std::vector<std::string> vPop, vPush;
155 std::string::size_type end_position,pos= 0;
158 pos = getIde(pos,input,srcState,rFilename,linenr);
160 pos = getIde(++pos,input,trgState,rFilename,linenr);
163 pos = input.find( "label",pos);
165 #ifdef FAUDES_CHECKED
167 if(!rPd.ExistsState(srcState)) {
168 std::stringstream errstr;
169 errstr << rFilename << " L:"<< linenr<< " state not exists : " << srcState << " !";
170 throw Exception( "pd_dotparser::ParseTransition", errstr.str(), 200);
173 if(!rPd.ExistsState(trgState)) {
174 std::stringstream errstr;
175 errstr << rFilename << " L:"<< linenr<< " state not exists : " << trgState << " !";
176 throw Exception( "pd_dotparser::ParseTransition", errstr.str(), 200);
180 if(pos == std::string::npos) {
181 std::stringstream errstr;
182 errstr << rFilename << " L:"<< linenr<< " missing label for transition : " << srcState << "->" << trgState << " !";
183 throw Exception( "pd_dotparser::ParseTransition", errstr.str(), 200);
188 pos = getIde(pos,input,label,rFilename,linenr);
191 end_position = std::min(label.find( ','),label.find( '['));
193 if(end_position != std::string::npos )
196 eventName = label.substr(0,end_position);
203 if(! rPd.ExistsEvent(eventName))
204 rPd.InsEvent(eventName);
207 pos = label.find( "[");
208 if (pos != std::string::npos)
211 end_position = label.find( "]",++pos);
214 #ifdef FAUDES_CHECKED
215 std::string::size_type tmp = label.find( '[',pos);
216 if(tmp < end_position){
217 std::stringstream errstr;
218 errstr << rFilename << " L:"<< linenr<< " Expected ']' find '[' .";
219 throw Exception( "pd_dotparser::ParseTransition", errstr.str(), 200);
224 if (end_position != std::string::npos)
226 std::string found_text = label.substr(pos, end_position-pos);
227 vPop = split(found_text, ",",rFilename,linenr);
233 #ifdef FAUDES_CHECKED
234 std::stringstream errstr;
235 errstr << rFilename << " L:"<< linenr << " Missing ']'." ;
236 throw Exception( "pd_dotparser::ParseTransition", errstr.str(), 200);
241 pos = label.find( '[',++pos);
242 if (pos != std::string::npos)
244 end_position = label.find( "]",++pos);
245 if (end_position != std::string::npos)
247 std::string found_text = label.substr(pos, end_position-pos);
249 vPush = split(found_text, ",",rFilename,linenr);
255 return rPd.SetTransition(srcState,eventName,trgState,vPop,vPush);
257 #ifdef FAUDES_CHECKED
258 std::stringstream errstr;
259 errstr << rFilename << " L:"<< linenr << " Missing ']'." ;
260 throw Exception( "pd_dotparser::ParseTransition", errstr.str(), 200);
264 #ifdef FAUDES_CHECKED
265 std::stringstream errstr;
266 errstr << rFilename << " L:"<< linenr << " Missing '[' for pushed symbols." ;
267 throw Exception( "pd_dotparser::ParseTransition", errstr.str(), 200);
271 #ifdef FAUDES_CHECKED
272 std::stringstream errstr;
273 errstr << rFilename << " L:"<< linenr << " Missing '[' for pop and pushed symbols." ;
274 throw Exception( "pd_dotparser::ParseTransition", errstr.str(), 200);
286 std::string::size_type pos= 0;
287 std::string eventName, attr;
290 getIde(pos,input,eventName,rFileName,lineNr);
293 pos = input.find( "attr",pos);
294 getIde(pos,input,attr,rFileName,lineNr);
296 #ifdef FAUDES_CHECKED
297 if(rPd.ExistsEvent(eventName)) {
298 std::stringstream errstr;
299 errstr << rFileName << " L:"<< lineNr<< " event : " << eventName << " already exists !";
300 throw Exception( "pd_dotparser::ParseEvent", errstr.str(), 200);
305 Idx event = rPd.InsEvent(eventName);
309 for( unsigned i = 0; i < attr.size(); i++) {
311 if(attr[i] == 'C') rPd.SetControllable(event);
312 if(attr[i] == 'c') rPd.ClrControllable(event);
314 if(attr[i] == 'O') rPd.SetObservable(event);
315 if(attr[i] == 'o') rPd.ClrObservable(event);
317 if(attr[i] == 'F') rPd.SetForcible(event);
318 if(attr[i] == 'f') rPd.ClrForcible(event);
320 if(attr[i] == 'A') rPd.SetHighlevel(event);
321 if(attr[i] == 'a') rPd.SetLowlevel(event);
327 std::string::size_type pos= 0;
331 getIde(pos,input,state,rFileName,lineNr);
334 if(!rPd.ExistsState(state))
338 if(input.find( "->")!= std::string::npos) {
339 rPd.SetInitState(state);
343 pos = input.find( "shape=double",++pos);
344 if(pos != std::string::npos)
345 rPd.SetMarkedState(state);
350 std::string::size_type pos= 0;
354 getIde(pos,input,bottom,rFilename,linenr);
357 rPd.InsStackSymbol(bottom);
358 rPd.SetStackBottom(bottom);
365 std::ifstream file (fileName.c_str(), std::ios::in | std::ios::binary);
375 while ( getline(file,line) )
378 std::string sub = line;
381 sub.erase(std::remove_if(sub.begin(), sub.end(), ::isspace), sub.end());
384 sub = sub.substr(0,sub.find_first_of( "//"));
389 if(sub.find( "shape=none") != std::string::npos ||
390 sub.find( "shape=point") != std::string::npos )
395 if(sub.find( "label=<")!= std::string::npos ||
396 sub.find( "<br")!= std::string::npos)
399 if(sub.find( "digraph")!= std::string::npos)
400 sub = sub.substr(sub.find( "{"));
403 if(sub.find( "attr=\"")!= std::string::npos) {
405 std::string attr = sub.substr(sub.find( "attr=\""));
407 std::for_each(attr.begin(), attr.end(), tolower);
409 if(attr.find( "stackbottom")!= std::string::npos)
415 if(sub.find( "->")!= std::string::npos &&
416 sub.find( "label")!= std::string::npos) {
419 if(sub.find( '"') != std::string::npos)
428 #ifdef FAUDES_CHECKED
429 if(pd.InitStates().Empty()){
430 std::stringstream errstr;
431 errstr << "Missing initial State : " << fileName;
432 FD_WARN( "pd_dotparser::CreatePdFromDot : " + errstr.str());
436 if(!pd.ExistsStackSymbol(pd.StackBottom())){
437 std::stringstream errstr;
438 errstr << "Missing stack bottom : " << fileName;
439 FD_WARN( "pd_dotparser::CreatePdFromDot : " + errstr.str());
446 #ifdef FAUDES_CHECKED
447 std::stringstream errstr;
448 errstr << "Unable to open file : " << fileName;
449 throw Exception( "pd_dotparser::CreatePdFromDot", errstr.str(), 1);
libFAUDES 2.28c
--- 2016.09.30
--- c++ api documentaion by doxygen
|