From 8ed33c3e9e2648a5a0150c05e06c228336e9e9d6 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sun, 17 Aug 2014 13:32:22 +0200 Subject: Fixed minimum parameter count calculation * the minimum count of parameters to a external function is the maximum parameter count minus all optional parameters * updated error message of "FunctionBase" member method "getError" to reflect the newly implemented possibility of optional parameters --- src/function/base.h | 35 +++++++++++++++++++++++++---------- src/support/type/filter.h | 4 ++-- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/function/base.h b/src/function/base.h index a8f93b9..3726aa8 100644 --- a/src/function/base.h +++ b/src/function/base.h @@ -26,8 +26,9 @@ template < typename... Types > class FunctionBase : public xalan::Function { - static const std::size_t parameter_count = sizeof...(Types); - static const std::size_t optional_parameter_count = std::tuple_size< + static const std::size_t maximum_parameter_count = sizeof...(Types); + static const std::size_t minimum_parameter_count = maximum_parameter_count + - std::tuple_size< typename filter_derived< boost::optional_detail::optional_tag, Types... @@ -56,7 +57,7 @@ class FunctionBase : public xalan::Function { this->callConstructDocument( parameters, locator, - typename IndexSequence::type() + typename IndexSequence::type() ) ); @@ -90,11 +91,25 @@ class FunctionBase : public xalan::Function { const xalan::XalanDOMString& getError( xalan::XalanDOMString& result) const { - result.assign(std::string( - "The function expects " + - std::to_string(parameter_count) + - " parameter(s)" - ).data()); + const std::string startText("The function expects "); + const std::string endText(" parameter(s)"); + + if ( minimum_parameter_count == maximum_parameter_count ) { + result.assign(std::string( + startText + + std::to_string(minimum_parameter_count) + + endText + ).data()); + } else { + result.assign(std::string( + startText + + "between " + + std::to_string(minimum_parameter_count) + + " and " + + std::to_string(maximum_parameter_count) + + endText + ).data()); + } return result; } @@ -140,8 +155,8 @@ class FunctionBase : public xalan::Function { } ); - if ( parameters.size() > parameter_count || - parameters.size() < optional_parameter_count || + if ( parameters.size() > maximum_parameter_count || + parameters.size() < minimum_parameter_count || anyNull ) { xalan::XPathExecutionContext::GetAndReleaseCachedString guard( executionContext diff --git a/src/support/type/filter.h b/src/support/type/filter.h index 4a0e19f..1433b30 100644 --- a/src/support/type/filter.h +++ b/src/support/type/filter.h @@ -7,13 +7,13 @@ namespace InputXSLT { template < - typename BaseReference, + typename Base, typename Head, typename... Tail > struct filter_derived { typedef typename std::conditional< - std::is_base_of::value, + std::is_base_of::value, std::tuple, std::tuple >::type type; -- cgit v1.2.3