| 1 | #include "sopnamsp.h" | 
|---|
| 2 | #include "cxxexecutor.h" | 
|---|
| 3 |  | 
|---|
| 4 | #include <typeinfo> | 
|---|
| 5 |  | 
|---|
| 6 | #include "strutilxx.h" | 
|---|
| 7 | #include "dvlist.h" | 
|---|
| 8 | #include "cxxcmplnk.h" | 
|---|
| 9 |  | 
|---|
| 10 | #include "nomgadapter.h" | 
|---|
| 11 | #include "pistdimgapp.h" | 
|---|
| 12 |  | 
|---|
| 13 |  | 
|---|
| 14 | /* --Methode-- */ | 
|---|
| 15 | CxxExecutor::CxxExecutor(PIACmd *mpiac, PIStdImgApp* /* app */) | 
|---|
| 16 | : mUserCodeFn(""), mUserFctFn("") | 
|---|
| 17 | , mCompOpt(""), mLinkOpt(""), mMyLibs("") | 
|---|
| 18 | , mDefRoot("cxx_spiapp"), mDefFunc("usercxx"), mPrtLevel(2), mFgPutVar(false) | 
|---|
| 19 | { | 
|---|
| 20 | mIncList.resize(0); | 
|---|
| 21 | mCallArgs.resize(0); | 
|---|
| 22 |  | 
|---|
| 23 | mIncImportList.resize(0); | 
|---|
| 24 | mModuleImportList.resize(0); | 
|---|
| 25 |  | 
|---|
| 26 | // La liste de tous les modules que l'on peut ajouter | 
|---|
| 27 | mModuleImportDefaultList.resize(0); | 
|---|
| 28 | mModuleImportDefaultList.push_back("Samba"); | 
|---|
| 29 | mModuleImportDefaultList.push_back("SkyMap"); | 
|---|
| 30 | mModuleImportDefaultList.push_back("SkyT"); | 
|---|
| 31 | mModuleImportDefaultList.push_back("FitsIOServer"); | 
|---|
| 32 | mModuleImportDefaultList.push_back("IFFTW"); | 
|---|
| 33 | mModuleImportDefaultList.push_back("LinAlg"); | 
|---|
| 34 | mModuleImportDefaultList.push_back("XAstroPack"); | 
|---|
| 35 |  | 
|---|
| 36 | // On enregistre les nouvelles commandes | 
|---|
| 37 | string hgrp = "CxxExecutorCmd"; | 
|---|
| 38 | string usage,kw; | 
|---|
| 39 |  | 
|---|
| 40 | kw = "c++exec"; | 
|---|
| 41 | usage = "c++exec: Execute the following c++ user code\n"; | 
|---|
| 42 | usage+= "Usage: c++exec c++ user code\n"; | 
|---|
| 43 | usage+= "Warning: c++ user code can be found in \"TmpDir/"+mDefRoot+".h\"\n"; | 
|---|
| 44 | usage+= "         total generated code can be found in \"TmpDir/"+mDefRoot+".cc\""; | 
|---|
| 45 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
| 46 |  | 
|---|
| 47 | kw = "c++execfrf"; | 
|---|
| 48 | usage = "c++execfrf: Execute c++ user_code [user_function_code]\n"; | 
|---|
| 49 | usage+= "Usage: c++execfrf fileuser.cc [fileuserfct.cc]\n"; | 
|---|
| 50 | usage+= "Warning: total generated code can be found in \"TmpDir/"+mDefRoot+".cc\""; | 
|---|
| 51 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
| 52 |  | 
|---|
| 53 | kw = "c++args"; | 
|---|
| 54 | usage = "c++args: Define user function arguments for c++exec and c++execfrf\n"; | 
|---|
| 55 | usage+= "Usage: c++args arg1 arg2 arg3 ...\n"; | 
|---|
| 56 | usage+= "       c++args -? : give current arguments\n"; | 
|---|
| 57 | usage+= "       c++args    : reset current arguments"; | 
|---|
| 58 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
| 59 |  | 
|---|
| 60 | kw = "c++create"; | 
|---|
| 61 | usage = "c++create: create a file \"file.cc\" to be used by spiapp\n"; | 
|---|
| 62 | usage+= "Usage: c++create file.cc func c++ user code...\n"; | 
|---|
| 63 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
| 64 |  | 
|---|
| 65 | kw = "c++createfrf"; | 
|---|
| 66 | usage = "c++createfrf: create a file \"file.cc\" to be used by spiapp\n"; | 
|---|
| 67 | usage+= "        with a user file code \"fileuser.cc\"\n"; | 
|---|
| 68 | usage+= "        and an optional user function code \"fileuserfct.cc\"\n"; | 
|---|
| 69 | usage+= "Usage: c++createfrf file.cc func fileuser.cc [fileuserfct.cc]\n"; | 
|---|
| 70 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
| 71 |  | 
|---|
| 72 | kw = "c++compile"; | 
|---|
| 73 | usage = "c++compile: compile a file (file.cc -> file.so)\n"; | 
|---|
| 74 | usage+= "Usage: c++compile file\n"; | 
|---|
| 75 | usage+= "Warning: give \"file\" or \"file.so\" to create \"file.so\" from \"file.cc\"\n"; | 
|---|
| 76 | usage+= "       : to be used before c++link"; | 
|---|
| 77 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
| 78 |  | 
|---|
| 79 | kw = "c++link"; | 
|---|
| 80 | usage = "c++link: link function \"func\" in file.so to spiapp\n"; | 
|---|
| 81 | usage+= "Usage: c++link file.so func"; | 
|---|
| 82 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
| 83 |  | 
|---|
| 84 | kw = "c++include"; | 
|---|
| 85 | usage = "c++include: add personnal includes to be used by executor\n"; | 
|---|
| 86 | usage+= "Usage: c++include myinc1.h myinc2.h ...\n"; | 
|---|
| 87 | usage+= "       c++include -? : list current additionnal include files\n"; | 
|---|
| 88 | usage+= "       c++include    : reset to no additionnal include files\n"; | 
|---|
| 89 | usage+= "Warning: to be used before c++create c++compile c++exec..."; | 
|---|
| 90 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
| 91 |  | 
|---|
| 92 | kw = "c++compileopt"; | 
|---|
| 93 | usage = "c++compileopt: add personnal compile options\n"; | 
|---|
| 94 | usage+= "Usage: c++compileopt -g -O5 -IMy_Inc_Dir ...\n"; | 
|---|
| 95 | usage+= "       c++compileopt -? : list current additionnal compile options\n"; | 
|---|
| 96 | usage+= "       c++compileopt    : reset to no additionnal compile options\n"; | 
|---|
| 97 | usage+= "Warning: to be used before c++create c++compile c++exec ..."; | 
|---|
| 98 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
| 99 |  | 
|---|
| 100 | kw = "c++linkopt"; | 
|---|
| 101 | usage = "c++linkopt: add personnal link options\n"; | 
|---|
| 102 | usage+= "Usage: c++linkopt -g -O5 ...\n"; | 
|---|
| 103 | usage+= "       c++linkopt -? : list current additionnal link options\n"; | 
|---|
| 104 | usage+= "       c++linkopt    : reset to no additionnal link options\n"; | 
|---|
| 105 | usage+= "Warning: to be used before c++create c++compile c++exec ..."; | 
|---|
| 106 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
| 107 |  | 
|---|
| 108 | kw = "c++mylibs"; | 
|---|
| 109 | usage = "c++mylibs: add personnal libraries\n"; | 
|---|
| 110 | usage+= "Usage: c++mylibs -LMy_Lib_Dir -lmylib1 -lmylib2 ...\n"; | 
|---|
| 111 | usage+= "       c++mylibs -? : list current additionnal libraries\n"; | 
|---|
| 112 | usage+= "       c++mylibs    : reset to no additionnal libraries\n"; | 
|---|
| 113 | usage+= "Warning: to be used before c++create c++compile c++exec ..."; | 
|---|
| 114 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
| 115 |  | 
|---|
| 116 | kw = "c++import"; | 
|---|
| 117 | usage = "c++import: Sophya additionnal modules to be use in C++ executor\n"; | 
|---|
| 118 | usage+= "Usage: c++import module1 ... : set list of modules to be used by executor\n"; | 
|---|
| 119 | usage+= "       c++import all : set all modules known by executor\n"; | 
|---|
| 120 | usage+= "       c++import     : reset to no additionnal module\n"; | 
|---|
| 121 | usage+= "       c++import -?  : list modules currently used in executor\n"; | 
|---|
| 122 | usage+= "       c++import -?? : list of available modules for executor\n"; | 
|---|
| 123 | usage+= "Warning: to be used before c++create c++compile c++exec ..."; | 
|---|
| 124 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
| 125 |  | 
|---|
| 126 | kw = "c++declareomgvar"; | 
|---|
| 127 | usage = "c++declareomgvar: Activate/Deactivate ObjectManager variables declaration \n"; | 
|---|
| 128 | usage+= "Usage: c++declareomgvar [false/true] \n"; | 
|---|
| 129 | usage+= "   if true, the ObjectManager variables are declared as $varname \n"; | 
|---|
| 130 | usage+= "   no arguments: display the current status of the flag (default=false\n"; | 
|---|
| 131 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
| 132 |  | 
|---|
| 133 | kw = "c++prtlevel"; | 
|---|
| 134 | usage = "c++prtlevel: Print level\n"; | 
|---|
| 135 | usage+= "Usage: c++prtlevel prtlevel\n"; | 
|---|
| 136 | usage+= "       prtlevel=0 : minimum printing\n"; | 
|---|
| 137 | usage+= "       prtlevel=1 : + compiler/linker output\n"; | 
|---|
| 138 | usage+= "       prtlevel=2 : + full infos (default)"; | 
|---|
| 139 | mpiac->RegisterCommand(kw, usage, this, hgrp); | 
|---|
| 140 |  | 
|---|
| 141 | } | 
|---|
| 142 |  | 
|---|
| 143 | /* --Methode-- */ | 
|---|
| 144 | CxxExecutor::~CxxExecutor() | 
|---|
| 145 | { | 
|---|
| 146 | } | 
|---|
| 147 |  | 
|---|
| 148 | /* --Methode-- */ | 
|---|
| 149 | int CxxExecutor::Execute(string& kw, vector<string>& tokens, string& toks) | 
|---|
| 150 | { | 
|---|
| 151 | int rc=0; | 
|---|
| 152 | if(kw == "c++exec") { | 
|---|
| 153 | if(tokens.size()<1) { | 
|---|
| 154 | cout<<"Usage: c++exec c++ user code"<<endl; | 
|---|
| 155 | return(1); | 
|---|
| 156 | } | 
|---|
| 157 | // Pour synchronisation d'execution simultanee | 
|---|
| 158 | ZSync zs(mutx_cxxe);  zs.NOp(); | 
|---|
| 159 |  | 
|---|
| 160 | rc = ExecuteCXX(toks); if(rc) return(1); | 
|---|
| 161 |  | 
|---|
| 162 | } else if(kw == "c++execfrf") { | 
|---|
| 163 | if(tokens.size()<1) { | 
|---|
| 164 | cout<<"Usage: c++execfrf fileuser.cc [fileuserfct.cc]"<<endl; | 
|---|
| 165 | return(1); | 
|---|
| 166 | } | 
|---|
| 167 | // Pour synchronisation d'execution simultanee | 
|---|
| 168 | ZSync zs(mutx_cxxe);  zs.NOp(); | 
|---|
| 169 |  | 
|---|
| 170 | rc = FillUserCode(tokens[0]); if(rc) return(1); | 
|---|
| 171 | if(tokens.size()>1) rc = FillUserFctFrF(tokens[1]); | 
|---|
| 172 | else              rc = FillUserFctFrF(); | 
|---|
| 173 | if(rc) return(1); | 
|---|
| 174 | rc = CrFile();   if(rc) return(1); | 
|---|
| 175 | rc = Compile();  if(rc) return(1); | 
|---|
| 176 | rc = Link();     if(rc) return(1); | 
|---|
| 177 | rc = Call();     if(rc) return(1); | 
|---|
| 178 |  | 
|---|
| 179 | } else if(kw == "c++args") { | 
|---|
| 180 | if(tokens.size()==1) if(tokens[0]=="-?") | 
|---|
| 181 | {cout<<"c++args "<<GetArgs()<<endl; return(0);} | 
|---|
| 182 | FillArgs(tokens); | 
|---|
| 183 |  | 
|---|
| 184 | } else if(kw == "c++create") { | 
|---|
| 185 | if(tokens.size()<3) { | 
|---|
| 186 | cout<<"Usage: c++create file.cc func c++ user code ..."<<endl; | 
|---|
| 187 | return(1); | 
|---|
| 188 | } | 
|---|
| 189 | // Pour synchronisation d'execution simultanee | 
|---|
| 190 | ZSync zs(mutx_cxxe);  zs.NOp(); | 
|---|
| 191 |  | 
|---|
| 192 | rc = FillUserCode(toks,2);        if(rc) return(1); | 
|---|
| 193 | rc = FillUserFctFrS();            if(rc) return(1); | 
|---|
| 194 | rc = CrFile(tokens[0],tokens[1]); if(rc) return(1); | 
|---|
| 195 |  | 
|---|
| 196 | } else if(kw == "c++createfrf") { | 
|---|
| 197 | if(tokens.size()<3) { | 
|---|
| 198 | cout<<"Usage: c++createfrf file.cc func fileuser.cc [fileuserfct.cc]"<<endl; | 
|---|
| 199 | return(1); | 
|---|
| 200 | } | 
|---|
| 201 | // Pour synchronisation d'execution simultanee | 
|---|
| 202 | ZSync zs(mutx_cxxe);  zs.NOp(); | 
|---|
| 203 |  | 
|---|
| 204 | rc = FillUserCode(tokens[2]); if(rc) return(1); | 
|---|
| 205 | if(tokens.size()>3) rc = FillUserFctFrF(tokens[3]); | 
|---|
| 206 | else              rc = FillUserFctFrF(tokens[3]); | 
|---|
| 207 | if(rc) return(1); | 
|---|
| 208 | rc = CrFile(tokens[0],tokens[1]); if(rc) return(1); | 
|---|
| 209 |  | 
|---|
| 210 | } else if(kw == "c++compile") { | 
|---|
| 211 | // Pour synchronisation d'execution simultanee | 
|---|
| 212 | ZSync zs(mutx_cxxe);  zs.NOp(); | 
|---|
| 213 |  | 
|---|
| 214 | if(tokens.size()>=1) rc = Compile(tokens[0]); | 
|---|
| 215 | else                 rc = Compile(); | 
|---|
| 216 | if(rc) return(1); | 
|---|
| 217 |  | 
|---|
| 218 | } else if(kw == "c++link") { | 
|---|
| 219 | // Pour synchronisation d'execution simultanee | 
|---|
| 220 | ZSync zs(mutx_cxxe);  zs.NOp(); | 
|---|
| 221 |  | 
|---|
| 222 | if(tokens.size()>=2)      rc = Link(tokens[0],tokens[1]); | 
|---|
| 223 | else if(tokens.size()>=1) rc = Link(tokens[0]); | 
|---|
| 224 | else                      rc = Link(); | 
|---|
| 225 | if(rc) return(1); | 
|---|
| 226 |  | 
|---|
| 227 | } else if(kw == "c++include") { | 
|---|
| 228 | if(tokens.size()==1) if(tokens[0]=="-?") | 
|---|
| 229 | {cout<<"c++include "<<GetInclude()<<endl; return(0);} | 
|---|
| 230 | FillInclude(tokens); | 
|---|
| 231 |  | 
|---|
| 232 | } else if(kw == "c++compileopt") { | 
|---|
| 233 | if(tokens.size()==1) if(tokens[0]=="-?") | 
|---|
| 234 | {cout<<"c++compileopt "<<GetCompileOpt()<<endl; return(0);} | 
|---|
| 235 | FillCompileOpt(tokens); | 
|---|
| 236 |  | 
|---|
| 237 | } else if(kw == "c++linkopt") { | 
|---|
| 238 | if(tokens.size()==1) if(tokens[0]=="-?") | 
|---|
| 239 | {cout<<"c++linkopt "<<GetLinkOpt()<<endl; return(0);} | 
|---|
| 240 | FillLinkOpt(tokens); | 
|---|
| 241 |  | 
|---|
| 242 | } else if(kw == "c++mylibs") { | 
|---|
| 243 | if(tokens.size()==1) if(tokens[0]=="-?") | 
|---|
| 244 | {cout<<"c++mylibs "<<GetLinkLibs()<<endl; return(0);} | 
|---|
| 245 | FillLinkLibs(tokens); | 
|---|
| 246 |  | 
|---|
| 247 | } else if(kw == "c++import") { | 
|---|
| 248 | if(tokens.size()==1) { | 
|---|
| 249 | if(tokens[0]=="-?") | 
|---|
| 250 | {cout<<"c++import "<<GetModuleImport()<<endl; return(0);} | 
|---|
| 251 | if(tokens[0]=="-??") { | 
|---|
| 252 | cout<<"c++import possibilities :"<<endl; | 
|---|
| 253 | if(mModuleImportDefaultList.size()>0) { | 
|---|
| 254 | for(uint_4 i=0;i<mModuleImportDefaultList.size();i++) | 
|---|
| 255 | cout<<" "<<mModuleImportDefaultList[i]; | 
|---|
| 256 | cout<<endl; | 
|---|
| 257 | } | 
|---|
| 258 | return(0); | 
|---|
| 259 | } | 
|---|
| 260 | } | 
|---|
| 261 | FillModuleImport(tokens); | 
|---|
| 262 | } else if(kw == "c++declareomgvar") { | 
|---|
| 263 | if (tokens.size() <1) { | 
|---|
| 264 | string fgstat = (mFgPutVar) ? "TRUE" : "FALSE" ; | 
|---|
| 265 | cout << " c++declareomgvar: Current flag status: " <<  fgstat << endl; | 
|---|
| 266 | } | 
|---|
| 267 | else { | 
|---|
| 268 | if (tokens[0] == "true") DeclareObjMgrVar(true); | 
|---|
| 269 | else  if (tokens[0] == "false") DeclareObjMgrVar(false); | 
|---|
| 270 | } | 
|---|
| 271 | } else if(kw == "c++prtlevel") { | 
|---|
| 272 | if(tokens.size()==1) if(tokens[0]=="-?") | 
|---|
| 273 | {cout<<"c++prtlevel prtlevel = "<<mPrtLevel<<endl; return(0);} | 
|---|
| 274 | if(tokens.size()>0) { | 
|---|
| 275 | int lp=atoi(tokens[0].c_str()); if(lp<0) lp=0; | 
|---|
| 276 | mPrtLevel=(uint_2) lp; | 
|---|
| 277 | } else mPrtLevel=2; | 
|---|
| 278 |  | 
|---|
| 279 | } | 
|---|
| 280 |  | 
|---|
| 281 | return(0); | 
|---|
| 282 | } | 
|---|
| 283 |  | 
|---|
| 284 | /* --Methode-- */ | 
|---|
| 285 | bool  CxxExecutor::IsThreadable(string const & kw) | 
|---|
| 286 | { | 
|---|
| 287 | if ( (kw == "c++exec") || (kw == "c++execfrf") || | 
|---|
| 288 | (kw == "c++create") || (kw == "c++createfrf") || | 
|---|
| 289 | (kw == "c++compile") || (kw == "c++link") )   return true; | 
|---|
| 290 | else return false; | 
|---|
| 291 | } | 
|---|
| 292 |  | 
|---|
| 293 | /* --Methode-- */ | 
|---|
| 294 | int  CxxExecutor::ExecuteCXX(string usercode,string userfct) | 
|---|
| 295 | { | 
|---|
| 296 | int rc=0; | 
|---|
| 297 | rc = FillUserCode(usercode,0); if(rc) return(1); | 
|---|
| 298 | rc = FillUserFctFrS(userfct);  if(rc) return(1); | 
|---|
| 299 | rc = CrFile();   if(rc) return(1); | 
|---|
| 300 | rc = Compile();  if(rc) return(1); | 
|---|
| 301 | rc = Link();     if(rc) return(1); | 
|---|
| 302 | rc = Call();     if(rc) return(1); | 
|---|
| 303 | return 0; | 
|---|
| 304 | } | 
|---|
| 305 |  | 
|---|
| 306 | /* --Methode-- */ | 
|---|
| 307 | int CxxExecutor::CrFile(string cfilename,string func) | 
|---|
| 308 | // Si un nom n'est pas precise alors TmpDir/cxx_spiapp.cc | 
|---|
| 309 | { | 
|---|
| 310 | if(cfilename.size()<1) cfilename = TmpDir() + mDefRoot + ".cc"; | 
|---|
| 311 |  | 
|---|
| 312 | if(func.size()<1) func = mDefFunc; | 
|---|
| 313 |  | 
|---|
| 314 | ofstream os(cfilename.c_str(),ios::out); | 
|---|
| 315 | if(!os) | 
|---|
| 316 | {cout<<"CxxExecutor::CrFile: unable to open "<<cfilename<<endl; | 
|---|
| 317 | return 1;} | 
|---|
| 318 |  | 
|---|
| 319 | PutInclude(os); | 
|---|
| 320 | os<<endl; | 
|---|
| 321 |  | 
|---|
| 322 | PutIncludeUser(os); | 
|---|
| 323 | os<<endl; | 
|---|
| 324 |  | 
|---|
| 325 | os<<"//-------------------------------------------------//"<<endl; | 
|---|
| 326 | os<<"//----------------- User Functions ----------------//"<<endl; | 
|---|
| 327 | os<<"//-------------------------------------------------//"<<endl; | 
|---|
| 328 | if(mUserFctFn.size()>0) os<<"#include \""<<mUserFctFn<<"\""<<endl; | 
|---|
| 329 | os<<endl; | 
|---|
| 330 |  | 
|---|
| 331 |  | 
|---|
| 332 | os<<"extern \"C\" {"<<endl; | 
|---|
| 333 | os<<"  int "<<func<<"( vector<string>& args );"<<endl; | 
|---|
| 334 | os<<"}"<<endl<<endl; | 
|---|
| 335 | os<<"int "<<func<<"( vector<string>& args )"<<endl; | 
|---|
| 336 | os<<"{"<<endl; | 
|---|
| 337 | os<<"// Some definitions to help using spiapp;"<<endl; | 
|---|
| 338 | os<<"NamedObjMgr omg;"<<endl; | 
|---|
| 339 | os<<"Services2NObjMgr& srvo = *omg.GetServiceObj();"<<endl; | 
|---|
| 340 | os<<endl; | 
|---|
| 341 |  | 
|---|
| 342 | PutObject(os); | 
|---|
| 343 | os<<endl; | 
|---|
| 344 |  | 
|---|
| 345 | if (mFgPutVar) PutVar(os); | 
|---|
| 346 | os<<endl; | 
|---|
| 347 |  | 
|---|
| 348 | os<<"//--------------------------------------------//"<<endl; | 
|---|
| 349 | os<<"//----------------- User Code ----------------//"<<endl; | 
|---|
| 350 | os<<"//--------------------------------------------//"<<endl; | 
|---|
| 351 | if(mUserCodeFn.size()>0) os<<"#include \""<<mUserCodeFn<<"\""<<endl; | 
|---|
| 352 | os<<endl; | 
|---|
| 353 |  | 
|---|
| 354 | os<<"return 0;"<<endl; | 
|---|
| 355 | os<<"}"<<endl; | 
|---|
| 356 |  | 
|---|
| 357 | if(mPrtLevel>1) | 
|---|
| 358 | cout<<"File "<<cfilename<<" for function "<<func<<" created :"<<endl; | 
|---|
| 359 | if(mPrtLevel>1 && mUserCodeFn.size()>0) | 
|---|
| 360 | cout<<"  User code was in file "<<mUserCodeFn<<endl; | 
|---|
| 361 | if(mPrtLevel>1 && mUserFctFn.size()>0) | 
|---|
| 362 | cout<<"  User function code was in file "<<mUserFctFn<<endl; | 
|---|
| 363 | return 0; | 
|---|
| 364 | } | 
|---|
| 365 |  | 
|---|
| 366 | /* --Methode-- */ | 
|---|
| 367 | void CxxExecutor::PutInclude(ofstream& os) | 
|---|
| 368 | { | 
|---|
| 369 | os<<"#include \"machdefs.h\""<<endl<<endl; | 
|---|
| 370 |  | 
|---|
| 371 | os<<"//---- System et stdc++ include files"<<endl | 
|---|
| 372 | <<"#include <stdio.h>"<<endl | 
|---|
| 373 | <<"#include <stdlib.h>"<<endl | 
|---|
| 374 | <<"#include <math.h>"<<endl | 
|---|
| 375 | <<"#include <ctype.h>"<<endl | 
|---|
| 376 | <<"#include <string.h>"<<endl | 
|---|
| 377 | <<"#include <iostream>"<<endl | 
|---|
| 378 | <<"#include <fstream>"<<endl | 
|---|
| 379 | <<"#include <complex>"<<endl | 
|---|
| 380 | <<endl | 
|---|
| 381 |  | 
|---|
| 382 | <<"#include <typeinfo>"<<endl | 
|---|
| 383 | <<"#include <string>"<<endl | 
|---|
| 384 | <<"#include <vector>"<<endl | 
|---|
| 385 | <<"#include <map>"<<endl | 
|---|
| 386 | <<"#include <functional>"<<endl | 
|---|
| 387 | <<"#include <list>"<<endl | 
|---|
| 388 | <<endl | 
|---|
| 389 |  | 
|---|
| 390 | #ifdef SANS_EVOLPLANCK | 
|---|
| 391 | <<"//---- Peida include files"<<endl | 
|---|
| 392 | <<"#include \"toutpeida.h\""<<endl | 
|---|
| 393 | #else | 
|---|
| 394 | // Si on enleve sopnamsp.h (using namespace SOPHYA), il faudra accoler | 
|---|
| 395 | // SOPHYA:: à toutes les déclarations automatiques - Reza, 10/09/2004 | 
|---|
| 396 | <<"//---- Sophya include files"<<endl | 
|---|
| 397 | <<"#include \"sopnamsp.h\""<<endl  // using namespace SOPHYA | 
|---|
| 398 | <<"#include \"basetools.h\""<<endl | 
|---|
| 399 | <<"#include \"systools.h\""<<endl | 
|---|
| 400 | <<"#include \"sutils.h\""<<endl | 
|---|
| 401 | <<"#include \"ntools.h\""<<endl | 
|---|
| 402 | <<"#include \"array.h\""<<endl | 
|---|
| 403 | <<"#include \"histats.h\""<<endl | 
|---|
| 404 | <<endl | 
|---|
| 405 | #endif | 
|---|
| 406 |  | 
|---|
| 407 | <<"//---- Spiapp include files"<<endl | 
|---|
| 408 | <<"#include \"nobjmgr.h\""<<endl | 
|---|
| 409 | <<"#include \"servnobjm.h\""<<endl | 
|---|
| 410 | <<endl; | 
|---|
| 411 |  | 
|---|
| 412 | os<<"//---- Include files from additionnal modules"<<endl; | 
|---|
| 413 | if(mIncImportList.size()>0) | 
|---|
| 414 | for(uint_4 i=0;i<mIncImportList.size();i++) | 
|---|
| 415 | os<<"#include \""<<mIncImportList[i]<<"\""<<endl; | 
|---|
| 416 | os<<endl; | 
|---|
| 417 |  | 
|---|
| 418 | os<<"//---- function to compare bits on double \n" | 
|---|
| 419 | <<"int_8 BitCmp64(double v,int_8 flg) \n" | 
|---|
| 420 | <<"{return ((int_8)((v<0.) ? v-0.1 : v+0.1))&flg;} \n" | 
|---|
| 421 | <<endl; | 
|---|
| 422 |  | 
|---|
| 423 | os<<"//---- function for Adding and displaying Objects  " << endl; | 
|---|
| 424 | os<<"void Keep_Object(AnyDataObj & obj, string const & nom) \n{ \n" | 
|---|
| 425 | <<"  string name = nom; \n  NamedObjMgr om; \n" | 
|---|
| 426 | <<"  if (om.GetObj(name)) \n" | 
|---|
| 427 | <<"    cerr << \"KeepObj()/Warning Already kept object \" << endl; \n" | 
|---|
| 428 | <<"  else om.AddObj(obj, name); \n" | 
|---|
| 429 | <<"} \n" << endl; | 
|---|
| 430 | os<<"void Display_Object(AnyDataObj & obj, string const & opt, string const & nom) \n { \n" | 
|---|
| 431 | <<"  string name = nom; \n  NamedObjMgr om; \n" | 
|---|
| 432 | <<"  if (!om.GetObj(name)) \n" | 
|---|
| 433 | <<"    om.AddObj(obj, name); \n" | 
|---|
| 434 | <<"  om.DisplayObj(name, opt); \n" | 
|---|
| 435 | <<"} \n" << endl; | 
|---|
| 436 | os<<"//---- function for getting and setting ObjectManager variables  " << endl; | 
|---|
| 437 | os<<"void Set_ObjMgrVar(MuTyV v, string const & nom) \n{ \n" | 
|---|
| 438 | <<"  NamedObjMgr om; \n" | 
|---|
| 439 | <<"  om.SetVar(nom, (string)v); \n" | 
|---|
| 440 | <<"} \n" << endl; | 
|---|
| 441 | os<<"MuTyV Get_ObjMgrVar(const char * nom) \n{ \n" | 
|---|
| 442 | <<"  string name = nom; NamedObjMgr om; \n" | 
|---|
| 443 | <<"  MuTyV v = om.GetVar(name); \n" | 
|---|
| 444 | <<"  return v; \n" | 
|---|
| 445 | <<"} \n" << endl; | 
|---|
| 446 |  | 
|---|
| 447 | os<<"//---- Macro for Objects and variables saving"<<endl | 
|---|
| 448 | <<"#define KeepObj(obj) Keep_Object(obj, #obj)"<<endl | 
|---|
| 449 | <<"#define GetOMVar(var) Get_ObjMgrVar( #var )"<<endl | 
|---|
| 450 | <<"#define SetOMVar(var) Set_ObjMgrVar(var, #var )"<<endl | 
|---|
| 451 | <<endl; | 
|---|
| 452 |  | 
|---|
| 453 | os<<"//---- Macro Displaying objects and command execution"<<endl; | 
|---|
| 454 | os<<"#define DisplayObj(obj, att) Display_Object(obj, att, #obj); \n" << endl; | 
|---|
| 455 | os<<"#define ExecuteCommand(cmd) srvo.ExecuteCommand(cmd); \n" << endl; | 
|---|
| 456 |  | 
|---|
| 457 | return; | 
|---|
| 458 | } | 
|---|
| 459 |  | 
|---|
| 460 | /* --Methode-- */ | 
|---|
| 461 | void CxxExecutor::PutIncludeUser(ofstream& os) | 
|---|
| 462 | { | 
|---|
| 463 | if(mIncList.size()<1) return; | 
|---|
| 464 | for(uint_4 i=0;i<mIncList.size();i++) | 
|---|
| 465 | os<<"#include \""<<mIncList[i]<<"\""<<endl; | 
|---|
| 466 | } | 
|---|
| 467 |  | 
|---|
| 468 | /* --Methode-- */ | 
|---|
| 469 | void CxxExecutor::PutObject(ofstream& os) | 
|---|
| 470 | { | 
|---|
| 471 | NamedObjMgr omg; | 
|---|
| 472 | NObjMgrAdapter* objmgrad; | 
|---|
| 473 | vector<string> objlist; | 
|---|
| 474 | string patt = "*"; | 
|---|
| 475 | omg.GetObjList(patt,objlist); | 
|---|
| 476 | int nobjs = objlist.size(); | 
|---|
| 477 |  | 
|---|
| 478 | os<<"//-------------- Object List --------------"<<endl; | 
|---|
| 479 | os<<"//Number of objects = "<<nobjs<<endl; | 
|---|
| 480 | os<<"string ___nomobj;"<<endl<<endl; | 
|---|
| 481 | if(nobjs<=0) return; | 
|---|
| 482 |  | 
|---|
| 483 | string dir,nobj,stmp,obtype; | 
|---|
| 484 | for(int i=0;i<nobjs;i++) { | 
|---|
| 485 | objmgrad = omg.GetObjAdapter(objlist[i]); | 
|---|
| 486 | omg.ParseObjectName(objlist[i],dir,nobj); | 
|---|
| 487 | obtype = objmgrad->GetDataObjType(); | 
|---|
| 488 | stmp = "___" + nobj; | 
|---|
| 489 |  | 
|---|
| 490 | os<<"___nomobj = \""<<nobj<<"\";"<<endl; | 
|---|
| 491 | os<<obtype<<"* "<<stmp | 
|---|
| 492 | <<" = dynamic_cast< "<<obtype<<" * >(omg.GetObj(___nomobj));"<<endl; | 
|---|
| 493 | #ifdef SANS_EVOLPLANCK | 
|---|
| 494 | os<<"if("<<stmp<<"==NULL) { \n" | 
|---|
| 495 | <<" long mExcErr = nullPtrErr; \n" | 
|---|
| 496 | <<" cerr << \"CxxExecutor::PutObject: Non existing object " | 
|---|
| 497 | <<" ... please update file \\n \" ;" | 
|---|
| 498 | <<" throw mExcErr ; \n } "<<endl; | 
|---|
| 499 | #else | 
|---|
| 500 | os<<"if("<<stmp<<"==NULL) throw NullPtrError" | 
|---|
| 501 | <<"(\"CxxExecutor::PutObject: Non existing object "<<nobj | 
|---|
| 502 | <<"... please update file\");"<<endl; | 
|---|
| 503 | #endif | 
|---|
| 504 | os<<obtype<<"& "<<nobj<<" = (*"<<stmp<<");"<<endl<<endl; | 
|---|
| 505 | } | 
|---|
| 506 |  | 
|---|
| 507 | return; | 
|---|
| 508 | } | 
|---|
| 509 |  | 
|---|
| 510 | /* --Methode-- */ | 
|---|
| 511 | void CxxExecutor::PutVar(ofstream& os) | 
|---|
| 512 | { | 
|---|
| 513 | os<<"//-------------- Variable List --------------"<<endl; | 
|---|
| 514 | NamedObjMgr omg; | 
|---|
| 515 | DVList& varlist = omg.GetVarList(); | 
|---|
| 516 | // varlist.Show(); varlist.Print(); | 
|---|
| 517 | DVList::ValList::const_iterator it; | 
|---|
| 518 | for(it=varlist.Begin(); it!=varlist.End(); it++) { | 
|---|
| 519 | string key = (*it).first; | 
|---|
| 520 | if (isalpha(key[0]) ) { | 
|---|
| 521 | os<<"___nomobj = \""<<key<<"\";"<<endl; | 
|---|
| 522 | os<<"MuTyV & $"<<key<<" = omg.GetVarList().Get(___nomobj);"<<endl; | 
|---|
| 523 | } | 
|---|
| 524 | } | 
|---|
| 525 |  | 
|---|
| 526 | return; | 
|---|
| 527 | } | 
|---|
| 528 |  | 
|---|
| 529 | /* --Methode-- */ | 
|---|
| 530 | int CxxExecutor::FillUserCode(string& usercode,uint_4 first) | 
|---|
| 531 | // User code is read from input. | 
|---|
| 532 | // - first is the first position in the "string" where the code starts | 
|---|
| 533 | // - Code is put into file "TmpDir/cxx_spiapp.h". | 
|---|
| 534 | { | 
|---|
| 535 | mUserCodeFn = ""; | 
|---|
| 536 |  | 
|---|
| 537 | // get the string part which is after word "first" | 
|---|
| 538 | string code = usercode; | 
|---|
| 539 | if(code.size()<=0) {cout<<"CxxExecutor::FillUserCode: no user code"<<endl; | 
|---|
| 540 | return 1;} | 
|---|
| 541 | size_t q; | 
|---|
| 542 | for(uint_4 i=0;i<=first;i++) { | 
|---|
| 543 | q = code.find_first_not_of(" \t"); | 
|---|
| 544 | if(q>=code.size()) {code=""; break;} | 
|---|
| 545 | code = code.substr(q); | 
|---|
| 546 | if(i==first) break; | 
|---|
| 547 | q = code.find_first_of(" \t"); | 
|---|
| 548 | if(q>=code.size()) {code=""; break;} | 
|---|
| 549 | code = code.substr(q); | 
|---|
| 550 | } | 
|---|
| 551 | if(code.size()<=0) | 
|---|
| 552 | {cout<<"CxxExecutor::FillUserCode: no user code after "<<first<<endl; | 
|---|
| 553 | return 1;} | 
|---|
| 554 |  | 
|---|
| 555 | // Fill the file with user code | 
|---|
| 556 | mUserCodeFn = TmpDir() + mDefRoot + ".h"; | 
|---|
| 557 | ofstream os(mUserCodeFn.c_str(),ios::out); | 
|---|
| 558 | if(!os) {cout<<"CxxExecutor::FillUserCode: unable to open " | 
|---|
| 559 | <<mUserCodeFn<<endl;  mUserCodeFn = ""; return 1;} | 
|---|
| 560 | os<<code<<endl; | 
|---|
| 561 | if(mPrtLevel>1) | 
|---|
| 562 | cout<<"User code filled from standard input into "<<mUserCodeFn<<endl; | 
|---|
| 563 | return 0; | 
|---|
| 564 | } | 
|---|
| 565 |  | 
|---|
| 566 | /* --Methode-- */ | 
|---|
| 567 | int CxxExecutor::FillUserFctFrS(string userfctcode) | 
|---|
| 568 | // - Fill user Fonction code from string "userfct" | 
|---|
| 569 | // - Code is put into file "TmpDir/cxx_spiapp_fct.h". | 
|---|
| 570 | { | 
|---|
| 571 | mUserFctFn  = ""; | 
|---|
| 572 | if(userfctcode.size()<1) return 0; | 
|---|
| 573 | mUserFctFn  = TmpDir() + mDefRoot + "_fct.h"; | 
|---|
| 574 | ofstream os(mUserFctFn.c_str(),ios::out); | 
|---|
| 575 | if(!os) {cout<<"CxxExecutor::FillUserFctFrS: unable to open " | 
|---|
| 576 | <<mUserFctFn<<endl;  mUserFctFn = ""; return 1;} | 
|---|
| 577 | os<<userfctcode<<endl; | 
|---|
| 578 | if(mPrtLevel>1) | 
|---|
| 579 | cout<<"User Function code filled from standard input into "<<mUserFctFn<<endl; | 
|---|
| 580 | return 0; | 
|---|
| 581 | } | 
|---|
| 582 |  | 
|---|
| 583 | /* --Methode-- */ | 
|---|
| 584 | int CxxExecutor::FillUserCode(string filename) | 
|---|
| 585 | // User code is read from "filename". | 
|---|
| 586 | { | 
|---|
| 587 | mUserCodeFn = filename; | 
|---|
| 588 | if(mPrtLevel>1 && mUserCodeFn.size()>0) | 
|---|
| 589 | cout<<"User code filled from file "<<mUserCodeFn<<endl; | 
|---|
| 590 | return 0; | 
|---|
| 591 | } | 
|---|
| 592 |  | 
|---|
| 593 | /* --Methode-- */ | 
|---|
| 594 | int CxxExecutor::FillUserFctFrF(string filefctname) | 
|---|
| 595 | // User function code is read from "filefctname". | 
|---|
| 596 | { | 
|---|
| 597 | mUserFctFn = filefctname; | 
|---|
| 598 | if(mPrtLevel>1 && mUserFctFn.size()>0) | 
|---|
| 599 | cout<<"User Function code filled from file "<<mUserFctFn<<endl; | 
|---|
| 600 | return 0; | 
|---|
| 601 | } | 
|---|
| 602 |  | 
|---|
| 603 | /* --Methode-- */ | 
|---|
| 604 | int CxxExecutor::Compile(string rootfilename) | 
|---|
| 605 | //--------------------------------------------------------// | 
|---|
| 606 | // rootfilename = | name           | "" ou (default)      // | 
|---|
| 607 | //--------------------------------------------------------// | 
|---|
| 608 | // fichier .cc    | name.cc        | TmpDir/cxx_spiapp.cc // | 
|---|
| 609 | //                | ../dir/name.cc |                      // | 
|---|
| 610 | // fichier .o     | TmpDir/name.o  | TmpDir/cxx_spiapp.o  // | 
|---|
| 611 | // fichier .so    | TmpDir/name.so | TmpDir/cxx_spiapp.so // | 
|---|
| 612 | //--------------------------------------------------------// | 
|---|
| 613 | { | 
|---|
| 614 | if(rootfilename.size()<1) rootfilename = TmpDir() + mDefRoot; | 
|---|
| 615 | if(mPrtLevel>1) cout<<"Compile "<<rootfilename<<endl; | 
|---|
| 616 |  | 
|---|
| 617 | int rc; | 
|---|
| 618 | #ifdef SANS_EVOLPLANCK | 
|---|
| 619 | CxxCompilerLinker cxx; | 
|---|
| 620 | string sophlib = " -lPIE -lm "; | 
|---|
| 621 | cxx.AddLinkOptions(sophlib); | 
|---|
| 622 | #else | 
|---|
| 623 | CxxCompilerLinker cxx(true,true,true); | 
|---|
| 624 | #endif | 
|---|
| 625 | if(TmpDir().size()>0) cxx.SetTmpDir(TmpDir()); | 
|---|
| 626 | if(mPrtLevel>0) cxx.SetVerbose(true); | 
|---|
| 627 | else          cxx.SetVerbose(false); | 
|---|
| 628 |  | 
|---|
| 629 | // Compilation | 
|---|
| 630 | string fcc = rootfilename + ".cc"; | 
|---|
| 631 | string fo  = ""; | 
|---|
| 632 | cxx.AddCompileOptions(mCompOpt); | 
|---|
| 633 | rc = cxx.Compile(fcc,fo); | 
|---|
| 634 | if(mPrtLevel>1) cout << "Compilation rc = "<<rc<< endl; | 
|---|
| 635 | if(rc) return 1; | 
|---|
| 636 |  | 
|---|
| 637 | // Fabrication Shared Lib. | 
|---|
| 638 | string fso = ""; | 
|---|
| 639 | cxx.AddLinkOptions(mLinkOpt); | 
|---|
| 640 | cxx.AddLinkOptions(mMyLibs); | 
|---|
| 641 | rc = cxx.BuildSO(fo,fso); | 
|---|
| 642 | if(mPrtLevel>1) cout << "Shared Library rc = "<<rc<< endl; | 
|---|
| 643 | if(rc) return 2; | 
|---|
| 644 |  | 
|---|
| 645 | return 0; | 
|---|
| 646 | } | 
|---|
| 647 |  | 
|---|
| 648 | /* --Methode-- */ | 
|---|
| 649 | //int CxxExecutor::Compile(string rootfilename) | 
|---|
| 650 | // Ne marche pas si TmpDir != "" | 
|---|
| 651 | //{ | 
|---|
| 652 | //if(rootfilename.size()<1) rootfilename = mDefRoot; | 
|---|
| 653 | //if(mPrtLevel>1) cout<<"Compile: "<<rootfilename<<endl; | 
|---|
| 654 | //int rc = 0; | 
|---|
| 655 | //rc = CrMakefile(); | 
|---|
| 656 | //if(rc) return(1); | 
|---|
| 657 | //string make  = ""; | 
|---|
| 658 | //make += "make -f " + mDefRoot + "_Makefile"; | 
|---|
| 659 | //make += " CXXFLAGS=\"" + mCompOpt + "\""; | 
|---|
| 660 | //make += " LDFLAGS=\""  + mLinkOpt + "\""; | 
|---|
| 661 | //make += " MYLIBS=\""   + mMyLibs  + "\""; | 
|---|
| 662 | //make += " " + rootfilename; | 
|---|
| 663 | //rc = system(make.c_str()); | 
|---|
| 664 | //if(rc) | 
|---|
| 665 | //  {cout<<"CxxExecutor::Compile : \n"<<make<<" Failed"<<endl; | 
|---|
| 666 | //   return 1000+rc;} | 
|---|
| 667 | //return 0; | 
|---|
| 668 | //} | 
|---|
| 669 |  | 
|---|
| 670 | /* --Methode-- */ | 
|---|
| 671 | //int CxxExecutor::CrMakefile(void) | 
|---|
| 672 | // Ne marche pas si TmpDir != "" | 
|---|
| 673 | //{ | 
|---|
| 674 | //string makename = TmpDir() + mDefRoot + "_Makefile"; | 
|---|
| 675 | //ofstream os(makename.c_str(),ios::out); | 
|---|
| 676 | //if(!os) | 
|---|
| 677 | //  {cout<<"CxxExecutor::CrMakefile: unable to open file for Makefile"<<endl; | 
|---|
| 678 | //   return 1;} | 
|---|
| 679 | //--------------------------------------------------------------------- | 
|---|
| 680 | //os<<"MODULEDECCXXFLAGS := -msg_quiet"<<endl; | 
|---|
| 681 | //os<<"include $(SOPHYABASEREP)/Include/MakefileUser.h"<<endl; | 
|---|
| 682 | //os<<"MYLIBS ="<<endl; | 
|---|
| 683 | //os<<"LIBS = -L$(SLB) -lPI -lextsophya -lsophya -lm"<<endl; | 
|---|
| 684 | //os<<"ifeq ($(MACHEROS),OSF1)"<<endl; | 
|---|
| 685 | //os<<"LIBS := $(LIBS) -lfor"<<endl; | 
|---|
| 686 | //os<<"endif"<<endl; | 
|---|
| 687 | //os<<"ifeq ($(MACHEROS),Linux)"<<endl; | 
|---|
| 688 | //os<<"#LIBS := $(LIBS) -ldl -lf2c"<<endl; | 
|---|
| 689 | //os<<"LIBS := $(LIBS) -ldl -lg2c"<<endl; | 
|---|
| 690 | //os<<"endif"<<endl; | 
|---|
| 691 | //os<<"%.so:%.o"<<endl; | 
|---|
| 692 | //os<<"%:%.cc"<<endl; | 
|---|
| 693 | //os<<"%:%.o"<<endl; | 
|---|
| 694 | //os<<"%.o:%.cc"<<endl; | 
|---|
| 695 | //os<<"%.o:%.c"<<endl; | 
|---|
| 696 | //os<<"%:%.c"<<endl; | 
|---|
| 697 | //os<<endl; | 
|---|
| 698 | //os<<".PRECIOUS: %.so"<<endl; | 
|---|
| 699 | //os<<endl; | 
|---|
| 700 | //os<<"%:%.so"<<endl; | 
|---|
| 701 | //os<<"\t"<<"echo $@ \" made (.so) \""<<endl; | 
|---|
| 702 | //os<<"%.so:%.o"<<endl; | 
|---|
| 703 | //os<<"\t"<<"$(LINK.cc) -shared -o $@ $< $(LIBS) $(MYLIBS)"<<endl; | 
|---|
| 704 | //os<<"%.o:%.cc"<<endl; | 
|---|
| 705 | //os<<"\t"<<"$(COMPILE.cc) -o $@ $<"<<endl; | 
|---|
| 706 | //os<<"%.o:%.c"<<endl; | 
|---|
| 707 | //os<<"\t"<<"$(COMPILE.c) -c $(CFLAGS) $(USERFLAGS) -o $@ $<"<<endl; | 
|---|
| 708 | //--------------------------------------------------------------------- | 
|---|
| 709 | //return 0; | 
|---|
| 710 | //} | 
|---|
| 711 |  | 
|---|
| 712 | /* --Methode-- */ | 
|---|
| 713 | int CxxExecutor::Link(string libname,string func) | 
|---|
| 714 | { | 
|---|
| 715 | if(libname.size()<1) libname = TmpDir() + mDefRoot + ".so"; | 
|---|
| 716 | else               libname = TmpDir() + libname; | 
|---|
| 717 | if(func.size()<1) func = mDefFunc; | 
|---|
| 718 |  | 
|---|
| 719 | NamedObjMgr omg; | 
|---|
| 720 | PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter(); | 
|---|
| 721 |  | 
|---|
| 722 | string key("linkff2"); | 
|---|
| 723 | vector<string> arg; arg.push_back(libname); arg.push_back(func); | 
|---|
| 724 | string toks = libname + " " + func; | 
|---|
| 725 | int rc = mpiac->ExecuteCommand(key,arg,toks); | 
|---|
| 726 | if(mPrtLevel>1) cout<<"Link from "<<libname<<" for function "<<func | 
|---|
| 727 | <<" (rc="<<rc<<")"<<endl; | 
|---|
| 728 | return 0; | 
|---|
| 729 | } | 
|---|
| 730 |  | 
|---|
| 731 | /* --Methode-- */ | 
|---|
| 732 | int CxxExecutor::Call(string func) | 
|---|
| 733 | { | 
|---|
| 734 | if(func.size()<1) func = mDefFunc; | 
|---|
| 735 |  | 
|---|
| 736 | NamedObjMgr omg; | 
|---|
| 737 | PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter(); | 
|---|
| 738 |  | 
|---|
| 739 | string key("call"); | 
|---|
| 740 | vector<string> arg; arg.push_back(func); | 
|---|
| 741 | string toks = func; | 
|---|
| 742 | if(mCallArgs.size()>0) | 
|---|
| 743 | for(uint_4 i=0;i<mCallArgs.size();i++) arg.push_back(mCallArgs[i]); | 
|---|
| 744 | mpiac->ExecuteCommand(key,arg,toks); | 
|---|
| 745 | return 0; | 
|---|
| 746 | } | 
|---|
| 747 |  | 
|---|
| 748 | /* --Methode-- */ | 
|---|
| 749 | void CxxExecutor::FillArgs(vector<string>& args) | 
|---|
| 750 | { | 
|---|
| 751 | mCallArgs.resize(0); | 
|---|
| 752 | if(args.size()<1) return; | 
|---|
| 753 | for(uint_4 i=0;i<args.size();i++) mCallArgs.push_back(args[i]); | 
|---|
| 754 | } | 
|---|
| 755 |  | 
|---|
| 756 | void CxxExecutor::FillArgs(string& args) | 
|---|
| 757 | { | 
|---|
| 758 | mCallArgs.resize(0); | 
|---|
| 759 | FillVStringFrString(args,mCallArgs,' '); | 
|---|
| 760 | } | 
|---|
| 761 |  | 
|---|
| 762 | string CxxExecutor::GetArgs(void) | 
|---|
| 763 | { | 
|---|
| 764 | string dum = ""; | 
|---|
| 765 | if(mCallArgs.size()<1) return dum; | 
|---|
| 766 | for(uint_4 i=0;i<mCallArgs.size();i++) dum += mCallArgs[i] + " "; | 
|---|
| 767 | return dum; | 
|---|
| 768 | } | 
|---|
| 769 |  | 
|---|
| 770 | /* --Methode-- */ | 
|---|
| 771 | void CxxExecutor::FillInclude(vector<string>& inc) | 
|---|
| 772 | { | 
|---|
| 773 | mIncList.resize(0); | 
|---|
| 774 | if(inc.size()<1) return; | 
|---|
| 775 | for(uint_4 i=0;i<inc.size();i++) mIncList.push_back(inc[i]); | 
|---|
| 776 | } | 
|---|
| 777 |  | 
|---|
| 778 | void CxxExecutor::FillInclude(string& inc) | 
|---|
| 779 | { | 
|---|
| 780 | mIncList.resize(0); | 
|---|
| 781 | FillVStringFrString(inc,mIncList,' '); | 
|---|
| 782 | } | 
|---|
| 783 |  | 
|---|
| 784 | string CxxExecutor::GetInclude(void) | 
|---|
| 785 | { | 
|---|
| 786 | string dum = ""; | 
|---|
| 787 | if(mIncList.size()<1) return dum; | 
|---|
| 788 | for(uint_4 i=0;i<mIncList.size();i++) dum += mIncList[i] + " "; | 
|---|
| 789 | return dum; | 
|---|
| 790 | } | 
|---|
| 791 |  | 
|---|
| 792 | /* --Methode-- */ | 
|---|
| 793 | void CxxExecutor::FillCompileOpt(vector<string>& copt) | 
|---|
| 794 | { | 
|---|
| 795 | mCompOpt = ""; | 
|---|
| 796 | if(copt.size()<1) return; | 
|---|
| 797 | for(uint_4 i=0;i<copt.size();i++) mCompOpt += copt[i] + " "; | 
|---|
| 798 | } | 
|---|
| 799 |  | 
|---|
| 800 | void CxxExecutor::FillCompileOpt(string& copt) | 
|---|
| 801 | { | 
|---|
| 802 | mCompOpt = copt; | 
|---|
| 803 | } | 
|---|
| 804 |  | 
|---|
| 805 | string CxxExecutor::GetCompileOpt(void) | 
|---|
| 806 | { | 
|---|
| 807 | return mCompOpt; | 
|---|
| 808 | } | 
|---|
| 809 |  | 
|---|
| 810 | /* --Methode-- */ | 
|---|
| 811 | void CxxExecutor::FillLinkOpt(vector<string>& lopt) | 
|---|
| 812 | { | 
|---|
| 813 | mLinkOpt = ""; | 
|---|
| 814 | if(lopt.size()<1) return; | 
|---|
| 815 | for(uint_4 i=0;i<lopt.size();i++) mLinkOpt += lopt[i] + " "; | 
|---|
| 816 | } | 
|---|
| 817 |  | 
|---|
| 818 | void CxxExecutor::FillLinkOpt(string& lopt) | 
|---|
| 819 | { | 
|---|
| 820 | mLinkOpt = lopt; | 
|---|
| 821 | } | 
|---|
| 822 |  | 
|---|
| 823 | string CxxExecutor::GetLinkOpt(void) | 
|---|
| 824 | { | 
|---|
| 825 | return mLinkOpt; | 
|---|
| 826 | } | 
|---|
| 827 |  | 
|---|
| 828 | /* --Methode-- */ | 
|---|
| 829 | void CxxExecutor::FillLinkLibs(vector<string>& llibs) | 
|---|
| 830 | { | 
|---|
| 831 | mMyLibs = ""; | 
|---|
| 832 | if(llibs.size()<1) return; | 
|---|
| 833 | for(uint_4 i=0;i<llibs.size();i++) mMyLibs += llibs[i] + " "; | 
|---|
| 834 | } | 
|---|
| 835 |  | 
|---|
| 836 | void CxxExecutor::FillLinkLibs(string& llibs) | 
|---|
| 837 | { | 
|---|
| 838 | mMyLibs = llibs; | 
|---|
| 839 | } | 
|---|
| 840 |  | 
|---|
| 841 | string CxxExecutor::GetLinkLibs(void) | 
|---|
| 842 | { | 
|---|
| 843 | return mMyLibs; | 
|---|
| 844 | } | 
|---|
| 845 |  | 
|---|
| 846 | /* --Methode-- */ | 
|---|
| 847 | void CxxExecutor::FillModuleImport(vector<string>& import) | 
|---|
| 848 | { | 
|---|
| 849 | mModuleImportList.resize(0); | 
|---|
| 850 | mIncImportList.resize(0); | 
|---|
| 851 | if(import.size()<1) return; | 
|---|
| 852 |  | 
|---|
| 853 | if(import[0]=="all" || import[0]=="All" || import[0]=="ALL") { | 
|---|
| 854 | mModuleImportList = mModuleImportDefaultList; | 
|---|
| 855 | } else { | 
|---|
| 856 | for(uint_4 i=0;i<import.size();i++) mModuleImportList.push_back(import[i]); | 
|---|
| 857 | } | 
|---|
| 858 |  | 
|---|
| 859 | // Set additionnal Includes | 
|---|
| 860 | if(mModuleImportList.size()>0) | 
|---|
| 861 | for(uint_4 i=0;i<mModuleImportList.size();i++) { | 
|---|
| 862 | if(     mModuleImportList[i]=="FitsIOServer") | 
|---|
| 863 | mIncImportList.push_back("fitsioserver.h"); | 
|---|
| 864 | else if(mModuleImportList[i]=="IFFTW") | 
|---|
| 865 | mIncImportList.push_back("fftwserver.h"); | 
|---|
| 866 | else if(mModuleImportList[i]=="LinAlg") | 
|---|
| 867 | mIncImportList.push_back("intflapack.h"); | 
|---|
| 868 | else if(     mModuleImportList[i]=="Samba") | 
|---|
| 869 | {mIncImportList.push_back("skymap.h"); mIncImportList.push_back("samba.h");} | 
|---|
| 870 | else if(mModuleImportList[i]=="SkyMap") | 
|---|
| 871 | mIncImportList.push_back("skymap.h"); | 
|---|
| 872 | else if(mModuleImportList[i]=="SkyT") | 
|---|
| 873 | mIncImportList.push_back("skyt.h"); | 
|---|
| 874 | else if(mModuleImportList[i]=="XAstroPack") | 
|---|
| 875 | mIncImportList.push_back("xastropack.h"); | 
|---|
| 876 | } | 
|---|
| 877 |  | 
|---|
| 878 | return; | 
|---|
| 879 | } | 
|---|
| 880 |  | 
|---|
| 881 | void CxxExecutor::FillModuleImport(string& import) | 
|---|
| 882 | { | 
|---|
| 883 | mModuleImportList.resize(0); | 
|---|
| 884 | vector<string> vsimport; | 
|---|
| 885 | FillVStringFrString(import,vsimport,' '); | 
|---|
| 886 | FillModuleImport(vsimport); | 
|---|
| 887 | } | 
|---|
| 888 |  | 
|---|
| 889 | string CxxExecutor::GetModuleImport(void) | 
|---|
| 890 | { | 
|---|
| 891 | string dum = ""; | 
|---|
| 892 | if(mModuleImportList.size()<1) return dum; | 
|---|
| 893 | for(uint_4 i=0;i<mModuleImportList.size();i++) dum += mModuleImportList[i] + " "; | 
|---|
| 894 | return dum; | 
|---|
| 895 | } | 
|---|