| 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/util.h" | 5 #include "tools/json_schema_compiler/util.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 | 8 |
| 9 namespace json_schema_compiler { | 9 namespace json_schema_compiler { |
| 10 namespace util { | 10 namespace util { |
| 11 | 11 |
| 12 bool GetItemFromList(const base::ListValue& from, int index, int* out) { | 12 bool PopulateItem(const base::Value& from, int* out) { |
| 13 return from.GetInteger(index, out); | 13 return from.GetAsInteger(out); |
| 14 } | 14 } |
| 15 | 15 |
| 16 bool GetItemFromList(const base::ListValue& from, int index, bool* out) { | 16 bool PopulateItem(const base::Value& from, bool* out) { |
| 17 return from.GetBoolean(index, out); | 17 return from.GetAsBoolean(out); |
| 18 } | 18 } |
| 19 | 19 |
| 20 bool GetItemFromList(const base::ListValue& from, int index, double* out) { | 20 bool PopulateItem(const base::Value& from, double* out) { |
| 21 return from.GetDouble(index, out); | 21 return from.GetAsDouble(out); |
| 22 } | 22 } |
| 23 | 23 |
| 24 bool GetItemFromList(const base::ListValue& from, int index, std::string* out) { | 24 bool PopulateItem(const base::Value& from, std::string* out) { |
| 25 return from.GetString(index, out); | 25 return from.GetAsString(out); |
| 26 } | 26 } |
| 27 | 27 |
| 28 bool GetItemFromList(const base::ListValue& from, | 28 bool PopulateItem(const base::Value& from, linked_ptr<base::Value>* out) { |
| 29 int index, | 29 *out = make_linked_ptr(from.DeepCopy()); |
| 30 linked_ptr<base::Value>* out) { | |
| 31 const base::Value* value = NULL; | |
| 32 if (!from.Get(index, &value)) | |
| 33 return false; | |
| 34 *out = make_linked_ptr(value->DeepCopy()); | |
| 35 return true; | 30 return true; |
| 36 } | 31 } |
| 37 | 32 |
| 38 bool GetItemFromList(const base::ListValue& from, int index, | 33 bool PopulateItem(const base::Value& from, |
| 39 linked_ptr<base::DictionaryValue>* out) { | 34 linked_ptr<base::DictionaryValue>* out) { |
| 40 const base::DictionaryValue* dict = NULL; | 35 const base::DictionaryValue* dict = NULL; |
| 41 if (!from.GetDictionary(index, &dict)) | 36 if (!from.GetAsDictionary(&dict)) |
| 42 return false; | 37 return false; |
| 43 *out = make_linked_ptr(dict->DeepCopy()); | 38 *out = make_linked_ptr(dict->DeepCopy()); |
| 44 return true; | 39 return true; |
| 45 } | 40 } |
| 46 | 41 |
| 47 void AddItemToList(const int from, base::ListValue* out) { | 42 void AddItemToList(const int from, base::ListValue* out) { |
| 48 out->Append(new base::FundamentalValue(from)); | 43 out->Append(new base::FundamentalValue(from)); |
| 49 } | 44 } |
| 50 | 45 |
| 51 void AddItemToList(const bool from, base::ListValue* out) { | 46 void AddItemToList(const bool from, base::ListValue* out) { |
| 52 out->Append(new base::FundamentalValue(from)); | 47 out->Append(new base::FundamentalValue(from)); |
| 53 } | 48 } |
| 54 | 49 |
| 55 void AddItemToList(const double from, base::ListValue* out) { | 50 void AddItemToList(const double from, base::ListValue* out) { |
| 56 out->Append(new base::FundamentalValue(from)); | 51 out->Append(new base::FundamentalValue(from)); |
| 57 } | 52 } |
| 58 | 53 |
| 59 void AddItemToList(const std::string& from, base::ListValue* out) { | 54 void AddItemToList(const std::string& from, base::ListValue* out) { |
| 60 out->Append(new base::StringValue(from)); | 55 out->Append(new base::StringValue(from)); |
| 61 } | 56 } |
| 62 | 57 |
| 63 void AddItemToList(const linked_ptr<base::Value>& from, | 58 void AddItemToList(const linked_ptr<base::Value>& from, base::ListValue* out) { |
| 64 base::ListValue* out) { | |
| 65 out->Append(from->DeepCopy()); | 59 out->Append(from->DeepCopy()); |
| 66 } | 60 } |
| 67 | 61 |
| 68 void AddItemToList(const linked_ptr<base::DictionaryValue>& from, | 62 void AddItemToList(const linked_ptr<base::DictionaryValue>& from, |
| 69 base::ListValue* out) { | 63 base::ListValue* out) { |
| 70 out->Append(static_cast<base::Value*>(from->DeepCopy())); | 64 out->Append(static_cast<base::Value*>(from->DeepCopy())); |
| 71 } | 65 } |
| 72 | 66 |
| 73 std::string ValueTypeToString(base::Value::Type type) { | 67 std::string ValueTypeToString(base::Value::Type type) { |
| 74 switch(type) { | 68 switch (type) { |
| 75 case base::Value::TYPE_NULL: | 69 case base::Value::TYPE_NULL: |
| 76 return "null"; | 70 return "null"; |
| 77 case base::Value::TYPE_BOOLEAN: | 71 case base::Value::TYPE_BOOLEAN: |
| 78 return "boolean"; | 72 return "boolean"; |
| 79 case base::Value::TYPE_INTEGER: | 73 case base::Value::TYPE_INTEGER: |
| 80 return "integer"; | 74 return "integer"; |
| 81 case base::Value::TYPE_DOUBLE: | 75 case base::Value::TYPE_DOUBLE: |
| 82 return "number"; | 76 return "number"; |
| 83 case base::Value::TYPE_STRING: | 77 case base::Value::TYPE_STRING: |
| 84 return "string"; | 78 return "string"; |
| 85 case base::Value::TYPE_BINARY: | 79 case base::Value::TYPE_BINARY: |
| 86 return "binary"; | 80 return "binary"; |
| 87 case base::Value::TYPE_DICTIONARY: | 81 case base::Value::TYPE_DICTIONARY: |
| 88 return "dictionary"; | 82 return "dictionary"; |
| 89 case base::Value::TYPE_LIST: | 83 case base::Value::TYPE_LIST: |
| 90 return "list"; | 84 return "list"; |
| 91 } | 85 } |
| 92 NOTREACHED(); | 86 NOTREACHED(); |
| 93 return ""; | 87 return ""; |
| 94 } | 88 } |
| 95 | 89 |
| 96 } // namespace api_util | 90 } // namespace api_util |
| 97 } // namespace extensions | 91 } // namespace extensions |
| OLD | NEW |