Calculator.h (10447:a465576671d4) | Calculator.h (10448:bc1a3b7ab5ef) |
---|---|
1/* Copyright (c) 2012 Massachusetts Institute of Technology 2 * 3 * Permission is hereby granted, free of charge, to any person obtaining a copy 4 * of this software and associated documentation files (the "Software"), to deal 5 * in the Software without restriction, including without limitation the rights 6 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 * copies of the Software, and to permit persons to whom the Software is 8 * furnished to do so, subject to the following conditions: 9 * 10 * The above copyright notice and this permission notice shall be included in 11 * all copies or substantial portions of the Software. 12 * 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 * THE SOFTWARE. 20 */ 21 |
|
1#ifndef __LIBUTIL_CALCULATOR_H__ 2#define __LIBUTIL_CALCULATOR_H__ 3 4#include <sstream> 5 | 22#ifndef __LIBUTIL_CALCULATOR_H__ 23#define __LIBUTIL_CALCULATOR_H__ 24 25#include <sstream> 26 |
27#include "model/Model.h" |
|
6#include "String.h" 7#include "Map.h" 8#include "Assert.h" 9 10namespace LibUtil 11{ 12 using std::istringstream; | 28#include "String.h" 29#include "Map.h" 30#include "Assert.h" 31 32namespace LibUtil 33{ 34 using std::istringstream; |
35 using std::ostringstream; |
|
13 14 /* 15 * program: 16 * END // END is end-of-input 17 * expr_list END 18 * 19 * expr_list: 20 * expression SEP expr_list // SEP is semicolon --- 37 unchanged lines hidden (view full) --- 58 }; 59 60 public: 61 Calculator(); 62 virtual ~Calculator(); 63 64 public: 65 void reset(); | 36 37 /* 38 * program: 39 * END // END is end-of-input 40 * expr_list END 41 * 42 * expr_list: 43 * expression SEP expr_list // SEP is semicolon --- 37 unchanged lines hidden (view full) --- 81 }; 82 83 public: 84 Calculator(); 85 virtual ~Calculator(); 86 87 public: 88 void reset(); |
66 void evaluateString(const String& str_); | 89 void evaluateString(const String& str_, 90 const std::map<String, String> &config, 91 DSENT::Model *ms_model, 92 std::map<std::string, double> &outputs); |
67 68 protected: 69 Token getToken(istringstream& ist_); | 93 94 protected: 95 Token getToken(istringstream& ist_); |
70 double prim(istringstream& ist_, bool is_get_); 71 double term(istringstream& ist_, bool is_get_); 72 double expr(istringstream& ist_, bool is_get_); 73 virtual double getEnvVar(const String& var_name_) const; | |
74 | 96 |
97 double prim(istringstream& ist_, bool is_get_, 98 const std::map<String, String> &config, 99 DSENT::Model *ms_model); 100 101 double term(istringstream& ist_, bool is_get_, 102 const std::map<String, String> &config, 103 DSENT::Model *ms_model); 104 105 double expr(istringstream& ist_, bool is_get_, 106 const std::map<String, String> &config, 107 DSENT::Model *ms_model); 108 109 virtual double getEnvVar( 110 const String& var_name_, 111 const std::map<String, String> &config, 112 DSENT::Model *ms_model) const; 113 |
|
75 protected: 76 String m_reserved_chars_; 77 Map<double> m_var_; 78 79 Token m_curr_token_; 80 double m_value_number_; 81 String m_value_string_; | 114 protected: 115 String m_reserved_chars_; 116 Map<double> m_var_; 117 118 Token m_curr_token_; 119 double m_value_number_; 120 String m_value_string_; |
82 }; // class Calculator | 121 }; |
83} // namespace LibUtil 84 85#endif // __LIBUTIL_CALCULATOR_H__ 86 | 122} // namespace LibUtil 123 124#endif // __LIBUTIL_CALCULATOR_H__ 125 |