Index: base/memory/scoped_nsobject.h |
diff --git a/base/memory/scoped_nsobject.h b/base/memory/scoped_nsobject.h |
index 65e35d5623280599c6498b1a89595e9143392ba8..cdcdd6380e6413501ad8e4a77a512b5bc54f2779 100644 |
--- a/base/memory/scoped_nsobject.h |
+++ b/base/memory/scoped_nsobject.h |
@@ -160,4 +160,49 @@ class scoped_nsobject<NSAutoreleasePool> { |
DISALLOW_COPY_AND_ASSIGN(scoped_nsobject); |
}; |
+// Equivalent of scoped_nsobject for a id<protocol>. |
Mark Mentovai
2012/01/26 14:21:15
This is just scoped_nsobject without the helpful *
qsr
2012/01/26 14:34:50
Done.
|
+template<typename NST> |
+class scoped_nsprotocol { |
+ public: |
+ explicit scoped_nsprotocol(NST object = nil) : object_(object) { |
+ } |
+ |
+ ~scoped_nsprotocol() { |
+ [object_ release]; |
+ } |
+ |
+ void reset(NST object = nil) { |
+ [object_ release]; |
+ object_ = object; |
+ } |
+ |
+ bool operator==(NST that) const { return object_ == that; } |
+ bool operator!=(NST that) const { return object_ != that; } |
+ |
+ operator NST() const { |
+ return object_; |
+ } |
+ |
+ NST get() const { |
+ return object_; |
+ } |
+ |
+ void swap(scoped_nsprotocol& that) { |
+ NST temp = that.object_; |
+ that.object_ = object_; |
+ object_ = temp; |
+ } |
+ |
+ NST release() WARN_UNUSED_RESULT { |
+ NST temp = object_; |
+ object_ = nil; |
+ return temp; |
+ } |
+ |
+ private: |
+ NST object_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(scoped_nsprotocol); |
+}; |
+ |
#endif // BASE_MEMORY_SCOPED_NSOBJECT_H_ |