diff options
author | pastarmovj@chromium.org <pastarmovj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-19 15:23:10 +0000 |
---|---|---|
committer | pastarmovj@chromium.org <pastarmovj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-19 15:23:10 +0000 |
commit | 5fb35372c80f9436a980281cc826d8a72fcf8915 (patch) | |
tree | 8ca072f766b796ce32064dc6a9b2eee1f9ef35ac /base/values.cc | |
parent | 57c06b5ec1aacada9f73ee01717a7c5a81baff40 (diff) | |
download | chromium_src-5fb35372c80f9436a980281cc826d8a72fcf8915.zip chromium_src-5fb35372c80f9436a980281cc826d8a72fcf8915.tar.gz chromium_src-5fb35372c80f9436a980281cc826d8a72fcf8915.tar.bz2 |
Adds Find method to the ListValue class.
This method makes working with lists easierand will be needed from the
refactored signed settings code.
BUG=chromium-os:14054
TEST=base_unittest --gtest_filter=ValuesTest.List
Review URL: http://codereview.chromium.org/7892052
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@101741 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/values.cc')
-rw-r--r-- | base/values.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/base/values.cc b/base/values.cc index 17aba16..60b0d70 100644 --- a/base/values.cc +++ b/base/values.cc @@ -4,6 +4,8 @@ #include "base/values.h" +#include <algorithm> + #include "base/float_util.h" #include "base/logging.h" #include "base/string_util.h" @@ -58,6 +60,22 @@ Value* CopyWithoutEmptyChildren(Value* node) { } } +// A small functor for comparing Values for std::find_if and similar. +class ValueEquals { + public: + // Pass the value against which all consecutive calls of the () operator will + // compare their argument to. This Value object must not be destroyed while + // the ValueEquals is in use. + ValueEquals(const Value* first) : first_(first) { } + + bool operator ()(const Value* second) const { + return first_->Equals(second); + } + + private: + const Value* first_; +}; + } // namespace namespace base { @@ -865,6 +883,10 @@ bool ListValue::Insert(size_t index, Value* in_value) { return true; } +ListValue::const_iterator ListValue::Find(const Value& value) const { + return std::find_if(list_.begin(), list_.end(), ValueEquals(&value)); +} + bool ListValue::GetAsList(ListValue** out_value) { if (out_value) *out_value = this; |