From 3875a586ff7325e26bb9b57673a205f820ee6013 Mon Sep 17 00:00:00 2001
From: Adam Wardynski <award@.(B-4.4.46a)>
Date: Fri, 3 Dec 2010 15:32:01 +0100
Subject: [PATCH] Sentence context argument check in Operator's apply.

---
 libwccl/ops/operator.h | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/libwccl/ops/operator.h b/libwccl/ops/operator.h
index 61d1d88..9ce8be5 100644
--- a/libwccl/ops/operator.h
+++ b/libwccl/ops/operator.h
@@ -57,7 +57,7 @@ public:
 	/**
 	 * Applies the functional operator to given sentence context.
 	 * @returns Result of the application of this operator.
-	 * @param sc SentenceContext of the Sentence to apply the operator to.
+	 * @param sentence_context SentenceContext of the Sentence to apply the operator to.
 	 * @note The result is conciously marked as const, so a copy of operator data
 	 * is not created unless necessary.
 	 * @see apply() - equivalent method; the \link operator()() operator() \endlink allows
@@ -77,12 +77,12 @@ public:
 	 * for you to modify as you may see fit if you need it;
 	 * this is convenience method over having to create a copy yourself.
 	 */
-	boost::shared_ptr<const T> operator()(const SentenceContext& sc);
+	boost::shared_ptr<const T> operator()(const SentenceContext& sentence_context);
 
 	/**
 	 * Applies the functional operator to given sentence context.
 	 * @returns Result of the application of this operator.
-	 * @param sc SentenceContext of the Sentence to apply the operator to.
+	 * @param sentence_context SentenceContext of the Sentence to apply the operator to.
 	 * @note The result is conciously marked as const, so a copy of operator data
 	 * is not created unless necessary.
 	 * @see \link operator()() operator() \endlink - an equivalent of this method that allows for functional
@@ -91,13 +91,13 @@ public:
 	 * for you to modify as you may see fit if you need it;
 	 * this is convenience method over having to create a copy yourself.
 	 */
-	boost::shared_ptr<const T> apply(const SentenceContext& sc);
+	boost::shared_ptr<const T> apply(const SentenceContext& sentence_context);
 
 	/**
 	 * Applies the functional operator to given sentence context, returning pointer
 	 * to a mutable Value.
 	 * @returns Result of the application of this operator.
-	 * @param sc SentenceContext of the Sentence to apply the operator to.
+	 * @param sentence_context SentenceContext of the Sentence to apply the operator to.
 	 * @see \link operator()() operator() \endlink, apply - you may still be
 	 * better off using them if you expect to work on a raw value rather
 	 * than a pointer, as in e.g.
@@ -110,7 +110,7 @@ public:
 	 * shared_ptr<StrSet> s_ptr2 = op_ptr->copy_apply(sc);
 	 * \endcode
 	 */
-	boost::shared_ptr<T> copy_apply(const SentenceContext& sc);
+	boost::shared_ptr<T> copy_apply(const SentenceContext& sentence_context);
 
 	/**
 	 * Applies the functional operator to given sentence context.
@@ -211,7 +211,12 @@ private:
 	boost::shared_ptr<const Function<T> > function_body_;
 };
 
+
+
+//
 //--- implementation details ---
+//
+
 
 inline
 FunctionalOperator::FunctionalOperator(
@@ -244,8 +249,18 @@ Operator<T>::Operator(
 }
 
 template <class T> inline
-boost::shared_ptr<const T> Operator<T>::apply(const SentenceContext &sc) {
-	return function_body_->apply(FunExecContext(sc, variables_));
+boost::shared_ptr<const T> Operator<T>::apply(const SentenceContext &sentence_context) {
+	if(sentence_context.size() == 0) {
+		throw InvalidArgument(
+				"sentence_context",
+				"Received an empty sentence.");
+	}
+	if(!sentence_context.is_current_inside()) {
+		throw InvalidArgument(
+				"sentence_context",
+				"Current position is outside boundaries of the sentence.");
+	}
+	return function_body_->apply(FunExecContext(sentence_context, variables_));
 }
 
 template <class T> inline
-- 
GitLab