| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 // // there is only one singleton for that type, which will conflict. If | 29 // // there is only one singleton for that type, which will conflict. If |
| 30 // // you're putting in some struct that's unique to you, go ahead. | 30 // // you're putting in some struct that's unique to you, go ahead. |
| 31 // PropertyAccessor<int>* my_accessor() const { | 31 // PropertyAccessor<int>* my_accessor() const { |
| 32 // static PropertyAccessor<int>* accessor = NULL; | 32 // static PropertyAccessor<int>* accessor = NULL; |
| 33 // if (!accessor) accessor = new PropertyAccessor<int>; | 33 // if (!accessor) accessor = new PropertyAccessor<int>; |
| 34 // return accessor; | 34 // return accessor; |
| 35 // } | 35 // } |
| 36 // | 36 // |
| 37 // void doit(SomeObjectThatImplementsPropertyBag* object) { | 37 // void doit(SomeObjectThatImplementsPropertyBag* object) { |
| 38 // PropertyAccessor<int>* accessor = my_accessor(); | 38 // PropertyAccessor<int>* accessor = my_accessor(); |
| 39 // int* property = accessor.GetProperty(object); | 39 // int* property = accessor->GetProperty(object); |
| 40 // if (property) | 40 // if (property) |
| 41 // ... use property ... | 41 // ... use property ... |
| 42 // | 42 // |
| 43 // accessor.SetProperty(object, 22); | 43 // accessor->SetProperty(object, 22); |
| 44 // } | 44 // } |
| 45 class PropertyBag { | 45 class PropertyBag { |
| 46 public: | 46 public: |
| 47 // The type that uniquely identifies a property type. | 47 // The type that uniquely identifies a property type. |
| 48 typedef int PropID; | 48 typedef int PropID; |
| 49 enum { NULL_PROP_ID = -1 }; // Invalid property ID. | 49 enum { NULL_PROP_ID = -1 }; // Invalid property ID. |
| 50 | 50 |
| 51 // Properties are all derived from this class. They must be deletable and | 51 // Properties are all derived from this class. They must be deletable and |
| 52 // copyable | 52 // copyable |
| 53 class Prop { | 53 class Prop { |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 |