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

Unified Diff: tools/json_schema_compiler/h_generator.py

Issue 10790040: JSON Schema Compiler now supports conversion from Choice to base::Value. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: GetChoiceType() no longer takes a parameter, and switch has a space after it Created 8 years, 5 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/cc_generator.py ('k') | tools/json_schema_compiler/test/choices.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/json_schema_compiler/h_generator.py
diff --git a/tools/json_schema_compiler/h_generator.py b/tools/json_schema_compiler/h_generator.py
index 5f59ffbe04603f83e730b78cf7bbec8c94698bb7..ba7c5ca133a27b4a4ebc5e87089b5a77071a143c 100644
--- a/tools/json_schema_compiler/h_generator.py
+++ b/tools/json_schema_compiler/h_generator.py
@@ -35,6 +35,7 @@ class HGenerator(object):
.Append('#include <vector>')
.Append()
.Append('#include "base/basictypes.h"')
+ .Append('#include "base/logging.h"')
.Append('#include "base/memory/linked_ptr.h"')
.Append('#include "base/memory/scoped_ptr.h"')
.Append('#include "base/values.h"')
@@ -214,6 +215,9 @@ class HGenerator(object):
(c.Eblock()
.Sblock(' private:')
+ .Concat(self._GeneratePrivatePropertyStructures(
+ type_.properties.values()))
+ .Append()
.Append('DISALLOW_COPY_AND_ASSIGN(%(classname)s);')
.Eblock('};')
)
@@ -303,6 +307,22 @@ class HGenerator(object):
c.Append(create_enum_value)
return c
+ def _GeneratePrivatePropertyStructures(self, props):
+ """Generate the private structures required by a property such as OBJECT
+ classes and enums.
+ """
+ c = Code()
+ for prop in props:
+ if prop.type_ == PropertyType.ARRAY:
+ c.Concat(self._GeneratePrivatePropertyStructures([prop.item_type]))
+ c.Append()
+ elif prop.type_ == PropertyType.CHOICES:
+ # We only need GetChoiceValue() if there is a ToValue() method.
+ if prop.from_client:
+ c.Append('scoped_ptr<base::Value> Get%sChoiceValue() const;' % (
+ cpp_util.Classname(prop.name)))
+ return c
+
def _GenerateCreateCallbackArguments(self, function):
"""Generates functions for passing paramaters to a callback.
"""
« no previous file with comments | « tools/json_schema_compiler/cc_generator.py ('k') | tools/json_schema_compiler/test/choices.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698