Chromium Code Reviews| 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..6a075e2477800b10d1e651fd77c36f8fc87b1865 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,6 +163,12 @@ 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().release()); |
|
dcheng
2016/03/22 17:42:34
No .release().
Devlin
2016/03/22 17:58:40
Done.
|
| +} |
| + |
| // Set |out| to the the contents of |from|. Requires PopulateItem to be |
| // implemented for |T|. |
| template <class T> |