| Index: tools/json_schema_compiler/util.h
|
| diff --git a/tools/json_schema_compiler/util.h b/tools/json_schema_compiler/util.h
|
| index 59d65d01031d8ea9879da482e5bcc5fafc3180db..945f06143e5d8f00dcea9397bac7ef39a05b64eb 100644
|
| --- a/tools/json_schema_compiler/util.h
|
| +++ b/tools/json_schema_compiler/util.h
|
| @@ -57,6 +57,19 @@ bool PopulateItem(const base::Value& from, linked_ptr<T>* out) {
|
| return true;
|
| }
|
|
|
| +// This template is used for types generated by tools/json_schema_compiler.
|
| +template <class T>
|
| +bool PopulateItem(const base::Value& from, T* out) {
|
| + const base::DictionaryValue* dict = nullptr;
|
| + if (!from.GetAsDictionary(&dict))
|
| + return false;
|
| + T obj;
|
| + if (!T::Populate(*dict, &obj))
|
| + return false;
|
| + *out = std::move(obj);
|
| + return true;
|
| +}
|
| +
|
| // This template is used for types generated by tools/json_schema_compiler with
|
| // error generation enabled.
|
| template <class T>
|
| @@ -82,7 +95,9 @@ bool PopulateArrayFromList(const base::ListValue& list, std::vector<T>* out) {
|
| for (const base::Value* value : list) {
|
| if (!PopulateItem(*value, &item))
|
| return false;
|
| - out->push_back(item);
|
| + // T might not be movable, but in that case it should be copyable, and this
|
| + // will still work.
|
| + out->push_back(std::move(item));
|
| }
|
|
|
| return true;
|
| @@ -148,12 +163,18 @@ void AddItemToList(const linked_ptr<T>& from, base::ListValue* out) {
|
| out->Append(from->ToValue().release());
|
| }
|
|
|
| +// This template is used for types generated by tools/json_schema_compiler.
|
| +template <class T>
|
| +void AddItemToList(const T& from, base::ListValue* out) {
|
| + out->Append(from.ToValue());
|
| +}
|
| +
|
| // Set |out| to the the contents of |from|. Requires PopulateItem to be
|
| // implemented for |T|.
|
| template <class T>
|
| void PopulateListFromArray(const std::vector<T>& from, base::ListValue* out) {
|
| out->Clear();
|
| - for (const auto& item : from)
|
| + for (const T& item : from)
|
| AddItemToList(item, out);
|
| }
|
|
|
|
|