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/simple_api.json |
| 7 // DO NOT EDIT. |
| 8 |
| 9 #include "tools/json_schema_compiler/util.h" |
| 10 #include "tools/json_schema_compiler/test/simple_api.h" |
| 11 |
| 12 using base::Value; |
| 13 using base::DictionaryValue; |
| 14 using base::ListValue; |
| 15 |
| 16 namespace test { |
| 17 namespace api { |
| 18 namespace simple_api { |
| 19 |
| 20 // |
| 21 // Types |
| 22 // |
| 23 |
| 24 TestType::TestType() {} |
| 25 TestType::~TestType() {} |
| 26 |
| 27 // static |
| 28 bool TestType::Populate(const Value& value, TestType* out) { |
| 29 if (!value.IsType(Value::TYPE_DICTIONARY)) |
| 30 return false; |
| 31 const DictionaryValue* dict = static_cast<const DictionaryValue*>(&value); |
| 32 |
| 33 Value* integer_value = NULL; |
| 34 if (!dict->GetWithoutPathExpansion("integer", &integer_value)) |
| 35 return false; |
| 36 { |
| 37 if (!integer_value->IsType(Value::TYPE_INTEGER)) |
| 38 return false; |
| 39 if (!integer_value->GetAsInteger(&out->integer)) |
| 40 return false; |
| 41 } |
| 42 |
| 43 Value* boolean_value = NULL; |
| 44 if (!dict->GetWithoutPathExpansion("boolean", &boolean_value)) |
| 45 return false; |
| 46 { |
| 47 if (!boolean_value->IsType(Value::TYPE_BOOLEAN)) |
| 48 return false; |
| 49 if (!boolean_value->GetAsBoolean(&out->boolean)) |
| 50 return false; |
| 51 } |
| 52 |
| 53 Value* string_value = NULL; |
| 54 if (!dict->GetWithoutPathExpansion("string", &string_value)) |
| 55 return false; |
| 56 { |
| 57 if (!string_value->IsType(Value::TYPE_STRING)) |
| 58 return false; |
| 59 if (!string_value->GetAsString(&out->string)) |
| 60 return false; |
| 61 } |
| 62 |
| 63 Value* number_value = NULL; |
| 64 if (!dict->GetWithoutPathExpansion("number", &number_value)) |
| 65 return false; |
| 66 { |
| 67 if (!number_value->IsType(Value::TYPE_DOUBLE)) |
| 68 return false; |
| 69 if (!number_value->GetAsDouble(&out->number)) |
| 70 return false; |
| 71 } |
| 72 |
| 73 return true; |
| 74 } |
| 75 |
| 76 scoped_ptr<DictionaryValue> TestType::ToValue() const { |
| 77 scoped_ptr<DictionaryValue> value(new DictionaryValue()); |
| 78 |
| 79 value->SetWithoutPathExpansion("integer", Value::CreateIntegerValue(integer)); |
| 80 value->SetWithoutPathExpansion("boolean", Value::CreateBooleanValue(boolean)); |
| 81 value->SetWithoutPathExpansion("string", Value::CreateStringValue(string)); |
| 82 value->SetWithoutPathExpansion("number", Value::CreateDoubleValue(number)); |
| 83 |
| 84 return value.Pass(); |
| 85 } |
| 86 |
| 87 |
| 88 // |
| 89 // Functions |
| 90 // |
| 91 |
| 92 OptionalString::Params::Params() {} |
| 93 OptionalString::Params::~Params() {} |
| 94 |
| 95 // static |
| 96 scoped_ptr<OptionalString::Params> OptionalString::Params::Create(const ListValu
e& args) { |
| 97 if (args.GetSize() > 1) |
| 98 return scoped_ptr<Params>(); |
| 99 scoped_ptr<Params> params(new Params()); |
| 100 |
| 101 Value* str_value = NULL; |
| 102 if (!args.Get(0, &str_value) || str_value->IsType(Value::TYPE_NULL)) |
| 103 return params.Pass(); |
| 104 { |
| 105 if (!str_value->IsType(Value::TYPE_STRING)) |
| 106 return scoped_ptr<Params>(); |
| 107 std::string temp; |
| 108 if (str_value->GetAsString(&temp)) |
| 109 params->str.reset(new std::string(temp)); |
| 110 } |
| 111 |
| 112 return params.Pass(); |
| 113 } |
| 114 |
| 115 |
| 116 Value* OptionalString::Result::Create() { |
| 117 return Value::CreateNullValue(); |
| 118 } |
| 119 |
| 120 Value* GetTestType::Result::Create(const TestType& result) { |
| 121 return result.ToValue().release(); |
| 122 } |
| 123 |
| 124 Value* OptionalCallbackParams::Result::Create(const TestType& result) { |
| 125 return result.ToValue().release(); |
| 126 } |
| 127 |
| 128 IncrementInteger::Params::Params() {} |
| 129 IncrementInteger::Params::~Params() {} |
| 130 |
| 131 // static |
| 132 scoped_ptr<IncrementInteger::Params> IncrementInteger::Params::Create(const List
Value& args) { |
| 133 if (args.GetSize() != 1) |
| 134 return scoped_ptr<Params>(); |
| 135 scoped_ptr<Params> params(new Params()); |
| 136 |
| 137 Value* num_value = NULL; |
| 138 if (!args.Get(0, &num_value) || num_value->IsType(Value::TYPE_NULL)) |
| 139 return scoped_ptr<Params>(); |
| 140 { |
| 141 if (!num_value->IsType(Value::TYPE_INTEGER)) |
| 142 return scoped_ptr<Params>(); |
| 143 if (!num_value->GetAsInteger(¶ms->num)) |
| 144 return scoped_ptr<Params>(); |
| 145 } |
| 146 |
| 147 return params.Pass(); |
| 148 } |
| 149 |
| 150 |
| 151 Value* IncrementInteger::Result::Create(const int result) { |
| 152 return Value::CreateIntegerValue(result); |
| 153 } |
| 154 |
| 155 } // simple_api |
| 156 } // api |
| 157 } // test |
OLD | NEW |