Skip to content
Snippets Groups Projects
setpredicate.h 1.17 KiB
Newer Older
#ifndef SETPREDICATE_H
#define SETPREDICATE_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 {

/**
 * Abstract base class for predicates which operate on two sets
 */
template<class T>
class SetPredicate : public Predicate {
	BOOST_MPL_ASSERT(( boost::mpl::count<boost::mpl::list<StrSet, TSet>, T> ));
public:
	typedef boost::shared_ptr<Function<T> > SetFunctionPtr;

	SetPredicate(const SetFunctionPtr& set1_expr, const SetFunctionPtr& set2_expr)
		: set1_expr_(set1_expr), set2_expr_(set2_expr)
	{
		BOOST_ASSERT(set1_expr_);
		BOOST_ASSERT(set2_expr_);
	}

	virtual std::string to_string(const Corpus2::Tagset& tagset) const {
		return BinaryFunctionFormatter::to_string(tagset, *this, *set1_expr_, *set2_expr_);
	}

	virtual std::string to_raw_string() const {
		return BinaryFunctionFormatter::to_raw_string(*this, *set1_expr_, *set2_expr_);
	}

protected:
	const SetFunctionPtr set1_expr_;
	const SetFunctionPtr set2_expr_;

	typedef FunctionBase::BaseRetValPtr BaseRetValPtr;
};

} /* end ns Wccl */

#endif // SETPREDICATE_H