From bc4d465484c67fa27d6c59807176d5f57155d9f5 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 3 May 2016 18:23:59 +0200 Subject: [PATCH] Clean up makeAny functions Let the templated makeAny(v) just call Any(v), so that any special handling of argument types needs to be only done for the Any ctor, not also for makeAny (both the original makeAny implementation and the Any ctor implementation internally use cppu::getTypeFavourUnsigned to determine the UNO type, so this does not cause any difference in behavior): * The specialization of makeAny for bool can be dropped. * The overload of makeAny for OUStringConcat is replaced with an overloaded Any ctor, so that Any(s + "foo") works now, too. Curiously, only the Any ctor had been deleted for a sal_uInt16 argument (which can conflict with sal_Unicode), but not makeAny. So introduce a specialization of makeAny for sal_uInt16, so that that continues to work. (For backwards compatiblity in the non-LIBO_INTERNAL_ONLY case; and in the LIBO_INIERNAL_ONLY case we're moving away from the sal_uInt16/sal_Unicode clash anyway thanks to C++11 char16_t, so it is arguably better to allow makeAny for sal_uIn16 than to prohibit it.) Change-Id: I7803703769730024863bb4e5b1b3416b81bd8960 --- include/com/sun/star/uno/Any.h | 12 +++++++----- include/com/sun/star/uno/Any.hxx | 27 ++++++++------------------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/include/com/sun/star/uno/Any.h b/include/com/sun/star/uno/Any.h index 90107d5cbb4b..8367eca7718b 100644 --- a/include/com/sun/star/uno/Any.h +++ b/include/com/sun/star/uno/Any.h @@ -23,14 +23,13 @@ #include +#include #include #include #include #include #include -namespace rtl { class OUString; } - namespace com { namespace sun @@ -78,6 +77,11 @@ public: /// Ctor support for C++ bool. explicit inline Any( bool value ); +#if defined LIBO_INTERNAL_ONLY + template + explicit inline Any(rtl::OUStringConcat const & value); +#endif + /** Copy constructor: Sets value of the given any. @param rAny another any @@ -289,9 +293,7 @@ template<> bool Any::has() const SAL_DELETED_FUNCTION; template< class C > inline Any SAL_CALL makeAny( const C & value ); -// additionally specialized for C++ bool -template<> -inline Any SAL_CALL makeAny( bool const & value ); +template<> inline Any SAL_CALL makeAny(sal_uInt16 const & value); template<> Any SAL_CALL makeAny(Any const &) SAL_DELETED_FUNCTION; diff --git a/include/com/sun/star/uno/Any.hxx b/include/com/sun/star/uno/Any.hxx index cbd8fb6e287e..d0a45061caa1 100644 --- a/include/com/sun/star/uno/Any.hxx +++ b/include/com/sun/star/uno/Any.hxx @@ -73,6 +73,11 @@ inline Any::Any( bool value ) cpp_acquire ); } +#if defined LIBO_INTERNAL_ONLY +template +Any::Any(rtl::OUStringConcat const & value): Any(rtl::OUString(value)) +{} +#endif inline Any::Any( const Any & rAny ) { @@ -183,27 +188,11 @@ inline bool Any::operator != ( const Any & rAny ) const template< class C > inline Any SAL_CALL makeAny( const C & value ) { - return Any( &value, ::cppu::getTypeFavourUnsigned(&value) ); + return Any(value); } -// additionally specialized for C++ bool - -template<> -inline Any SAL_CALL makeAny( bool const & value ) -{ - const sal_Bool b = value; - return Any( &b, cppu::UnoType::get() ); -} - - -#ifdef LIBO_INTERNAL_ONLY // "RTL_FAST_STRING" -template< class C1, class C2 > -inline Any SAL_CALL makeAny( const rtl::OUStringConcat< C1, C2 >& value ) -{ - const rtl::OUString str( value ); - return Any( &str, ::cppu::getTypeFavourUnsigned(&str) ); -} -#endif +template<> Any makeAny(sal_uInt16 const & value) +{ return Any(&value, cppu::UnoType::get()); } template Any toAny(T const & value) { return makeAny(value); }