Vulpes  0.1.0
Versatile and parallel compUtational Library for high-order discontinuous Polytopal Element Simulations
Loading...
Searching...
No Matches
vulpes::vutils::ExpressionParser< N > Class Template Reference

Compiles and evaluates a scalar math expression at runtime. More...

#include <expression_parser.hpp>

Public Member Functions

template<typename... Args>
 ExpressionParser (const char *expression, Args &&... args)
 Compile an expression given as a C string.
template<typename... Args>
 ExpressionParser (const std::string &expression, Args &&... args)
 Compile an expression given as a std::string.
double evaluate (const double *data) const
 Evaluate the compiled expression against a data buffer.

Private Member Functions

template<typename... Args>
void init (const char *expression, Args &&... args)
 Register variables and compile the expression.

Private Attributes

mathpresso::Context m_context
mathpresso::Expression m_expr

Detailed Description

template<size_t N>
class vulpes::vutils::ExpressionParser< N >

Compiles and evaluates a scalar math expression at runtime.

Wraps mathpresso to compile a textual expression referencing exactly N named double variables, then evaluate it repeatedly against raw data buffers without re-parsing.

Template Parameters
NNumber of variables the expression depends on.

Constructor & Destructor Documentation

◆ ExpressionParser() [1/2]

template<size_t N>
template<typename... Args>
vulpes::vutils::ExpressionParser< N >::ExpressionParser ( const char * expression,
Args &&... args )
inlineexplicit

Compile an expression given as a C string.

Template Parameters
ArgsPack of variable names (convertible to std::string_view), must contain exactly N names.
Parameters
expressionThe math expression to compile.
argsNames of the N variables referenced by expression, in the order they appear in the data buffer passed to evaluate().
Exceptions
std::runtime_errorif compilation fails.

◆ ExpressionParser() [2/2]

template<size_t N>
template<typename... Args>
vulpes::vutils::ExpressionParser< N >::ExpressionParser ( const std::string & expression,
Args &&... args )
inlineexplicit

Compile an expression given as a std::string.

Template Parameters
ArgsPack of variable names (convertible to std::string_view), must contain exactly N names.
Parameters
expressionThe math expression to compile.
argsNames of the N variables referenced by expression, in the order they appear in the data buffer passed to evaluate().
Exceptions
std::runtime_errorif compilation fails.

Member Function Documentation

◆ evaluate()

template<size_t N>
double vulpes::vutils::ExpressionParser< N >::evaluate ( const double * data) const
inline

Evaluate the compiled expression against a data buffer.

Parameters
dataPointer to N contiguous doubles, one per variable, in the order given to the constructor.
Returns
The expression's numeric result.

◆ init()

template<size_t N>
template<typename... Args>
void vulpes::vutils::ExpressionParser< N >::init ( const char * expression,
Args &&... args )
inlineprivate

Register variables and compile the expression.

Template Parameters
ArgsPack of variable names, must contain exactly N names.
Parameters
expressionThe math expression to compile.
argsNames of the N variables referenced by expression.
Exceptions
std::runtime_errorif compilation fails.

Member Data Documentation

◆ m_context

template<size_t N>
mathpresso::Context vulpes::vutils::ExpressionParser< N >::m_context
private

◆ m_expr

template<size_t N>
mathpresso::Expression vulpes::vutils::ExpressionParser< N >::m_expr
private

The documentation for this class was generated from the following file: