OLD | NEW |
---|---|
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 a |
15 // ownership | |
Nico
2016/04/04 17:14:56
likewise
dcheng
2016/04/04 17:43:38
Done.
| |
15 // of a reference to any type that is maintained by Retain and Release methods. | 16 // of a reference to any type that is maintained by Retain and Release methods. |
16 // | 17 // |
17 // The Traits structure must provide the Retain and Release methods for type T. | 18 // 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 | 19 // 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 | 20 // for each type to use this interface. For example, an appropriate definition |
20 // of ScopedTypeRefTraits for CGLContextObj would be: | 21 // of ScopedTypeRefTraits for CGLContextObj would be: |
21 // | 22 // |
22 // template<> | 23 // template<> |
23 // struct ScopedTypeRefTraits<CGLContextObj> { | 24 // struct ScopedTypeRefTraits<CGLContextObj> { |
24 // static CGLContextObj InvalidValue() { return nullptr; } | 25 // static CGLContextObj InvalidValue() { return nullptr; } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 T get() const { | 125 T get() const { |
125 return object_; | 126 return object_; |
126 } | 127 } |
127 | 128 |
128 void swap(ScopedTypeRef& that) { | 129 void swap(ScopedTypeRef& that) { |
129 T temp = that.object_; | 130 T temp = that.object_; |
130 that.object_ = object_; | 131 that.object_ = object_; |
131 object_ = temp; | 132 object_ = temp; |
132 } | 133 } |
133 | 134 |
134 // ScopedTypeRef<>::release() is like scoped_ptr<>::release. It is NOT | 135 // ScopedTypeRef<>::release() is like std::unique_ptr<>::release. It is NOT |
135 // a wrapper for Release(). To force a ScopedTypeRef<> object to call | 136 // a wrapper for Release(). To force a ScopedTypeRef<> object to call |
136 // Release(), use ScopedTypeRef<>::reset(). | 137 // Release(), use ScopedTypeRef<>::reset(). |
137 T release() WARN_UNUSED_RESULT { | 138 T release() WARN_UNUSED_RESULT { |
138 T temp = object_; | 139 T temp = object_; |
139 object_ = Traits::InvalidValue(); | 140 object_ = Traits::InvalidValue(); |
140 return temp; | 141 return temp; |
141 } | 142 } |
142 | 143 |
143 private: | 144 private: |
144 T object_; | 145 T object_; |
145 }; | 146 }; |
146 | 147 |
147 } // namespace base | 148 } // namespace base |
148 | 149 |
149 #endif // BASE_MAC_SCOPED_TYPEREF_H_ | 150 #endif // BASE_MAC_SCOPED_TYPEREF_H_ |
OLD | NEW |