SCalc
session.hh
Go to the documentation of this file.
1 
45 namespace SCalc {
46 
47  class ParserResult;
48  class Expression;
49  class FuncDef;
50 
52  std::string version();
53 
54 
74  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:
98  Session();
99 
102  ~Session();
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 
176  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 
212  int evaluable(Expression * expr);
213 
217  int register_func_def(FuncDef *);
222 
227  int replace_func_def(FuncDef *);
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 };
void eval_and_free(const char *)
Evaluates a string and frees the result if possible.
int get_func(const char *name)
Get the corresponding function number (or -1 if not defined).
Definition: session.hh:234
An expression !
Definition: expression.hh:131
std::vector< std::string > variables
The variables defined.
Definition: session.hh:78
void fill_default(double *)
const char * varname(int i)
Returns the name of variable number i.
int evaluable(Expression *expr)
int nb_funcs()
The number of defined functions.
Definition: session.hh:251
int register_varname(const std::string &str)
Registers a variable name and returns its number.
std::map< std::string, int > functions_numbers
Definition: session.hh:91
int replace_func_def(FuncDef *)
std::string version()
The version string of the library.
The result of an SCalc::Session::eval().
Definition: expression.hh:36
int unset_var(int)
int nb_args_func(std::string)
Returns the number of arguments of a function.
Expression * constant(double value)
std::map< std::string, int > variables_numbers
The cross reference to the variables.
Definition: session.hh:80
int nb_vars_set()
Returns the number of variables that have a value.
Definition: session.hh:200
int set_var(int, double)
std::set< int > vars_set()
int nb_args_func(const char *name)
Overloaded for convenience.
Definition: session.hh:247
ParserResult * eval(const char *)
Evaluates a string.
std::vector< std::string > func_names()
The function names.
int register_func_def(FuncDef *)
A function definition with any number of parameters.
Definition: functions.hh:39
int get_func(std::string)
Get the corresponding function number (or -1 if not defined).
FuncDef * get_func_def(std::string)
Get the function definition of the given name.
std::vector< FuncDef * > functions
The function vector:
Definition: session.hh:94
std::map< int, double > values
Definition: session.hh:84
std::vector< std::string > varnames()
Returns an array of variable names.
Definition: session.hh:159
Definition: session.hh:45
int nb_vars_defined()
Returns the number of currently defined variables.
Definition: session.hh:166
FuncDef * get_func_def(const char *name)
Overloaded function for convenience.
Definition: session.hh:241