Changeset 4063 in Sophya for trunk/SophyaLib/SysTools/commander.cc
- Timestamp:
- Apr 27, 2012, 12:34:31 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/SysTools/commander.cc
r4034 r4063 442 442 443 443 // ------------------------------------------------------------ 444 // Classe Cmd_CE_VarList 445 // ------------------------------------------------------------ 446 /*! 447 \internal 448 \class SOPHYA::Cmd_CE_VarList 449 \ingroup SysTools 450 This class, reserved for internal use by class Commander, enables the CExpressionEvaluator class 451 to access the interpreter variable values. 452 */ 453 454 class Cmd_CE_VarList : public CE_VarListInterface { 455 public: 456 Cmd_CE_VarList(Commander& cmd) : cmd_(cmd) { } 457 virtual void Update(); 458 virtual double* GetVarPointer(std::string const& name); 459 private: 460 Commander& cmd_; 461 std::map<std::string, double> namevals_; 462 }; 463 464 /* --Methode-- */ 465 void Cmd_CE_VarList::Update() 466 { 467 bool exist=false; 468 string sval; 469 std::map<std::string, double>::iterator it; 470 for(it=namevals_.begin(); it!=namevals_.end(); it++) { 471 exist=cmd_.GetVar((*it).first, sval); 472 if (!exist) throw NotFoundExc("Cmd_CE_VarList::Update() missing variable !"); 473 (*it).second=atof(sval.c_str()); 474 } 475 return; 476 } 477 478 /* --Methode-- */ 479 double* Cmd_CE_VarList::GetVarPointer(std::string const& name) 480 { 481 std::map<std::string, double>::iterator it=namevals_.find(name); 482 if (it!=namevals_.end()) return &((*it).second); 483 bool exist=false; 484 string sval; 485 exist=cmd_.GetVar(name, sval); 486 if (!exist) return NULL; 487 namevals_[name]=atof(sval.c_str()); 488 it=namevals_.find(name); 489 if (it!=namevals_.end()) return &((*it).second); 490 return NULL; 491 } 492 493 494 // ------------------------------------------------------------ 444 495 // Classe Commander 445 496 // ------------------------------------------------------------ … … 492 543 hist.open("history.pic"); 493 544 histon = true; 494 trace = false; timing = false; 545 trace = false; timing = false; varcexp = true; 495 546 gltimer = NULL; 496 547 felevel_ = 0; … … 561 612 usage += " > sleep nsec # sleep nsec seconds \n"; 562 613 usage += " > readstdin varname # reads a line from stdin into $varname \n"; 563 usage += " > timingon timingoff traceon traceoff \n";614 usage += " > timingon timingoff traceon traceoff varcexpon varcexpoff \n"; 564 615 RegisterHelp(kw, usage, grp); 565 616 … … 1085 1136 try { 1086 1137 double res = 0.; 1087 if (tokens.size() > 2) {1088 string sex = tokens[1]; 1138 string sex=tokens[1]; 1139 if (tokens.size() > 2) 1089 1140 for(unsigned int js=2; js<tokens.size(); js++) sex += tokens[js]; 1090 CExpressionEvaluator cex(sex); 1141 if (varcexp) { //--- Evaluation d'expression avec decodage de noms de variables 1142 Cmd_CE_VarList cevl(*this); 1143 CExpressionEvaluator cex(sex,&cevl); 1091 1144 res = cex.Value(); 1092 1145 } 1093 else { 1094 CExpressionEvaluator cex( tokens[1]);1146 else { //--- Evaluation d'expression SANS decodage des noms de variables 1147 CExpressionEvaluator cex(sex); 1095 1148 res = cex.Value(); 1096 1149 } … … 1957 2010 if (gltimer) delete gltimer; gltimer = NULL; timing = false; 1958 2011 } 2012 else if (kw == "varcexpon") 2013 { cout << "Commander::Interpret() -> Activating variable name decoding in expression evaluation " << endl; varcexp = true; } 2014 else if (kw == "varcexpoff") 2015 { cout << "Commander::Interpret() -> Deactivating variable name decoding in expression evaluation " << endl; varcexp = false; } 1959 2016 else if (kw == "exec") { 1960 2017 if (tokens.size() < 1) { cout << "Commander::Interpret() Usage: exec filename" << endl; return(0); }
Note:
See TracChangeset
for help on using the changeset viewer.