blob: 26e2b3bcf962a3a4d19c5b92ccd2bbee4e36313d [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
21bool KeyValueStore::ContainsString(const string &name) const {
22 return ContainsKey(string_properties_, name);
23}
24
Darin Petkov63138a92012-02-06 14:09:15 +010025bool KeyValueStore::ContainsUint(const string &name) const {
26 return ContainsKey(uint_properties_, name);
27}
28
mukesh agrawal7a4e4002011-09-06 11:26:05 -070029bool KeyValueStore::GetBool(const string &name) const {
30 map<string, bool>::const_iterator it(bool_properties_.find(name));
mukesh agrawal1a056262011-10-05 14:36:54 -070031 CHECK(it != bool_properties_.end()) << "for bool property " << name;
mukesh agrawal7a4e4002011-09-06 11:26:05 -070032 return it->second;
33}
34
35const string &KeyValueStore::GetString(const string &name) const {
36 map<string, string>::const_iterator it(string_properties_.find(name));
mukesh agrawal1a056262011-10-05 14:36:54 -070037 CHECK(it != string_properties_.end()) << "for string property " << name;
mukesh agrawal7a4e4002011-09-06 11:26:05 -070038 return it->second;
39}
40
Darin Petkov63138a92012-02-06 14:09:15 +010041uint32 KeyValueStore::GetUint(const string &name) const {
42 map<string, uint32>::const_iterator it(uint_properties_.find(name));
43 CHECK(it != uint_properties_.end()) << "for uint property " << name;
44 return it->second;
45}
46
mukesh agrawal7a4e4002011-09-06 11:26:05 -070047void KeyValueStore::SetBool(const string &name, bool value) {
48 bool_properties_[name] = value;
49}
50
51void KeyValueStore::SetString(const string &name, const string &value) {
52 string_properties_[name] = value;
53}
54
Darin Petkov63138a92012-02-06 14:09:15 +010055void KeyValueStore::SetUint(const string &name, uint32 value) {
56 uint_properties_[name] = value;
57}
58
Darin Petkov7f060332012-03-14 11:46:47 +010059string KeyValueStore::LookupString(const string &name,
60 const string &default_value) const {
61 return ContainsString(name) ? GetString(name) : default_value;
62}
63
mukesh agrawal7a4e4002011-09-06 11:26:05 -070064} // namespace shill