From 452a26cefe3d9cdcf1670d1e8ed3037f11679f5e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adam=20Wardy=C5=84ski?= <no@email>
Date: Mon, 8 Nov 2010 15:07:58 +0100
Subject: [PATCH] Predicate checking if two values are equal

---
 libwccl/ops/equals.h | 62 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
 create mode 100644 libwccl/ops/equals.h

diff --git a/libwccl/ops/equals.h b/libwccl/ops/equals.h
new file mode 100644
index 0000000..984e809
--- /dev/null
+++ b/libwccl/ops/equals.h
@@ -0,0 +1,62 @@
+#ifndef EQUALS_H
+#define EQUALS_H
+
+#include <boost/shared_ptr.hpp>
+#include <boost/mpl/list.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/count.hpp>
+#include <libwccl/ops/predicate.h>
+#include <libwccl/ops/formatters.h>
+
+namespace Wccl {
+
+/**
+ * Predicate that checks for equality of values
+ */
+template <class T>
+class Equals : public Predicate {
+public:
+	typedef boost::shared_ptr<Function<T> > ArgFunctionPtr;
+
+	Equals(const ArgFunctionPtr& arg1_expr, const ArgFunctionPtr& arg2_expr)
+		: arg1_expr_(arg1_expr), arg2_expr_(arg2_expr)
+	{
+		BOOST_ASSERT(arg1_expr_);
+		BOOST_ASSERT(arg2_expr_);
+	}
+
+	virtual std::string to_string(const Corpus2::Tagset& tagset) const {
+		return BinaryFunctionFormatter::to_string(tagset, *this, *arg1_expr_, *arg2_expr_);
+	}
+
+	virtual std::string to_raw_string() const {
+		return BinaryFunctionFormatter::to_raw_string(*this, *arg1_expr_, *arg2_expr_);
+	}
+
+	virtual const std::string raw_operator_name() const {
+		return "equals";
+	}
+
+protected:
+	const ArgFunctionPtr arg1_expr_;
+	const ArgFunctionPtr arg2_expr_;
+
+	typedef FunctionBase::BaseRetValPtr BaseRetValPtr;
+
+	/**
+	 * Take values of arguments from expressions and return True if they are equal,
+	 * False otherwise.
+	 */
+	virtual BaseRetValPtr apply_internal(const SentenceContext& context) const {
+		boost::shared_ptr<T> arg1 = this->arg1_expr_->apply(context);
+		boost::shared_ptr<T> arg2 = this->arg2_expr_->apply(context);
+		if(arg1->equals(*arg2)) {
+			return Predicate::True->apply(context);
+		}
+		return Predicate::False->apply(context);
+	}
+};
+
+} /* end ns Wccl */
+
+#endif // EQUALS_H
-- 
GitLab