blob: 8fb2139b2486801b20e91581e75d51bcd278d14b [file] [log] [blame]
Darin Petkov63138a92012-02-06 14:09:15 +01001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
mukesh agrawal7a4e4002011-09-06 11:26:05 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "shill/key_value_store.h"
6
7#include <base/logging.h>
Eric Shienbrood3e20a232012-02-16 11:35:56 -05008#include <base/stl_util.h>
mukesh agrawal7a4e4002011-09-06 11:26:05 -07009
10using std::map;
11using std::string;
12
13namespace shill {
14
15KeyValueStore::KeyValueStore() {}
16
17bool KeyValueStore::ContainsBool(const string &name) const {
18 return ContainsKey(bool_properties_, name);
19}
20
Paul Stewart1062d9d2012-04-27 10:42:27 -070021bool KeyValueStore::ContainsInt(const string &name) const {
22 return ContainsKey(int_properties_, name);
23}
24
mukesh agrawal7a4e4002011-09-06 11:26:05 -070025bool KeyValueStore::ContainsString(const string &name) const {
26 return ContainsKey(string_properties_, name);
27}
28
Darin Petkov63138a92012-02-06 14:09:15 +010029bool KeyValueStore::ContainsUint(const string &name) const {
30 return ContainsKey(uint_properties_, name);
31}
32
mukesh agrawal7a4e4002011-09-06 11:26:05 -070033bool KeyValueStore::GetBool(const string &name) const {
34 map<string, bool>::const_iterator it(bool_properties_.find(name));
mukesh agrawal1a056262011-10-05 14:36:54 -070035 CHECK(it != bool_properties_.end()) << "for bool property " << name;
mukesh agrawal7a4e4002011-09-06 11:26:05 -070036 return it->second;
37}
38
Paul Stewart1062d9d2012-04-27 10:42:27 -070039int32 KeyValueStore::GetInt(const string &name) const {
40 map<string, int32>::const_iterator it(int_properties_.find(name));
41 CHECK(it != int_properties_.end()) << "for int property " << name;
42 return it->second;
43}
44
mukesh agrawal7a4e4002011-09-06 11:26:05 -070045const string &KeyValueStore::GetString(const string &name) const {
46 map<string, string>::const_iterator it(string_properties_.find(name));
mukesh agrawal1a056262011-10-05 14:36:54 -070047 CHECK(it != string_properties_.end()) << "for string property " << name;
mukesh agrawal7a4e4002011-09-06 11:26:05 -070048 return it->second;
49}
50
Darin Petkov63138a92012-02-06 14:09:15 +010051uint32 KeyValueStore::GetUint(const string &name) const {
52 map<string, uint32>::const_iterator it(uint_properties_.find(name));
53 CHECK(it != uint_properties_.end()) << "for uint property " << name;
54 return it->second;
55}
56
mukesh agrawal7a4e4002011-09-06 11:26:05 -070057void KeyValueStore::SetBool(const string &name, bool value) {
58 bool_properties_[name] = value;
59}
60
Paul Stewart1062d9d2012-04-27 10:42:27 -070061void KeyValueStore::SetInt(const string &name, int32 value) {
62 int_properties_[name] = value;
63}
64
mukesh agrawal7a4e4002011-09-06 11:26:05 -070065void KeyValueStore::SetString(const string &name, const string &value) {
66 string_properties_[name] = value;
67}
68
Darin Petkov63138a92012-02-06 14:09:15 +010069void KeyValueStore::SetUint(const string &name, uint32 value) {
70 uint_properties_[name] = value;
71}
72
Paul Stewart88125fb2012-03-26 07:13:51 -070073void KeyValueStore::RemoveString(const string &name) {
74 string_properties_.erase(name);
75}
76
Paul Stewart1062d9d2012-04-27 10:42:27 -070077void KeyValueStore::RemoveInt(const string &name) {
78 int_properties_.erase(name);
79}
80
Darin Petkovb536a742012-04-26 11:31:28 +020081bool KeyValueStore::LookupBool(const string &name, bool default_value) const {
82 map<string, bool>::const_iterator it(bool_properties_.find(name));
83 return it == bool_properties_.end() ? default_value : it->second;
84}
85
Darin Petkov7f060332012-03-14 11:46:47 +010086string KeyValueStore::LookupString(const string &name,
87 const string &default_value) const {
Darin Petkovb536a742012-04-26 11:31:28 +020088 map<string, string>::const_iterator it(string_properties_.find(name));
89 return it == string_properties_.end() ? default_value : it->second;
Darin Petkov7f060332012-03-14 11:46:47 +010090}
91
mukesh agrawal7a4e4002011-09-06 11:26:05 -070092} // namespace shill