37 static std::unique_ptr<MathExpression>
Create(
const char *pszExpression,
38 const char *pszDialect);
52 double *pdfLocation) = 0;
66 std::vector<double> *padfLocation) = 0;
99 virtual const std::vector<double> &
Results()
const = 0;
104#if GDAL_VRT_ENABLE_EXPRTK
112 explicit ExprtkExpression(std::string_view osExpression);
114 ~ExprtkExpression()
override;
116 void RegisterVariable(std::string_view osVariable,
117 double *pdfLocation)
override;
119 void RegisterVector(std::string_view osVariable,
120 std::vector<double> *padfLocation)
override;
122 CPLErr Compile()
override;
124 CPLErr Evaluate()
override;
126 const std::vector<double> &Results()
const override;
131 std::unique_ptr<Impl> m_pImpl;
136#if GDAL_VRT_ENABLE_MUPARSER
141class MuParserExpression final :
public MathExpression
144 explicit MuParserExpression(std::string_view osExpression);
146 ~MuParserExpression()
override;
148 void RegisterVariable(std::string_view osVariable,
149 double *pdfLocation)
override;
151 void RegisterVector(std::string_view osVariable,
152 std::vector<double> *padfLocation)
override;
154 CPLErr Compile()
override;
156 CPLErr Evaluate()
override;
158 const std::vector<double> &Results()
const override;
163 std::unique_ptr<Impl> m_pImpl;
168inline std::unique_ptr<MathExpression>
170 const char *pszDialect)
172 if (
EQUAL(pszDialect,
"exprtk"))
174#if GDAL_VRT_ENABLE_EXPRTK
175 return std::make_unique<gdal::ExprtkExpression>(pszExpression);
178 "Dialect '%s' is not supported by this GDAL build. A GDAL "
179 "build with ExprTk is needed.",
183 else if (
EQUAL(pszDialect,
"muparser"))
185#if GDAL_VRT_ENABLE_MUPARSER
186 return std::make_unique<gdal::MuParserExpression>(pszExpression);
189 "Dialect '%s' is not supported by this GDAL build. A GDAL "
190 "build with muparser is needed.",
196 CPLError(CE_Failure,
CPLE_IllegalArg,
"Unknown expression dialect: %s",
202bool MuParserHasDefineFunUserData();
Class to support evaluation of a mathematical expression.
Definition vrtexpression.h:27
virtual CPLErr Compile()=0
Compile the expression.
static std::unique_ptr< MathExpression > Create(const char *pszExpression, const char *pszDialect)
Create a MathExpression using a specified dialect.
virtual CPLErr Evaluate()=0
Evaluate the expression.
virtual void RegisterVariable(std::string_view osVariable, double *pdfLocation)=0
Register a variable to be used in the expression.
virtual void RegisterVector(std::string_view osVariable, std::vector< double > *padfLocation)=0
Register a vector to be used in the expression.
virtual const std::vector< double > & Results() const =0
Access the results from the last time the expression was evaluated.
CPL error handling services.
#define CPLE_IllegalArg
Illegal argument.
Definition cpl_error.h:93
CPLErr
Error category.
Definition cpl_error.h:37
#define EQUAL(a, b)
Alias for strcasecmp() == 0.
Definition cpl_port.h:541