OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 CHROME_COMMON_PROPERTY_BAG_H_ | 5 #ifndef CHROME_COMMON_PROPERTY_BAG_H_ |
6 #define CHROME_COMMON_PROPERTY_BAG_H_ | 6 #define CHROME_COMMON_PROPERTY_BAG_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 // Provides typesafe accessor functions for a property bag, and manages the | 124 // Provides typesafe accessor functions for a property bag, and manages the |
125 // unique identifiers for properties via the PropertyAccessorBase. | 125 // unique identifiers for properties via the PropertyAccessorBase. |
126 // | 126 // |
127 // Note that class T must be derived from PropertyBag::Prop. | 127 // Note that class T must be derived from PropertyBag::Prop. |
128 template<class T> | 128 template<class T> |
129 class PropertyAccessor : public PropertyAccessorBase { | 129 class PropertyAccessor : public PropertyAccessorBase { |
130 public: | 130 public: |
131 PropertyAccessor() : PropertyAccessorBase() {} | 131 PropertyAccessor() : PropertyAccessorBase() {} |
132 virtual ~PropertyAccessor() {} | 132 virtual ~PropertyAccessor() {} |
133 | 133 |
134 // Takes ownership of the |prop| pointer. | 134 // Makes a copy of the |prop| object for storage. |
135 void SetProperty(PropertyBag* bag, const T& prop) { | 135 void SetProperty(PropertyBag* bag, const T& prop) { |
136 SetPropertyInternal(bag, new Container(prop)); | 136 SetPropertyInternal(bag, new Container(prop)); |
137 } | 137 } |
138 | 138 |
139 // Returns our property in the given bag or NULL if there is no match. The | 139 // Returns our property in the given bag or NULL if there is no match. The |
140 // returned pointer's ownership will stay with the property bag. | 140 // returned pointer's ownership will stay with the property bag. |
141 T* GetProperty(PropertyBag* bag) { | 141 T* GetProperty(PropertyBag* bag) { |
142 PropertyBag::Prop* prop = GetPropertyInternal(bag); | 142 PropertyBag::Prop* prop = GetPropertyInternal(bag); |
143 if (!prop) | 143 if (!prop) |
144 return NULL; | 144 return NULL; |
(...skipping 21 matching lines...) Expand all Loading... |
166 return new Container(data_); | 166 return new Container(data_); |
167 } | 167 } |
168 | 168 |
169 T data_; | 169 T data_; |
170 }; | 170 }; |
171 | 171 |
172 DISALLOW_COPY_AND_ASSIGN(PropertyAccessor); | 172 DISALLOW_COPY_AND_ASSIGN(PropertyAccessor); |
173 }; | 173 }; |
174 | 174 |
175 #endif // CHROME_COMMON_PROPERTY_BAG_H_ | 175 #endif // CHROME_COMMON_PROPERTY_BAG_H_ |
OLD | NEW |