Index: tools/json_schema_compiler/cpp_util.py |
diff --git a/tools/json_schema_compiler/cpp_util.py b/tools/json_schema_compiler/cpp_util.py |
index ab8e1596ea8f862909d0f16e6dc12dda214823e3..fde082e907d6fef3e53814dab06af0039b7031e0 100644 |
--- a/tools/json_schema_compiler/cpp_util.py |
+++ b/tools/json_schema_compiler/cpp_util.py |
@@ -30,10 +30,8 @@ def CreateFundamentalValue(prop, var): |
"""Returns the C++ code for creating a value of the given property type |
using the given variable. |
- var: Fundamental or Fundamental* |
+ var: Fundamental |
""" |
- if prop.optional: |
- var = '*' + var |
return { |
PropertyType.STRING: 'Value::CreateStringValue(%s)', |
PropertyType.BOOLEAN: 'Value::CreateBooleanValue(%s)', |
@@ -55,26 +53,23 @@ def GetAsFundamentalValue(prop, src, dst): |
PropertyType.DOUBLE: '%s->GetAsDouble(%s)', |
}[prop.type_] % (src, dst) |
-def GetFundamentalValue(prop, src, name, dst): |
- """Returns the C++ code for retrieving a fundamental type from a |
- DictionaryValue into a variable. |
- |
- src: DictionaryValue* |
- name: key |
- dst: Property* |
- """ |
+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.
|
return { |
- PropertyType.STRING: '%s->GetString("%s", %s)', |
- PropertyType.BOOLEAN: '%s->GetBoolean("%s", %s)', |
- PropertyType.INTEGER: '%s->GetInteger("%s", %s)', |
- PropertyType.DOUBLE: '%s->GetDouble("%s", %s)', |
- }[prop.type_] % (src, name, dst) |
+ PropertyType.STRING: 'Value::TYPE_STRING', |
+ PropertyType.INTEGER: 'Value::TYPE_INTEGER', |
+ PropertyType.BOOLEAN: 'Value::TYPE_BOOLEAN', |
+ PropertyType.DOUBLE: 'Value::TYPE_DOUBLE', |
+ PropertyType.REF: 'Value::TYPE_DICTIONARY', |
+ PropertyType.OBJECT: 'Value::TYPE_DICTIONARY', |
+ PropertyType.ARRAY: 'Value::TYPE_LIST' |
+ }[prop.type_] |
+ |
def CreateValueFromSingleProperty(prop, var): |
"""Creates a Value given a single property. Use for everything except |
PropertyType.ARRAY. |
- var: raw value |
+ var: variable or variable* |
""" |
if prop.type_ == PropertyType.REF or prop.type_ == PropertyType.OBJECT: |
if prop.optional: |
@@ -82,33 +77,22 @@ def CreateValueFromSingleProperty(prop, var): |
else: |
return '%s.ToValue().release()' % var |
elif prop.type_.is_fundamental: |
+ if prop.optional: |
+ var = '*' + var |
return CreateFundamentalValue(prop, var) |
else: |
raise NotImplementedError('Conversion of single %s to Value not implemented' |
% repr(prop.type_)) |
-def GetValueFromList(prop, src, index, dst): |
- """Returns the C++ code for retrieving a fundamental type from a |
- DictionaryValue into a variable. |
- |
- src: ListValue& |
- index: int |
- dst: Property* |
+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.
|
+ """Gets a const parameter declaration of a given model.Property and its C++ |
+ type. |
""" |
- return { |
- PropertyType.REF: '%s.GetDictionary(%d, %s)', |
- PropertyType.STRING: '%s.GetString(%d, %s)', |
- PropertyType.BOOLEAN: '%s.GetBoolean(%d, %s)', |
- PropertyType.INTEGER: '%s.GetInteger(%d, %s)', |
- PropertyType.DOUBLE: '%s.GetDouble(%d, %s)', |
- }[prop.type_] % (src, index, dst) |
- |
-def GetConstParameterDeclaration(param, type_generator): |
if param.type_ == PropertyType.REF: |
arg = 'const %(type)s& %(name)s' |
else: |
arg = 'const %(type)s %(name)s' |
return arg % { |
- 'type': type_generator.GetType(param, wrap_optional=True), |
+ 'type': type_, |
'name': param.unix_name, |
} |