[Mac] Use a custom view to implement colored app windows.
[chromium-blink-merge.git] / tools / json_schema_compiler / util.cc
blob3e36cfc7a6957c7226fa0c5b2b10e78a7a6a104e
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/stl_util.h"
8 #include "base/values.h"
10 namespace json_schema_compiler {
11 namespace util {
13 bool PopulateItem(const base::Value& from, int* out) {
14 return from.GetAsInteger(out);
17 bool PopulateItem(const base::Value& from, bool* out) {
18 return from.GetAsBoolean(out);
21 bool PopulateItem(const base::Value& from, double* out) {
22 return from.GetAsDouble(out);
25 bool PopulateItem(const base::Value& from, std::string* out) {
26 return from.GetAsString(out);
29 bool PopulateItem(const base::Value& from, std::vector<char>* out) {
30 const base::BinaryValue* binary = nullptr;
31 if (!from.GetAsBinary(&binary))
32 return false;
33 out->assign(binary->GetBuffer(), binary->GetBuffer() + binary->GetSize());
34 return true;
37 bool PopulateItem(const base::Value& from, linked_ptr<base::Value>* out) {
38 *out = make_linked_ptr(from.DeepCopy());
39 return true;
42 bool PopulateItem(const base::Value& from,
43 linked_ptr<base::DictionaryValue>* out) {
44 const base::DictionaryValue* dict = nullptr;
45 if (!from.GetAsDictionary(&dict))
46 return false;
47 *out = make_linked_ptr(dict->DeepCopy());
48 return true;
51 void AddItemToList(const int from, base::ListValue* out) {
52 out->Append(new base::FundamentalValue(from));
55 void AddItemToList(const bool from, base::ListValue* out) {
56 out->Append(new base::FundamentalValue(from));
59 void AddItemToList(const double from, base::ListValue* out) {
60 out->Append(new base::FundamentalValue(from));
63 void AddItemToList(const std::string& from, base::ListValue* out) {
64 out->Append(new base::StringValue(from));
67 void AddItemToList(const std::vector<char>& from, base::ListValue* out) {
68 out->Append(base::BinaryValue::CreateWithCopiedBuffer(vector_as_array(&from),
69 from.size()));
72 void AddItemToList(const linked_ptr<base::Value>& from, base::ListValue* out) {
73 out->Append(from->DeepCopy());
76 void AddItemToList(const linked_ptr<base::DictionaryValue>& from,
77 base::ListValue* out) {
78 out->Append(static_cast<base::Value*>(from->DeepCopy()));
81 std::string ValueTypeToString(base::Value::Type type) {
82 switch (type) {
83 case base::Value::TYPE_NULL:
84 return "null";
85 case base::Value::TYPE_BOOLEAN:
86 return "boolean";
87 case base::Value::TYPE_INTEGER:
88 return "integer";
89 case base::Value::TYPE_DOUBLE:
90 return "number";
91 case base::Value::TYPE_STRING:
92 return "string";
93 case base::Value::TYPE_BINARY:
94 return "binary";
95 case base::Value::TYPE_DICTIONARY:
96 return "dictionary";
97 case base::Value::TYPE_LIST:
98 return "list";
100 NOTREACHED();
101 return "";
104 } // namespace util
105 } // namespace json_schema_compiler