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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_SCOPED_NSOBJECT_H_ 5 #ifndef BASE_SCOPED_NSOBJECT_H_
6 #define BASE_SCOPED_NSOBJECT_H_ 6 #define BASE_SCOPED_NSOBJECT_H_
7 7
8 #import <Foundation/Foundation.h> 8 #import <Foundation/Foundation.h>
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 10
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 object_ = nil; 66 object_ = nil;
67 return temp; 67 return temp;
68 } 68 }
69 69
70 private: 70 private:
71 NST* object_; 71 NST* object_;
72 72
73 DISALLOW_COPY_AND_ASSIGN(scoped_nsobject); 73 DISALLOW_COPY_AND_ASSIGN(scoped_nsobject);
74 }; 74 };
75 75
76 // Specialization to make scoped_nsobject<id> work.
77 template<>
78 class scoped_nsobject<id> {
79 public:
80 typedef id element_type;
81
82 explicit scoped_nsobject(id object = nil)
83 : object_(object) {
84 }
85
86 ~scoped_nsobject() {
87 [object_ release];
88 }
89
90 void reset(id object = nil) {
91 [object_ release];
92 object_ = object;
93 }
94
95 bool operator==(id that) const {
96 return object_ == that;
97 }
98
99 bool operator!=(id that) const {
100 return object_ != that;
101 }
102
103 operator id() const {
104 return object_;
105 }
106
107 id get() const {
108 return object_;
109 }
110
111 void swap(scoped_nsobject& that) {
112 id temp = that.object_;
113 that.object_ = object_;
114 object_ = temp;
115 }
116
117 // scoped_nsobject<>::release() is like scoped_ptr<>::release. It is NOT
118 // a wrapper for [object_ release]. To force a scoped_nsobject<> object to
119 // call [object_ release], use scoped_nsobject<>::reset().
120 id release() {
121 id temp = object_;
122 object_ = nil;
123 return temp;
124 }
125
126 private:
127 id object_;
128
129 DISALLOW_COPY_AND_ASSIGN(scoped_nsobject);
130 };
131
76 #endif // BASE_SCOPED_NSOBJECT_H_ 132 #endif // BASE_SCOPED_NSOBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698