Index: tools/json_schema_compiler/util_cc_helper.py |
diff --git a/tools/json_schema_compiler/util_cc_helper.py b/tools/json_schema_compiler/util_cc_helper.py |
index 864028364eece9787ba441fa9a846c845fe95e7b..180c0e7c5cc6098b831b6fe954ee81dabbd16b17 100644 |
--- a/tools/json_schema_compiler/util_cc_helper.py |
+++ b/tools/json_schema_compiler/util_cc_helper.py |
@@ -55,25 +55,38 @@ class UtilCCHelper(object): |
'dst': dst |
} |
- def CreateValueFromArray(self, cpp_namespace, type_, src, optional): |
+ def CreateValueFromArray(self, |
+ src, |
+ optional=False, |
+ is_enum=False, |
+ enum_namespace=None): |
"""Generates code to create a scoped_pt<Value> from the array at src. |
- |cpp_namespace| The namespace which contains |type_|. This is needed for |
- enum conversions, where the ToString method is on the containing |
+ |enum_namespace| The namespace which contains |item_type|. This is needed |
+ for enum conversions, where the ToString method is on the containing |
namespace. |
- |type_| The type of the values being converted. This is needed for enum |
- conversions, to know whether to use the Enum form of conversion. |
+ |item_type| The type of each array item of the values being converted. |
+ This is needed for enum conversions, to know whether to use the Enum |
+ form of conversion. |
|src| The variable to convert, either a vector or scoped_ptr<vector>. |
- |optional| Whether |type_| was optional. Optional types are pointers so |
- must be treated differently. |
+ |optional| Whether the whole array was optional. Optional types are |
+ pointers so must be treated differently. |
+ |is_enum| Whether the values are enums. Enums are treated specially because |
+ they need their ToString() values called, not an integer. |
+ |enum_namespace| The namespace of the enum being converted, if any. |
+ The enum might not necessarily have a namespace. |
""" |
- if type_.item_type.property_type == PropertyType.ENUM: |
+ if is_enum: |
# Enums are treated specially because C++ templating thinks that they're |
# ints, but really they're strings. |
if optional: |
- name = 'CreateValueFromOptionalEnumArray<%s>' % cpp_namespace |
+ name = 'CreateValueFromOptionalEnumArray' |
else: |
- name = 'CreateValueFromEnumArray<%s>' % cpp_namespace |
+ name = 'CreateValueFromEnumArray' |
+ if enum_namespace: |
+ name += '<%s>' % enum_namespace |
+ else: |
+ name += 'WithoutNamespace' |
else: |
if optional: |
name = 'CreateValueFromOptionalArray' |