]> git.tdb.fi Git - builder.git/blob - source/booleanevaluator.h
Refactor BooleanEvaluator to have overloaded constructors
[builder.git] / source / booleanevaluator.h
1 #ifndef BOOLEANEVALUATOR_H_
2 #define BOOLEANEVALUATOR_H_
3
4 #include <functional>
5 #include <string>
6 #include <vector>
7
8 class BooleanEvaluator
9 {
10 public:
11         using ValueFunction = std::function<bool(const std::string &)>;
12         using CompareFunction = std::function<bool(const std::string &, const std::string *)>;
13
14 private:
15         CompareFunction func;
16         std::string ops;
17         std::vector<std::string> var_stack;
18         std::vector<unsigned char> value_stack;
19         std::vector<char> op_stack;
20         bool last_was_op;
21
22 public:
23         BooleanEvaluator(const ValueFunction &);
24         BooleanEvaluator(const CompareFunction &);
25
26         bool evaluate(const std::string &);
27 private:
28         void push_op(char);
29         bool pop_value();
30         void collapse(unsigned);
31         unsigned precedence(char);
32         bool is_unary(char);
33         bool is_logic(char);
34 };
35
36 #endif