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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 """Returns the Value::Type corresponding to the model.PropertyType. | 44 """Returns the Value::Type corresponding to the model.PropertyType. |
45 """ | 45 """ |
46 return { | 46 return { |
47 PropertyType.STRING: 'Value::TYPE_STRING', | 47 PropertyType.STRING: 'Value::TYPE_STRING', |
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 PropertyType.ANY: 'Value::TYPE_DICTIONARY', |
55 }[prop.type_] | 56 }[prop.type_] |
56 | 57 |
57 | |
58 def CreateValueFromSingleProperty(prop, var): | |
59 """Creates a Value given a single property. Use for everything except | |
60 PropertyType.ARRAY. | |
61 | |
62 var: variable or variable* | |
63 """ | |
64 if prop.type_ in (PropertyType.REF, PropertyType.OBJECT): | |
65 if prop.optional: | |
66 return '%s->ToValue().release()' % var | |
67 else: | |
68 return '%s.ToValue().release()' % var | |
69 elif prop.type_.is_fundamental: | |
70 if prop.optional: | |
71 var = '*' + var | |
72 return { | |
73 PropertyType.STRING: 'Value::CreateStringValue(%s)', | |
74 PropertyType.BOOLEAN: 'Value::CreateBooleanValue(%s)', | |
75 PropertyType.INTEGER: 'Value::CreateIntegerValue(%s)', | |
76 PropertyType.DOUBLE: 'Value::CreateDoubleValue(%s)', | |
77 }[prop.type_] % var | |
78 else: | |
79 raise NotImplementedError('Conversion of single %s to Value not implemented' | |
80 % repr(prop.type_)) | |
81 | |
82 def GetParameterDeclaration(param, type_): | 58 def GetParameterDeclaration(param, type_): |
83 """Gets a const parameter declaration of a given model.Property and its C++ | 59 """Gets a parameter declaration of a given model.Property and its C++ |
84 type. | 60 type. |
85 """ | 61 """ |
86 if param.type_ in (PropertyType.REF, PropertyType.OBJECT, PropertyType.ARRAY, | 62 if param.type_ in (PropertyType.REF, PropertyType.OBJECT, PropertyType.ARRAY, |
87 PropertyType.STRING): | 63 PropertyType.STRING): |
88 arg = '%(type)s& %(name)s' | 64 arg = '%(type)s& %(name)s' |
89 else: | 65 else: |
90 arg = '%(type)s %(name)s' | 66 arg = '%(type)s %(name)s' |
91 return arg % { | 67 return arg % { |
92 'type': type_, | 68 'type': type_, |
93 'name': param.unix_name, | 69 'name': param.unix_name, |
94 } | 70 } |
OLD | NEW |