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