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 26 matching lines...) Expand all Loading... | |
37 const 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 // This is used for getting an enum out of a ListValue. | |
48 template<class T> | |
49 bool GetItemFromList(const ListValue& from, int index, T* out) { | |
50 int value; | |
51 if (!from.GetInteger(index, &value)) | |
52 return false; | |
53 *out = static_cast<T>(value); | |
not at google - send to devlin
2012/09/14 01:44:51
i don't understand, ListValue enums are stored as
cduvall
2012/09/17 22:07:46
I clarified the comment. This happens in the JSC t
| |
54 return true; | |
55 } | |
56 | |
47 // Populates |out| with |list|. Returns false if there is no list at the | 57 // Populates |out| with |list|. Returns false if there is no list at the |
48 // specified key or if the list has anything other than |T|. | 58 // specified key or if the list has anything other than |T|. |
49 template <class T> | 59 template <class T> |
50 bool PopulateArrayFromList( | 60 bool PopulateArrayFromList( |
51 const base::ListValue& list, std::vector<T>* out) { | 61 const base::ListValue& list, std::vector<T>* out) { |
52 out->clear(); | 62 out->clear(); |
53 T value; | 63 T value; |
54 for (size_t i = 0; i < list.GetSize(); ++i) { | 64 for (size_t i = 0; i < list.GetSize(); ++i) { |
55 if (!GetItemFromList(list, i, &value)) | 65 if (!GetItemFromList(list, i, &value)) |
56 return false; | 66 return false; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 const scoped_ptr<std::vector<T> >& from) { | 181 const scoped_ptr<std::vector<T> >& from) { |
172 if (from.get()) | 182 if (from.get()) |
173 return CreateValueFromArray(*from); | 183 return CreateValueFromArray(*from); |
174 return scoped_ptr<Value>(); | 184 return scoped_ptr<Value>(); |
175 } | 185 } |
176 | 186 |
177 } // namespace util | 187 } // namespace util |
178 } // namespace json_schema_compiler | 188 } // namespace json_schema_compiler |
179 | 189 |
180 #endif // TOOLS_JSON_SCHEMA_COMPILER_UTIL_H__ | 190 #endif // TOOLS_JSON_SCHEMA_COMPILER_UTIL_H__ |
OLD | NEW |