SCalc
session.hh
Go to the documentation of this file.
1
45namespace SCalc {
46
47 class ParserResult;
48 class Expression;
49 class FuncDef;
50
52 std::string version();
53
54
75 class Session {
76 protected:
78 std::vector<std::string> variables;
80 std::map<std::string,int> variables_numbers;
81
84 std::map<int, double> values;
85
91 std::map<std::string, int> functions_numbers;
92
94 std::vector<FuncDef *> functions;
95 public:
99
103
122 ParserResult * eval(const char *);
123
133 void eval_and_free(const char *);
134
142 int register_varname(const std::string &str);
143
144 int register_varname(const char * str);
145
149 const char * varname(int i);
150
159 std::vector<std::string> varnames() {
160 std::vector<std::string> d = variables;
161 return d;
162 };
166 int nb_vars_defined() {return variables.size();};
167
173
179 int set_var(int, double);
180
181 int set_var(const char * var, double val) {
182 return set_var(register_varname(var), val);
183 };
184
185 int set_var(const std::string & var, double val) {
186 return set_var(register_varname(var), val);
187 };
188
191 int unset_var(int);
192
194 int unset_var(std::string varname);
195 int unset_var(const char * varname) {
196 return unset_var(std::string(varname));
197 };
198
200 int nb_vars_set() {return values.size();};
201
204 std::set<int> vars_set();
205
208 void fill_default(double * );
209
213
222
228
229
231 int get_func(std::string);
232
234 int get_func(const char * name)
235 { return get_func(std::string(name));};
236
238 FuncDef * get_func_def(std::string);
239
241 FuncDef * get_func_def(const char * name)
242 { return get_func_def(std::string(name));};
243
245 int nb_args_func(std::string);
247 int nb_args_func(const char * name)
248 { return nb_args_func(std::string(name));};
249
251 int nb_funcs() { return functions.size();};
252
254 std::vector<std::string> func_names();
255
262 Expression * constant(double value);
263
264 };
265
266};
An expression !
Definition: expression.hh:131
A function definition with any number of parameters.
Definition: functions.hh:39
The result of an SCalc::Session::eval().
Definition: expression.hh:36
A class representing a whole session.
Definition: session.hh:75
std::vector< std::string > func_names()
The function names.
std::vector< FuncDef * > functions
The function vector:
Definition: session.hh:94
std::set< int > vars_set()
int nb_vars_set()
Returns the number of variables that have a value.
Definition: session.hh:200
std::map< std::string, int > functions_numbers
Definition: session.hh:91
Expression * constant(double value)
std::map< int, double > values
Definition: session.hh:84
void fill_default(double *)
FuncDef * get_func_def(std::string)
Get the function definition of the given name.
int nb_funcs()
The number of defined functions.
Definition: session.hh:251
int replace_func_def(FuncDef *)
int unset_var(int)
std::vector< std::string > varnames()
Returns an array of variable names.
Definition: session.hh:159
int register_func_def(FuncDef *)
int evaluable(Expression *expr)
int set_var(int, double)
std::vector< std::string > variables
The variables defined.
Definition: session.hh:78
FuncDef * get_func_def(const char *name)
Overloaded function for convenience.
Definition: session.hh:241
int get_func(const char *name)
Get the corresponding function number (or -1 if not defined).
Definition: session.hh:234
int register_varname(const std::string &str)
Registers a variable name and returns its number.
int unset_var(std::string varname)
Unset a variable of the given name.
void eval_and_free(const char *)
Evaluates a string and frees the result if possible.
int nb_vars_defined()
Returns the number of currently defined variables.
Definition: session.hh:166
int nb_args_func(std::string)
Returns the number of arguments of a function.
int get_func(std::string)
Get the corresponding function number (or -1 if not defined).
std::map< std::string, int > variables_numbers
The cross reference to the variables.
Definition: session.hh:80
ParserResult * eval(const char *)
Evaluates a string.
const char * varname(int i)
Returns the name of variable number i.
int nb_args_func(const char *name)
Overloaded for convenience.
Definition: session.hh:247
std::string version()
The version string of the library.