Bug 944176: Implement move construction and move assignment for mozilla::Scoped derivatives. r=waldo

This commit is contained in:
Jim Blandy 2014-03-27 09:52:48 -07:00
Родитель 7a81916776
Коммит 4138c776b2
1 изменённых файлов: 37 добавлений и 6 удалений

Просмотреть файл

@ -52,8 +52,10 @@
* the scope, graphics contexts, etc.
*/
#include "mozilla/Assertions.h"
#include "mozilla/Attributes.h"
#include "mozilla/GuardObjects.h"
#include "mozilla/Move.h"
#include "mozilla/NullPtr.h"
namespace mozilla {
@ -83,12 +85,23 @@ class Scoped
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
}
explicit Scoped(const Resource& v
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: value(v)
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
}
/* Move constructor. */
explicit Scoped(Scoped&& v
MOZ_GUARD_OBJECT_NOTIFIER_PARAM)
: value(Move(v.value))
{
MOZ_GUARD_OBJECT_NOTIFIER_INIT;
v.value = Traits::empty();
}
~Scoped() {
Traits::release(value);
}
@ -146,6 +159,14 @@ class Scoped
return *this;
}
/* Move assignment operator. */
Scoped& operator=(Scoped&& rhs) {
MOZ_ASSERT(&rhs != this, "self-move-assignment not allowed");
this->~Scoped();
new(this) Scoped(Move(rhs));
return *this;
}
private:
explicit Scoped(const Scoped& value) MOZ_DELETE;
Scoped& operator=(const Scoped& value) MOZ_DELETE;
@ -169,20 +190,30 @@ struct name : public mozilla::Scoped<Traits<Type> > \
{ \
typedef mozilla::Scoped<Traits<Type> > Super; \
typedef typename Super::Resource Resource; \
name& operator=(Resource ptr) { \
Super::operator=(ptr); \
name& operator=(Resource rhs) { \
Super::operator=(rhs); \
return *this; \
} \
name& operator=(name&& rhs) { \
Super::operator=(Move(rhs)); \
return *this; \
} \
explicit name(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM) \
: Super(MOZ_GUARD_OBJECT_NOTIFIER_ONLY_PARAM_TO_PARENT) \
{} \
explicit name(Resource ptr \
explicit name(Resource rhs \
MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \
: Super(ptr MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \
: Super(rhs \
MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \
{} \
explicit name(name&& rhs \
MOZ_GUARD_OBJECT_NOTIFIER_PARAM) \
: Super(Move(rhs) \
MOZ_GUARD_OBJECT_NOTIFIER_PARAM_TO_PARENT) \
{} \
private: \
explicit name(name& source) MOZ_DELETE; \
name& operator=(name& source) MOZ_DELETE; \
explicit name(name&) MOZ_DELETE; \
name& operator=(name&) MOZ_DELETE; \
};
/*