Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: base/property_bag.h

Issue 8652002: Move PropertyBag to base. Originally this was in chrome\common because only chrome used it. Now t... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: move to base namespace and forward declare where possible Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/base.gypi ('k') | base/property_bag.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 BASE_PROPERTY_BAG_H_
6 #define CONTENT_COMMON_PROPERTY_BAG_H_ 6 #define BASE_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 #include "base/base_export.h"
13 13
14 template <typename T> 14 template <typename T> class linked_ptr;
15 class linked_ptr; 15
16 namespace base {
17
16 class PropertyAccessorBase; 18 class PropertyAccessorBase;
17 19
18 // A property bag holds a generalized list of arbitrary metadata called 20 // A property bag holds a generalized list of arbitrary metadata called
19 // properties. Each property is a class type derived from PropertyBag::Prop 21 // properties. Each property is a class type derived from PropertyBag::Prop
20 // that can be set and retrieved. 22 // that can be set and retrieved.
21 // 23 //
22 // The property bag is not read or written directly. Instead, callers go 24 // The property bag is not read or written directly. Instead, callers go
23 // through a PropertyAccessor. The Accessor generates the unique IDs that 25 // through a PropertyAccessor. The Accessor generates the unique IDs that
24 // identify different properties. The Accessor is templatized to also provide 26 // identify different properties. The Accessor is templatized to also provide
25 // typesafety to the callers. 27 // typesafety to the callers.
(...skipping 10 matching lines...) Expand all
36 // } 38 // }
37 // 39 //
38 // void doit(SomeObjectThatImplementsPropertyBag* object) { 40 // void doit(SomeObjectThatImplementsPropertyBag* object) {
39 // PropertyAccessor<int>* accessor = my_accessor(); 41 // PropertyAccessor<int>* accessor = my_accessor();
40 // int* property = accessor->GetProperty(object); 42 // int* property = accessor->GetProperty(object);
41 // if (property) 43 // if (property)
42 // ... use property ... 44 // ... use property ...
43 // 45 //
44 // accessor->SetProperty(object, 22); 46 // accessor->SetProperty(object, 22);
45 // } 47 // }
46 class CONTENT_EXPORT PropertyBag { 48 class BASE_EXPORT PropertyBag {
47 public: 49 public:
48 // The type that uniquely identifies a property type. 50 // The type that uniquely identifies a property type.
49 typedef int PropID; 51 typedef int PropID;
50 enum { NULL_PROP_ID = -1 }; // Invalid property ID. 52 enum { NULL_PROP_ID = -1 }; // Invalid property ID.
51 53
52 // Properties are all derived from this class. They must be deletable and 54 // Properties are all derived from this class. They must be deletable and
53 // copyable 55 // copyable
54 class Prop { 56 class Prop {
55 public: 57 public:
56 virtual ~Prop() {} 58 virtual ~Prop() {}
(...skipping 30 matching lines...) Expand all
87 89
88 PropertyMap props_; 90 PropertyMap props_;
89 91
90 // Copy and assign is explicitly allowed for this class. 92 // Copy and assign is explicitly allowed for this class.
91 }; 93 };
92 94
93 // PropertyAccessorBase ------------------------------------------------------- 95 // PropertyAccessorBase -------------------------------------------------------
94 96
95 // Manages getting the unique IDs to identify a property. Callers should use 97 // Manages getting the unique IDs to identify a property. Callers should use
96 // PropertyAccessor below instead. 98 // PropertyAccessor below instead.
97 class CONTENT_EXPORT PropertyAccessorBase { 99 class BASE_EXPORT PropertyAccessorBase {
98 public: 100 public:
99 PropertyAccessorBase(); 101 PropertyAccessorBase();
100 virtual ~PropertyAccessorBase() {} 102 virtual ~PropertyAccessorBase() {}
101 103
102 // Removes our property, if any, from the given property bag. 104 // Removes our property, if any, from the given property bag.
103 void DeleteProperty(PropertyBag* bag) { 105 void DeleteProperty(PropertyBag* bag) {
104 bag->DeleteProperty(prop_id_); 106 bag->DeleteProperty(prop_id_);
105 } 107 }
106 108
107 protected: 109 protected:
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 virtual Prop* copy() { 168 virtual Prop* copy() {
167 return new Container(data_); 169 return new Container(data_);
168 } 170 }
169 171
170 T data_; 172 T data_;
171 }; 173 };
172 174
173 DISALLOW_COPY_AND_ASSIGN(PropertyAccessor); 175 DISALLOW_COPY_AND_ASSIGN(PropertyAccessor);
174 }; 176 };
175 177
176 #endif // CONTENT_COMMON_PROPERTY_BAG_H_ 178 } // namespace base
179
180 #endif // BASE_PROPERTY_BAG_H_
OLDNEW
« no previous file with comments | « base/base.gypi ('k') | base/property_bag.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698