OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/memory/linked_ptr.h" | |
6 #include "content/common/property_bag.h" | |
7 | |
8 PropertyBag::PropertyBag() { | |
9 } | |
10 | |
11 PropertyBag::PropertyBag(const PropertyBag& other) { | |
12 operator=(other); | |
13 } | |
14 | |
15 PropertyBag::~PropertyBag() { | |
16 } | |
17 | |
18 PropertyBag& PropertyBag::operator=(const PropertyBag& other) { | |
19 props_.clear(); | |
20 | |
21 // We need to make copies of each property using the virtual copy() method. | |
22 for (PropertyMap::const_iterator i = other.props_.begin(); | |
23 i != other.props_.end(); ++i) | |
24 props_[i->first] = linked_ptr<Prop>(i->second->copy()); | |
25 return *this; | |
26 } | |
27 | |
28 void PropertyBag::SetProperty(PropID id, Prop* prop) { | |
29 props_[id] = linked_ptr<Prop>(prop); | |
30 } | |
31 | |
32 PropertyBag::Prop* PropertyBag::GetProperty(PropID id) { | |
33 PropertyMap::const_iterator found = props_.find(id); | |
34 if (found == props_.end()) | |
35 return NULL; | |
36 return found->second.get(); | |
37 } | |
38 | |
39 const PropertyBag::Prop* PropertyBag::GetProperty(PropID id) const { | |
40 PropertyMap::const_iterator found = props_.find(id); | |
41 if (found == props_.end()) | |
42 return NULL; | |
43 return found->second.get(); | |
44 } | |
45 | |
46 void PropertyBag::DeleteProperty(PropID id) { | |
47 PropertyMap::iterator found = props_.find(id); | |
48 if (found == props_.end()) | |
49 return; // Not found, nothing to do. | |
50 props_.erase(found); | |
51 } | |
52 | |
53 PropertyAccessorBase::PropertyAccessorBase() { | |
54 static PropertyBag::PropID next_id = 1; | |
55 prop_id_ = next_id++; | |
56 } | |
OLD | NEW |