OLD | NEW |
(Empty) | |
| 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 // GENERATED FROM THE API DEFINITION IN |
| 6 // tools/json_schema_compiler/test/choices.json |
| 7 // DO NOT EDIT. |
| 8 |
| 9 #include "tools/json_schema_compiler/util.h" |
| 10 #include "tools/json_schema_compiler/test/choices.h" |
| 11 |
| 12 using base::Value; |
| 13 using base::DictionaryValue; |
| 14 using base::ListValue; |
| 15 |
| 16 namespace test { |
| 17 namespace api { |
| 18 namespace choices { |
| 19 |
| 20 // |
| 21 // Functions |
| 22 // |
| 23 |
| 24 TakesIntegersOptional::Params::Params() {} |
| 25 TakesIntegersOptional::Params::~Params() {} |
| 26 |
| 27 // static |
| 28 scoped_ptr<TakesIntegersOptional::Params> TakesIntegersOptional::Params::Create(
const ListValue& args) { |
| 29 if (args.GetSize() > 1) |
| 30 return scoped_ptr<Params>(); |
| 31 scoped_ptr<Params> params(new Params()); |
| 32 |
| 33 Value* nums_value = NULL; |
| 34 if (!args.Get(0, &nums_value) || nums_value->IsType(Value::TYPE_NULL)) |
| 35 return params.Pass(); |
| 36 params->nums_type = NUMS_NONE; |
| 37 switch (nums_value->GetType()) { |
| 38 case Value::TYPE_LIST: { |
| 39 { |
| 40 ListValue* list = NULL; |
| 41 if (!nums_value->GetAsList(&list)) |
| 42 return scoped_ptr<Params>(); |
| 43 if (!json_schema_compiler::util::PopulateOptionalArrayFromList(*list, &p
arams->nums_array)) |
| 44 return scoped_ptr<Params>(); |
| 45 } |
| 46 params->nums_type = NUMS_ARRAY; |
| 47 break; |
| 48 } |
| 49 case Value::TYPE_INTEGER: { |
| 50 { |
| 51 int temp; |
| 52 if (nums_value->GetAsInteger(&temp)) |
| 53 params->nums_integer.reset(new int(temp)); |
| 54 } |
| 55 params->nums_type = NUMS_INTEGER; |
| 56 break; |
| 57 } |
| 58 default: |
| 59 return scoped_ptr<Params>(); |
| 60 } |
| 61 |
| 62 return params.Pass(); |
| 63 } |
| 64 |
| 65 |
| 66 Value* TakesIntegersOptional::Result::Create() { |
| 67 return Value::CreateNullValue(); |
| 68 } |
| 69 |
| 70 Value* ReturnChoices::Result::Create(const std::vector<int>& result_array) { |
| 71 ListValue* value = new ListValue(); |
| 72 json_schema_compiler::util::PopulateListFromArray(result_array, value); |
| 73 return value; |
| 74 } |
| 75 Value* ReturnChoices::Result::Create(const int result_integer) { |
| 76 return Value::CreateIntegerValue(result_integer); |
| 77 } |
| 78 |
| 79 TakesIntegers::Params::Params() {} |
| 80 TakesIntegers::Params::~Params() {} |
| 81 |
| 82 // static |
| 83 scoped_ptr<TakesIntegers::Params> TakesIntegers::Params::Create(const ListValue&
args) { |
| 84 if (args.GetSize() != 1) |
| 85 return scoped_ptr<Params>(); |
| 86 scoped_ptr<Params> params(new Params()); |
| 87 |
| 88 Value* nums_value = NULL; |
| 89 if (!args.Get(0, &nums_value) || nums_value->IsType(Value::TYPE_NULL)) |
| 90 return scoped_ptr<Params>(); |
| 91 params->nums_type = NUMS_NONE; |
| 92 switch (nums_value->GetType()) { |
| 93 case Value::TYPE_LIST: { |
| 94 { |
| 95 ListValue* list = NULL; |
| 96 if (!nums_value->GetAsList(&list)) |
| 97 return scoped_ptr<Params>(); |
| 98 if (!json_schema_compiler::util::PopulateOptionalArrayFromList(*list, &p
arams->nums_array)) |
| 99 return scoped_ptr<Params>(); |
| 100 } |
| 101 params->nums_type = NUMS_ARRAY; |
| 102 break; |
| 103 } |
| 104 case Value::TYPE_INTEGER: { |
| 105 { |
| 106 int temp; |
| 107 if (nums_value->GetAsInteger(&temp)) |
| 108 params->nums_integer.reset(new int(temp)); |
| 109 } |
| 110 params->nums_type = NUMS_INTEGER; |
| 111 break; |
| 112 } |
| 113 default: |
| 114 return scoped_ptr<Params>(); |
| 115 } |
| 116 |
| 117 return params.Pass(); |
| 118 } |
| 119 |
| 120 |
| 121 Value* TakesIntegers::Result::Create() { |
| 122 return Value::CreateNullValue(); |
| 123 } |
| 124 |
| 125 ObjectWithChoices::Params::StringInfo::StringInfo() {} |
| 126 ObjectWithChoices::Params::StringInfo::~StringInfo() {} |
| 127 |
| 128 // static |
| 129 bool ObjectWithChoices::Params::StringInfo::Populate(const Value& value, StringI
nfo* out) { |
| 130 if (!value.IsType(Value::TYPE_DICTIONARY)) |
| 131 return false; |
| 132 const DictionaryValue* dict = static_cast<const DictionaryValue*>(&value); |
| 133 |
| 134 Value* integers_value = NULL; |
| 135 if (dict->GetWithoutPathExpansion("integers", &integers_value)) { |
| 136 out->integers_type = INTEGERS_NONE; |
| 137 switch (integers_value->GetType()) { |
| 138 case Value::TYPE_LIST: { |
| 139 { |
| 140 ListValue* list = NULL; |
| 141 if (!integers_value->GetAsList(&list)) |
| 142 return false; |
| 143 if (!json_schema_compiler::util::PopulateOptionalArrayFromList(*list,
&out->integers_array)) |
| 144 return false; |
| 145 } |
| 146 out->integers_type = INTEGERS_ARRAY; |
| 147 break; |
| 148 } |
| 149 case Value::TYPE_INTEGER: { |
| 150 { |
| 151 int temp; |
| 152 if (integers_value->GetAsInteger(&temp)) |
| 153 out->integers_integer.reset(new int(temp)); |
| 154 } |
| 155 out->integers_type = INTEGERS_INTEGER; |
| 156 break; |
| 157 } |
| 158 default: |
| 159 return false; |
| 160 } |
| 161 } |
| 162 |
| 163 Value* strings_value = NULL; |
| 164 if (!dict->GetWithoutPathExpansion("strings", &strings_value)) |
| 165 return false; |
| 166 out->strings_type = STRINGS_NONE; |
| 167 switch (strings_value->GetType()) { |
| 168 case Value::TYPE_LIST: { |
| 169 { |
| 170 ListValue* list = NULL; |
| 171 if (!strings_value->GetAsList(&list)) |
| 172 return false; |
| 173 if (!json_schema_compiler::util::PopulateOptionalArrayFromList(*list, &o
ut->strings_array)) |
| 174 return false; |
| 175 } |
| 176 out->strings_type = STRINGS_ARRAY; |
| 177 break; |
| 178 } |
| 179 case Value::TYPE_STRING: { |
| 180 { |
| 181 std::string temp; |
| 182 if (strings_value->GetAsString(&temp)) |
| 183 out->strings_string.reset(new std::string(temp)); |
| 184 } |
| 185 out->strings_type = STRINGS_STRING; |
| 186 break; |
| 187 } |
| 188 default: |
| 189 return false; |
| 190 } |
| 191 |
| 192 return true; |
| 193 } |
| 194 |
| 195 |
| 196 |
| 197 ObjectWithChoices::Params::Params() {} |
| 198 ObjectWithChoices::Params::~Params() {} |
| 199 |
| 200 // static |
| 201 scoped_ptr<ObjectWithChoices::Params> ObjectWithChoices::Params::Create(const Li
stValue& args) { |
| 202 if (args.GetSize() != 1) |
| 203 return scoped_ptr<Params>(); |
| 204 scoped_ptr<Params> params(new Params()); |
| 205 |
| 206 Value* string_info_value = NULL; |
| 207 if (!args.Get(0, &string_info_value) || string_info_value->IsType(Value::TYPE_
NULL)) |
| 208 return scoped_ptr<Params>(); |
| 209 { |
| 210 if (!string_info_value->IsType(Value::TYPE_DICTIONARY)) |
| 211 return scoped_ptr<Params>(); |
| 212 DictionaryValue* dictionary = NULL; |
| 213 if (!string_info_value->GetAsDictionary(&dictionary)) |
| 214 return scoped_ptr<Params>(); |
| 215 if (!StringInfo::Populate(*dictionary, ¶ms->string_info)) |
| 216 return scoped_ptr<Params>(); |
| 217 } |
| 218 |
| 219 return params.Pass(); |
| 220 } |
| 221 |
| 222 |
| 223 Value* ObjectWithChoices::Result::Create() { |
| 224 return Value::CreateNullValue(); |
| 225 } |
| 226 |
| 227 } // choices |
| 228 } // api |
| 229 } // test |
OLD | NEW |