summaryrefslogtreecommitdiffstats
path: root/base/property_bag.cc
blob: 9578e648302ed638b8c22d5136df62f10e163e46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2011 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 "base/property_bag.h"

#include "base/memory/linked_ptr.h"

namespace base {

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();
}

const PropertyBag::Prop* PropertyBag::GetProperty(PropID id) const {
  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++;
}

}  // namespace base