| 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/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 template<typename T> | 45 template<typename T> |
| 46 struct ScopedTypeRefTraits; | 46 struct ScopedTypeRefTraits; |
| 47 | 47 |
| 48 template<typename T, typename Traits = ScopedTypeRefTraits<T>> | 48 template<typename T, typename Traits = ScopedTypeRefTraits<T>> |
| 49 class ScopedTypeRef { | 49 class ScopedTypeRef { |
| 50 public: | 50 public: |
| 51 typedef T element_type; | 51 typedef T element_type; |
| 52 | 52 |
| 53 ScopedTypeRef( | 53 ScopedTypeRef( |
| 54 T object = NULL, | 54 T object = 0, |
| 55 base::scoped_policy::OwnershipPolicy policy = base::scoped_policy::ASSUME) | 55 base::scoped_policy::OwnershipPolicy policy = base::scoped_policy::ASSUME) |
| 56 : object_(object) { | 56 : object_(object) { |
| 57 if (object_ && policy == base::scoped_policy::RETAIN) | 57 if (object_ && policy == base::scoped_policy::RETAIN) |
| 58 Traits::Retain(object_); | 58 Traits::Retain(object_); |
| 59 } | 59 } |
| 60 | 60 |
| 61 ScopedTypeRef(const ScopedTypeRef<T, Traits>& that) | 61 ScopedTypeRef(const ScopedTypeRef<T, Traits>& that) |
| 62 : object_(that.object_) { | 62 : object_(that.object_) { |
| 63 if (object_) | 63 if (object_) |
| 64 Traits::Retain(object_); | 64 Traits::Retain(object_); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 return temp; | 123 return temp; |
| 124 } | 124 } |
| 125 | 125 |
| 126 private: | 126 private: |
| 127 T object_; | 127 T object_; |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 } // namespace base | 130 } // namespace base |
| 131 | 131 |
| 132 #endif // BASE_MAC_SCOPED_TYPEREF_H_ | 132 #endif // BASE_MAC_SCOPED_TYPEREF_H_ |
| OLD | NEW |