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