summaryrefslogtreecommitdiff
path: root/impl/Operator.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'impl/Operator.hpp')
-rw-r--r--impl/Operator.hpp50
1 files changed, 43 insertions, 7 deletions
diff --git a/impl/Operator.hpp b/impl/Operator.hpp
index 9f17cbf..d6b92f2 100644
--- a/impl/Operator.hpp
+++ b/impl/Operator.hpp
@@ -1,17 +1,53 @@
-#ifndef OPERATOR_H
-#define OPERATOR_H
+#ifndef OPERATOR_HPP
+#define OPERATOR_HPP
+
+template<typename T>
+T infinity() { }
+
+template<>
+float infinity() {
+ return INFINITY;
+}
-#include <map>
-#include <string>
#include <vector>
-#include "Expression.hpp"
+
+template<typename T>
+struct VariableAssignment;
+template<typename T>
+struct Expression;
template<typename T>
struct Operator {
- virtual const T eval(const std::vector< Expression<T> >&, const std::map<std::string, T>&) const = 0;
- virtual std::string output() const = 0;
+ virtual T operator() (const std::vector< Expression<T>* >&, const VariableAssignment<T>&) const = 0;
+};
+template<typename T>
+struct Maximum : public Operator<T> {
+ virtual T operator() (const std::vector< Expression<T>* >& args, const VariableAssignment<T>& assignment) const {
+ T value = -infinity<T>();
+ for (typename std::vector< Expression<T>* >::const_iterator it = args.begin();
+ it != args.end();
+ ++it) {
+ T temporary = (**it)(assignment);
+ value = (temporary < value ? value : temporary);
+ }
+ return value;
+ }
+};
+template<typename T>
+struct Minimumm : public Operator<T> {
+ virtual T operator() (const std::vector< Expression<T>* >& args, const VariableAssignment<T>& assignment) const {
+ T value = -infinity<T>();
+ for (typename std::vector< Expression<T>* >::const_iterator it = args.begin();
+ it != args.end();
+ ++it) {
+ T temporary = (**it)(assignment);
+ value = (temporary > value ? value : temporary);
+ }
+ return value;
+ }
};
+#include "VariableAssignment.hpp"
#include "Expression.hpp"
#endif