Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1813)

Unified Diff: base/values.cc

Issue 7892052: Adds Find method to the ListValue class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed up the return type a little. Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« base/values.h ('K') | « base/values.h ('k') | base/values_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/values.cc
diff --git a/base/values.cc b/base/values.cc
index 17aba167a1f7cf42dfd9d3bac05fbee00b85d5ab..f53fc3c0705ef99fff00b1b26f78461762d15c9c 100644
--- a/base/values.cc
+++ b/base/values.cc
@@ -58,6 +58,19 @@ Value* CopyWithoutEmptyChildren(Value* node) {
}
}
+// A small functor for comparing Values for std::find_if and similar.
+class CompareValues {
Mattias Nissler (ping if slow) 2011/09/15 13:40:39 Maybe ValueEquals? It isn't really useful as a com
pastarmovj 2011/09/16 08:03:49 Done. Actually picked something even more specific
+ public:
+ CompareValues(const Value& first) : first_(first) { }
+
+ bool operator ()(const Value* second) const {
+ return first_.Equals(second);
+ }
+
+ private:
+ const Value& first_;
Mattias Nissler (ping if slow) 2011/09/15 13:40:39 In chromium, we'd usually use a pointer for this.
pastarmovj 2011/09/16 08:03:49 Done.
+};
+
} // namespace
namespace base {
@@ -865,6 +878,11 @@ bool ListValue::Insert(size_t index, Value* in_value) {
return true;
}
+ListValue::const_iterator ListValue::Find(const Value& value) const {
+ CompareValues compare(value);
+ return std::find_if(list_.begin(), list_.end(), compare);
+}
+
bool ListValue::GetAsList(ListValue** out_value) {
if (out_value)
*out_value = this;
« base/values.h ('K') | « base/values.h ('k') | base/values_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698