| 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 8762fa6447b394d85e2bf9a73345234ed91fc23f..c514a1c8958506b25517024e6514823d66ba28f8 100644
|
| --- a/tools/json_schema_compiler/cpp_util.py
|
| +++ b/tools/json_schema_compiler/cpp_util.py
|
| @@ -26,21 +26,6 @@ def Classname(s):
|
| """
|
| return '_'.join([x[0].upper() + x[1:] for x in s.split('.')])
|
|
|
| -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*
|
| - """
|
| - if prop.optional:
|
| - var = '*' + var
|
| - return {
|
| - PropertyType.STRING: 'Value::CreateStringValue(%s)',
|
| - PropertyType.BOOLEAN: 'Value::CreateBooleanValue(%s)',
|
| - PropertyType.INTEGER: 'Value::CreateIntegerValue(%s)',
|
| - PropertyType.DOUBLE: 'Value::CreateDoubleValue(%s)',
|
| - }[prop.type_] % var
|
| -
|
| def GetAsFundamentalValue(prop, src, dst):
|
| """Returns the C++ code for retrieving a fundamental type from a
|
| Value into a variable.
|
| @@ -55,60 +40,54 @@ 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):
|
| + """Returns the Value::Type corresponding to the model.PropertyType.
|
| """
|
| 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.type_ in (PropertyType.REF, PropertyType.OBJECT):
|
| if prop.optional:
|
| return '%s->ToValue().release()' % var
|
| else:
|
| return '%s.ToValue().release()' % var
|
| elif prop.type_.is_fundamental:
|
| - return CreateFundamentalValue(prop, var)
|
| + if prop.optional:
|
| + var = '*' + var
|
| + return {
|
| + PropertyType.STRING: 'Value::CreateStringValue(%s)',
|
| + PropertyType.BOOLEAN: 'Value::CreateBooleanValue(%s)',
|
| + PropertyType.INTEGER: 'Value::CreateIntegerValue(%s)',
|
| + PropertyType.DOUBLE: 'Value::CreateDoubleValue(%s)',
|
| + }[prop.type_] % 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 GetParameterDeclaration(param, type_):
|
| + """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_.is_fundamental:
|
| - arg = 'const %(type)s %(name)s'
|
| - else:
|
| + if param.type_ in (PropertyType.REF, PropertyType.OBJECT, PropertyType.ARRAY,
|
| + PropertyType.STRING):
|
| 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,
|
| }
|
|
|