Chromium Code Reviews| 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 12 matching lines...) Expand all Loading... | |
| 23 | 23 |
| 24 eg experimental.downloads -> Experimental_Downloads | 24 eg experimental.downloads -> Experimental_Downloads |
| 25 updateAll -> UpdateAll. | 25 updateAll -> UpdateAll. |
| 26 """ | 26 """ |
| 27 return '_'.join([x[0].upper() + x[1:] for x in s.split('.')]) | 27 return '_'.join([x[0].upper() + x[1:] for x in s.split('.')]) |
| 28 | 28 |
| 29 def CreateFundamentalValue(prop, var): | 29 def CreateFundamentalValue(prop, var): |
| 30 """Returns the C++ code for creating a value of the given property type | 30 """Returns the C++ code for creating a value of the given property type |
| 31 using the given variable. | 31 using the given variable. |
| 32 | 32 |
| 33 var: Fundamental or Fundamental* | 33 var: Fundamental |
| 34 """ | 34 """ |
| 35 if prop.optional: | |
| 36 var = '*' + var | |
| 37 return { | 35 return { |
| 38 PropertyType.STRING: 'Value::CreateStringValue(%s)', | 36 PropertyType.STRING: 'Value::CreateStringValue(%s)', |
| 39 PropertyType.BOOLEAN: 'Value::CreateBooleanValue(%s)', | 37 PropertyType.BOOLEAN: 'Value::CreateBooleanValue(%s)', |
| 40 PropertyType.INTEGER: 'Value::CreateIntegerValue(%s)', | 38 PropertyType.INTEGER: 'Value::CreateIntegerValue(%s)', |
| 41 PropertyType.DOUBLE: 'Value::CreateDoubleValue(%s)', | 39 PropertyType.DOUBLE: 'Value::CreateDoubleValue(%s)', |
| 42 }[prop.type_] % var | 40 }[prop.type_] % var |
| 43 | 41 |
| 44 def GetAsFundamentalValue(prop, src, dst): | 42 def GetAsFundamentalValue(prop, src, dst): |
| 45 """Returns the C++ code for retrieving a fundamental type from a | 43 """Returns the C++ code for retrieving a fundamental type from a |
| 46 Value into a variable. | 44 Value into a variable. |
| 47 | 45 |
| 48 src: Value* | 46 src: Value* |
| 49 dst: Property* | 47 dst: Property* |
| 50 """ | 48 """ |
| 51 return { | 49 return { |
| 52 PropertyType.STRING: '%s->GetAsString(%s)', | 50 PropertyType.STRING: '%s->GetAsString(%s)', |
| 53 PropertyType.BOOLEAN: '%s->GetAsBoolean(%s)', | 51 PropertyType.BOOLEAN: '%s->GetAsBoolean(%s)', |
| 54 PropertyType.INTEGER: '%s->GetAsInteger(%s)', | 52 PropertyType.INTEGER: '%s->GetAsInteger(%s)', |
| 55 PropertyType.DOUBLE: '%s->GetAsDouble(%s)', | 53 PropertyType.DOUBLE: '%s->GetAsDouble(%s)', |
| 56 }[prop.type_] % (src, dst) | 54 }[prop.type_] % (src, dst) |
| 57 | 55 |
| 58 def GetFundamentalValue(prop, src, name, dst): | 56 def GetValueType(prop): |
|
not at google - send to devlin
2012/02/20 03:44:24
needs comment
calamity
2012/02/20 05:03:37
Done.
| |
| 59 """Returns the C++ code for retrieving a fundamental type from a | 57 return { |
| 60 DictionaryValue into a variable. | 58 PropertyType.STRING: 'Value::TYPE_STRING', |
| 59 PropertyType.INTEGER: 'Value::TYPE_INTEGER', | |
| 60 PropertyType.BOOLEAN: 'Value::TYPE_BOOLEAN', | |
| 61 PropertyType.DOUBLE: 'Value::TYPE_DOUBLE', | |
| 62 PropertyType.REF: 'Value::TYPE_DICTIONARY', | |
| 63 PropertyType.OBJECT: 'Value::TYPE_DICTIONARY', | |
| 64 PropertyType.ARRAY: 'Value::TYPE_LIST' | |
| 65 }[prop.type_] | |
| 61 | 66 |
| 62 src: DictionaryValue* | |
| 63 name: key | |
| 64 dst: Property* | |
| 65 """ | |
| 66 return { | |
| 67 PropertyType.STRING: '%s->GetString("%s", %s)', | |
| 68 PropertyType.BOOLEAN: '%s->GetBoolean("%s", %s)', | |
| 69 PropertyType.INTEGER: '%s->GetInteger("%s", %s)', | |
| 70 PropertyType.DOUBLE: '%s->GetDouble("%s", %s)', | |
| 71 }[prop.type_] % (src, name, dst) | |
| 72 | 67 |
| 73 def CreateValueFromSingleProperty(prop, var): | 68 def CreateValueFromSingleProperty(prop, var): |
| 74 """Creates a Value given a single property. Use for everything except | 69 """Creates a Value given a single property. Use for everything except |
| 75 PropertyType.ARRAY. | 70 PropertyType.ARRAY. |
| 76 | 71 |
| 77 var: raw value | 72 var: variable or variable* |
| 78 """ | 73 """ |
| 79 if prop.type_ == PropertyType.REF or prop.type_ == PropertyType.OBJECT: | 74 if prop.type_ == PropertyType.REF or prop.type_ == PropertyType.OBJECT: |
| 80 if prop.optional: | 75 if prop.optional: |
| 81 return '%s->ToValue().release()' % var | 76 return '%s->ToValue().release()' % var |
| 82 else: | 77 else: |
| 83 return '%s.ToValue().release()' % var | 78 return '%s.ToValue().release()' % var |
| 84 elif prop.type_.is_fundamental: | 79 elif prop.type_.is_fundamental: |
| 80 if prop.optional: | |
| 81 var = '*' + var | |
| 85 return CreateFundamentalValue(prop, var) | 82 return CreateFundamentalValue(prop, var) |
| 86 else: | 83 else: |
| 87 raise NotImplementedError('Conversion of single %s to Value not implemented' | 84 raise NotImplementedError('Conversion of single %s to Value not implemented' |
| 88 % repr(prop.type_)) | 85 % repr(prop.type_)) |
| 89 | 86 |
| 90 def GetValueFromList(prop, src, index, dst): | 87 def GetConstParameterDeclaration(param, type_): |
|
not at google - send to devlin
2012/02/20 03:44:24
I know that this method was already here, but it's
calamity
2012/02/20 05:03:37
Done.
| |
| 91 """Returns the C++ code for retrieving a fundamental type from a | 88 """Gets a const parameter declaration of a given model.Property and its C++ |
| 92 DictionaryValue into a variable. | 89 type. |
| 93 | |
| 94 src: ListValue& | |
| 95 index: int | |
| 96 dst: Property* | |
| 97 """ | 90 """ |
| 98 return { | |
| 99 PropertyType.REF: '%s.GetDictionary(%d, %s)', | |
| 100 PropertyType.STRING: '%s.GetString(%d, %s)', | |
| 101 PropertyType.BOOLEAN: '%s.GetBoolean(%d, %s)', | |
| 102 PropertyType.INTEGER: '%s.GetInteger(%d, %s)', | |
| 103 PropertyType.DOUBLE: '%s.GetDouble(%d, %s)', | |
| 104 }[prop.type_] % (src, index, dst) | |
| 105 | |
| 106 def GetConstParameterDeclaration(param, type_generator): | |
| 107 if param.type_ == PropertyType.REF: | 91 if param.type_ == PropertyType.REF: |
| 108 arg = 'const %(type)s& %(name)s' | 92 arg = 'const %(type)s& %(name)s' |
| 109 else: | 93 else: |
| 110 arg = 'const %(type)s %(name)s' | 94 arg = 'const %(type)s %(name)s' |
| 111 return arg % { | 95 return arg % { |
| 112 'type': type_generator.GetType(param, wrap_optional=True), | 96 'type': type_, |
| 113 'name': param.unix_name, | 97 'name': param.unix_name, |
| 114 } | 98 } |
| OLD | NEW |