| Index: tools/json_schema_compiler/cpp_type_generator.py
|
| diff --git a/tools/json_schema_compiler/cpp_type_generator.py b/tools/json_schema_compiler/cpp_type_generator.py
|
| index 269a99572c1453a789597dbbcf6b0b5dae01b79b..4d9c858531ccfe57e41cd9c541fc50f8ad426cc7 100644
|
| --- a/tools/json_schema_compiler/cpp_type_generator.py
|
| +++ b/tools/json_schema_compiler/cpp_type_generator.py
|
| @@ -35,27 +35,43 @@ class CppTypeGenerator(object):
|
| self._default_namespace = model.namespaces.values()[0]
|
| self._schema_loader = schema_loader
|
|
|
| - def GetEnumNoneValue(self, type_):
|
| + def _AddEnumScope(self, type_, value, is_in_declaration, use_override=True):
|
| + """Decorates the given value with a FOO_ or Foo:: prefix depending whether
|
| + type_ is an enum class. If in a declaration, Foo:: prefixes are never added,
|
| + but FOO_ prefixes are.
|
| + """
|
| + prefix_override = use_override and type_.cpp_enum_prefix_override
|
| + name_prefix = ''
|
| + if not type_.is_enum_class or prefix_override:
|
| + name_prefix = (prefix_override or self.FollowRef(type_).unix_name) + '_'
|
| +
|
| + name_prefix = name_prefix.upper();
|
| + if not type_.is_enum_class or is_in_declaration:
|
| + return '%s%s' % (name_prefix, value)
|
| +
|
| + return '%s::%s%s' % (self.FollowRef(type_).simple_name, name_prefix, value)
|
| +
|
| + def GetEnumNoneValue(self, type_, is_in_declaration=False):
|
| """Gets the enum value in the given model.Property indicating no value has
|
| been set.
|
| """
|
| - return '%s_NONE' % self.FollowRef(type_).unix_name.upper()
|
| + return self._AddEnumScope(type_, 'NONE', is_in_declaration, False)
|
|
|
| - def GetEnumLastValue(self, type_):
|
| + def GetEnumLastValue(self, type_, is_in_declaration=False):
|
| """Gets the enum value in the given model.Property indicating the last value
|
| for the type.
|
| """
|
| - return '%s_LAST' % self.FollowRef(type_).unix_name.upper()
|
| + return self._AddEnumScope(type_, 'LAST', is_in_declaration, False)
|
|
|
| - def GetEnumValue(self, type_, enum_value):
|
| + def GetEnumValue(self, type_, enum_value, is_in_declaration=False):
|
| """Gets the enum value of the given model.Property of the given type.
|
|
|
| e.g VAR_STRING
|
| """
|
| - value = cpp_util.Classname(enum_value.name.upper())
|
| - prefix = (type_.cpp_enum_prefix_override or
|
| - self.FollowRef(type_).unix_name)
|
| - value = '%s_%s' % (prefix.upper(), value)
|
| + value = self._AddEnumScope(type_,
|
| + cpp_util.Classname(enum_value.name.upper()),
|
| + is_in_declaration)
|
| +
|
| # To avoid collisions with built-in OS_* preprocessor definitions, we add a
|
| # trailing slash to enum names that start with OS_.
|
| if value.startswith("OS_"):
|
|
|