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