Index: tools/json_schema_compiler/cc_generator.py |
diff --git a/tools/json_schema_compiler/cc_generator.py b/tools/json_schema_compiler/cc_generator.py |
index 8cea17b588af55ed93f5df205ca5076d9bf6080d..5665445769f7bf3fb7cedd04fa2cb9885de3cddd 100644 |
--- a/tools/json_schema_compiler/cc_generator.py |
+++ b/tools/json_schema_compiler/cc_generator.py |
@@ -88,7 +88,7 @@ class CCGenerator(object): |
) |
for event in self._namespace.events.values(): |
(c.Concat(self._GenerateCreateCallbackArguments( |
- cpp_util.Classname(event.name), event)) |
+ cpp_util.Classname(event.name), event, generate_to_json=True)) |
.Append() |
) |
(c.Concat(self._cpp_type_generator.GetNamespaceEnd()) |
@@ -679,7 +679,10 @@ class CCGenerator(object): |
) |
return c |
- def _GenerateCreateCallbackArguments(self, function_scope, callback): |
+ def _GenerateCreateCallbackArguments(self, |
+ function_scope, |
+ callback, |
+ generate_to_json=False): |
"""Generate all functions to create Value parameters for a callback. |
E.g for function "Bar", generate Bar::Results::Create |
@@ -688,6 +691,7 @@ class CCGenerator(object): |
function_scope: the function scope path, e.g. Foo::Bar for the function |
Foo::Bar::Baz(). |
callback: the Function object we are creating callback arguments for. |
+ generate_to_json: Generate a ToJson method. |
""" |
c = Code() |
params = callback.params |
@@ -714,9 +718,22 @@ class CCGenerator(object): |
c.Append('return create_results.Pass();') |
c.Eblock('}') |
+ if generate_to_json: |
+ c.Append() |
+ (c.Sblock('std::string %(function_scope)s::' |
+ 'ToJson(%(declaration_list)s) {') |
+ .Append('scoped_ptr<base::ListValue> create_results = ' |
+ 'Create(%(param_list)s);') |
+ .Append('std::string json;') |
+ .Append('base::JSONWriter::Write(create_results.get(), &json);') |
+ .Append('return json;') |
+ ) |
+ c.Eblock('}') |
+ |
c.Substitute({ |
'function_scope': function_scope, |
- 'declaration_list': ', '.join(declaration_list) |
+ 'declaration_list': ', '.join(declaration_list), |
+ 'param_list': ', '.join([param.unix_name for param in param_list]) |
not at google - send to devlin
2012/07/26 02:39:58
I think if you leave out the [] it becomes a gener
mitchellwrosen
2012/07/26 17:38:59
Done.
|
}) |
return c |