Style/readability clean-up for certificate reporting code
[chromium-blink-merge.git] / base / prefs / pref_value_map.h
blob7d43f2b96ca1c811cb2f961951765174bd0b29be
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.
5 #ifndef BASE_PREFS_PREF_VALUE_MAP_H_
6 #define BASE_PREFS_PREF_VALUE_MAP_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/containers/scoped_ptr_hash_map.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/prefs/base_prefs_export.h"
16 namespace base {
17 class Value;
20 // A generic string to value map used by the PrefStore implementations.
21 class BASE_PREFS_EXPORT PrefValueMap {
22 public:
23 using Map = base::ScopedPtrHashMap<std::string, scoped_ptr<base::Value>>;
24 using iterator = Map::iterator;
25 using const_iterator = Map::const_iterator;
27 PrefValueMap();
28 virtual ~PrefValueMap();
30 // Gets the value for |key| and stores it in |value|. Ownership remains with
31 // the map. Returns true if a value is present. If not, |value| is not
32 // touched.
33 bool GetValue(const std::string& key, const base::Value** value) const;
34 bool GetValue(const std::string& key, base::Value** value);
36 // Sets a new |value| for |key|. |value| must be non-null. Returns true if the
37 // value changed.
38 bool SetValue(const std::string& key, scoped_ptr<base::Value> value);
40 // Removes the value for |key| from the map. Returns true if a value was
41 // removed.
42 bool RemoveValue(const std::string& key);
44 // Clears the map.
45 void Clear();
47 // Swaps the contents of two maps.
48 void Swap(PrefValueMap* other);
50 iterator begin();
51 iterator end();
52 const_iterator begin() const;
53 const_iterator end() const;
55 // Gets a boolean value for |key| and stores it in |value|. Returns true if
56 // the value was found and of the proper type.
57 bool GetBoolean(const std::string& key, bool* value) const;
59 // Sets the value for |key| to the boolean |value|.
60 void SetBoolean(const std::string& key, bool value);
62 // Gets a string value for |key| and stores it in |value|. Returns true if
63 // the value was found and of the proper type.
64 bool GetString(const std::string& key, std::string* value) const;
66 // Sets the value for |key| to the string |value|.
67 void SetString(const std::string& key, const std::string& value);
69 // Gets an int value for |key| and stores it in |value|. Returns true if
70 // the value was found and of the proper type.
71 bool GetInteger(const std::string& key, int* value) const;
73 // Sets the value for |key| to the int |value|.
74 void SetInteger(const std::string& key, const int value);
76 // Sets the value for |key| to the double |value|.
77 void SetDouble(const std::string& key, const double value);
79 // Compares this value map against |other| and stores all key names that have
80 // different values in |differing_keys|. This includes keys that are present
81 // only in one of the maps.
82 void GetDifferingKeys(const PrefValueMap* other,
83 std::vector<std::string>* differing_keys) const;
85 private:
86 Map prefs_;
88 DISALLOW_COPY_AND_ASSIGN(PrefValueMap);
91 #endif // BASE_PREFS_PREF_VALUE_MAP_H_