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