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_
12 #include "base/basictypes.h"
13 #include "base/prefs/base_prefs_export.h"
19 // A generic string to value map used by the PrefStore implementations.
20 class BASE_PREFS_EXPORT PrefValueMap
{
22 typedef std::map
<std::string
, base::Value
*>::iterator iterator
;
23 typedef std::map
<std::string
, base::Value
*>::const_iterator const_iterator
;
26 virtual ~PrefValueMap();
28 // Gets the value for |key| and stores it in |value|. Ownership remains with
29 // the map. Returns true if a value is present. If not, |value| is not
31 bool GetValue(const std::string
& key
, const base::Value
** value
) const;
32 bool GetValue(const std::string
& key
, base::Value
** value
);
34 // Sets a new |value| for |key|. Takes ownership of |value|, which must be
35 // non-NULL. Returns true if the value changed.
36 bool SetValue(const std::string
& key
, base::Value
* value
);
38 // Removes the value for |key| from the map. Returns true if a value was
40 bool RemoveValue(const std::string
& key
);
45 // Swaps the contents of two maps.
46 void Swap(PrefValueMap
* other
);
50 const_iterator
begin() const;
51 const_iterator
end() const;
53 // Gets a boolean value for |key| and stores it in |value|. Returns true if
54 // the value was found and of the proper type.
55 bool GetBoolean(const std::string
& key
, bool* value
) const;
57 // Sets the value for |key| to the boolean |value|.
58 void SetBoolean(const std::string
& key
, bool value
);
60 // Gets a string value for |key| and stores it in |value|. Returns true if
61 // the value was found and of the proper type.
62 bool GetString(const std::string
& key
, std::string
* value
) const;
64 // Sets the value for |key| to the string |value|.
65 void SetString(const std::string
& key
, const std::string
& value
);
67 // Gets an int value for |key| and stores it in |value|. Returns true if
68 // the value was found and of the proper type.
69 bool GetInteger(const std::string
& key
, int* value
) const;
71 // Sets the value for |key| to the int |value|.
72 void SetInteger(const std::string
& key
, const int value
);
74 // Compares this value map against |other| and stores all key names that have
75 // different values in |differing_keys|. This includes keys that are present
76 // only in one of the maps.
77 void GetDifferingKeys(const PrefValueMap
* other
,
78 std::vector
<std::string
>* differing_keys
) const;
81 typedef std::map
<std::string
, base::Value
*> Map
;
85 DISALLOW_COPY_AND_ASSIGN(PrefValueMap
);
88 #endif // BASE_PREFS_PREF_VALUE_MAP_H_