summaryrefslogtreecommitdiffstats
path: root/base/values.h
diff options
context:
space:
mode:
authordanno@chromium.org <danno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-04 08:44:35 +0000
committerdanno@chromium.org <danno@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-04 08:44:35 +0000
commit4aeb940818b0c129c9fc17d39eca1ef2f24c76a5 (patch)
treec9135978608a83e2aeafce25aa67a1fa1b15b7ba /base/values.h
parent1d2f1bbda6ece9e0a0e37a84cecd89f2f6ddc00b (diff)
downloadchromium_src-4aeb940818b0c129c9fc17d39eca1ef2f24c76a5.zip
chromium_src-4aeb940818b0c129c9fc17d39eca1ef2f24c76a5.tar.gz
chromium_src-4aeb940818b0c129c9fc17d39eca1ef2f24c76a5.tar.bz2
Add dictionary comparing functions to DictionaryValue and unit tests
TEST=none BUG=none Review URL: http://codereview.chromium.org/3035045 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54879 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/values.h')
-rw-r--r--base/values.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/base/values.h b/base/values.h
index d99a46f..57139d8 100644
--- a/base/values.h
+++ b/base/values.h
@@ -367,6 +367,16 @@ class DictionaryValue : public Value {
// replaced.
void MergeDictionary(const DictionaryValue* dictionary);
+ // Builds a vector containing all of the paths that are different between
+ // the dictionary and a second specified dictionary. These are paths of
+ // values that are either in one dictionary or the other but not both, OR
+ // paths that are present in both dictionaries but differ in value.
+ // Path strings are in ascending lexicographical order in the generated
+ // vector. |different_paths| is cleared before added any paths.
+ void GetDifferingPaths(
+ const DictionaryValue* other,
+ std::vector<std::string>* different_paths) const;
+
// This class provides an iterator for the keys in the dictionary.
// It can't be used to modify the dictionary.
//
@@ -393,6 +403,17 @@ class DictionaryValue : public Value {
key_iterator end_keys() const { return key_iterator(dictionary_.end()); }
private:
+ // Does the actual heavy lifting for GetDifferingPaths.
+ // Returns true if a path is added to different_paths, otherwise false.
+ // The difference compuation is calculated recursively. The keys for
+ // dictionaries that are handled by recursive calls more shallow than
+ // the current one are concatenated and passed through to deeper calls in
+ // |path_prefix|.
+ bool GetDifferingPathsHelper(
+ const std::string& path_prefix,
+ const DictionaryValue* other,
+ std::vector<std::string>* different_paths) const;
+
ValueMap dictionary_;
DISALLOW_COPY_AND_ASSIGN(DictionaryValue);