OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef TOOLS_JSON_SCHEMA_COMPILER_UTIL_H__ | 5 #ifndef TOOLS_JSON_SCHEMA_COMPILER_UTIL_H__ |
6 #define TOOLS_JSON_SCHEMA_COMPILER_UTIL_H__ | 6 #define TOOLS_JSON_SCHEMA_COMPILER_UTIL_H__ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 bool GetItemFromList(const ListValue& from, int index, double* out); | 27 bool GetItemFromList(const ListValue& from, int index, double* out); |
28 bool GetItemFromList(const ListValue& from, int index, std::string* out); | 28 bool GetItemFromList(const ListValue& from, int index, std::string* out); |
29 bool GetItemFromList(const ListValue& from, int index, | 29 bool GetItemFromList(const ListValue& from, int index, |
30 linked_ptr<base::DictionaryValue>* out); | 30 linked_ptr<base::DictionaryValue>* out); |
31 bool GetItemFromList(const ListValue& from, int index, | 31 bool GetItemFromList(const ListValue& from, int index, |
32 linked_ptr<any::Any>* out); | 32 linked_ptr<any::Any>* out); |
33 | 33 |
34 // This template is used for types generated by tools/json_schema_compiler. | 34 // This template is used for types generated by tools/json_schema_compiler. |
35 template<class T> | 35 template<class T> |
36 bool GetItemFromList(const ListValue& from, int index, linked_ptr<T>* out) { | 36 bool GetItemFromList(const ListValue& from, int index, linked_ptr<T>* out) { |
37 DictionaryValue* dict; | 37 const DictionaryValue* dict; |
38 if (!from.GetDictionary(index, &dict)) | 38 if (!from.GetDictionary(index, &dict)) |
39 return false; | 39 return false; |
40 scoped_ptr<T> obj(new T()); | 40 scoped_ptr<T> obj(new T()); |
41 if (!T::Populate(*dict, obj.get())) | 41 if (!T::Populate(*dict, obj.get())) |
42 return false; | 42 return false; |
43 *out = linked_ptr<T>(obj.release()); | 43 *out = linked_ptr<T>(obj.release()); |
44 return true; | 44 return true; |
45 } | 45 } |
46 | 46 |
47 // Populates |out| with |list|. Returns false if there is no list at the | 47 // Populates |out| with |list|. Returns false if there is no list at the |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 const scoped_ptr<std::vector<T> >& from) { | 171 const scoped_ptr<std::vector<T> >& from) { |
172 if (from.get()) | 172 if (from.get()) |
173 return CreateValueFromArray(*from); | 173 return CreateValueFromArray(*from); |
174 return scoped_ptr<Value>(); | 174 return scoped_ptr<Value>(); |
175 } | 175 } |
176 | 176 |
177 } // namespace util | 177 } // namespace util |
178 } // namespace json_schema_compiler | 178 } // namespace json_schema_compiler |
179 | 179 |
180 #endif // TOOLS_JSON_SCHEMA_COMPILER_UTIL_H__ | 180 #endif // TOOLS_JSON_SCHEMA_COMPILER_UTIL_H__ |
OLD | NEW |