1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
14 * Simple integer arithmetics to be used for the work sizes calculation
15 * Supported ops: +,-,*,/,%,(,)
17 * Variables defined as single chars and should not include one of the ops, whitespaces or 0-9
21 class SimpleMathExpression {
23 SimpleMathExpression() :m_parsed(false) {}
24 void SetVariables(const std::map<char, int>& vars);
25 bool SetExpression(const std::string& expression);
26 bool IsParsed()const { return m_parsed; }
27 int Evaluate()const; // undefined behavior if not parsed properly
30 std::map<char, int> m_variables;
31 std::string m_expression;
42 explicit Token(TokenType t = Value, int v = 0, char o = 0) :type(t), value(v), op(o) {}
44 std::vector<Token> m_parsedTokens;
46 static const std::set<char> whitespaces;
47 using Operator = std::pair<int, std::function<int(int, int)>>; // priority, function
48 static const std::map<char, Operator> operators;