| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from code import Code | 5 from code import Code |
| 6 from model import PropertyType | 6 from model import PropertyType |
| 7 import cpp_util | 7 import cpp_util |
| 8 import model | 8 import model |
| 9 import os | 9 import os |
| 10 import schema_util | 10 import schema_util |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 c.Append() | 154 c.Append() |
| 155 return c | 155 return c |
| 156 | 156 |
| 157 def _GenerateType(self, type_): | 157 def _GenerateType(self, type_): |
| 158 """Generates a struct for a type. | 158 """Generates a struct for a type. |
| 159 """ | 159 """ |
| 160 classname = cpp_util.Classname(schema_util.StripSchemaNamespace(type_.name)) | 160 classname = cpp_util.Classname(schema_util.StripSchemaNamespace(type_.name)) |
| 161 c = Code() | 161 c = Code() |
| 162 | 162 |
| 163 if type_.functions: | 163 if type_.functions: |
| 164 # Types with functions are not instantiable in C++ because they are | |
| 165 # handled in pure Javascript and hence have no properties or | |
| 166 # additionalProperties. | |
| 167 if type_.properties: | |
| 168 raise NotImplementedError('\n'.join(model.GetModelHierarchy(type_)) + | |
| 169 '\nCannot generate both functions and properties on a type') | |
| 170 c.Sblock('namespace %(classname)s {') | 164 c.Sblock('namespace %(classname)s {') |
| 171 for function in type_.functions.values(): | 165 for function in type_.functions.values(): |
| 172 (c.Concat(self._GenerateFunction(function)) | 166 (c.Concat(self._GenerateFunction(function)) |
| 173 .Append() | 167 .Append() |
| 174 ) | 168 ) |
| 175 c.Eblock('}') | 169 c.Eblock('}') |
| 176 elif type_.type_ == PropertyType.ARRAY: | 170 elif type_.type_ == PropertyType.ARRAY: |
| 177 if type_.description: | 171 if type_.description: |
| 178 c.Comment(type_.description) | 172 c.Comment(type_.description) |
| 179 c.Append('typedef std::vector<%(item_type)s> %(classname)s;') | 173 c.Append('typedef std::vector<%(item_type)s> %(classname)s;') |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 c.Comment(param.description) | 296 c.Comment(param.description) |
| 303 if param.type_ == PropertyType.ANY: | 297 if param.type_ == PropertyType.ANY: |
| 304 c.Comment("Value* Result::Create(Value*) not generated " | 298 c.Comment("Value* Result::Create(Value*) not generated " |
| 305 "because it's redundant.") | 299 "because it's redundant.") |
| 306 continue | 300 continue |
| 307 c.Append('Value* Create(const %s);' % cpp_util.GetParameterDeclaration( | 301 c.Append('Value* Create(const %s);' % cpp_util.GetParameterDeclaration( |
| 308 param, self._cpp_type_generator.GetType(param))) | 302 param, self._cpp_type_generator.GetType(param))) |
| 309 c.Eblock('};') | 303 c.Eblock('};') |
| 310 | 304 |
| 311 return c | 305 return c |
| OLD | NEW |