VLink  2.0.0
A high-performance communication middleware
exprtk_api.h File Reference

Thin, ABI-stable facade over the ExprTk mathematical expression engine. More...

#include <memory>
#include <string>
#include "../base/macros.h"
Include dependency graph for exprtk_api.h:

Go to the source code of this file.

Classes

class  vlink::ExprtkSymbolTable
 Opaque wrapper around exprtk::symbol_table<double>. More...
 
class  vlink::ExprtkExpression
 Opaque wrapper around exprtk::expression<double> plus its compiler. More...
 

Namespaces

 

Macros

#define VLINK_EXPRTK_API_EXPORT   __attribute__((visibility("default")))
 

Detailed Description

Thin, ABI-stable facade over the ExprTk mathematical expression engine.

ExprTk (thirdparty/exprtk/include/exprtk/exprtk.hpp) is a header-only template library of roughly 46k lines. Every translation unit that includes it instantiates the full parser/optimizer/evaluator for double, which previously caused the same engine to be compiled into nine separate object files (CLI dump, analyzer, perception, the three webviz converters, and so on). The result was severe object-code bloat and long compile times.

This header exposes the small subset of ExprTk that VLink actually uses behind two opaque PIMPL classes. The real ExprTk templates are compiled exactly once, inside the vlink::exprtk_api shared library; consumers include only this header and link vlink::exprtk_api, so ExprTk never enters their translation units again.

Usage model
The classes mirror the ExprTk compile-then-evaluate workflow one-to-one:
  1. Build a vlink::ExprtkSymbolTable, registering constants and variables. Variables are bound by-reference, so the caller-owned storage must outlive the symbol table and must not be relocated (e.g. reserve a std::vector up front).
  2. Create a vlink::ExprtkExpression and register the symbol table into it.
  3. Call vlink::ExprtkExpression::compile once.
  4. Update the bound variable storage and call vlink::ExprtkExpression::value as many times as needed; each call re-reads the current variable values.
// Evaluate "a + b * 2" with a == 3, b == 4 -> 11
double a = 3.0;
double b = 4.0;
symbols.add_constants(); // pi, epsilon, inf, ...
symbols.add_variable("a", a); // bound by reference
symbols.add_variable("b", b); // bound by reference
expr.register_symbol_table(symbols);
if (expr.compile("a + b * 2")) {
double result = expr.value(); // 11.0
b = 10.0;
result = expr.value(); // 23.0, no recompilation needed
}
Note
The value type is fixed to double, which matches every existing VLink call site. Only a single vlink::ExprtkSymbolTable may be registered into a given vlink::ExprtkExpression, but one symbol table may be registered into many expressions to share variable storage.

Macro Definition Documentation

◆ VLINK_EXPRTK_API_EXPORT

#define VLINK_EXPRTK_API_EXPORT   __attribute__((visibility("default")))