Changeset 1237 in Sophya for trunk/SophyaPI/PIext/cxxexecutor.cc
- Timestamp:
- Oct 18, 2000, 8:12:00 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaPI/PIext/cxxexecutor.cc
r1233 r1237 3 3 #include <typeinfo> 4 4 5 #include "strutilxx.h" 5 6 #include "dvlist.h" 6 7 … … 9 10 10 11 11 void FillVStringFrString(string s,vector<string>& vs,char sep = ' ');12 13 14 12 /* --Methode-- */ 15 13 CxxExecutor::CxxExecutor(PIACmd *mpiac, PIStdImgApp* /* app */) 16 : mCompOpt(""), mLinkOpt(""), mMyLibs("") 17 { 18 mUserCode.resize(0); 14 : mUserCodeFn(""), mCompOpt(""), mLinkOpt(""), mMyLibs("") 15 { 19 16 mIncList.resize(0); 20 17 mCallArgs.resize(0); 21 22 NamedObjMgr omg;23 18 24 19 // On enregistre les nouvelles commandes … … 28 23 kw = "c++exec"; 29 24 usage = "c++exec: Execute the following c++ user code\n"; 30 usage+= "Usage: c++exec c++ user code"; 25 usage+= "Usage: c++exec c++ user code\n"; 26 usage+= "Warning: c++ user code can be found in \"cxx_spiapp.h\"\n"; 27 usage+= " total generated code can be found in \"cxx_spiapp.cc\""; 31 28 mpiac->RegisterCommand(kw, usage, this, hgrp); 32 29 33 30 kw = "c++execfrf"; 34 31 usage = "c++execfrf: Execute c++ user code contained in a file\n"; 35 usage+= "Usage: c++execfrf fileuser.cc"; 32 usage+= "Usage: c++execfrf fileuser.cc\n"; 33 usage+= "Warning: total generated code can be found in \"cxx_spiapp.cc\""; 36 34 mpiac->RegisterCommand(kw, usage, this, hgrp); 37 35 38 36 kw = "c++args"; 39 usage = "c++args: Define user function arguments \n";37 usage = "c++args: Define user function arguments for c++exec and c++execfrf\n"; 40 38 usage+= "Usage: c++args arg1 arg2 arg3 ...\n"; 41 39 usage+= " c++args -? : give current arguments\n"; … … 100 98 101 99 100 //// A VIRER quand variable de objmanager OK --> Pour Reza 102 101 kw = "c++setvar"; 103 102 usage = "c++setvar: Setting test variable \n"; … … 114 113 usage+= "c++varlist "; 115 114 mpiac->RegisterCommand(kw, usage, this, hgrp); 115 //// A VIRER quand variable de objmanager OK --> Pour Reza 116 116 117 117 } … … 193 193 194 194 195 195 //// A VIRER quand variable de objmanager OK --> Pour Reza 196 196 } else if(kw == "c++setvar") { 197 197 if(tokens.size()<2) { … … 215 215 cout<<omg.GetVarList(); 216 216 } 217 //// A VIRER quand variable de objmanager OK --> Pour Reza 217 218 218 219 … … 224 225 { 225 226 ofstream os(cfilename.c_str(),ios::out); 226 if(!os) { 227 cout<<"CxxExecutor::CrFile: unable to open "<<cfilename<<endl; 228 return 1; 229 } 227 if(!os) 228 {cout<<"CxxExecutor::CrFile: unable to open "<<cfilename<<endl; 229 return 1;} 230 230 231 231 PutInclude(os); … … 243 243 os<<"NamedObjMgr omg;"<<endl; 244 244 os<<"Services2NObjMgr& srvo = *omg.GetServiceObj();"<<endl; 245 os<<"//omg.AddObj(OBJECT* object,string nom_object);"<<endl;246 245 os<<endl; 247 246 … … 252 251 os<<endl; 253 252 254 PutUserCode(os); 255 os<<endl; 256 257 os<<endl; 253 os<<"//--------------------------------------------//"<<endl; 254 os<<"//------------- Code utilisateur -------------//"<<endl; 255 os<<"//--------------------------------------------//"<<endl; 256 os<<endl; 257 os<<"#include \""<<mUserCodeFn<<"\""<<endl; 258 os<<endl; 259 258 260 os<<"return 0;"<<endl; 259 261 os<<"}"<<endl; 260 262 261 263 cout<<"File "<<cfilename<<" for function "<<func<<" created"<<endl; 264 cout<<"User code is in file "<<mUserCodeFn<<" included in "<<cfilename<<endl; 262 265 return 0; 263 266 } … … 360 363 string key = (*it).first; 361 364 os<<"___nomobj = \""<<key<<"\";"<<endl; 362 os<<"MuTyV & "<<key<<" = omg.GetVarList().Get(___nomobj);"<<endl; 363 } 364 365 } 366 367 /* --Methode-- */ 368 void CxxExecutor::PutUserCode(ofstream& os) 369 { 370 os<<"//--------------------------------------------//"<<endl; 371 os<<"//------------- Code utilisateur -------------//"<<endl; 372 os<<"//--------------------------------------------//"<<endl; 373 os<<endl; 374 if(mUserCode.size()<1) return; 375 for(uint_4 i=0;i<mUserCode.size();i++) os<<mUserCode[i]<<endl; 365 os<<"MuTyV & $"<<key<<" = omg.GetVarList().Get(___nomobj);"<<endl; 366 } 367 368 return; 376 369 } 377 370 … … 379 372 int CxxExecutor::FillUserCode(vector<string>& usercode,uint_4 first) 380 373 // - first is the first position in the vector<> where the code starts 381 { 382 mUserCode.resize(0); 374 // User code is read from input. It is put into file "cxx_spiapp.h". 375 { 376 mUserCodeFn = ""; 383 377 uint_4 nus = usercode.size(); 384 if(nus<=first) { 385 cout<<"CxxExecutor::FillUserCode: no user code"<<endl; 386 return 1; 387 } 388 string dum = ""; 378 if(nus<=first) {cout<<"CxxExecutor::FillUserCode: no user code"<<endl; 379 return 1;} 380 mUserCodeFn = "cxx_spiapp.h"; 381 ofstream os(mUserCodeFn.c_str(),ios::out); 382 if(!os) {cout<<"CxxExecutor::FillUserCode: unable to open " 383 <<mUserCodeFn<<endl; mUserCodeFn = ""; return 1;} 389 384 // On ajoute un blanc pour les chaines de caracteres contenant des blancs 390 for(uint_4 i=first;i<nus;i++) dum += " " + usercode[i]; 391 // Tout dans une seule ligne pour eviter les pbs (cf au bas du fichier) 392 mUserCode.push_back(dum); 393 cout<<"User code filled from standard input"<<endl; 385 for(uint_4 i=first;i<nus;i++) os<<" "<<usercode[i]; 386 os<<endl; 387 cout<<"User code filled from standard input into "<<mUserCodeFn<<endl; 394 388 return 0; 395 389 } … … 397 391 /* --Methode-- */ 398 392 int CxxExecutor::FillUserCode(string filename) 399 { 400 mUserCode.resize(0); 401 402 ifstream is(filename.c_str()); 403 if(!is) { 404 cout<<"CxxExecutor::FillUserCode: unable to open "<<filename<<endl; 405 return 1; 406 } 407 408 int nline = 4096; // Au plus 4096 characters par ligne! 409 char *str = new char[nline+2]; 410 while(is) 411 {is.getline(str,nline); mUserCode.push_back((string) str);} 412 delete [] str; 413 if(mUserCode.size()<=0) { 414 return 2; 415 cout<<"CxxExecutor::FillUserCode: no user code"<<endl; 416 } 417 393 // User code is read from "filename". 394 { 395 mUserCodeFn = filename; 418 396 cout<<"User code filled from file "<<filename<<endl; 419 397 return 0; … … 501 479 vector<string> arg; arg.push_back(func); 502 480 if(mCallArgs.size()>0) 503 for( inti=0;i<mCallArgs.size();i++) arg.push_back(mCallArgs[i]);481 for(uint_4 i=0;i<mCallArgs.size();i++) arg.push_back(mCallArgs[i]); 504 482 mpiac->ExecuteCommand(key,arg); 505 483 return 0; … … 609 587 /* --Methode-- DO NOT DELETE.... cmv property !!! 610 588 int CxxExecutor::FillUserCode(vector<string>& usercode,uint_4 first) 611 // - first is the first position in the vector<> where the code starts 612 { 613 mUserCode.resize(0); 589 { 590 mUserCodeFn = ""; 614 591 uint_4 nus = usercode.size(); 615 592 if(nus<=first) { … … 617 594 return 1; 618 595 } 596 mUserCodeFn = "cxx_spiapp.h"; 597 ofstream os(mUserCodeFn.c_str(),ios::out); 598 if(!os) 599 {cout<<"CxxExecutor::FillUserCode: unable to open "<<mUserCodeFn<<endl; 600 mUserCodeFn = ""; return 1;} 619 601 // **** 1er probleme **** 620 602 // - Pour la lisibilite et eviter les bugs avec les chaines de caracteres … … 653 635 // 2-/ c'est le dernier charactere 654 636 if((str[j]==';' && !comment) || lastchar) 655 { mUserCode.push_back(dum); dum = "";}637 {os<<dum<<endl; dum = "";} 656 638 } 657 639 } 658 cout<<"User code filled from standard input "<<endl;640 cout<<"User code filled from standard input into "<<mUserCodeFn<<endl; 659 641 return 0; 660 642 } 661 643 */ 662 663 664 void FillVStringFrString(string s,vector<string>& vs,char sep)665 // Use string "s" to fill vector of strings "vs"666 // considering char "sep" as a separator.667 // Vector is filled from its end (no reset done).668 // Tp write a "sep" char, use \'sep'669 // Warning: separator "sep" could not be set to '\'670 // Ex: sep=' ': s="aaa bbb cc d " -> vs=(aaa,bbb,cc,d)671 // Ex: sep=';': s="aaa ;bbb; cc;d " -> vs=(aaa ,bbb, cc,d )672 // Ex: sep=';': s=";aaa\;bbb;;;ccc;ddd" -> vs=(aaa;bbb,ccc,ddd)673 // Ex: sep=';': s=";aaa\;bbb;;;ccc;ddd\" -> vs=(aaa;bbb,ccc,ddd\)674 {675 uint_4 ls = s.size();676 if(ls<=0 || sep=='\\') return;677 s += sep; // add a separator at the end678 const char* str = s.c_str();679 ls = strlen(str); // str[ls-1]==sep cf ci-dessus680 string dum = "";681 for(uint_4 i=0; i<ls; i++) {682 if(i==0 && str[i]==sep) {683 continue;684 } else if(str[i]=='\\') {685 if(str[i+1]!=sep || i==ls-2) dum += str[i];686 } else if(str[i]!=sep) {687 dum += str[i];688 } else { // C'est un "sep" mais est-ce vraiment un separateur?689 if(str[i-1]=='\\' && i!=ls-1) dum += str[i];690 else { // C'est un separateur, ne delimite t-il pas d'autres separateurs?691 if(dum.size()<=0) continue;692 vs.push_back(dum);693 dum = "";694 }695 }696 }697 }
Note:
See TracChangeset
for help on using the changeset viewer.