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
3 // found in the LICENSE file.
5 #include "tools/json_schema_compiler/util.h"
7 #include "base/values.h"
9 namespace json_schema_compiler
{
12 bool GetItemFromList(const base::ListValue
& from
, int index
, int* out
) {
13 return from
.GetInteger(index
, out
);
16 bool GetItemFromList(const base::ListValue
& from
, int index
, bool* out
) {
17 return from
.GetBoolean(index
, out
);
20 bool GetItemFromList(const base::ListValue
& from
, int index
, double* out
) {
21 return from
.GetDouble(index
, out
);
24 bool GetItemFromList(const base::ListValue
& from
, int index
, std::string
* out
) {
25 return from
.GetString(index
, out
);
28 bool GetItemFromList(const base::ListValue
& from
,
30 linked_ptr
<base::Value
>* out
) {
31 const base::Value
* value
= NULL
;
32 if (!from
.Get(index
, &value
))
34 *out
= make_linked_ptr(value
->DeepCopy());
38 bool GetItemFromList(const base::ListValue
& from
, int index
,
39 linked_ptr
<base::DictionaryValue
>* out
) {
40 const base::DictionaryValue
* dict
= NULL
;
41 if (!from
.GetDictionary(index
, &dict
))
43 *out
= make_linked_ptr(dict
->DeepCopy());
47 void AddItemToList(const int from
, base::ListValue
* out
) {
48 out
->Append(new base::FundamentalValue(from
));
51 void AddItemToList(const bool from
, base::ListValue
* out
) {
52 out
->Append(new base::FundamentalValue(from
));
55 void AddItemToList(const double from
, base::ListValue
* out
) {
56 out
->Append(new base::FundamentalValue(from
));
59 void AddItemToList(const std::string
& from
, base::ListValue
* out
) {
60 out
->Append(new base::StringValue(from
));
63 void AddItemToList(const linked_ptr
<base::Value
>& from
,
64 base::ListValue
* out
) {
65 out
->Append(from
->DeepCopy());
68 void AddItemToList(const linked_ptr
<base::DictionaryValue
>& from
,
69 base::ListValue
* out
) {
70 out
->Append(static_cast<base::Value
*>(from
->DeepCopy()));
73 std::string
ValueTypeToString(base::Value::Type type
) {
75 case base::Value::TYPE_NULL
:
77 case base::Value::TYPE_BOOLEAN
:
79 case base::Value::TYPE_INTEGER
:
81 case base::Value::TYPE_DOUBLE
:
83 case base::Value::TYPE_STRING
:
85 case base::Value::TYPE_BINARY
:
87 case base::Value::TYPE_DICTIONARY
:
89 case base::Value::TYPE_LIST
:
96 } // namespace api_util
97 } // namespace extensions