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

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: Simplified the code a bit. 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
« no previous file with comments | « 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..60b0d70f1ed07f7a92c1f6ca7f5815dae3c38fa6 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;
« no previous file with comments | « base/values.h ('k') | base/values_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698