#ifndef STORM_STORAGE_EXPRESSIONS_EXPRTKEXPRESSIONEVALUATOR_H_ #define STORM_STORAGE_EXPRESSIONS_EXPRTKEXPRESSIONEVALUATOR_H_ #include #include #include #include "src/storage/expressions/ExpressionEvaluatorBase.h" #include "exprtk.hpp" #include "src/storage/expressions/ToExprtkStringVisitor.h" namespace storm { namespace expressions { template class ExprtkExpressionEvaluatorBase : public ExpressionEvaluatorBase { public: ExprtkExpressionEvaluatorBase(storm::expressions::ExpressionManager const& manager); bool asBool(Expression const& expression) const override; int_fast64_t asInt(Expression const& expression) const override; void setBooleanValue(storm::expressions::Variable const& variable, bool value) override; void setIntegerValue(storm::expressions::Variable const& variable, int_fast64_t value) override; void setRationalValue(storm::expressions::Variable const& variable, double value) override; protected: typedef double ValueType; typedef exprtk::expression CompiledExpressionType; typedef std::unordered_map, CompiledExpressionType> CacheType; /*! * Adds a compiled version of the given expression to the internal storage. * * @param expression The expression that is to be compiled. */ CompiledExpressionType& getCompiledExpression(storm::expressions::Expression const& expression) const; // The parser used. mutable exprtk::parser parser; // The symbol table used. mutable exprtk::symbol_table symbolTable; // The actual data that is fed into the expression. std::vector booleanValues; std::vector integerValues; std::vector rationalValues; // A mapping of expressions to their compiled counterpart. mutable CacheType compiledExpressions; }; class ExprtkExpressionEvaluator : public ExprtkExpressionEvaluatorBase { public: /*! * Creates an expression evaluator that is capable of evaluating expressions managed by the given manager. * * @param manager The manager responsible for the expressions. */ ExprtkExpressionEvaluator(storm::expressions::ExpressionManager const& manager); double asRational(Expression const& expression) const override; }; } } #endif /* STORM_STORAGE_EXPRESSIONS_EXPRTKEXPRESSIONEVALUATOR_H_ */