Changeset 6185 for code/branches/presentation2/src
- Timestamp:
- Nov 30, 2009, 11:32:53 PM (15 years ago)
- Location:
- code/branches/presentation2/src/libraries
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation2/src/libraries/core/ConsoleCommandCompilation.cc
r6105 r6185 158 158 float calculate(const std::string& calculation) 159 159 { 160 ExprParser expr(calculation); 160 ExprParser expr; 161 expr.parse(calculation); 161 162 if (expr.getSuccess()) 162 163 { -
code/branches/presentation2/src/libraries/util/ExprParser.cc
r5738 r6185 47 47 namespace orxonox 48 48 { 49 ExprParser::ExprParser( const std::string& str)49 ExprParser::ExprParser() 50 50 { 51 51 this->failed_ = false; 52 this->variables_["pi"] = 3.1415926535897932; 53 this->variables_["e"] = 2.7182818284590452; 54 } 55 56 void ExprParser::setVariable(const std::string& varname, double value) 57 { 58 this->variables_[varname] = value; 59 } 60 61 void ExprParser::parse(const std::string& str) 62 { 52 63 this->reading_stream = str.c_str(); 53 64 if (str.size() == 0 || *reading_stream == '\0') … … 343 354 else 344 355 { 345 #define SWITCH word 346 CASE_1("pi") 347 value = 3.1415926535897932; 348 CASE("e") 349 value = 2.7182818284590452; 350 CASE_ELSE 356 std::map<std::string, double>::const_iterator it = this->variables_.find(word); 357 if (it != this->variables_.end()) 358 value = it->second; 359 else 351 360 { 352 361 this->failed_ = true; … … 358 367 } 359 368 else if (*reading_stream == 40) 360 { // expres ion in paranthesis369 { // expression in parenthesis 361 370 ++reading_stream; 362 371 value = parse_last_argument(); -
code/branches/presentation2/src/libraries/util/ExprParser.h
r5738 r6185 36 36 37 37 #include "UtilPrereqs.h" 38 39 #include <map> 38 40 #include <string> 39 41 … … 71 73 72 74 73 ExprParser(const std::string& str); 75 ExprParser(); 76 void parse(const std::string& str); 74 77 const std::string& getRemains() { return this->remains_; } 75 78 double getResult() { return this->result_; } 76 79 bool getSuccess() { return !this->failed_; } 80 81 void setVariable(const std::string& varname, double value); 77 82 78 83 private: … … 97 102 double result_; 98 103 std::string remains_; 99 104 std::map<std::string, double> variables_; 100 105 }; 101 106
Note: See TracChangeset
for help on using the changeset viewer.