OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 from code import Code | 5 from code import Code |
6 from model import PropertyType, Type | 6 from model import PropertyType, Type |
7 import cpp_util | 7 import cpp_util |
8 import model | 8 import model |
9 import schema_util | 9 import schema_util |
10 import sys | 10 import sys |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 """ | 181 """ |
182 classname = cpp_util.Classname(schema_util.StripNamespace(type_.name)) | 182 classname = cpp_util.Classname(schema_util.StripNamespace(type_.name)) |
183 c = Code() | 183 c = Code() |
184 (c.Append('// static') | 184 (c.Append('// static') |
185 .Append('bool %(namespace)s::Populate(') | 185 .Append('bool %(namespace)s::Populate(') |
186 .Sblock(' const base::Value& value, %(name)s* out) {') | 186 .Sblock(' const base::Value& value, %(name)s* out) {') |
187 ) | 187 ) |
188 if type_.property_type == PropertyType.CHOICES: | 188 if type_.property_type == PropertyType.CHOICES: |
189 for choice in type_.choices: | 189 for choice in type_.choices: |
190 value_type = cpp_util.GetValueType(self._type_helper.FollowRef(choice)) | 190 value_type = cpp_util.GetValueType(self._type_helper.FollowRef(choice)) |
191 (c.Sblock('if (value.IsType(%s)) {' % value_type) | 191 (c.Sblock('if (value.IsType(base::%s)) {' % value_type) |
192 .Concat(self._GeneratePopulateVariableFromValue( | 192 .Concat(self._GeneratePopulateVariableFromValue( |
193 choice, | 193 choice, |
194 '(&value)', | 194 '(&value)', |
195 'out->as_%s' % choice.unix_name, | 195 'out->as_%s' % choice.unix_name, |
196 'false', | 196 'false', |
197 is_ptr=True)) | 197 is_ptr=True)) |
198 .Append('return true;') | 198 .Append('return true;') |
199 .Eblock('}') | 199 .Eblock('}') |
200 ) | 200 ) |
201 c.Append('return false;') | 201 c.Append('return false;') |
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 else: | 638 else: |
639 (c.Append('if (!%(cpp_type)s::Populate(*%(src_var)s, &%(dst_var)s))') | 639 (c.Append('if (!%(cpp_type)s::Populate(*%(src_var)s, &%(dst_var)s))') |
640 .Append(' return %(failure_value)s;') | 640 .Append(' return %(failure_value)s;') |
641 ) | 641 ) |
642 elif underlying_type.property_type == PropertyType.ENUM: | 642 elif underlying_type.property_type == PropertyType.ENUM: |
643 c.Concat(self._GenerateStringToEnumConversion(type_, | 643 c.Concat(self._GenerateStringToEnumConversion(type_, |
644 src_var, | 644 src_var, |
645 dst_var, | 645 dst_var, |
646 failure_value)) | 646 failure_value)) |
647 elif underlying_type.property_type == PropertyType.BINARY: | 647 elif underlying_type.property_type == PropertyType.BINARY: |
648 (c.Append('if (!%(src_var)s->IsType(%(value_type)s))') | 648 (c.Append('if (!%(src_var)s->IsType(base::%(value_type)s))') |
649 .Append(' return %(failure_value)s;') | 649 .Append(' return %(failure_value)s;') |
650 .Append('const base::BinaryValue* binary_value =') | 650 .Append('const base::BinaryValue* binary_value =') |
651 .Append(' static_cast<const base::BinaryValue*>(%(src_var)s);') | 651 .Append(' static_cast<const base::BinaryValue*>(%(src_var)s);') |
652 ) | 652 ) |
653 if is_ptr: | 653 if is_ptr: |
654 (c.Append('%(dst_var)s.reset(') | 654 (c.Append('%(dst_var)s.reset(') |
655 .Append(' new std::string(binary_value->GetBuffer(),') | 655 .Append(' new std::string(binary_value->GetBuffer(),') |
656 .Append(' binary_value->GetSize()));') | 656 .Append(' binary_value->GetSize()));') |
657 ) | 657 ) |
658 else: | 658 else: |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 """ | 834 """ |
835 c = Code() | 835 c = Code() |
836 underlying_type = self._type_helper.FollowRef(prop.type_) | 836 underlying_type = self._type_helper.FollowRef(prop.type_) |
837 if (underlying_type.property_type == PropertyType.ENUM and | 837 if (underlying_type.property_type == PropertyType.ENUM and |
838 prop.optional): | 838 prop.optional): |
839 c.Append('%s->%s = %s;' % ( | 839 c.Append('%s->%s = %s;' % ( |
840 dst, | 840 dst, |
841 prop.unix_name, | 841 prop.unix_name, |
842 self._type_helper.GetEnumNoneValue(prop.type_))) | 842 self._type_helper.GetEnumNoneValue(prop.type_))) |
843 return c | 843 return c |
OLD | NEW |