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 """Utilies and constants specific to Chromium C++ code. | 4 """Utilies and constants specific to Chromium C++ code. |
5 """ | 5 """ |
6 | 6 |
7 from datetime import datetime | 7 from datetime import datetime |
8 from model import PropertyType | 8 from model import PropertyType |
9 | 9 |
10 CHROMIUM_LICENSE = ( | 10 CHROMIUM_LICENSE = ( |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 PropertyType.INTEGER: 'Value::TYPE_INTEGER', | 48 PropertyType.INTEGER: 'Value::TYPE_INTEGER', |
49 PropertyType.BOOLEAN: 'Value::TYPE_BOOLEAN', | 49 PropertyType.BOOLEAN: 'Value::TYPE_BOOLEAN', |
50 PropertyType.DOUBLE: 'Value::TYPE_DOUBLE', | 50 PropertyType.DOUBLE: 'Value::TYPE_DOUBLE', |
51 PropertyType.ENUM: 'Value::TYPE_STRING', | 51 PropertyType.ENUM: 'Value::TYPE_STRING', |
52 PropertyType.REF: 'Value::TYPE_DICTIONARY', | 52 PropertyType.REF: 'Value::TYPE_DICTIONARY', |
53 PropertyType.OBJECT: 'Value::TYPE_DICTIONARY', | 53 PropertyType.OBJECT: 'Value::TYPE_DICTIONARY', |
54 PropertyType.ARRAY: 'Value::TYPE_LIST' | 54 PropertyType.ARRAY: 'Value::TYPE_LIST' |
55 }[prop.type_] | 55 }[prop.type_] |
56 | 56 |
57 | 57 |
58 def CreateValueFromSingleProperty(prop, var): | 58 def CreateValueFromSingleProperty(prop, var, util_cc_helper): |
not at google - send to devlin
2012/02/24 03:53:05
I don't think this method needs to be in cpp_util,
calamity
2012/02/24 15:10:40
Done.
| |
59 """Creates a Value given a single property. Use for everything except | 59 """Creates a Value given a single property. Generated code passes ownership |
60 PropertyType.ARRAY. | 60 to caller. |
61 | 61 |
62 var: variable or variable* | 62 var: variable or variable* |
63 """ | 63 """ |
64 if prop.type_ in (PropertyType.REF, PropertyType.OBJECT): | 64 if prop.type_ in (PropertyType.REF, PropertyType.OBJECT): |
65 if prop.optional: | 65 if prop.optional: |
66 return '%s->ToValue().release()' % var | 66 return '%s->ToValue().release()' % var |
67 else: | 67 else: |
68 return '%s.ToValue().release()' % var | 68 return '%s.ToValue().release()' % var |
69 elif prop.type_ == PropertyType.ENUM: | |
70 return 'CreateEnumValue(%s).release()' % var | |
71 elif prop.type_ == PropertyType.ARRAY: | |
72 return '%s.release()' % util_cc_helper.CreateValueFromArray(prop, var) | |
69 elif prop.type_.is_fundamental: | 73 elif prop.type_.is_fundamental: |
70 if prop.optional: | 74 if prop.optional: |
71 var = '*' + var | 75 var = '*' + var |
72 return { | 76 return { |
73 PropertyType.STRING: 'Value::CreateStringValue(%s)', | 77 PropertyType.STRING: 'Value::CreateStringValue(%s)', |
74 PropertyType.BOOLEAN: 'Value::CreateBooleanValue(%s)', | 78 PropertyType.BOOLEAN: 'Value::CreateBooleanValue(%s)', |
75 PropertyType.INTEGER: 'Value::CreateIntegerValue(%s)', | 79 PropertyType.INTEGER: 'Value::CreateIntegerValue(%s)', |
76 PropertyType.DOUBLE: 'Value::CreateDoubleValue(%s)', | 80 PropertyType.DOUBLE: 'Value::CreateDoubleValue(%s)', |
77 }[prop.type_] % var | 81 }[prop.type_] % var |
78 else: | 82 else: |
79 raise NotImplementedError('Conversion of single %s to Value not implemented' | 83 raise NotImplementedError('Conversion of single %s to Value not implemented' |
80 % repr(prop.type_)) | 84 % repr(prop.type_)) |
81 | 85 |
82 def GetParameterDeclaration(param, type_): | 86 def GetParameterDeclaration(param, type_): |
83 """Gets a const parameter declaration of a given model.Property and its C++ | 87 """Gets a parameter declaration of a given model.Property and its C++ |
84 type. | 88 type. |
85 """ | 89 """ |
86 if param.type_ in (PropertyType.REF, PropertyType.OBJECT, PropertyType.ARRAY, | 90 if param.type_ in (PropertyType.REF, PropertyType.OBJECT, PropertyType.ARRAY, |
87 PropertyType.STRING): | 91 PropertyType.STRING): |
88 arg = '%(type)s& %(name)s' | 92 arg = '%(type)s& %(name)s' |
89 else: | 93 else: |
90 arg = '%(type)s %(name)s' | 94 arg = '%(type)s %(name)s' |
91 return arg % { | 95 return arg % { |
92 'type': type_, | 96 'type': type_, |
93 'name': param.unix_name, | 97 'name': param.unix_name, |
94 } | 98 } |
OLD | NEW |