| 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 BASE_JSON_JSON_VALUE_CONVERTER_H_ | 5 #ifndef BASE_JSON_JSON_VALUE_CONVERTER_H_ |
| 6 #define BASE_JSON_JSON_VALUE_CONVERTER_H_ | 6 #define BASE_JSON_JSON_VALUE_CONVERTER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 virtual bool Convert( | 266 virtual bool Convert( |
| 267 const base::Value& value, ScopedVector<Element>* field) const OVERRIDE { | 267 const base::Value& value, ScopedVector<Element>* field) const OVERRIDE { |
| 268 const base::ListValue* list = NULL; | 268 const base::ListValue* list = NULL; |
| 269 if (!value.GetAsList(&list)) { | 269 if (!value.GetAsList(&list)) { |
| 270 // The field is not a list. | 270 // The field is not a list. |
| 271 return false; | 271 return false; |
| 272 } | 272 } |
| 273 | 273 |
| 274 field->reserve(list->GetSize()); | 274 field->reserve(list->GetSize()); |
| 275 for (size_t i = 0; i < list->GetSize(); ++i) { | 275 for (size_t i = 0; i < list->GetSize(); ++i) { |
| 276 base::Value* element = NULL; | 276 const base::Value* element = NULL; |
| 277 if (!list->Get(i, &element)) | 277 if (!list->Get(i, &element)) |
| 278 continue; | 278 continue; |
| 279 | 279 |
| 280 scoped_ptr<Element> e(new Element); | 280 scoped_ptr<Element> e(new Element); |
| 281 if (basic_converter_.Convert(*element, e.get())) { | 281 if (basic_converter_.Convert(*element, e.get())) { |
| 282 field->push_back(e.release()); | 282 field->push_back(e.release()); |
| 283 } else { | 283 } else { |
| 284 DVLOG(1) << "failure at " << i << "-th element"; | 284 DVLOG(1) << "failure at " << i << "-th element"; |
| 285 return false; | 285 return false; |
| 286 } | 286 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 300 RepeatedMessageConverter() {} | 300 RepeatedMessageConverter() {} |
| 301 | 301 |
| 302 virtual bool Convert(const base::Value& value, | 302 virtual bool Convert(const base::Value& value, |
| 303 ScopedVector<NestedType>* field) const OVERRIDE { | 303 ScopedVector<NestedType>* field) const OVERRIDE { |
| 304 const base::ListValue* list = NULL; | 304 const base::ListValue* list = NULL; |
| 305 if (!value.GetAsList(&list)) | 305 if (!value.GetAsList(&list)) |
| 306 return false; | 306 return false; |
| 307 | 307 |
| 308 field->reserve(list->GetSize()); | 308 field->reserve(list->GetSize()); |
| 309 for (size_t i = 0; i < list->GetSize(); ++i) { | 309 for (size_t i = 0; i < list->GetSize(); ++i) { |
| 310 base::Value* element = NULL; | 310 const base::Value* element = NULL; |
| 311 if (!list->Get(i, &element)) | 311 if (!list->Get(i, &element)) |
| 312 continue; | 312 continue; |
| 313 | 313 |
| 314 scoped_ptr<NestedType> nested(new NestedType); | 314 scoped_ptr<NestedType> nested(new NestedType); |
| 315 if (converter_.Convert(*element, nested.get())) { | 315 if (converter_.Convert(*element, nested.get())) { |
| 316 field->push_back(nested.release()); | 316 field->push_back(nested.release()); |
| 317 } else { | 317 } else { |
| 318 DVLOG(1) << "failure at " << i << "-th element"; | 318 DVLOG(1) << "failure at " << i << "-th element"; |
| 319 return false; | 319 return false; |
| 320 } | 320 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 337 : convert_func_(convert_func) {} | 337 : convert_func_(convert_func) {} |
| 338 | 338 |
| 339 virtual bool Convert(const base::Value& value, | 339 virtual bool Convert(const base::Value& value, |
| 340 ScopedVector<NestedType>* field) const OVERRIDE { | 340 ScopedVector<NestedType>* field) const OVERRIDE { |
| 341 const base::ListValue* list = NULL; | 341 const base::ListValue* list = NULL; |
| 342 if (!value.GetAsList(&list)) | 342 if (!value.GetAsList(&list)) |
| 343 return false; | 343 return false; |
| 344 | 344 |
| 345 field->reserve(list->GetSize()); | 345 field->reserve(list->GetSize()); |
| 346 for (size_t i = 0; i < list->GetSize(); ++i) { | 346 for (size_t i = 0; i < list->GetSize(); ++i) { |
| 347 base::Value* element = NULL; | 347 const base::Value* element = NULL; |
| 348 if (!list->Get(i, &element)) | 348 if (!list->Get(i, &element)) |
| 349 continue; | 349 continue; |
| 350 | 350 |
| 351 scoped_ptr<NestedType> nested(new NestedType); | 351 scoped_ptr<NestedType> nested(new NestedType); |
| 352 if ((*convert_func_)(element, nested.get())) { | 352 if ((*convert_func_)(element, nested.get())) { |
| 353 field->push_back(nested.release()); | 353 field->push_back(nested.release()); |
| 354 } else { | 354 } else { |
| 355 DVLOG(1) << "failure at " << i << "-th element"; | 355 DVLOG(1) << "failure at " << i << "-th element"; |
| 356 return false; | 356 return false; |
| 357 } | 357 } |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 | 518 |
| 519 private: | 519 private: |
| 520 ScopedVector<internal::FieldConverterBase<StructType> > fields_; | 520 ScopedVector<internal::FieldConverterBase<StructType> > fields_; |
| 521 | 521 |
| 522 DISALLOW_COPY_AND_ASSIGN(JSONValueConverter); | 522 DISALLOW_COPY_AND_ASSIGN(JSONValueConverter); |
| 523 }; | 523 }; |
| 524 | 524 |
| 525 } // namespace base | 525 } // namespace base |
| 526 | 526 |
| 527 #endif // BASE_JSON_JSON_VALUE_CONVERTER_H_ | 527 #endif // BASE_JSON_JSON_VALUE_CONVERTER_H_ |
| OLD | NEW |