diff options
author | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-08 21:26:41 +0000 |
---|---|---|
committer | kalman@chromium.org <kalman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-11-08 21:26:41 +0000 |
commit | 32c0e003a39395f42c800928f4b25fe77715c414 (patch) | |
tree | 439d4fec3aa8ab9520b008d20dcdb58dd9adaabf /base/values.h | |
parent | 3aedf268a834b0710acb31b28b1b5bd34eb3cd91 (diff) | |
download | chromium_src-32c0e003a39395f42c800928f4b25fe77715c414.zip chromium_src-32c0e003a39395f42c800928f4b25fe77715c414.tar.gz chromium_src-32c0e003a39395f42c800928f4b25fe77715c414.tar.bz2 |
Add a key/value iterator to DictionaryValue (in addition to the existing key
iterator).
BUG=
TEST=ValuesTest.DictionaryIterator
Review URL: http://codereview.chromium.org/8351059
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109102 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/values.h')
-rw-r--r-- | base/values.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/base/values.h b/base/values.h index 90cc40c..aa26b3e 100644 --- a/base/values.h +++ b/base/values.h @@ -342,6 +342,24 @@ class BASE_EXPORT DictionaryValue : public Value { key_iterator begin_keys() const { return key_iterator(dictionary_.begin()); } key_iterator end_keys() const { return key_iterator(dictionary_.end()); } + // This class provides an iterator over both keys and values in the + // dictionary. It can't be used to modify the dictionary. + class Iterator { + public: + explicit Iterator(const DictionaryValue& target) + : target_(target), it_(target.dictionary_.begin()) {} + + bool HasNext() const { return it_ != target_.dictionary_.end(); } + void Advance() { ++it_; } + + const std::string& key() const { return it_->first; } + const Value& value() const { return *it_->second; } + + private: + const DictionaryValue& target_; + ValueMap::const_iterator it_; + }; + // Overridden from Value: virtual DictionaryValue* DeepCopy() const OVERRIDE; virtual bool Equals(const Value* other) const OVERRIDE; |