| 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 | 6 from model import PropertyType |
| 7 import any_helper | 7 import any_helper |
| 8 import cpp_util | 8 import cpp_util |
| 9 import model | 9 import model |
| 10 import schema_util | 10 import schema_util |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 return '%s->ToValue().release()' % var | 337 return '%s->ToValue().release()' % var |
| 338 else: | 338 else: |
| 339 return '%s.ToValue().release()' % var | 339 return '%s.ToValue().release()' % var |
| 340 elif prop.type_ == PropertyType.ANY: | 340 elif prop.type_ == PropertyType.ANY: |
| 341 return '%s.DeepCopy()' % self._any_helper.GetValue(prop, var) | 341 return '%s.DeepCopy()' % self._any_helper.GetValue(prop, var) |
| 342 elif prop.type_ == PropertyType.ADDITIONAL_PROPERTIES: | 342 elif prop.type_ == PropertyType.ADDITIONAL_PROPERTIES: |
| 343 return '%s.DeepCopy()' % var | 343 return '%s.DeepCopy()' % var |
| 344 elif prop.type_ == PropertyType.ENUM: | 344 elif prop.type_ == PropertyType.ENUM: |
| 345 return 'CreateEnumValue(%s).release()' % var | 345 return 'CreateEnumValue(%s).release()' % var |
| 346 elif prop.type_ == PropertyType.BINARY: | 346 elif prop.type_ == PropertyType.BINARY: |
| 347 return '%s->DeepCopy()' % var | 347 if prop.optional: |
| 348 vardot = var + '->' |
| 349 else: |
| 350 vardot = var + '.' |
| 351 return ('base::BinaryValue::CreateWithCopiedBuffer(%sdata(), %ssize())' % |
| 352 (vardot, vardot)) |
| 348 elif self._IsArrayOrArrayRef(prop): | 353 elif self._IsArrayOrArrayRef(prop): |
| 349 return '%s.release()' % self._util_cc_helper.CreateValueFromArray( | 354 return '%s.release()' % self._util_cc_helper.CreateValueFromArray( |
| 350 self._cpp_type_generator.GetReferencedProperty(prop), var, | 355 self._cpp_type_generator.GetReferencedProperty(prop), var, |
| 351 prop.optional) | 356 prop.optional) |
| 352 elif self._IsFundamentalOrFundamentalRef(prop): | 357 elif self._IsFundamentalOrFundamentalRef(prop): |
| 353 if prop.optional: | 358 if prop.optional: |
| 354 var = '*' + var | 359 var = '*' + var |
| 355 prop = self._cpp_type_generator.GetReferencedProperty(prop); | 360 prop = self._cpp_type_generator.GetReferencedProperty(prop); |
| 356 return { | 361 return { |
| 357 PropertyType.STRING: 'base::Value::CreateStringValue(%s)', | 362 PropertyType.STRING: 'base::Value::CreateStringValue(%s)', |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 (c.Append('default:') | 529 (c.Append('default:') |
| 525 .Append(' return %(failure_value)s;') | 530 .Append(' return %(failure_value)s;') |
| 526 ) | 531 ) |
| 527 c.Eblock('}') | 532 c.Eblock('}') |
| 528 elif prop.type_ == PropertyType.ENUM: | 533 elif prop.type_ == PropertyType.ENUM: |
| 529 c.Sblock('{') | 534 c.Sblock('{') |
| 530 self._GenerateStringToEnumConversion(c, prop, value_var, 'enum_temp') | 535 self._GenerateStringToEnumConversion(c, prop, value_var, 'enum_temp') |
| 531 c.Append('%(dst)s->%(name)s = enum_temp;') | 536 c.Append('%(dst)s->%(name)s = enum_temp;') |
| 532 c.Eblock('}') | 537 c.Eblock('}') |
| 533 elif prop.type_ == PropertyType.BINARY: | 538 elif prop.type_ == PropertyType.BINARY: |
| 534 # This is the same if the property is optional or not. We need a pointer | |
| 535 # to the base::BinaryValue to be able to populate it, so a scoped_ptr is | |
| 536 # used whether it is optional or required. | |
| 537 (c.Append('if (!%(value_var)s->IsType(%(value_type)s))') | 539 (c.Append('if (!%(value_var)s->IsType(%(value_type)s))') |
| 538 .Append(' return %(failure_value)s;') | 540 .Append(' return %(failure_value)s;') |
| 539 .Append('%(dst)s->%(name)s.reset(') | 541 .Append('base::BinaryValue* binary_value =') |
| 540 .Append(' static_cast<base::BinaryValue*>(%(value_var)s)' | 542 .Append(' static_cast<base::BinaryValue*>(%(value_var)s);') |
| 541 '->DeepCopy());') | 543 ) |
| 542 ) | 544 if prop.optional: |
| 545 (c.Append('%(dst)s->%(name)s.reset(') |
| 546 .Append(' new std::string(binary_value->GetBuffer(),') |
| 547 .Append(' binary_value->GetSize()));') |
| 548 ) |
| 549 else: |
| 550 (c.Append('%(dst)s->%(name)s.assign(binary_value->GetBuffer(),') |
| 551 .Append(' binary_value->GetSize());') |
| 552 ) |
| 543 else: | 553 else: |
| 544 raise NotImplementedError(prop.type_) | 554 raise NotImplementedError(prop.type_) |
| 545 c.Eblock('}') | 555 c.Eblock('}') |
| 546 sub = { | 556 sub = { |
| 547 'value_var': value_var, | 557 'value_var': value_var, |
| 548 'name': prop.unix_name, | 558 'name': prop.unix_name, |
| 549 'dst': dst, | 559 'dst': dst, |
| 550 'failure_value': failure_value, | 560 'failure_value': failure_value, |
| 551 } | 561 } |
| 552 if prop.type_ not in (PropertyType.CHOICES, PropertyType.ANY): | 562 if prop.type_ not in (PropertyType.CHOICES, PropertyType.ANY): |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 """ | 707 """ |
| 698 return (self._cpp_type_generator.GetReferencedProperty(prop).type_ == | 708 return (self._cpp_type_generator.GetReferencedProperty(prop).type_ == |
| 699 PropertyType.ARRAY) | 709 PropertyType.ARRAY) |
| 700 | 710 |
| 701 def _IsFundamentalOrFundamentalRef(self, prop): | 711 def _IsFundamentalOrFundamentalRef(self, prop): |
| 702 """Determines if this property is a Fundamental type or is a ref to a | 712 """Determines if this property is a Fundamental type or is a ref to a |
| 703 Fundamental type. | 713 Fundamental type. |
| 704 """ | 714 """ |
| 705 return (self._cpp_type_generator.GetReferencedProperty(prop).type_. | 715 return (self._cpp_type_generator.GetReferencedProperty(prop).type_. |
| 706 is_fundamental) | 716 is_fundamental) |
| OLD | NEW |