|
|
| Expressionist (json o, EvalMethod method=EvalMethod::RECURSIVE) |
| | Construct from a JSON object, to be mutated/copied by evaluate()/produce().
|
| |
| | Expressionist (std::string s, EvalMethod method=EvalMethod::RECURSIVE) |
| |
|
| Expressionist (const char *s, EvalMethod method=EvalMethod::RECURSIVE) |
| | Same as the std::string overload; disambiguates string-literal calls.
|
| |
| | Expressionist (EvalMethod method=EvalMethod::RECURSIVE) |
| |
| void | evaluate () |
| |
| void | evaluate (json &object) const |
| |
| json | produce () const |
| |
| json | produce (json object) const |
| |
| void | setEvalMethod (EvalMethod method) |
| |
|
EvalMethod | getEvalMethod () const |
| | The currently selected resolution strategy.
|
| |
| void | setTag (const std::string &tag) |
| |
|
std::string | tag () const |
| | The currently configured expression tag.
|
| |
| void | setDisableKey (const std::string &key) |
| |
|
std::string | disableKey () const |
| | The currently configured disable key.
|
| |
|
const json & | object () const |
| | Access the (possibly evaluated) stored object.
|
| |
| void | addConstant (const std::string &name, double value) |
| |
| void | addUnaryFunction (const std::string &name, detail::UnaryFn fn) |
| |
| void | addBinaryFunction (const std::string &name, detail::BinaryFn fn) |
| |
Evaluates algebraic expressions embedded in nlohmann::json string fields, replacing them in place with their computed values. Variables in an expression are simply other keys of the same JSON tree, resolved lexically and in any definition order.
#include <expressionist.hpp>
#include <iostream>
int main() {
nlohmann::json data = nlohmann::json::parse(R"({
"a": 1,
"b": 2,
"c": "$a + b",
"f": "$pi / 3",
"g": "$sin(f) * b"
})");
ex.evaluate();
std::cout << ex.object().dump(2) << '\n';
}
Definition expressionist.hpp:1047
See the project README (this documentation's main page) for the full guide: nesting and scoping, the range operator, disabling evaluation for a subtree, the command-line tool, and the C/Python bindings.
- Examples
- main.cpp.