Chromium Code Reviews| 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 f15bae86e468a4444367f18ee18b9ed26cde7643..7a62f211dca9c9c7dec3215e54b685d2a94fc7f9 100644 |
| --- a/tools/json_schema_compiler/cpp_type_generator.py |
| +++ b/tools/json_schema_compiler/cpp_type_generator.py |
| @@ -25,24 +25,31 @@ class CppTypeGenerator(object): |
| """Manages the types of properties and provides utilities for getting the |
| C++ type out of a model.Property |
| """ |
| - def __init__(self, root_namespace, namespace=None, cpp_namespace=None): |
| + def __init__(self, model, root_namespace=''): |
|
not at google - send to devlin
2013/02/05 00:47:46
I don't know if root_namespace needs to be optiona
sashab
2013/02/05 01:14:41
Done.
|
| """Creates a cpp_type_generator. The given root_namespace should be of the |
| format extensions::api::sub. The generator will generate code suitable for |
| - use in the given namespace. |
| + use in the given model's namespace. |
| """ |
| self._type_namespaces = {} |
| self._root_namespace = root_namespace.split('::') |
| self._cpp_namespaces = {} |
| - if namespace and cpp_namespace: |
| - self._namespace = namespace |
| - self.AddNamespace(namespace, cpp_namespace) |
| - else: |
| - self._namespace = None |
| + self._namespace = None |
|
not at google - send to devlin
2013/02/05 00:47:46
I meant for this to be like
self._namespace = def
sashab
2013/02/05 01:14:41
Done.
|
| + |
| + for referenced_namespace in model.namespaces.values(): |
| + self.AddNamespace( |
| + referenced_namespace, |
| + referenced_namespace.unix_name) |
| def AddNamespace(self, namespace, cpp_namespace): |
|
not at google - send to devlin
2013/02/05 00:47:46
I don't think that AddNamespace needs to be called
sashab
2013/02/05 01:14:41
Done.
|
| """Maps a model.Namespace to its C++ namespace name. All mappings are |
| beneath the root namespace. |
| + |
| + Returns the added namespace. |
| """ |
| + # If this is the first namespace added, save it. |
| + if self._namespace is None: |
| + self._namespace = namespace |
|
not at google - send to devlin
2013/02/05 00:47:46
And this logic shouldn't be necessary.
sashab
2013/02/05 01:14:41
Done.
|
| + |
| self._cpp_namespaces[namespace] = cpp_namespace |
| for type_name in namespace.types: |
| # Allow $refs to refer to just 'Type' within namespaces. Otherwise they |
| @@ -53,6 +60,8 @@ class CppTypeGenerator(object): |
| for alias in type_aliases: |
| self._type_namespaces[alias] = namespace |
| + return namespace |
| + |
| def GetCppNamespaceName(self, namespace): |
| """Gets the mapped C++ namespace name for the given namespace relative to |
| the root namespace. |