Skip to content
Snippets Groups Projects
Commit 452a26ce authored by Adam Wardyński's avatar Adam Wardyński
Browse files

Predicate checking if two values are equal

parent 9fde90ed
Branches
No related merge requests found
#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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment