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 CONTENT_COMMON_PROPERTY_BAG_H_ | 5 #ifndef CONTENT_COMMON_PROPERTY_BAG_H_ |
6 #define CONTENT_COMMON_PROPERTY_BAG_H_ | 6 #define CONTENT_COMMON_PROPERTY_BAG_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "content/common/content_export.h" |
12 | 13 |
13 template <typename T> | 14 template <typename T> |
14 class linked_ptr; | 15 class linked_ptr; |
15 class PropertyAccessorBase; | 16 class PropertyAccessorBase; |
16 | 17 |
17 // A property bag holds a generalized list of arbitrary metadata called | 18 // A property bag holds a generalized list of arbitrary metadata called |
18 // properties. Each property is a class type derived from PropertyBag::Prop | 19 // properties. Each property is a class type derived from PropertyBag::Prop |
19 // that can be set and retrieved. | 20 // that can be set and retrieved. |
20 // | 21 // |
21 // The property bag is not read or written directly. Instead, callers go | 22 // The property bag is not read or written directly. Instead, callers go |
(...skipping 13 matching lines...) Expand all Loading... |
35 // } | 36 // } |
36 // | 37 // |
37 // void doit(SomeObjectThatImplementsPropertyBag* object) { | 38 // void doit(SomeObjectThatImplementsPropertyBag* object) { |
38 // PropertyAccessor<int>* accessor = my_accessor(); | 39 // PropertyAccessor<int>* accessor = my_accessor(); |
39 // int* property = accessor->GetProperty(object); | 40 // int* property = accessor->GetProperty(object); |
40 // if (property) | 41 // if (property) |
41 // ... use property ... | 42 // ... use property ... |
42 // | 43 // |
43 // accessor->SetProperty(object, 22); | 44 // accessor->SetProperty(object, 22); |
44 // } | 45 // } |
45 class PropertyBag { | 46 class CONTENT_EXPORT PropertyBag { |
46 public: | 47 public: |
47 // The type that uniquely identifies a property type. | 48 // The type that uniquely identifies a property type. |
48 typedef int PropID; | 49 typedef int PropID; |
49 enum { NULL_PROP_ID = -1 }; // Invalid property ID. | 50 enum { NULL_PROP_ID = -1 }; // Invalid property ID. |
50 | 51 |
51 // Properties are all derived from this class. They must be deletable and | 52 // Properties are all derived from this class. They must be deletable and |
52 // copyable | 53 // copyable |
53 class Prop { | 54 class Prop { |
54 public: | 55 public: |
55 virtual ~Prop() {} | 56 virtual ~Prop() {} |
(...skipping 30 matching lines...) Expand all Loading... |
86 | 87 |
87 PropertyMap props_; | 88 PropertyMap props_; |
88 | 89 |
89 // Copy and assign is explicitly allowed for this class. | 90 // Copy and assign is explicitly allowed for this class. |
90 }; | 91 }; |
91 | 92 |
92 // PropertyAccessorBase ------------------------------------------------------- | 93 // PropertyAccessorBase ------------------------------------------------------- |
93 | 94 |
94 // Manages getting the unique IDs to identify a property. Callers should use | 95 // Manages getting the unique IDs to identify a property. Callers should use |
95 // PropertyAccessor below instead. | 96 // PropertyAccessor below instead. |
96 class PropertyAccessorBase { | 97 class CONTENT_EXPORT PropertyAccessorBase { |
97 public: | 98 public: |
98 PropertyAccessorBase(); | 99 PropertyAccessorBase(); |
99 virtual ~PropertyAccessorBase() {} | 100 virtual ~PropertyAccessorBase() {} |
100 | 101 |
101 // Removes our property, if any, from the given property bag. | 102 // Removes our property, if any, from the given property bag. |
102 void DeleteProperty(PropertyBag* bag) { | 103 void DeleteProperty(PropertyBag* bag) { |
103 bag->DeleteProperty(prop_id_); | 104 bag->DeleteProperty(prop_id_); |
104 } | 105 } |
105 | 106 |
106 protected: | 107 protected: |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 return new Container(data_); | 167 return new Container(data_); |
167 } | 168 } |
168 | 169 |
169 T data_; | 170 T data_; |
170 }; | 171 }; |
171 | 172 |
172 DISALLOW_COPY_AND_ASSIGN(PropertyAccessor); | 173 DISALLOW_COPY_AND_ASSIGN(PropertyAccessor); |
173 }; | 174 }; |
174 | 175 |
175 #endif // CONTENT_COMMON_PROPERTY_BAG_H_ | 176 #endif // CONTENT_COMMON_PROPERTY_BAG_H_ |
OLD | NEW |