From 29940c41cc28722890145a909e885bf5558b6130 Mon Sep 17 00:00:00 2001
From: Adam Wardynski <award@.(B-4.4.46a)>
Date: Fri, 10 Dec 2010 16:51:44 +0100
Subject: [PATCH] Move check for Position in SentenceContext to the context. It
 is coherent now with the SentenceContext::is_inside(int abs_pos) -
 SentenceContext::is_inside(Position pos) is added, while
 Position::is_inside(SentenceContext) is removed

---
 .../ops/functions/bool/predicates/isinside.cpp    |  2 +-
 .../ops/functions/bool/predicates/isoutside.cpp   |  2 +-
 .../functions/bool/predicates/pointagreement.cpp  |  4 ++--
 libwccl/ops/functions/strset/getlemmas.cpp        |  2 +-
 libwccl/ops/functions/strset/getorth.cpp          |  2 +-
 libwccl/ops/functions/tset/catfilter.cpp          |  2 +-
 libwccl/ops/functions/tset/getsymbols.cpp         |  2 +-
 libwccl/sentencecontext.h                         | 15 +++++++++++++++
 libwccl/values/position.cpp                       |  6 ------
 libwccl/values/position.h                         | 11 -----------
 10 files changed, 23 insertions(+), 25 deletions(-)

diff --git a/libwccl/ops/functions/bool/predicates/isinside.cpp b/libwccl/ops/functions/bool/predicates/isinside.cpp
index a525d0b..a4a593a 100644
--- a/libwccl/ops/functions/bool/predicates/isinside.cpp
+++ b/libwccl/ops/functions/bool/predicates/isinside.cpp
@@ -6,7 +6,7 @@ namespace Wccl {
 IsInside::BaseRetValPtr IsInside::apply_internal(const FunExecContext& context) const
 {
 	const boost::shared_ptr<const Position>& pos = pos_expr_->apply(context);
-	return Predicate::evaluate(pos->is_inside(context.sentence_context()), context);
+	return Predicate::evaluate(context.sentence_context().is_inside(*pos), context);
 }
 
 std::string IsInside::to_string(const Corpus2::Tagset& tagset) const
diff --git a/libwccl/ops/functions/bool/predicates/isoutside.cpp b/libwccl/ops/functions/bool/predicates/isoutside.cpp
index d6228a6..5f6389e 100644
--- a/libwccl/ops/functions/bool/predicates/isoutside.cpp
+++ b/libwccl/ops/functions/bool/predicates/isoutside.cpp
@@ -6,7 +6,7 @@ namespace Wccl {
 IsOutside::BaseRetValPtr IsOutside::apply_internal(const FunExecContext& context) const
 {
 	const boost::shared_ptr<const Position>& pos = pos_expr_->apply(context);
-	return Predicate::evaluate(pos->is_outside(context.sentence_context()), context);
+	return Predicate::evaluate(context.sentence_context().is_outside(*pos), context);
 }
 
 std::string IsOutside::to_string(const Corpus2::Tagset& tagset) const
diff --git a/libwccl/ops/functions/bool/predicates/pointagreement.cpp b/libwccl/ops/functions/bool/predicates/pointagreement.cpp
index 8395083..6104f5e 100644
--- a/libwccl/ops/functions/bool/predicates/pointagreement.cpp
+++ b/libwccl/ops/functions/bool/predicates/pointagreement.cpp
@@ -26,11 +26,11 @@ PointAgreement::BaseRetValPtr PointAgreement::apply_internal(const FunExecContex
 	const SentenceContext& sc = context.sentence_context();
 
 	const boost::shared_ptr<const Position>& pos1 = pos1_expr_->apply(context);
-	if (pos1->is_outside(sc)) {
+	if (sc.is_outside(*pos1)) {
 		return Predicate::False(context);
 	}
 	const boost::shared_ptr<const Position>& pos2 = pos2_expr_->apply(context);
-	if (pos2->is_outside(sc)) {
+	if (sc.is_outside(*pos2)) {
 		return Predicate::False(context);
 	}
 
diff --git a/libwccl/ops/functions/strset/getlemmas.cpp b/libwccl/ops/functions/strset/getlemmas.cpp
index a1e9cbe..5153943 100644
--- a/libwccl/ops/functions/strset/getlemmas.cpp
+++ b/libwccl/ops/functions/strset/getlemmas.cpp
@@ -18,7 +18,7 @@ GetLemmas::BaseRetValPtr GetLemmas::apply_internal(const FunExecContext& context
 {
 	const boost::shared_ptr<const Position>& pos = pos_expr_->apply(context);
 	const SentenceContext& sc = context.sentence_context();
-	if(pos->is_outside(sc)) {
+	if (sc.is_outside(*pos)) {
 		return detail::DefaultFunction<StrSet>()->apply(context);
 	}
 	boost::shared_ptr<StrSet> u_set = boost::make_shared<StrSet>();
diff --git a/libwccl/ops/functions/strset/getorth.cpp b/libwccl/ops/functions/strset/getorth.cpp
index 0fd96ea..33371c4 100644
--- a/libwccl/ops/functions/strset/getorth.cpp
+++ b/libwccl/ops/functions/strset/getorth.cpp
@@ -18,7 +18,7 @@ GetOrth::BaseRetValPtr GetOrth::apply_internal(const FunExecContext& context) co
 {
 	const boost::shared_ptr<const Position>& pos = pos_expr_->apply(context);
 	const SentenceContext& sc = context.sentence_context();
-	if(pos->is_outside(sc)) {
+	if (sc.is_outside(*pos)) {
 		return detail::DefaultFunction<StrSet>()->apply(context);
 	}
 	boost::shared_ptr<StrSet> u_set = boost::make_shared<StrSet>();
diff --git a/libwccl/ops/functions/tset/catfilter.cpp b/libwccl/ops/functions/tset/catfilter.cpp
index d16faef..b5e1b24 100644
--- a/libwccl/ops/functions/tset/catfilter.cpp
+++ b/libwccl/ops/functions/tset/catfilter.cpp
@@ -25,7 +25,7 @@ CatFilter::BaseRetValPtr CatFilter::apply_internal(const FunExecContext& context
 {
 	const boost::shared_ptr<const Position>& pos = pos_expr_->apply(context);
 	const SentenceContext& sc = context.sentence_context();
-	if (pos->is_outside(sc)) {
+	if (sc.is_outside(*pos)) {
 		return detail::DefaultFunction<TSet>()->apply(context);
 	}
 
diff --git a/libwccl/ops/functions/tset/getsymbols.cpp b/libwccl/ops/functions/tset/getsymbols.cpp
index 4e4a376..d23f6ec 100644
--- a/libwccl/ops/functions/tset/getsymbols.cpp
+++ b/libwccl/ops/functions/tset/getsymbols.cpp
@@ -28,7 +28,7 @@ GetSymbols::BaseRetValPtr GetSymbols::apply_internal(const FunExecContext& conte
 {
 	const boost::shared_ptr<const Position>& pos = pos_expr_->apply(context);
 	const SentenceContext& sc = context.sentence_context();
-	if(pos->is_outside(sc)) {
+	if(sc.is_outside(*pos)) {
 		return detail::DefaultFunction<TSet>()->apply(context);
 	}
 
diff --git a/libwccl/sentencecontext.h b/libwccl/sentencecontext.h
index 7451d78..1fecb3f 100644
--- a/libwccl/sentencecontext.h
+++ b/libwccl/sentencecontext.h
@@ -57,6 +57,21 @@ public:
 		return abs_pos >= 0 && abs_pos < size();
 	}
 
+	/// Checks if the the given position is valid (in sentence bounds)
+	bool is_inside(const Position& pos) const {
+		return is_inside(get_abs_position(pos));
+	}
+
+	/// Checks if the the given absolute position is outside sentence, including nowhere
+	bool is_outside(int abs_pos) const {
+		return !is_inside(abs_pos);
+	}
+
+	/// Checks if the the given position is outside sentence, including nowhere
+	bool is_outside(const Position& pos) const {
+		return !is_inside(get_abs_position(pos));
+	}
+
 	/// Position setter
 	void set_position(int new_position) {
 		position_ = new_position;
diff --git a/libwccl/values/position.cpp b/libwccl/values/position.cpp
index 8b816c0..41a5aba 100644
--- a/libwccl/values/position.cpp
+++ b/libwccl/values/position.cpp
@@ -27,12 +27,6 @@ std::string Position::var_repr(const std::string &var_name)
 	return ss.str();
 }
 
-bool Position::is_inside(const SentenceContext& context) const
-{
-	int abs_position = context.get_abs_position(*this);
-	return context.is_inside(abs_position);
-}
-
 bool Position::equals(const Position& other, const SentenceContext& context) const
 {
 	return context.get_abs_position(*this) == context.get_abs_position(other);
diff --git a/libwccl/values/position.h b/libwccl/values/position.h
index 43984fe..943f280 100644
--- a/libwccl/values/position.h
+++ b/libwccl/values/position.h
@@ -48,17 +48,6 @@ public:
 	/// Value override
 	std::string to_raw_string() const;
 
-	/**
-	 * @returns True if Position is within bounds of a sentence, false otherwise.
-	 */
-	bool is_inside(const SentenceContext& context) const;
-
-	/**
-	 * @returns True if Position is outside of bounds of a sentence, false otherwise.
-	 */
-	bool is_outside(const SentenceContext& context) const {
-		return !is_inside(context);
-	}
 	/**
 	 * @returns True if underlying position values are equal, false otherwise.
 	 * @note This version does not take into account sentence context, only
-- 
GitLab