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

Unified Diff: tools/json_schema_compiler/util.h

Issue 1128523003: Add support for passing errors through PopulateArrayFromList. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated JSON schema tests. Created 5 years, 7 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 | « tools/json_schema_compiler/test/error_generation_unittest.cc ('k') | tools/json_schema_compiler/util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/util.h
diff --git a/tools/json_schema_compiler/util.h b/tools/json_schema_compiler/util.h
index c27e48adfc9762d15907c257ae2c2091d6b3d1d7..59d65d01031d8ea9879da482e5bcc5fafc3180db 100644
--- a/tools/json_schema_compiler/util.h
+++ b/tools/json_schema_compiler/util.h
@@ -18,14 +18,31 @@ namespace util {
// Populates the item |out| from the value |from|. These are used by template
// specializations of |Get(Optional)ArrayFromList|.
+bool PopulateItem(const base::Value& from, linked_ptr<base::Value>* out);
+
bool PopulateItem(const base::Value& from, int* out);
+bool PopulateItem(const base::Value& from, int* out, base::string16* error);
bool PopulateItem(const base::Value& from, bool* out);
+bool PopulateItem(const base::Value& from, bool* out, base::string16* error);
bool PopulateItem(const base::Value& from, double* out);
+bool PopulateItem(const base::Value& from, double* out, base::string16* error);
bool PopulateItem(const base::Value& from, std::string* out);
+bool PopulateItem(const base::Value& from,
+ std::string* out,
+ base::string16* error);
bool PopulateItem(const base::Value& from, std::vector<char>* out);
+bool PopulateItem(const base::Value& from,
+ std::vector<char>* out,
+ base::string16* error);
+bool PopulateItem(const base::Value& from,
+ linked_ptr<base::Value>* out,
+ base::string16* error);
bool PopulateItem(const base::Value& from, linked_ptr<base::Value>* out);
bool PopulateItem(const base::Value& from,
linked_ptr<base::DictionaryValue>* out);
+bool PopulateItem(const base::Value& from,
+ linked_ptr<base::DictionaryValue>* out,
+ base::string16* error);
// This template is used for types generated by tools/json_schema_compiler.
template <class T>
@@ -40,6 +57,22 @@ bool PopulateItem(const base::Value& from, linked_ptr<T>* out) {
return true;
}
+// This template is used for types generated by tools/json_schema_compiler with
+// error generation enabled.
+template <class T>
+bool PopulateItem(const base::Value& from,
+ linked_ptr<T>* out,
+ base::string16* error) {
+ const base::DictionaryValue* dict = nullptr;
+ if (!from.GetAsDictionary(&dict))
+ return false;
+ scoped_ptr<T> obj(new T());
+ if (!T::Populate(*dict, obj.get(), error))
+ return false;
+ *out = linked_ptr<T>(obj.release());
+ return true;
+}
+
// Populates |out| with |list|. Returns false if there is no list at the
// specified key or if the list has anything other than |T|.
template <class T>
@@ -55,6 +88,23 @@ bool PopulateArrayFromList(const base::ListValue& list, std::vector<T>* out) {
return true;
}
+// Populates |out| with |list|. Returns false and sets |error| if there is no
+// list at the specified key or if the list has anything other than |T|.
+template <class T>
+bool PopulateArrayFromList(const base::ListValue& list,
+ std::vector<T>* out,
+ base::string16* error) {
+ out->clear();
+ T item;
+ for (const base::Value* value : list) {
+ if (!PopulateItem(*value, &item, error))
+ return false;
+ out->push_back(item);
+ }
+
+ return true;
+}
+
// Creates a new vector containing |list| at |out|. Returns
// true on success or if there is nothing at the specified key. Returns false
// if anything other than a list of |T| is at the specified key.
@@ -69,6 +119,18 @@ bool PopulateOptionalArrayFromList(const base::ListValue& list,
return true;
}
+template <class T>
+bool PopulateOptionalArrayFromList(const base::ListValue& list,
+ scoped_ptr<std::vector<T>>* out,
+ base::string16* error) {
+ out->reset(new std::vector<T>());
+ if (!PopulateArrayFromList(list, out->get(), error)) {
+ out->reset();
+ return false;
+ }
+ return true;
+}
+
// Appends a Value newly created from |from| to |out|. These used by template
// specializations of |Set(Optional)ArrayToList|.
void AddItemToList(const int from, base::ListValue* out);
« no previous file with comments | « tools/json_schema_compiler/test/error_generation_unittest.cc ('k') | tools/json_schema_compiler/util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698