summaryrefslogtreecommitdiff
path: root/binaryurp
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2016-08-19 08:35:03 +0200
committerStephan Bergmann <sbergman@redhat.com>2016-08-19 08:35:03 +0200
commit9bc591fa1e3723cee508e1484ad422fdef956d7d (patch)
tree247a03d1adecb0da730bdc603594fd9eba997551 /binaryurp
parent178153e8220aa3bf29078f6df4ed6acd0b2f61e4 (diff)
cid#1371307: Move semantics for BinaryAny
Change-Id: I30b8bb71f8a9e093183ee85484ccd694f3e1e10d
Diffstat (limited to 'binaryurp')
-rw-r--r--binaryurp/source/binaryany.cxx31
-rw-r--r--binaryurp/source/binaryany.hxx4
2 files changed, 35 insertions, 0 deletions
diff --git a/binaryurp/source/binaryany.cxx b/binaryurp/source/binaryany.cxx
index f6fffc063541..a4163767ec3c 100644
--- a/binaryurp/source/binaryany.cxx
+++ b/binaryurp/source/binaryany.cxx
@@ -20,6 +20,7 @@
#include "sal/config.h"
#include <cassert>
+#include <utility>
#include "typelib/typeclass.h"
#include "typelib/typedescription.hxx"
@@ -29,6 +30,26 @@
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 () {
uno_any_construct(&data_, nullptr, nullptr, nullptr);
}
@@ -52,6 +73,10 @@ BinaryAny::BinaryAny(BinaryAny const & other) throw () {
uno_type_any_construct(&data_, other.data_.pData, other.data_.pType, nullptr);
}
+BinaryAny::BinaryAny(BinaryAny && other) throw () {
+ moveInternals(other.data_, data_);
+}
+
BinaryAny::~BinaryAny() throw () {
uno_any_destruct(&data_, nullptr);
}
@@ -63,6 +88,12 @@ BinaryAny & BinaryAny::operator =(BinaryAny const & other) throw () {
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 () {
return css::uno::TypeDescription(data_.pType);
}
diff --git a/binaryurp/source/binaryany.hxx b/binaryurp/source/binaryany.hxx
index 717216ae5473..1faf4841b79b 100644
--- a/binaryurp/source/binaryany.hxx
+++ b/binaryurp/source/binaryany.hxx
@@ -43,10 +43,14 @@ public:
BinaryAny(BinaryAny const & other) throw ();
+ BinaryAny(BinaryAny && other) throw ();
+
~BinaryAny() throw ();
BinaryAny & operator =(BinaryAny const & other) throw ();
+ BinaryAny & operator =(BinaryAny && other) throw ();
+
uno_Any& get() throw () { return data_; }
com::sun::star::uno::TypeDescription getType() const throw ();