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