blob: 3c0bee9199091b7e28e8f13b09d43afab7fd8fe9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#include "Expression.hpp"
#include "muParser.h"
#include "../../debug/log/Logger.hpp"
using namespace Math;
CExpression::CExpression() : m_parser(makeUnique<mu::Parser>()) {
;
}
void CExpression::addVariable(const std::string& name, double val) {
m_parser->DefineConst(name, val);
}
std::optional<double> CExpression::compute(const std::string& expr) {
try {
m_parser->SetExpr(expr);
return m_parser->Eval();
} catch (mu::Parser::exception_type& e) { Log::logger->log(Log::ERR, "CExpression::compute: mu threw: {}", e.GetMsg()); }
return std::nullopt;
}
|