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

Side by Side Diff: base/mac/scoped_typeref.h

Issue 1852433005: Convert //base to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase after r384946 Created 4 years, 8 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
« no previous file with comments | « base/mac/scoped_nsobject.h ('k') | base/macros.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_MAC_SCOPED_TYPEREF_H_ 5 #ifndef BASE_MAC_SCOPED_TYPEREF_H_
6 #define BASE_MAC_SCOPED_TYPEREF_H_ 6 #define BASE_MAC_SCOPED_TYPEREF_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_policy.h" 10 #include "base/memory/scoped_policy.h"
11 11
12 namespace base { 12 namespace base {
13 13
14 // ScopedTypeRef<> is patterned after scoped_ptr<>, but maintains a ownership 14 // ScopedTypeRef<> is patterned after std::unique_ptr<>, but maintains ownership
15 // of a reference to any type that is maintained by Retain and Release methods. 15 // of a reference to any type that is maintained by Retain and Release methods.
16 // 16 //
17 // The Traits structure must provide the Retain and Release methods for type T. 17 // The Traits structure must provide the Retain and Release methods for type T.
18 // A default ScopedTypeRefTraits is used but not defined, and should be defined 18 // A default ScopedTypeRefTraits is used but not defined, and should be defined
19 // for each type to use this interface. For example, an appropriate definition 19 // for each type to use this interface. For example, an appropriate definition
20 // of ScopedTypeRefTraits for CGLContextObj would be: 20 // of ScopedTypeRefTraits for CGLContextObj would be:
21 // 21 //
22 // template<> 22 // template<>
23 // struct ScopedTypeRefTraits<CGLContextObj> { 23 // struct ScopedTypeRefTraits<CGLContextObj> {
24 // static CGLContextObj InvalidValue() { return nullptr; } 24 // static CGLContextObj InvalidValue() { return nullptr; }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 T get() const { 124 T get() const {
125 return object_; 125 return object_;
126 } 126 }
127 127
128 void swap(ScopedTypeRef& that) { 128 void swap(ScopedTypeRef& that) {
129 T temp = that.object_; 129 T temp = that.object_;
130 that.object_ = object_; 130 that.object_ = object_;
131 object_ = temp; 131 object_ = temp;
132 } 132 }
133 133
134 // ScopedTypeRef<>::release() is like scoped_ptr<>::release. It is NOT 134 // ScopedTypeRef<>::release() is like std::unique_ptr<>::release. It is NOT
135 // a wrapper for Release(). To force a ScopedTypeRef<> object to call 135 // a wrapper for Release(). To force a ScopedTypeRef<> object to call
136 // Release(), use ScopedTypeRef<>::reset(). 136 // Release(), use ScopedTypeRef<>::reset().
137 T release() WARN_UNUSED_RESULT { 137 T release() WARN_UNUSED_RESULT {
138 T temp = object_; 138 T temp = object_;
139 object_ = Traits::InvalidValue(); 139 object_ = Traits::InvalidValue();
140 return temp; 140 return temp;
141 } 141 }
142 142
143 private: 143 private:
144 T object_; 144 T object_;
145 }; 145 };
146 146
147 } // namespace base 147 } // namespace base
148 148
149 #endif // BASE_MAC_SCOPED_TYPEREF_H_ 149 #endif // BASE_MAC_SCOPED_TYPEREF_H_
OLDNEW
« no previous file with comments | « base/mac/scoped_nsobject.h ('k') | base/macros.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698