From 0fbe22a77289a624e1346ab457734c2f64f8e6fb Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Mon, 6 Jun 2016 15:05:16 +0200 Subject: css::uno::Any move semantics (for LIBO_INTERNAL_ONLY) Change-Id: Ib582a744321e0f209395651ac2edffe30152ffba --- include/com/sun/star/uno/Any.h | 5 +++++ include/com/sun/star/uno/Any.hxx | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) (limited to 'include/com') diff --git a/include/com/sun/star/uno/Any.h b/include/com/sun/star/uno/Any.h index 26127f4add37..d6c7477d3f4c 100644 --- a/include/com/sun/star/uno/Any.h +++ b/include/com/sun/star/uno/Any.h @@ -135,6 +135,11 @@ public: */ inline Any & SAL_CALL operator = ( const Any & rAny ); +#if defined LIBO_INTERNAL_ONLY + inline Any(Any && other); + inline Any & operator =(Any && other); +#endif + /** Gets the type of the set value. @return a Type object of the set value diff --git a/include/com/sun/star/uno/Any.hxx b/include/com/sun/star/uno/Any.hxx index 8859fa76809b..1e1f24e85fc8 100644 --- a/include/com/sun/star/uno/Any.hxx +++ b/include/com/sun/star/uno/Any.hxx @@ -21,6 +21,7 @@ #include +#include #include #include #include @@ -120,6 +121,38 @@ inline Any & Any::operator = ( const Any & rAny ) return *this; } +#if defined LIBO_INTERNAL_ONLY + +namespace detail { + +inline void moveAnyInternals(Any & from, Any & to) { + uno_any_construct(&to, nullptr, nullptr, &cpp_acquire); + std::swap(from.pType, to.pType); + std::swap(from.pData, to.pData); + std::swap(from.pReserved, to.pReserved); + if (to.pData == &from.pReserved) { + to.pData = &to.pReserved; + } + // This leaves to.pData (where "to" is now VOID) dangling to somewhere (cf. + // CONSTRUCT_EMPTY_ANY, cppu/source/uno/prim.hxx), but what's relevant is + // only that it isn't a nullptr (as e.g. >>= -> uno_type_assignData -> + // _assignData takes a null pSource to mean "construct a default value"). +} + +} + +Any::Any(Any && other) { + detail::moveAnyInternals(other, *this); +} + +Any & Any::operator =(Any && other) { + uno_any_destruct(this, &cpp_release); + detail::moveAnyInternals(other, *this); + return *this; +} + +#endif + inline ::rtl::OUString Any::getValueTypeName() const { return ::rtl::OUString( pType->pTypeName ); -- cgit