24#ifndef TOKENIZER_H_INCLUDED
25#define TOKENIZER_H_INCLUDED
32#include "aquagpusph/ext/exprtk.hpp"
72 const std::lock_guard<std::mutex> lock(this->mutex);
74 vars.add_variable(name, val);
81 std::vector<std::string> exprVariables(
const std::string eq);
88 template<
typename T=
float>
91 const std::lock_guard<std::mutex> lock(this->mutex);
92 exprtk::parser<tokenizer_t> parser;
93 exprtk::expression<tokenizer_t> expr;
100 if (sz == eq.size()) {
106 std::string::size_type sz;
108 if (sz == eq.size()) {
114 expr.register_symbol_table(vars);
117 if (!parser.compile(eq, expr))
119 LOG(
L_ERROR, std::string(
"Error parsing \"") + eq +
"\":\n");
123 throw std::runtime_error(
"Invalid expression");
128 res_org = expr.value();
130 }
catch(std::out_of_range) {
131 LOG(
L_ERROR, std::string(
"Error parsing \"") + eq +
"\":\n");
134 std::to_string(res_org) +
" overflows the type \"" +
135 typeid(res).name() +
"\"\n");
148 if (vars.is_variable(name))
149 vars.remove_variable(name);
155 exprtk::symbol_table<tokenizer_t> vars;
159 static std::mutex mutex;
Set of auxiliar functions.
Terminal output, with Log automatic copying. (See Aqua::InputOutput::Logger for details)
#define LOG0(level, log)
Definition Logger.hpp:64
#define LOG(level, log)
Definition Logger.hpp:55
#define T
Definition Sort.hcl.in:83
T solve(const std::string eq)
Solve a math expression.
Definition Tokenizer_exprtk.hpp:89
void removeVariable(const std::string name)
Remove a variable if it has been registered.
Definition Tokenizer_exprtk.hpp:146
Tokenizer_exprtk()
Constructor.
Definition Tokenizer_exprtk.cpp:36
void registerVariable(const std::string name, T value)
Register a variable.
Definition Tokenizer_exprtk.hpp:69
Main AQUAgpusph namespace.
Definition ArgumentsManager.cpp:50
Tdst narrow_cast(Torg v)
Cast a value, checking that it is not overflowing.
Definition AuxiliarMethods.hpp:414
@ L_ERROR
Definition Logger.hpp:75
@ L_DEBUG
Definition Logger.hpp:72
long double tokenizer_t
Definition Tokenizer_exprtk.hpp:38
#define DECLDIR
Prefix to export C functions on the compiled library.
Definition sphPrerequisites.hpp:65