5 #include "Evaluator/Evaluator.h"
6 #include "Evaluator/detail/Evaluator.h"
12 #include <condition_variable>
19 #include <unordered_map>
22 #if defined(__GNUC__) && !defined(__APPLE__) && !defined(__llvm__)
29 #pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
33 #if defined __has_cpp_attribute
34 #if __has_cpp_attribute(fallthrough)
35 #define ATTR_FALLTHROUGH [[fallthrough]]
37 #define ATTR_FALLTHROUGH
40 #define ATTR_FALLTHROUGH
44 #define EVAL dd4hep::tools::Evaluator
50 enum { UNKNOWN, VARIABLE, EXPRESSION, FUNCTION, STRING } what;
52 std::string expression;
55 explicit Item() : what(UNKNOWN), variable(0),expression(),
function(0) {}
56 explicit Item(
double x) : what(VARIABLE), variable(x),expression(),
function(0) {}
57 explicit Item(std::string x) : what(EXPRESSION),variable(0),expression(std::move(x)),
function(0) {}
58 explicit Item(
void *x) : what(FUNCTION), variable(0),expression(),
function(x) {}
66 double (*f2)(double,double);
67 double (*f3)(double,double,double);
68 double (*f4)(double,double,double,double);
69 double (*f5)(double,double,double,double,double);
70 FCN(
void* p) { ptr = p; }
71 FCN(
double (*f)()) { f0 = f; }
72 FCN(
double (*f)(
double)) { f1 = f; }
73 FCN(
double (*f)(
double,
double)) { f2 = f; }
74 FCN(
double (*f)(
double,
double,
double)) { f3 = f; }
75 FCN(
double (*f)(
double,
double,
double,
double)) { f4 = f; }
76 FCN(
double (*f)(
double,
double,
double,
double,
double)) { f5 = f; }
81 typedef std::unordered_map<std::string,Item>
dic_type;
129 #define REMOVE_BLANKS \
130 for(pointer=name;;pointer++) if (!isspace(*pointer)) break; \
131 for(n=strlen(pointer);n>0;n--) if (!isspace(*(pointer+n-1))) break
133 #define SKIP_BLANKS \
135 c = (pointer > end) ? '\0' : *pointer; \
136 if (!isspace(c)) break; \
139 #define EVAL_EXIT(STATUS,POSITION) endp = POSITION; return STATUS
142 static constexpr
char sss[
MAX_N_PAR+2] =
"012345";
144 enum {
ENDL,
LBRA,
OR,
AND,
EQ,
NE,
GE,
GT,
LE,
LT,
147 static int engine(
char const*,
char const*,
double &,
char const* &,
const dic_type &);
149 static int variable(
const std::string & name,
double & result,
166 dic_type::const_iterator iter = dictionary.find(name);
167 if (iter == dictionary.end())
168 return EVAL::ERROR_UNKNOWN_VARIABLE;
170 Item
const& item = iter->second;
173 result = item.variable;
175 case Item::EXPRESSION: {
176 char const* exp_begin = (item.expression.c_str());
177 char const* exp_end = exp_begin + strlen(exp_begin) - 1;
178 if (engine(exp_begin, exp_end, result, exp_end, dictionary) == EVAL::OK)
180 return EVAL::ERROR_CALCULATION_ERROR;
183 return EVAL::ERROR_CALCULATION_ERROR;
187 static int execute_function(
const std::string & name, std::stack<double> & par,
188 double & result,
const dic_type & dictionary)
205 int npar = par.size();
206 if (npar >
MAX_N_PAR)
return EVAL::ERROR_UNKNOWN_FUNCTION;
208 dic_type::const_iterator iter = dictionary.find(sss[npar]+name);
209 if (iter == dictionary.end())
return EVAL::ERROR_UNKNOWN_FUNCTION;
211 Item
const& item = iter->second;
214 for(
int i=0; i<npar; i++) { pp[i] = par.top(); par.pop(); }
216 if (item.function == 0)
return EVAL::ERROR_CALCULATION_ERROR;
217 FCN fcn(item.function);
220 result = (*fcn.f0)();
223 result = (*fcn.f1)(pp[0]);
226 result = (*fcn.f2)(pp[1], pp[0]);
229 result = (*fcn.f3)(pp[2],pp[1],pp[0]);
232 result = (*fcn.f4)(pp[3],pp[2],pp[1],pp[0]);
235 result = (*fcn.f5)(pp[4],pp[3],pp[2],pp[1],pp[0]);
238 return (errno == 0) ? EVAL::OK : EVAL::ERROR_CALCULATION_ERROR;
241 static int operand(
char const* begin,
char const* end,
double & result,
242 char const* & endp,
const dic_type & dictionary)
261 char const* pointer = begin;
267 if (!isalpha(*pointer)) {
270 if ( pointer[0] ==
'0' && pointer < end && (pointer[1] ==
'x' || pointer[1] ==
'X') )
271 result = strtol(pointer, (
char **)(&pointer), 0);
274 result = strtod(pointer, (
char **)(&pointer));
278 EVAL_EXIT( EVAL::ERROR_CALCULATION_ERROR, begin );
284 while(pointer <= end) {
286 if ( !(c ==
'_' || c ==
':') && !isalnum(c))
break;
289 std::string name(begin, pointer-begin);
296 EVAL_STATUS = variable(name, result, dictionary);
297 EVAL_EXIT( EVAL_STATUS, (EVAL_STATUS == EVAL::OK) ? --pointer : begin);
302 std::stack<char const*> pos;
303 std::stack<double> par;
305 char const* par_begin = pointer+1;
309 c = (pointer > end) ?
'\0' : *pointer;
312 EVAL_EXIT( EVAL::ERROR_UNPAIRED_PARENTHESIS, pos.top() );
314 pos.push(pointer);
break;
316 if (pos.size() == 1) {
318 EVAL_STATUS = engine(par_begin, par_end, value, par_end, dictionary);
319 if (EVAL_STATUS == EVAL::WARNING_BLANK_STRING)
320 {
EVAL_EXIT( EVAL::ERROR_EMPTY_PARAMETER, --par_end ); }
321 if (EVAL_STATUS != EVAL::OK)
324 par_begin = pointer + 1;
328 if (pos.size() > 1) {
333 EVAL_STATUS = engine(par_begin, par_end, value, par_end, dictionary);
334 switch (EVAL_STATUS) {
338 case EVAL::WARNING_BLANK_STRING:
340 {
EVAL_EXIT( EVAL::ERROR_EMPTY_PARAMETER, --par_end ); }
345 EVAL_STATUS = execute_function(name, par, result, dictionary);
346 EVAL_EXIT( EVAL_STATUS, (EVAL_STATUS == EVAL::OK) ? pointer : begin);
366 static int maker(
int op, std::stack<double> & val)
368 if (val.size() < 2)
return EVAL::ERROR_SYNTAX_ERROR;
369 double val2 = val.top(); val.pop();
370 double val1 = val.top();
373 val.top() = (val1 || val2) ? 1. : 0.;
376 val.top() = (val1 && val2) ? 1. : 0.;
379 val.top() = (val1 == val2) ? 1. : 0.;
382 val.top() = (val1 != val2) ? 1. : 0.;
385 val.top() = (val1 >= val2) ? 1. : 0.;
388 val.top() = (val1 > val2) ? 1. : 0.;
391 val.top() = (val1 <= val2) ? 1. : 0.;
394 val.top() = (val1 < val2) ? 1. : 0.;
397 val.top() = val1 + val2;
400 val.top() = val1 - val2;
403 val.top() = val1 * val2;
406 if (val2 == 0.0)
return EVAL::ERROR_CALCULATION_ERROR;
407 val.top() = val1 / val2;
411 val.top() = pow(val1,val2);
412 if (errno == 0)
return EVAL::OK;
415 return EVAL::ERROR_CALCULATION_ERROR;
435 static int engine(
char const* begin,
char const* end,
double & result,
436 char const*& endp,
const dic_type & dictionary)
438 static constexpr
int SyntaxTable[17][17] = {
440 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 1 },
441 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 1 },
442 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
443 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
444 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
445 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
446 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
447 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
448 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
449 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
450 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
451 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
452 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
453 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
454 { 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
455 { 3, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0 },
456 { 3, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0 }
458 static constexpr
int ActionTable[15][16] = {
460 { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,-1 },
461 {-1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3 },
462 { 4, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4 },
463 { 4, 1, 4, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4 },
464 { 4, 1, 4, 4, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4 },
465 { 4, 1, 4, 4, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4 },
466 { 4, 1, 4, 4, 4, 4, 2, 2, 2, 2, 1, 1, 1, 1, 1, 4 },
467 { 4, 1, 4, 4, 4, 4, 2, 2, 2, 2, 1, 1, 1, 1, 1, 4 },
468 { 4, 1, 4, 4, 4, 4, 2, 2, 2, 2, 1, 1, 1, 1, 1, 4 },
469 { 4, 1, 4, 4, 4, 4, 2, 2, 2, 2, 1, 1, 1, 1, 1, 4 },
470 { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 1, 1, 1, 4 },
471 { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 1, 1, 1, 4 },
472 { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 1, 4 },
473 { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 1, 4 },
474 { 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 }
478 std::stack<char const*> pos;
479 std::stack<double> val;
481 char const* pointer = begin;
482 int iWhat, iCur, iPrev = 0, iTop, EVAL_STATUS;
485 op.push(0); pos.push(pointer);
487 if (c ==
'\0') {
EVAL_EXIT( EVAL::WARNING_BLANK_STRING, begin ); }
492 c = (pointer > end) ?
'\0' : *pointer;
493 if (isspace(c))
continue;
495 case '\0': iCur =
ENDL;
break;
496 case '(': iCur =
LBRA;
break;
498 if (*(pointer+1) ==
'|') {
499 pointer++; iCur =
OR;
break;
501 EVAL_EXIT( EVAL::ERROR_UNEXPECTED_SYMBOL, pointer );
504 if (*(pointer+1) ==
'&') {
505 pointer++; iCur =
AND;
break;
507 EVAL_EXIT( EVAL::ERROR_UNEXPECTED_SYMBOL, pointer );
510 if (*(pointer+1) ==
'=') {
511 pointer++; iCur =
EQ;
break;
513 EVAL_EXIT( EVAL::ERROR_UNEXPECTED_SYMBOL, pointer );
516 if (*(pointer+1) ==
'=') {
517 pointer++; iCur =
NE;
break;
519 EVAL_EXIT( EVAL::ERROR_UNEXPECTED_SYMBOL, pointer );
522 if (*(pointer+1) ==
'=') { pointer++; iCur =
GE; }
else { iCur =
GT; }
525 if (*(pointer+1) ==
'=') { pointer++; iCur =
LE; }
else { iCur =
LT; }
527 case '+': iCur =
PLUS;
break;
528 case '-': iCur =
MINUS;
break;
530 if (*(pointer+1) ==
'*') { pointer++; iCur =
POW; }
else{ iCur =
MULT; }
532 case '/': iCur =
DIV;
break;
533 case '^': iCur =
POW;
break;
534 case ')': iCur =
RBRA;
break;
536 if (c ==
'.' || isalnum(c)) {
539 EVAL_EXIT( EVAL::ERROR_UNEXPECTED_SYMBOL, pointer );
545 iWhat = SyntaxTable[iPrev][iCur];
549 EVAL_EXIT( EVAL::ERROR_SYNTAX_ERROR, pointer );
551 EVAL_STATUS = operand(pointer, end, value, pointer, dictionary);
552 if (EVAL_STATUS != EVAL::OK) {
EVAL_EXIT( EVAL_STATUS, pointer ); }
564 if (op.size() == 0) {
EVAL_EXIT( EVAL::ERROR_SYNTAX_ERROR, pointer ); }
566 switch (ActionTable[iTop][iCur]) {
568 if (op.size() > 1) pointer = pos.top();
569 EVAL_EXIT( EVAL::ERROR_UNPAIRED_PARENTHESIS, pointer );
571 if (val.size() == 1) {
575 EVAL_EXIT( EVAL::ERROR_SYNTAX_ERROR, pointer );
578 op.push(iCur); pos.push(pointer);
581 EVAL_STATUS = maker(iTop, val);
582 if (EVAL_STATUS != EVAL::OK) {
585 op.top() = iCur; pos.top() = pointer;
591 EVAL_STATUS = maker(iTop, val);
592 if (EVAL_STATUS != EVAL::OK) {
604 static int setItem(
const char * prefix,
const char * name,
607 if (name == 0 || *name ==
'\0') {
608 return EVAL::ERROR_NOT_A_NAME;
618 return EVAL::ERROR_NOT_A_NAME;
620 for(
int i=0; i<n; i++) {
621 char c = *(pointer+i);
622 if ( !(c ==
'_' || c==
':') && !isalnum(c)) {
623 return EVAL::ERROR_NOT_A_NAME;
629 std::string item_name = prefix + std::string(pointer,n);
631 dic_type::iterator iter = imp->
theDictionary.find(item_name);
634 if (item_name == name) {
635 return EVAL::WARNING_EXISTING_VARIABLE;
637 return EVAL::WARNING_EXISTING_FUNCTION;
645 static void print_error_status(std::ostream& os,
int status,
char const* extra) {
646 static char prefix[] =
"Evaluator::Object : ";
647 const char* opt = (extra ? extra :
"");
649 case EVAL::WARNING_EXISTING_VARIABLE:
650 os << prefix <<
"existing variable";
652 case EVAL::WARNING_EXISTING_FUNCTION:
653 os << prefix <<
"existing function";
655 case EVAL::WARNING_BLANK_STRING:
656 os << prefix <<
"blank string detected";
658 case EVAL::ERROR_NOT_A_NAME:
659 os << prefix <<
"invalid name : " << opt;
661 case EVAL::ERROR_SYNTAX_ERROR:
662 os << prefix <<
"systax error" ;
664 case EVAL::ERROR_UNPAIRED_PARENTHESIS:
665 os << prefix <<
"unpaired parenthesis";
667 case EVAL::ERROR_UNEXPECTED_SYMBOL:
668 os << prefix <<
"unexpected symbol : " << opt;
670 case EVAL::ERROR_UNKNOWN_VARIABLE:
671 os << prefix <<
"unknown variable : " << opt;
673 case EVAL::ERROR_UNKNOWN_FUNCTION:
674 os << prefix <<
"unknown function : " << opt;
676 case EVAL::ERROR_EMPTY_PARAMETER:
677 os << prefix <<
"empty parameter in function call: " << opt;
679 case EVAL::ERROR_CALCULATION_ERROR:
680 os << prefix <<
"calculation error";
691 Evaluator::Object::Object(
double meter,
double kilogram,
double second,
double ampere,
double kelvin
692 ,
double mole,
double candela,
double radians) : imp( new Struct()) {
694 setSystemOfUnits(meter, kilogram, second, ampere, kelvin
695 , mole, candela, radians );
699 Evaluator::Object::~Object() {
704 Evaluator::Object::EvalStatus Evaluator::Object::evaluate(
const char * expression)
const {
706 if (expression != 0) {
707 Struct::ReadLock guard(imp);
708 s.theStatus = engine(expression,
709 expression+strlen(expression)-1,
718 int Evaluator::Object::EvalStatus::status()
const {
723 double Evaluator::Object::EvalStatus::result()
const {
728 int Evaluator::Object::EvalStatus::error_position(
const char* expression)
const {
729 return thePosition - expression;
733 void Evaluator::Object::EvalStatus::print_error()
const {
734 std::stringstream str;
736 if ( str.str().empty() )
return;
737 std::cerr << str.str() << std::endl;
741 void Evaluator::Object::EvalStatus::print_error(std::ostream& os)
const {
742 print_error_status(os, theStatus, thePosition);
746 int Evaluator::Object::setEnviron(
const char* name,
const char* value) {
747 std::string prefix =
"${";
748 std::string item_name = prefix + std::string(name) + std::string(
"}");
752 Struct::WriteLock guard(imp);
754 item.what = Item::STRING;
755 item.expression = value;
758 dic_type::iterator iter = imp->
theDictionary.find(item_name);
760 iter->second = std::move(item);
761 if (item_name == name) {
762 return EVAL::WARNING_EXISTING_VARIABLE;
764 return EVAL::WARNING_EXISTING_FUNCTION;
774 Struct::ReadLock guard(imp);
775 Struct
const* cImp = imp;
776 dic_type::const_iterator iter = cImp->
theDictionary.find(name);
777 if (iter != cImp->theDictionary.end()) {
778 return std::make_pair(iter->second.expression.c_str(), EVAL::OK);
780 if ( ::strlen(name) > 3 ) {
782 std::string env_name(name+2,::strlen(name)-3);
783 const char* env_str = ::getenv(env_name.c_str());
784 if ( 0 != env_str ) {
785 return std::make_pair(env_str, EVAL::OK);
788 return std::make_pair(
nullptr,EVAL::ERROR_UNKNOWN_VARIABLE);
792 int Evaluator::Object::setVariable(
const char * name,
double value) {
793 return setItem(
"", name, Item(value), imp);
796 int Evaluator::Object::setVariable(
const char * name,
const char * expression) {
797 Item item(expression);
798 auto returnValue = setItem(
"", name, item, imp);
802 Struct::WriteLock guard(imp);
803 item.expression =
"";
808 void Evaluator::Object::setVariableNoLock(
const char * name,
double value) {
809 std::string item_name = name;
813 int Evaluator::Object::setFunction(
const char * name,
double (*fun)()) {
814 return setItem(
"0", name, Item(FCN(fun).ptr), imp);
817 int Evaluator::Object::setFunction(
const char * name,
double (*fun)(
double)) {
818 return setItem(
"1", name, Item(FCN(fun).ptr), imp);
821 int Evaluator::Object::setFunction(
const char * name,
double (*fun)(
double,
double)) {
822 return setItem(
"2", name, Item(FCN(fun).ptr), imp);
825 int Evaluator::Object::setFunction(
const char * name,
double (*fun)(
double,
double,
double)) {
826 return setItem(
"3", name, Item(FCN(fun).ptr), imp);
829 int Evaluator::Object::setFunction(
const char * name,
double (*fun)(
double,
double,
double,
double)) {
830 return setItem(
"4", name, Item(FCN(fun).ptr), imp);
833 int Evaluator::Object::setFunction(
const char * name,
double (*fun)(
double,
double,
double,
double,
double)) {
834 return setItem(
"5", name, Item(FCN(fun).ptr), imp);
837 void Evaluator::Object::setFunctionNoLock(
const char * name,
double (*fun)(
double)) {
838 std::string item_name =
"1"+std::string(name);
842 void Evaluator::Object::setFunctionNoLock(
const char * name,
double (*fun)(
double,
double)) {
843 std::string item_name =
"2"+std::string(name);
849 bool Evaluator::Object::findVariable(
const char * name)
const {
850 if (name == 0 || *name ==
'\0')
return false;
852 if (n == 0)
return false;
853 Struct::ReadLock guard(imp);
860 bool Evaluator::Object::findFunction(
const char * name,
int npar)
const {
861 if (name == 0 || *name ==
'\0')
return false;
862 if (npar < 0 || npar >
MAX_N_PAR)
return false;
864 if (n == 0)
return false;
865 Struct::ReadLock guard(imp);
866 return (imp->
theDictionary.find(sss[npar]+std::string(pointer,n)) ==
871 void Evaluator::Object::removeVariable(
const char * name) {
872 if (name == 0 || *name ==
'\0')
return;
875 Struct::WriteLock guard(imp);
880 void Evaluator::Object::removeFunction(
const char * name,
int npar) {
881 if (name == 0 || *name ==
'\0')
return;
882 if (npar < 0 || npar >
MAX_N_PAR)
return;
885 Struct::WriteLock guard(imp);
890 Evaluator::Evaluator(
double meter,
double kilogram,
double second,
double ampere,
double kelvin
891 ,
double mole,
double candela,
double radians) {
892 object =
new Object(meter, kilogram, second, ampere, kelvin, mole, candela, radians);
896 Evaluator::Evaluator(Evaluator&& other):object(other.object) {
897 other.object=
nullptr;
901 Evaluator::~Evaluator() {
906 std::pair<int,double> Evaluator::evaluate(
const std::string& expression)
const {
907 auto result =
object->evaluate(expression.c_str());
908 return std::make_pair(result.status(),result.result());
912 std::pair<int,double> Evaluator::evaluate(
const std::string& expression, std::ostream& os)
const {
913 auto result =
object->evaluate(expression.c_str());
914 int status = result.status();
915 if ( status != OK ) {
916 result.print_error(os);
918 return std::make_pair(result.status(),result.result());
922 int Evaluator::setEnviron(
const std::string& name,
const std::string& value)
const {
923 int result =
object->setEnviron(name.c_str(), value.c_str());
929 std::pair<int,std::string> result;
930 auto env_status =
object->getEnviron(name.c_str());
931 result.first = env_status.second;
932 if( env_status.first ) result.second = env_status.first;
938 std::pair<int,std::string> result;
939 auto env_status =
object->getEnviron(name.c_str());
940 result.first = env_status.second;
941 if ( env_status.first ) {
942 result.second = env_status.first;
944 if ( result.first != OK ) {
945 print_error_status(os, result.first, name.c_str());
951 int Evaluator::setVariable(
const std::string& name,
double value)
const {
952 int result =
object->setVariable(name.c_str(), value);
957 int Evaluator::setVariable(
const std::string& name,
double value, std::ostream& os)
const {
958 int result =
object->setVariable(name.c_str(), value);
959 if ( result != OK ) {
960 print_error_status(os, result, name.c_str());
966 int Evaluator::setVariable(
const std::string& name,
const std::string& value)
const {
967 int result =
object->setVariable(name.c_str(), value.c_str());
972 int Evaluator::setVariable(
const std::string& name,
const std::string& value, std::ostream& os)
const {
973 int result =
object->setVariable(name.c_str(), value.c_str());
974 if ( result != OK ) {
975 print_error_status(os, result, name.c_str());
981 bool Evaluator::findVariable(
const std::string& name)
const {
983 ret =
object->findVariable(name.c_str());
988 int Evaluator::setFunction(
const std::string& name,
double (*fun)())
const {
989 int result =
object->setFunction(name.c_str(), fun);
994 int Evaluator::setFunction(
const std::string& name,
double (*fun)(
double))
const {
995 int result =
object->setFunction(name.c_str(), fun);
1000 int Evaluator::setFunction(
const std::string& name,
double (*fun)(
double,
double))
const {
1001 int result =
object->setFunction(name.c_str(), fun);
1006 int Evaluator::setFunction(
const std::string& name,
double (*fun)(
double,
double,
double))
const {
1007 int result =
object->setFunction(name.c_str(), fun);
1012 int Evaluator::setFunction(
const std::string& name,
double (*fun)(
double,
double,
double,
double))
const {
1013 int result =
object->setFunction(name.c_str(), fun);
1018 int Evaluator::setFunction(
const std::string& name,
double (*fun)(
double,
double,
double,
double,
double))
const {
1019 int result =
object->setFunction(name.c_str(), fun);
1024 bool Evaluator::findFunction(
const std::string& name,
int npar)
const {
1026 ret =
object->findFunction(name.c_str(), npar);