Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(645)

Unified Diff: base/scoped_nsobject.h

Issue 159780: Add support for constrained windows on os x, based on Avi's GTMWindowSheetController. (Closed)
Patch Set: Merge with ToT Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/scoped_nsobject.h
diff --git a/base/scoped_nsobject.h b/base/scoped_nsobject.h
index 2c808c69a0393568b62ccc34f77e64d1b9234fb9..5f6d8bf8d77d5968065d339fd7a6bf078856b017 100644
--- a/base/scoped_nsobject.h
+++ b/base/scoped_nsobject.h
@@ -73,4 +73,60 @@ class scoped_nsobject {
DISALLOW_COPY_AND_ASSIGN(scoped_nsobject);
};
+// Specialization to make scoped_nsobject<id> work.
+template<>
+class scoped_nsobject<id> {
+ public:
+ typedef id element_type;
+
+ explicit scoped_nsobject(id object = nil)
+ : object_(object) {
+ }
+
+ ~scoped_nsobject() {
+ [object_ release];
+ }
+
+ void reset(id object = nil) {
+ [object_ release];
+ object_ = object;
+ }
+
+ bool operator==(id that) const {
+ return object_ == that;
+ }
+
+ bool operator!=(id that) const {
+ return object_ != that;
+ }
+
+ operator id() const {
+ return object_;
+ }
+
+ id get() const {
+ return object_;
+ }
+
+ void swap(scoped_nsobject& that) {
+ id temp = that.object_;
+ that.object_ = object_;
+ object_ = temp;
+ }
+
+ // scoped_nsobject<>::release() is like scoped_ptr<>::release. It is NOT
+ // a wrapper for [object_ release]. To force a scoped_nsobject<> object to
+ // call [object_ release], use scoped_nsobject<>::reset().
+ id release() {
+ id temp = object_;
+ object_ = nil;
+ return temp;
+ }
+
+ private:
+ id object_;
+
+ DISALLOW_COPY_AND_ASSIGN(scoped_nsobject);
+};
+
#endif // BASE_SCOPED_NSOBJECT_H_

Powered by Google App Engine
This is Rietveld 408576698