Skip to content
Snippets Groups Projects
Commit 3875a586 authored by Adam Wardynski's avatar Adam Wardynski
Browse files

Sentence context argument check in Operator's apply.

parent a6435107
No related merge requests found
...@@ -57,7 +57,7 @@ public: ...@@ -57,7 +57,7 @@ public:
/** /**
* Applies the functional operator to given sentence context. * Applies the functional operator to given sentence context.
* @returns Result of the application of this operator. * @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 * @note The result is conciously marked as const, so a copy of operator data
* is not created unless necessary. * is not created unless necessary.
* @see apply() - equivalent method; the \link operator()() operator() \endlink allows * @see apply() - equivalent method; the \link operator()() operator() \endlink allows
...@@ -77,12 +77,12 @@ public: ...@@ -77,12 +77,12 @@ public:
* for you to modify as you may see fit if you need it; * for you to modify as you may see fit if you need it;
* this is convenience method over having to create a copy yourself. * 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. * Applies the functional operator to given sentence context.
* @returns Result of the application of this operator. * @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 * @note The result is conciously marked as const, so a copy of operator data
* is not created unless necessary. * is not created unless necessary.
* @see \link operator()() operator() \endlink - an equivalent of this method that allows for functional * @see \link operator()() operator() \endlink - an equivalent of this method that allows for functional
...@@ -91,13 +91,13 @@ public: ...@@ -91,13 +91,13 @@ public:
* for you to modify as you may see fit if you need it; * for you to modify as you may see fit if you need it;
* this is convenience method over having to create a copy yourself. * 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 * Applies the functional operator to given sentence context, returning pointer
* to a mutable Value. * to a mutable Value.
* @returns Result of the application of this operator. * @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 * @see \link operator()() operator() \endlink, apply - you may still be
* better off using them if you expect to work on a raw value rather * better off using them if you expect to work on a raw value rather
* than a pointer, as in e.g. * than a pointer, as in e.g.
...@@ -110,7 +110,7 @@ public: ...@@ -110,7 +110,7 @@ public:
* shared_ptr<StrSet> s_ptr2 = op_ptr->copy_apply(sc); * shared_ptr<StrSet> s_ptr2 = op_ptr->copy_apply(sc);
* \endcode * \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. * Applies the functional operator to given sentence context.
...@@ -211,7 +211,12 @@ private: ...@@ -211,7 +211,12 @@ private:
boost::shared_ptr<const Function<T> > function_body_; boost::shared_ptr<const Function<T> > function_body_;
}; };
//
//--- implementation details --- //--- implementation details ---
//
inline inline
FunctionalOperator::FunctionalOperator( FunctionalOperator::FunctionalOperator(
...@@ -244,8 +249,18 @@ Operator<T>::Operator( ...@@ -244,8 +249,18 @@ Operator<T>::Operator(
} }
template <class T> inline template <class T> inline
boost::shared_ptr<const T> Operator<T>::apply(const SentenceContext &sc) { boost::shared_ptr<const T> Operator<T>::apply(const SentenceContext &sentence_context) {
return function_body_->apply(FunExecContext(sc, variables_)); 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 template <class T> inline
......
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