summaryrefslogtreecommitdiffstats
path: root/chrome/common/property_bag.cc
diff options
context:
space:
mode:
authorbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-09 23:29:51 +0000
committerbrettw@google.com <brettw@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-09 23:29:51 +0000
commit78f346a6f58cd39450c86e65fe85eca4bb458e05 (patch)
tree2b6a7881447a3bff0ad5f55328f5623cf4289058 /chrome/common/property_bag.cc
parent5534be7842eeeb47365e189e94e6d352e7de329e (diff)
downloadchromium_src-78f346a6f58cd39450c86e65fe85eca4bb458e05.zip
chromium_src-78f346a6f58cd39450c86e65fe85eca4bb458e05.tar.gz
chromium_src-78f346a6f58cd39450c86e65fe85eca4bb458e05.tar.bz2
Add a property bag which is a typesafe list of arbitrary data that can be
associated with any object. Review URL: http://codereview.chromium.org/13676 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6654 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/property_bag.cc')
-rw-r--r--chrome/common/property_bag.cc48
1 files changed, 48 insertions, 0 deletions
diff --git a/chrome/common/property_bag.cc b/chrome/common/property_bag.cc
new file mode 100644
index 0000000..f7c92a3
--- /dev/null
+++ b/chrome/common/property_bag.cc
@@ -0,0 +1,48 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/common/property_bag.h"
+
+PropertyBag::PropertyBag() {
+}
+
+PropertyBag::PropertyBag(const PropertyBag& other) {
+ operator=(other);
+}
+
+PropertyBag::~PropertyBag() {
+}
+
+PropertyBag& PropertyBag::operator=(const PropertyBag& other) {
+ props_.clear();
+
+ // We need to make copies of each property using the virtual copy() method.
+ for (PropertyMap::const_iterator i = other.props_.begin();
+ i != other.props_.end(); ++i)
+ props_[i->first] = linked_ptr<Prop>(i->second->copy());
+ return *this;
+}
+
+void PropertyBag::SetProperty(PropID id, Prop* prop) {
+ props_[id] = linked_ptr<Prop>(prop);
+}
+
+PropertyBag::Prop* PropertyBag::GetProperty(PropID id) {
+ PropertyMap::const_iterator found = props_.find(id);
+ if (found == props_.end())
+ return NULL;
+ return found->second.get();
+}
+
+void PropertyBag::DeleteProperty(PropID id) {
+ PropertyMap::iterator found = props_.find(id);
+ if (found == props_.end())
+ return; // Not found, nothing to do.
+ props_.erase(found);
+}
+
+PropertyAccessorBase::PropertyAccessorBase() {
+ static PropertyBag::PropID next_id = 1;
+ prop_id_ = next_id++;
+}