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..f26685cee9e0745a2a761e03711178ded046d43a 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 { |
grt (UTC plus 2)
2015/11/06 19:49:20
can you implement this in terms of ScopedGeneric?
anpol
2015/11/06 20:28:16
Looking at ScopedGeneric briefly:
* ScopedGDIObje
|
+ MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(ScopedGDIObject) |
+ |
public: |
- ScopedGDIObject() : object_(NULL) {} |
+ ScopedGDIObject() : object_(nullptr) {} |
+ ScopedGDIObject(decltype(nullptr)) : object_(nullptr) {} |
+ |
+ // Constructor that takes ownership of an object. |
explicit ScopedGDIObject(T object) : object_(object) {} |
+ // Constructor that transfers ownership from another ScopedGDIObject. |
+ ScopedGDIObject(ScopedGDIObject&& other) : object_(nullptr) { |
+ Set(other.release()); |
+ } |
+ |
~ScopedGDIObject() { |
Close(); |
} |
@@ -34,14 +45,27 @@ class ScopedGDIObject { |
object_ = object; |
} |
+ // operator= that deletes the currently owned object, if any. |
+ ScopedGDIObject& operator=(decltype(nullptr)) { |
+ Set(nullptr); |
+ return *this; |
+ } |
+ |
+ // operator= that takes ownership of an object. |
ScopedGDIObject& operator=(T object) { |
Set(object); |
return *this; |
} |
+ // operator= that transfers ownership from another ScopedGDIObject. |
+ ScopedGDIObject& operator=(ScopedGDIObject&& rhs) { |
+ Set(rhs.release()); |
+ return *this; |
+ } |
+ |
T release() { |
T object = object_; |
- object_ = NULL; |
+ object_ = nullptr; |
return object; |
} |
@@ -54,7 +78,6 @@ class ScopedGDIObject { |
} |
T object_; |
- DISALLOW_COPY_AND_ASSIGN(ScopedGDIObject); |
}; |
// An explicit specialization for HICON because we have to call DestroyIcon() |