Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(834)

Unified Diff: tools/json_schema_compiler/util_cc_helper.py

Issue 260893013: JSON Schema Compiler: Following r267534, properly convert arrays of enums (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: better Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/json_schema_compiler/util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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'
« no previous file with comments | « tools/json_schema_compiler/util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698