]> git.tdb.fi Git - builder.git/blobdiff - source/booleanevaluator.h
Support boolean logic in conditions
[builder.git] / source / booleanevaluator.h
diff --git a/source/booleanevaluator.h b/source/booleanevaluator.h
new file mode 100644 (file)
index 0000000..08ed432
--- /dev/null
@@ -0,0 +1,34 @@
+#ifndef BOOLEANEVALUATOR_H_
+#define BOOLEANEVALUATOR_H_
+
+#include <string>
+#include <vector>
+#include <sigc++/slot.h>
+
+class BooleanEvaluator
+{
+public:
+       typedef sigc::slot<bool, const std::string &, const std::string *> Slot;
+
+private:
+       Slot slot;
+       std::string ops;
+       std::vector<std::string> var_stack;
+       std::vector<unsigned char> value_stack;
+       std::vector<char> op_stack;
+       bool last_was_op;
+
+public:
+       BooleanEvaluator(const Slot &, bool = true);
+
+       bool evaluate(const std::string &);
+private:
+       void push_op(char);
+       bool pop_value();
+       void collapse(unsigned);
+       unsigned precedence(char);
+       bool is_unary(char);
+       bool is_logic(char);
+};
+
+#endif