Index: base/win/scoped_gdi_object.h |
diff --git a/base/win/scoped_gdi_object.h b/base/win/scoped_gdi_object.h |
index 57b013e2fbaae8cf80fc7f32a452b204fc4b923c..e61cc6208cb13f901a84912f0d27ab1f4ab52859 100644 |
--- a/base/win/scoped_gdi_object.h |
+++ b/base/win/scoped_gdi_object.h |
@@ -9,6 +9,7 @@ |
#include "base/basictypes.h" |
#include "base/logging.h" |
+#include "base/move.h" |
namespace base { |
namespace win { |
@@ -16,10 +17,20 @@ namespace win { |
// Like ScopedHandle but for GDI objects. |
template<class T> |
class ScopedGDIObject { |
+ MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(ScopedGDIObject) |
+ |
public: |
+ // Constructor that defaults to initializing with NULL. |
ScopedGDIObject() : object_(NULL) {} |
+ |
+ // Constructor that takes ownership of an object. |
sky
2015/11/03 17:23:15
This comment is useful as it clearly documents own
|
explicit ScopedGDIObject(T object) : object_(object) {} |
+ // Constructor that allows construction from an rvalue. |
+ ScopedGDIObject(ScopedGDIObject&& other) : object_(NULL) { |
sky
2015/11/03 17:23:14
If you can, make these nullptr.
|
+ Set(other.release()); |
+ } |
+ |
~ScopedGDIObject() { |
Close(); |
} |
@@ -34,11 +45,18 @@ class ScopedGDIObject { |
object_ = object; |
} |
+ // operator= that takes ownership of an object. |
ScopedGDIObject& operator=(T object) { |
Set(object); |
return *this; |
} |
+ // operator= that allows assignment from an rvalue. |
+ ScopedGDIObject& operator=(ScopedGDIObject&& rhs) { |
+ Set(rhs.release()); |
+ return *this; |
+ } |
+ |
T release() { |
T object = object_; |
object_ = NULL; |
@@ -54,7 +72,6 @@ class ScopedGDIObject { |
} |
T object_; |
- DISALLOW_COPY_AND_ASSIGN(ScopedGDIObject); |
}; |
// An explicit specialization for HICON because we have to call DestroyIcon() |