Changeset 1269 in Sophya for trunk/SophyaPI/PIext/cxxexecutor.cc


Ignore:
Timestamp:
Nov 1, 2000, 6:30:27 PM (25 years ago)
Author:
ercodmgr
Message:

Retour de ExecuteCXX pour CxxExecWind
Finalisation de CxxExecWind cmv 1/11/00

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaPI/PIext/cxxexecutor.cc

    r1268 r1269  
    1313CxxExecutor::CxxExecutor(PIACmd *mpiac, PIStdImgApp* /* app */)
    1414  : mUserCodeFn(""), mUserFctFn(""), mCompOpt(""), mLinkOpt(""), mMyLibs("")
    15   , mDefTmp(""), mDefRoot("cxx_spiapp"), mDefFunc("usercxx")
     15  , mDefTmp(""), mDefRoot("cxx_spiapp"), mDefFunc("usercxx"), mPrtLevel(1)
    1616{
    1717mIncList.resize(0);
     
    121121    return(1);
    122122  }
    123   rc = FillUserCode(toks,0); if(rc) return(1);
    124   rc = CrFile();   if(rc) return(1);
    125   rc = Compile();  if(rc) return(1);
    126   rc = Link();     if(rc) return(1);
    127   rc = Call();     if(rc) return(1);
     123  rc = ExecuteCXX(toks); if(rc) return(1);
    128124
    129125} else if(kw == "c++execfrf") {
     
    132128    return(1);
    133129  }
    134   if(tokens.size()>1) rc = FillUserCode(tokens[0],tokens[1]);
    135     else              rc = FillUserCode(tokens[0]);
    136   if(rc) return(1);
     130  rc = FillUserCode(tokens[0]); if(rc) return(1);
     131  if(tokens.size()>1) rc = FillUserFctFrF(tokens[1]);
    137132  rc = CrFile();   if(rc) return(1);
    138133  rc = Compile();  if(rc) return(1);
     
    158153    return(1);
    159154  }
    160   if(tokens.size()>3) rc = FillUserCode(tokens[2],tokens[3]);
    161     else              rc = FillUserCode(tokens[2]);
    162   if(rc) return(1);
     155  rc = FillUserCode(tokens[2]); if(rc) return(1);
     156  if(tokens.size()>3) FillUserFctFrF(tokens[3]);
    163157  rc = CrFile(tokens[0],tokens[1]); if(rc) return(1);
    164158
     
    199193
    200194/* --Methode-- */
     195int  CxxExecutor::ExecuteCXX(string usercode,string userfct)
     196{
     197int rc=0;
     198rc = FillUserCode(usercode,0); if(rc) return(1);
     199rc = FillUserFctFrS(userfct);
     200rc = CrFile();   if(rc) return(1);
     201rc = Compile();  if(rc) return(1);
     202rc = Link();     if(rc) return(1);
     203rc = Call();     if(rc) return(1);
     204return 0;
     205}
     206
     207/* --Methode-- */
    201208int CxxExecutor::CrFile(string cfilename,string func)
    202209{
     
    216223
    217224os<<"//-------------------------------------------------//"<<endl;
    218 os<<"//------------- Fonctions utilisateur -------------//"<<endl;
     225os<<"//----------------- User Functions ----------------//"<<endl;
    219226os<<"//-------------------------------------------------//"<<endl;
    220227if(mUserFctFn.size()>0) os<<"#include \""<<mUserFctFn<<"\""<<endl;
     
    239246
    240247os<<"//--------------------------------------------//"<<endl;
    241 os<<"//------------- Code utilisateur -------------//"<<endl;
     248os<<"//----------------- User Code ----------------//"<<endl;
    242249os<<"//--------------------------------------------//"<<endl;
    243 os<<endl;
    244 os<<"#include \""<<mUserCodeFn<<"\""<<endl;
     250if(mUserCodeFn.size()>0) os<<"#include \""<<mUserCodeFn<<"\""<<endl;
    245251os<<endl;
    246252
     
    248254os<<"}"<<endl;
    249255
    250 cout<<"File "<<cfilename<<" for function "<<func<<" created"<<endl;
    251 cout<<"User code is in file "<<mUserCodeFn<<" included in "<<cfilename<<endl;
     256if(mPrtLevel)
     257  cout<<"File "<<cfilename<<" for function "<<func<<" created :"<<endl;
     258if(mPrtLevel && mUserCodeFn.size()>0)
     259  cout<<"  User code was in file "<<mUserCodeFn<<endl;
     260if(mPrtLevel && mUserFctFn.size()>0)
     261  cout<<"  User function code was in file "<<mUserFctFn<<endl;
    252262return 0;
    253263}
     
    364374{
    365375mUserCodeFn = "";
    366 mUserFctFn  = "";
    367376
    368377// get the string part which is after word "first"
     
    389398if(!os) {cout<<"CxxExecutor::FillUserCode: unable to open "
    390399             <<mUserCodeFn<<endl;  mUserCodeFn = ""; return 1;}
    391 os<<" "<<code;
    392 cout<<"User code filled from standard input into "<<mUserCodeFn<<endl;
    393 return 0;
    394 }
    395 
    396 /* --Methode-- */
    397 int CxxExecutor::FillUserCode(string filename,string filefctname)
    398 // User code is read from "filename" an optionally from filefctname.
     400os<<code<<endl;
     401if(mPrtLevel)
     402  cout<<"User code filled from standard input into "<<mUserCodeFn<<endl;
     403return 0;
     404}
     405
     406/* --Methode-- */
     407int CxxExecutor::FillUserFctFrS(string userfct)
     408// - Fill user Fonction code from string "userfct"
     409// It is put into file "TmpDir/cxx_spiapp_fct.h".
     410{
     411mUserFctFn  = "";
     412if(userfct.size()<1) return 0;
     413mUserFctFn  = mDefTmp + mDefRoot + "_fct.h";
     414ofstream os(mUserFctFn.c_str(),ios::out);
     415if(!os) {cout<<"CxxExecutor::FillUserFctFrS: unable to open "
     416             <<mUserFctFn<<endl;  mUserFctFn = ""; return 1;}
     417os<<userfct<<endl;
     418if(mPrtLevel)
     419  cout<<"User Function code filled from standard input into "<<mUserFctFn<<endl;
     420return 0;
     421}
     422
     423/* --Methode-- */
     424int CxxExecutor::FillUserCode(string filename)
     425// User code is read from "filename".
    399426{
    400427mUserCodeFn = filename;
    401 mUserFctFn  = filefctname;
    402 cout<<"User code filled from file "<<filename<<endl;
     428if(mPrtLevel && mUserCodeFn.size()>0)
     429  cout<<"User code filled from file "<<mUserCodeFn<<endl;
     430return 0;
     431}
     432
     433/* --Methode-- */
     434int CxxExecutor::FillUserFctFrF(string filefctname="")
     435{
     436mUserFctFn = filefctname;
     437if(mPrtLevel && mUserFctFn.size()>0)
     438  cout<<"User Function code filled from file "<<mUserFctFn<<endl;
    403439return 0;
    404440}
     
    408444{
    409445if(rootfilename.size()<1) rootfilename = mDefRoot;
    410 cout<<"Compile: "<<rootfilename<<endl;
     446if(mPrtLevel) cout<<"Compile: "<<rootfilename<<endl;
    411447int rc = 0;
    412448rc = CrMakefile();
     
    477513string toks = libname + " " + func;
    478514int rc = mpiac->ExecuteCommand(key,arg,toks);
    479 cout<<"Link from "<<libname<<" for function "<<func
    480     <<" (rc="<<rc<<")"<<endl;
     515if(mPrtLevel) cout<<"Link from "<<libname<<" for function "<<func
     516                 <<" (rc="<<rc<<")"<<endl;
    481517return 0;
    482518}
Note: See TracChangeset for help on using the changeset viewer.