| 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" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 if (object_ && policy == base::scoped_policy::RETAIN) | 60 if (object_ && policy == base::scoped_policy::RETAIN) |
| 61 object_ = Traits::Retain(object_); | 61 object_ = Traits::Retain(object_); |
| 62 } | 62 } |
| 63 | 63 |
| 64 ScopedTypeRef(const ScopedTypeRef<T, Traits>& that) | 64 ScopedTypeRef(const ScopedTypeRef<T, Traits>& that) |
| 65 : object_(that.object_) { | 65 : object_(that.object_) { |
| 66 if (object_) | 66 if (object_) |
| 67 object_ = Traits::Retain(object_); | 67 object_ = Traits::Retain(object_); |
| 68 } | 68 } |
| 69 | 69 |
| 70 // This allows passing an object to a function that takes its superclass. |
| 71 template <typename R, typename RTraits> |
| 72 ScopedTypeRef(const ScopedTypeRef<R, RTraits>& that_as_subclass) |
| 73 : object_(that_as_subclass.get()) { |
| 74 if (object_) |
| 75 object_ = Traits::Retain(object_); |
| 76 } |
| 77 |
| 70 // Without this, passing a ScopedTypeRef<A,TraitsX> to construct a | 78 // Without this, passing a ScopedTypeRef<A,TraitsX> to construct a |
| 71 // ScopedTypeRef<A,TraitsY> would automatically cast down to an A, and then | 79 // ScopedTypeRef<A,TraitsY> would automatically cast down to an A, and then |
| 72 // ASSUME ownership of A, when a retain is what was needed. | 80 // ASSUME ownership of A, when a retain is what was needed. |
| 73 template<typename OtherTraits> | 81 template<typename OtherTraits> |
| 74 ScopedTypeRef(const ScopedTypeRef<T, OtherTraits>& that_with_other_traits) | 82 ScopedTypeRef(const ScopedTypeRef<T, OtherTraits>& that_with_other_traits) |
| 75 : object_(that_with_other_traits.get()) { | 83 : object_(that_with_other_traits.get()) { |
| 76 if (object_) | 84 if (object_) |
| 77 object_ = Traits::Retain(object_); | 85 object_ = Traits::Retain(object_); |
| 78 } | 86 } |
| 79 | 87 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 return temp; | 148 return temp; |
| 141 } | 149 } |
| 142 | 150 |
| 143 private: | 151 private: |
| 144 T object_; | 152 T object_; |
| 145 }; | 153 }; |
| 146 | 154 |
| 147 } // namespace base | 155 } // namespace base |
| 148 | 156 |
| 149 #endif // BASE_MAC_SCOPED_TYPEREF_H_ | 157 #endif // BASE_MAC_SCOPED_TYPEREF_H_ |
| OLD | NEW |