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

Unified Diff: tools/json_schema_compiler/util_cc_helper.py

Issue 9309044: Supporting more APIs with json_schema_compiler (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: DictionaryValue* to linked_ptr<DictionaryValue> Created 8 years, 11 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
Index: tools/json_schema_compiler/util_cc_helper.py
diff --git a/tools/json_schema_compiler/util_cc_helper.py b/tools/json_schema_compiler/util_cc_helper.py
new file mode 100644
index 0000000000000000000000000000000000000000..6b57ca7b76a0e9c499a1ab54a4714ee7d299ba22
--- /dev/null
+++ b/tools/json_schema_compiler/util_cc_helper.py
@@ -0,0 +1,71 @@
+from model import PropertyType
+import code
+
+API_UTIL_NAMESPACE = 'json_schema_compiler::util'
+
+class UtilCCHelper(object):
+
+ def __init__(self, type_manager):
+ self.type_manager = type_manager
+
+ def GetArray(self, array_prop, src, name, dst):
+ """src: DictionaryValue*
+ dst: Property variable name
+ """
+ prop = array_prop.item_type
+ sub = {
+ 'namespace': API_UTIL_NAMESPACE,
+ 'name': name,
+ 'src': src,
+ 'dst': dst,
+ }
+
+ sub['type'] = self.type_manager.GetType(prop)
+ if array_prop.optional:
+ val = '%(namespace)s::GetOptionalArrayFromDictionary(*%(src)s, "%(name)s", &%(dst)s)'
+ else:
+ val = '%(namespace)s::GetArrayFromDictionary(*%(src)s, "%(name)s", &%(dst)s)'
+
+ return val % sub
+
+ def GetArrayFromList(self, array_prop, src, dst):
+ """src: ListValue*
+ dst: Property
+ """
+ prop = array_prop.item_type
+ sub = {
+ 'namespace': API_UTIL_NAMESPACE,
+ 'src': src,
+ 'dst': dst,
+ 'type': self.type_manager.GetType(prop),
+ }
+
+ if array_prop.optional:
+ val = '%(namespace)s::GetOptionalArrayFromList(*%(src)s, &%(dst)s)'
+ else:
+ val = '%(namespace)s::GetArrayFromList(*%(src)s, &%(dst)s)'
+
+ return val % sub
+
+ def SetArray(self, array_prop, src, name, dst):
+ """src: Property variable name
+ dst: DictionaryValue*
+ """
+ prop = array_prop.item_type
+ sub = {
+ 'namespace': API_UTIL_NAMESPACE,
+ 'src': src,
+ 'name': name,
+ 'dst': dst,
+ 'type': self.type_manager.GetType(prop),
+ }
+
+ if array_prop.optional:
+ val = '%(namespace)s::SetOptionalArrayFromDictionary(%(src)s, "%(name)s", %(dst)s)'
+ else:
+ val = '%(namespace)s::SetArrayFromDictionary(%(src)s, "%(name)s", %(dst)s)'
+
+ return val % sub
+
+ def GetIncludePath(self):
+ return '#include "tools/json_schema_compiler/util.h"'

Powered by Google App Engine
This is Rietveld 408576698