diff options
author | Zeno Albisser <zeno.albisser@digia.com> | 2013-08-15 21:46:11 +0200 |
---|---|---|
committer | Zeno Albisser <zeno.albisser@digia.com> | 2013-08-15 21:46:11 +0200 |
commit | 679147eead574d186ebf3069647b4c23e8ccace6 (patch) | |
tree | fc247a0ac8ff119f7c8550879ebb6d3dd8d1ff69 /chromium/tools/json_schema_compiler/util.cc | |
download | qtwebengine-chromium-679147eead574d186ebf3069647b4c23e8ccace6.tar.gz |
Initial import.
Diffstat (limited to 'chromium/tools/json_schema_compiler/util.cc')
-rw-r--r-- | chromium/tools/json_schema_compiler/util.cc | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/chromium/tools/json_schema_compiler/util.cc b/chromium/tools/json_schema_compiler/util.cc new file mode 100644 index 00000000000..d0e77659e6a --- /dev/null +++ b/chromium/tools/json_schema_compiler/util.cc @@ -0,0 +1,97 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "tools/json_schema_compiler/util.h" + +#include "base/values.h" + +namespace json_schema_compiler { +namespace util { + +bool GetItemFromList(const base::ListValue& from, int index, int* out) { + return from.GetInteger(index, out); +} + +bool GetItemFromList(const base::ListValue& from, int index, bool* out) { + return from.GetBoolean(index, out); +} + +bool GetItemFromList(const base::ListValue& from, int index, double* out) { + return from.GetDouble(index, out); +} + +bool GetItemFromList(const base::ListValue& from, int index, std::string* out) { + return from.GetString(index, out); +} + +bool GetItemFromList(const base::ListValue& from, + int index, + linked_ptr<base::Value>* out) { + const base::Value* value = NULL; + if (!from.Get(index, &value)) + return false; + *out = make_linked_ptr(value->DeepCopy()); + return true; +} + +bool GetItemFromList(const base::ListValue& from, int index, + linked_ptr<base::DictionaryValue>* out) { + const base::DictionaryValue* dict = NULL; + if (!from.GetDictionary(index, &dict)) + return false; + *out = make_linked_ptr(dict->DeepCopy()); + return true; +} + +void AddItemToList(const int from, base::ListValue* out) { + out->Append(new base::FundamentalValue(from)); +} + +void AddItemToList(const bool from, base::ListValue* out) { + out->Append(new base::FundamentalValue(from)); +} + +void AddItemToList(const double from, base::ListValue* out) { + out->Append(new base::FundamentalValue(from)); +} + +void AddItemToList(const std::string& from, base::ListValue* out) { + out->Append(new base::StringValue(from)); +} + +void AddItemToList(const linked_ptr<base::Value>& from, + base::ListValue* out) { + out->Append(from->DeepCopy()); +} + +void AddItemToList(const linked_ptr<base::DictionaryValue>& from, + base::ListValue* out) { + out->Append(static_cast<base::Value*>(from->DeepCopy())); +} + +std::string ValueTypeToString(Value::Type type) { + switch(type) { + case Value::TYPE_NULL: + return "null"; + case Value::TYPE_BOOLEAN: + return "boolean"; + case Value::TYPE_INTEGER: + return "integer"; + case Value::TYPE_DOUBLE: + return "number"; + case Value::TYPE_STRING: + return "string"; + case Value::TYPE_BINARY: + return "binary"; + case Value::TYPE_DICTIONARY: + return "dictionary"; + case Value::TYPE_LIST: + return "list"; + } + NOTREACHED(); + return ""; +} + +} // namespace api_util +} // namespace extensions |