| 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 #include "tools/json_schema_compiler/any.h" |
| 5 #include "tools/json_schema_compiler/util.h" | 6 #include "tools/json_schema_compiler/util.h" |
| 6 | 7 |
| 7 #include "base/values.h" | 8 #include "base/values.h" |
| 8 | 9 |
| 9 namespace json_schema_compiler { | 10 namespace json_schema_compiler { |
| 10 namespace util { | 11 namespace util { |
| 11 | 12 |
| 12 bool GetItemFromList(const ListValue& from, int index, int* out) { | 13 bool GetItemFromList(const ListValue& from, int index, int* out) { |
| 13 return from.GetInteger(index, out); | 14 return from.GetInteger(index, out); |
| 14 } | 15 } |
| 15 | 16 |
| 16 bool GetItemFromList(const ListValue& from, int index, bool* out) { | 17 bool GetItemFromList(const ListValue& from, int index, bool* out) { |
| 17 return from.GetBoolean(index, out); | 18 return from.GetBoolean(index, out); |
| 18 } | 19 } |
| 19 | 20 |
| 20 bool GetItemFromList(const ListValue& from, int index, double* out) { | 21 bool GetItemFromList(const ListValue& from, int index, double* out) { |
| 21 return from.GetDouble(index, out); | 22 return from.GetDouble(index, out); |
| 22 } | 23 } |
| 23 | 24 |
| 24 bool GetItemFromList(const ListValue& from, int index, std::string* out) { | 25 bool GetItemFromList(const ListValue& from, int index, std::string* out) { |
| 25 return from.GetString(index, out); | 26 return from.GetString(index, out); |
| 26 } | 27 } |
| 27 | 28 |
| 28 bool GetItemFromList(const ListValue& from, int index, | 29 bool GetItemFromList(const ListValue& from, int index, |
| 30 linked_ptr<any::Any>* out) { |
| 31 Value* value = NULL; |
| 32 if (!from.Get(index, &value)) |
| 33 return false; |
| 34 scoped_ptr<any::Any> any_object(new any::Any()); |
| 35 any_object->Init(*value); |
| 36 *out = linked_ptr<any::Any>(any_object.release()); |
| 37 return true; |
| 38 } |
| 39 |
| 40 bool GetItemFromList(const ListValue& from, int index, |
| 29 linked_ptr<base::DictionaryValue>* out) { | 41 linked_ptr<base::DictionaryValue>* out) { |
| 30 DictionaryValue* dict = NULL; | 42 DictionaryValue* dict = NULL; |
| 31 if (!from.GetDictionary(index, &dict)) { | 43 if (!from.GetDictionary(index, &dict)) |
| 32 return false; | 44 return false; |
| 33 } | |
| 34 *out = linked_ptr<DictionaryValue>(dict->DeepCopy()); | 45 *out = linked_ptr<DictionaryValue>(dict->DeepCopy()); |
| 35 return true; | 46 return true; |
| 36 } | 47 } |
| 37 | 48 |
| 38 void AddItemToList(const int from, base::ListValue* out) { | 49 void AddItemToList(const int from, base::ListValue* out) { |
| 39 out->Append(base::Value::CreateIntegerValue(from)); | 50 out->Append(base::Value::CreateIntegerValue(from)); |
| 40 } | 51 } |
| 41 void AddItemToList(const bool from, base::ListValue* out) { | 52 void AddItemToList(const bool from, base::ListValue* out) { |
| 42 out->Append(base::Value::CreateBooleanValue(from)); | 53 out->Append(base::Value::CreateBooleanValue(from)); |
| 43 } | 54 } |
| 44 void AddItemToList(const double from, base::ListValue* out) { | 55 void AddItemToList(const double from, base::ListValue* out) { |
| 45 out->Append(base::Value::CreateDoubleValue(from)); | 56 out->Append(base::Value::CreateDoubleValue(from)); |
| 46 } | 57 } |
| 47 void AddItemToList(const std::string& from, base::ListValue* out) { | 58 void AddItemToList(const std::string& from, base::ListValue* out) { |
| 48 out->Append(base::Value::CreateStringValue(from)); | 59 out->Append(base::Value::CreateStringValue(from)); |
| 49 } | 60 } |
| 50 void AddItemToList(const linked_ptr<base::DictionaryValue>& from, | 61 void AddItemToList(const linked_ptr<base::DictionaryValue>& from, |
| 51 base::ListValue* out) { | 62 base::ListValue* out) { |
| 52 out->Append(static_cast<Value*>(from->DeepCopy())); | 63 out->Append(static_cast<Value*>(from->DeepCopy())); |
| 53 } | 64 } |
| 65 void AddItemToList(const linked_ptr<any::Any>& from, |
| 66 base::ListValue* out) { |
| 67 out->Append(from->value().DeepCopy()); |
| 68 } |
| 54 | 69 |
| 55 } // namespace api_util | 70 } // namespace api_util |
| 56 } // namespace extensions | 71 } // namespace extensions |
| OLD | NEW |