Kaydet (Commit) 9bc591fa authored tarafından Stephan Bergmann's avatar Stephan Bergmann

cid#1371307: Move semantics for BinaryAny

Change-Id: I30b8bb71f8a9e093183ee85484ccd694f3e1e10d
üst 178153e8
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "sal/config.h" #include "sal/config.h"
#include <cassert> #include <cassert>
#include <utility>
#include "typelib/typeclass.h" #include "typelib/typeclass.h"
#include "typelib/typedescription.hxx" #include "typelib/typedescription.hxx"
...@@ -29,6 +30,26 @@ ...@@ -29,6 +30,26 @@
namespace binaryurp { namespace binaryurp {
namespace {
// Cf. com::sun::star::uno::detail::moveAnyInternals in
// include/com/sun/star/uno/Any.hxx:
void moveInternals(uno_Any & from, uno_Any & to) {
uno_any_construct(&to, nullptr, nullptr, nullptr);
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").
}
}
BinaryAny::BinaryAny() throw () { BinaryAny::BinaryAny() throw () {
uno_any_construct(&data_, nullptr, nullptr, nullptr); uno_any_construct(&data_, nullptr, nullptr, nullptr);
} }
...@@ -52,6 +73,10 @@ BinaryAny::BinaryAny(BinaryAny const & other) throw () { ...@@ -52,6 +73,10 @@ BinaryAny::BinaryAny(BinaryAny const & other) throw () {
uno_type_any_construct(&data_, other.data_.pData, other.data_.pType, nullptr); uno_type_any_construct(&data_, other.data_.pData, other.data_.pType, nullptr);
} }
BinaryAny::BinaryAny(BinaryAny && other) throw () {
moveInternals(other.data_, data_);
}
BinaryAny::~BinaryAny() throw () { BinaryAny::~BinaryAny() throw () {
uno_any_destruct(&data_, nullptr); uno_any_destruct(&data_, nullptr);
} }
...@@ -63,6 +88,12 @@ BinaryAny & BinaryAny::operator =(BinaryAny const & other) throw () { ...@@ -63,6 +88,12 @@ BinaryAny & BinaryAny::operator =(BinaryAny const & other) throw () {
return *this; return *this;
} }
BinaryAny & BinaryAny::operator =(BinaryAny && other) throw () {
uno_any_destruct(&data_, nullptr);
moveInternals(other.data_, data_);
return *this;
}
css::uno::TypeDescription BinaryAny::getType() const throw () { css::uno::TypeDescription BinaryAny::getType() const throw () {
return css::uno::TypeDescription(data_.pType); return css::uno::TypeDescription(data_.pType);
} }
......
...@@ -43,10 +43,14 @@ public: ...@@ -43,10 +43,14 @@ public:
BinaryAny(BinaryAny const & other) throw (); BinaryAny(BinaryAny const & other) throw ();
BinaryAny(BinaryAny && other) throw ();
~BinaryAny() throw (); ~BinaryAny() throw ();
BinaryAny & operator =(BinaryAny const & other) throw (); BinaryAny & operator =(BinaryAny const & other) throw ();
BinaryAny & operator =(BinaryAny && other) throw ();
uno_Any& get() throw () { return data_; } uno_Any& get() throw () { return data_; }
com::sun::star::uno::TypeDescription getType() const throw (); com::sun::star::uno::TypeDescription getType() const throw ();
......
Markdown is supported
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