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

Side by Side 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, 10 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 unified diff | Download patch
OLDNEW
(Empty)
1 from model import PropertyType
2 import code
3
4 API_UTIL_NAMESPACE = 'json_schema_compiler::util'
5
6 class UtilCCHelper(object):
7
8 def __init__(self, type_manager):
9 self.type_manager = type_manager
10
11 def GetArray(self, array_prop, src, name, dst):
12 """src: DictionaryValue*
13 dst: Property variable name
14 """
15 prop = array_prop.item_type
16 sub = {
17 'namespace': API_UTIL_NAMESPACE,
18 'name': name,
19 'src': src,
20 'dst': dst,
21 }
22
23 sub['type'] = self.type_manager.GetType(prop)
24 if array_prop.optional:
25 val = '%(namespace)s::GetOptionalArrayFromDictionary(*%(src)s, "%(name)s", &%(dst)s)'
26 else:
27 val = '%(namespace)s::GetArrayFromDictionary(*%(src)s, "%(name)s", &%(dst) s)'
28
29 return val % sub
30
31 def GetArrayFromList(self, array_prop, src, dst):
32 """src: ListValue*
33 dst: Property
34 """
35 prop = array_prop.item_type
36 sub = {
37 'namespace': API_UTIL_NAMESPACE,
38 'src': src,
39 'dst': dst,
40 'type': self.type_manager.GetType(prop),
41 }
42
43 if array_prop.optional:
44 val = '%(namespace)s::GetOptionalArrayFromList(*%(src)s, &%(dst)s)'
45 else:
46 val = '%(namespace)s::GetArrayFromList(*%(src)s, &%(dst)s)'
47
48 return val % sub
49
50 def SetArray(self, array_prop, src, name, dst):
51 """src: Property variable name
52 dst: DictionaryValue*
53 """
54 prop = array_prop.item_type
55 sub = {
56 'namespace': API_UTIL_NAMESPACE,
57 'src': src,
58 'name': name,
59 'dst': dst,
60 'type': self.type_manager.GetType(prop),
61 }
62
63 if array_prop.optional:
64 val = '%(namespace)s::SetOptionalArrayFromDictionary(%(src)s, "%(name)s", %(dst)s)'
65 else:
66 val = '%(namespace)s::SetArrayFromDictionary(%(src)s, "%(name)s", %(dst)s) '
67
68 return val % sub
69
70 def GetIncludePath(self):
71 return '#include "tools/json_schema_compiler/util.h"'
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698