Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_NSOBJECT_H_ | 5 #ifndef BASE_MAC_SCOPED_NSOBJECT_H_ |
| 6 #define BASE_MAC_SCOPED_NSOBJECT_H_ | 6 #define BASE_MAC_SCOPED_NSOBJECT_H_ |
| 7 | 7 |
| 8 #include <type_traits> | 8 #include <type_traits> |
| 9 | 9 |
| 10 // Include NSObject.h directly because Foundation.h pulls in many dependencies. | 10 // Include NSObject.h directly because Foundation.h pulls in many dependencies. |
| 11 // (Approx 100k lines of code versus 1.5k for NSObject.h). scoped_nsobject gets | 11 // (Approx 100k lines of code versus 1.5k for NSObject.h). scoped_nsobject gets |
| 12 // singled out because it is most typically included from other header files. | 12 // singled out because it is most typically included from other header files. |
| 13 #import <Foundation/NSObject.h> | 13 #import <Foundation/NSObject.h> |
| 14 | 14 |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/mac/scoped_typeref.h" | 16 #include "base/mac/scoped_typeref.h" |
| 17 | 17 |
| 18 @class NSAutoreleasePool; | 18 @class NSAutoreleasePool; |
| 19 | 19 |
| 20 namespace base { | 20 namespace base { |
| 21 | 21 |
| 22 // scoped_nsobject<> is patterned after scoped_ptr<>, but maintains ownership | 22 // scoped_nsobject<> is patterned after std::unique_ptr<>, but maintains |
| 23 // ownership | |
|
Nico
2016/04/04 17:14:56
likewise
dcheng
2016/04/04 17:43:38
Done.
| |
| 23 // of an NSObject subclass object. Style deviations here are solely for | 24 // of an NSObject subclass object. Style deviations here are solely for |
| 24 // compatibility with scoped_ptr<>'s interface, with which everyone is already | 25 // compatibility with std::unique_ptr<>'s interface, with which everyone is |
| 26 // already | |
| 25 // familiar. | 27 // familiar. |
| 26 // | 28 // |
| 27 // scoped_nsobject<> takes ownership of an object (in the constructor or in | 29 // scoped_nsobject<> takes ownership of an object (in the constructor or in |
| 28 // reset()) by taking over the caller's existing ownership claim. The caller | 30 // reset()) by taking over the caller's existing ownership claim. The caller |
| 29 // must own the object it gives to scoped_nsobject<>, and relinquishes an | 31 // must own the object it gives to scoped_nsobject<>, and relinquishes an |
| 30 // ownership claim to that object. scoped_nsobject<> does not call -retain, | 32 // ownership claim to that object. scoped_nsobject<> does not call -retain, |
| 31 // callers have to call this manually if appropriate. | 33 // callers have to call this manually if appropriate. |
| 32 // | 34 // |
| 33 // scoped_nsprotocol<> has the same behavior as scoped_nsobject, but can be used | 35 // scoped_nsprotocol<> has the same behavior as scoped_nsobject, but can be used |
| 34 // with protocols. | 36 // with protocols. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 // Specialization to make scoped_nsobject<id> work. | 91 // Specialization to make scoped_nsobject<id> work. |
| 90 template<> | 92 template<> |
| 91 class scoped_nsobject<id> : public scoped_nsprotocol<id> { | 93 class scoped_nsobject<id> : public scoped_nsprotocol<id> { |
| 92 public: | 94 public: |
| 93 using scoped_nsprotocol<id>::scoped_nsprotocol; | 95 using scoped_nsprotocol<id>::scoped_nsprotocol; |
| 94 }; | 96 }; |
| 95 | 97 |
| 96 } // namespace base | 98 } // namespace base |
| 97 | 99 |
| 98 #endif // BASE_MAC_SCOPED_NSOBJECT_H_ | 100 #endif // BASE_MAC_SCOPED_NSOBJECT_H_ |
| OLD | NEW |