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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 // GetItemFromList to be implemented for |T|. | 143 // GetItemFromList to be implemented for |T|. |
144 template <class T> | 144 template <class T> |
145 void PopulateListFromOptionalArray( | 145 void PopulateListFromOptionalArray( |
146 const scoped_ptr<std::vector<T> >& from, | 146 const scoped_ptr<std::vector<T> >& from, |
147 base::ListValue* out) { | 147 base::ListValue* out) { |
148 if (from.get()) | 148 if (from.get()) |
149 PopulateListFromArray(*from, out); | 149 PopulateListFromArray(*from, out); |
150 | 150 |
151 } | 151 } |
152 | 152 |
153 // Sets |out|.|name| to a newly created ListValue containing |from|. Requires | |
154 // GetItemFromList to be implemented for |T|. | |
155 template <class T> | 153 template <class T> |
156 void PopulateDictionaryFromArray( | 154 scoped_ptr<Value> CreateValueFromArray( |
157 const std::vector<T>& from, | 155 const std::vector<T>& from) { |
158 const std::string& name, | |
159 base::DictionaryValue* out) { | |
160 base::ListValue* list = new base::ListValue(); | 156 base::ListValue* list = new base::ListValue(); |
161 out->SetWithoutPathExpansion(name, list); | |
162 PopulateListFromArray(from, list); | 157 PopulateListFromArray(from, list); |
| 158 return scoped_ptr<Value>(list); |
163 } | 159 } |
164 | 160 |
165 // If |from| is non-NULL, sets |out|.|name| to a newly created ListValue | |
166 // containing |from|. Requires GetItemFromList to be implemented for |T|. | |
167 template <class T> | 161 template <class T> |
168 void PopulateDictionaryFromOptionalArray( | 162 scoped_ptr<Value> CreateValueFromOptionalArray( |
169 const scoped_ptr<std::vector<T> >& from, | 163 const scoped_ptr<std::vector<T> >& from) { |
170 const std::string& name, | |
171 base::DictionaryValue* out) { | |
172 if (from.get()) | 164 if (from.get()) |
173 PopulateDictionaryFromArray(*from, name, out); | 165 return CreateValueFromArray(*from); |
| 166 return scoped_ptr<Value>(); |
174 } | 167 } |
175 | 168 |
176 | |
177 } // namespace api_util | 169 } // namespace api_util |
178 } // namespace extensions | 170 } // namespace extensions |
179 | 171 |
180 #endif // TOOLS_JSON_SCHEMA_COMPILER_UTIL_H__ | 172 #endif // TOOLS_JSON_SCHEMA_COMPILER_UTIL_H__ |
OLD | NEW |