| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_OBJC_PROPERTY_RELEASER_H_ | 5 #ifndef BASE_MAC_OBJC_PROPERTY_RELEASER_H_ |
| 6 #define BASE_MAC_OBJC_PROPERTY_RELEASER_H_ | 6 #define BASE_MAC_OBJC_PROPERTY_RELEASER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #import <Foundation/Foundation.h> | 9 #import <Foundation/Foundation.h> |
| 10 | 10 |
| 11 #include "base/base_api.h" | 11 #include "base/base_export.h" |
| 12 | 12 |
| 13 namespace base { | 13 namespace base { |
| 14 namespace mac { | 14 namespace mac { |
| 15 | 15 |
| 16 // ObjCPropertyReleaser is a C++ class that can automatically release | 16 // ObjCPropertyReleaser is a C++ class that can automatically release |
| 17 // synthesized Objective-C properties marked "retain" or "copy". The expected | 17 // synthesized Objective-C properties marked "retain" or "copy". The expected |
| 18 // use is to place an ObjCPropertyReleaser object within an Objective-C class | 18 // use is to place an ObjCPropertyReleaser object within an Objective-C class |
| 19 // definition. When built with the -fobjc-call-cxx-cdtors compiler option, | 19 // definition. When built with the -fobjc-call-cxx-cdtors compiler option, |
| 20 // the ObjCPropertyReleaser's destructor will be called when the Objective-C | 20 // the ObjCPropertyReleaser's destructor will be called when the Objective-C |
| 21 // object that owns it is deallocated, and it will send a -release message to | 21 // object that owns it is deallocated, and it will send a -release message to |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // notAProperty_ because it doesn't correspond to any declared @property. | 76 // notAProperty_ because it doesn't correspond to any declared @property. |
| 77 // | 77 // |
| 78 // Another way of doing this would be to provide a base class that others can | 78 // Another way of doing this would be to provide a base class that others can |
| 79 // inherit from, and to have the base class' -dealloc walk the property lists | 79 // inherit from, and to have the base class' -dealloc walk the property lists |
| 80 // of all subclasses in an object to send the -release messages. Since this | 80 // of all subclasses in an object to send the -release messages. Since this |
| 81 // involves a base reaching into its subclasses, it's deemed scary, so don't | 81 // involves a base reaching into its subclasses, it's deemed scary, so don't |
| 82 // do it. ObjCPropertyReleaser's design ensures that the property releaser | 82 // do it. ObjCPropertyReleaser's design ensures that the property releaser |
| 83 // will only operate on instance variables in the immediate object in which | 83 // will only operate on instance variables in the immediate object in which |
| 84 // the property releaser is placed. | 84 // the property releaser is placed. |
| 85 | 85 |
| 86 class BASE_API ObjCPropertyReleaser { | 86 class BASE_EXPORT ObjCPropertyReleaser { |
| 87 public: | 87 public: |
| 88 // ObjCPropertyReleaser can only be owned by an Objective-C object, so its | 88 // ObjCPropertyReleaser can only be owned by an Objective-C object, so its |
| 89 // memory is always guaranteed to be 0-initialized. Not defining the default | 89 // memory is always guaranteed to be 0-initialized. Not defining the default |
| 90 // constructor can prevent an otherwise no-op -.cxx_construct method from | 90 // constructor can prevent an otherwise no-op -.cxx_construct method from |
| 91 // showing up in Objective-C classes that contain a ObjCPropertyReleaser. | 91 // showing up in Objective-C classes that contain a ObjCPropertyReleaser. |
| 92 | 92 |
| 93 // Upon destruction (expected to occur from an Objective-C object's | 93 // Upon destruction (expected to occur from an Objective-C object's |
| 94 // -.cxx_destruct method), release all properties. | 94 // -.cxx_destruct method), release all properties. |
| 95 ~ObjCPropertyReleaser() { | 95 ~ObjCPropertyReleaser() { |
| 96 ReleaseProperties(); | 96 ReleaseProperties(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 119 | 119 |
| 120 private: | 120 private: |
| 121 id object_; | 121 id object_; |
| 122 Class class_; | 122 Class class_; |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 } // namespace mac | 125 } // namespace mac |
| 126 } // namespace base | 126 } // namespace base |
| 127 | 127 |
| 128 #endif // BASE_MAC_OBJC_PROPERTY_RELEASER_H_ | 128 #endif // BASE_MAC_OBJC_PROPERTY_RELEASER_H_ |
| OLD | NEW |