Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 from model import PropertyType | |
| 2 import code | |
| 3 | |
| 4 API_UTIL_NAMESPACE = 'json_schema_compiler::util' | |
| 5 | |
| 6 class UtilCCHelper(object): | |
| 7 """A util class that generates code that uses tools/json_schema_compiler/util. cc. | |
| 8 """ | |
|
not at google - send to devlin
2012/02/05 23:42:12
line length
calamity
2012/02/06 11:51:18
Done.
| |
| 9 def __init__(self, type_manager): | |
| 10 self.type_manager = type_manager | |
|
not at google - send to devlin
2012/02/05 23:42:12
type_manager should be private
calamity
2012/02/06 11:51:18
Done.
| |
| 11 | |
| 12 def GetArray(self, array_prop, src, name, dst): | |
| 13 """Generates code to get an array from a src.name into dst. | |
| 14 | |
| 15 src: DictionaryValue* | |
| 16 dst: std::vector or scoped_ptr<std::vector> | |
| 17 """ | |
| 18 prop = array_prop.item_type | |
| 19 sub = { | |
| 20 'namespace': API_UTIL_NAMESPACE, | |
| 21 'name': name, | |
| 22 'src': src, | |
| 23 'dst': dst, | |
| 24 } | |
| 25 | |
| 26 sub['type'] = self.type_manager.GetType(prop) | |
| 27 if array_prop.optional: | |
| 28 val = '%(namespace)s::GetOptionalArrayFromDictionary(*%(src)s, "%(name)s", &%(dst)s)' | |
| 29 else: | |
| 30 val = '%(namespace)s::GetArrayFromDictionary(*%(src)s, "%(name)s", &%(dst) s)' | |
| 31 | |
| 32 return val % sub | |
| 33 | |
| 34 def GetArrayFromList(self, array_prop, src, dst): | |
| 35 """Generates code to get an array from src into dst. | |
| 36 | |
| 37 src: ListValue* | |
| 38 dst: std::vector or scoped_ptr<std::vector> | |
| 39 """ | |
| 40 prop = array_prop.item_type | |
| 41 sub = { | |
| 42 'namespace': API_UTIL_NAMESPACE, | |
| 43 'src': src, | |
| 44 'dst': dst, | |
| 45 'type': self.type_manager.GetType(prop), | |
| 46 } | |
| 47 | |
| 48 if array_prop.optional: | |
| 49 val = '%(namespace)s::GetOptionalArrayFromList(*%(src)s, &%(dst)s)' | |
| 50 else: | |
| 51 val = '%(namespace)s::GetArrayFromList(*%(src)s, &%(dst)s)' | |
| 52 | |
| 53 return val % sub | |
| 54 | |
| 55 def SetArray(self, array_prop, src, name, dst): | |
| 56 """Sets dst.name to the array at src | |
| 57 | |
| 58 src: std::vector or scoped_ptr<std::vector> | |
| 59 dst: DictionaryValue* | |
| 60 """ | |
| 61 prop = array_prop.item_type | |
| 62 sub = { | |
| 63 'namespace': API_UTIL_NAMESPACE, | |
| 64 'src': src, | |
| 65 'name': name, | |
| 66 'dst': dst, | |
| 67 'type': self.type_manager.GetType(prop), | |
| 68 } | |
| 69 | |
| 70 if array_prop.optional: | |
| 71 val = '%(namespace)s::SetOptionalArrayToDictionary(%(src)s, "%(name)s", %( dst)s)' | |
|
not at google - send to devlin
2012/02/05 23:42:12
line wrap
calamity
2012/02/06 11:51:18
Done.
| |
| 72 else: | |
| 73 val = '%(namespace)s::SetArrayToDictionary(%(src)s, "%(name)s", %(dst)s)' | |
| 74 | |
| 75 return val % sub | |
| 76 | |
| 77 def SetArrayToList(self, array_prop, src, dst): | |
| 78 """Sets dst to the array at src | |
| 79 | |
| 80 src: std::vector or scoped_ptr<std::vector> | |
| 81 dst: ListValue* | |
| 82 """ | |
| 83 prop = array_prop.item_type | |
| 84 sub = { | |
| 85 'namespace': API_UTIL_NAMESPACE, | |
| 86 'src': src, | |
| 87 'dst': dst, | |
| 88 'type': self.type_manager.GetType(prop), | |
| 89 } | |
| 90 | |
| 91 if array_prop.optional: | |
| 92 val = '%(namespace)s::SetOptionalArrayToList(%(src)s, %(dst)s)' | |
| 93 else: | |
| 94 val = '%(namespace)s::SetArrayToList(%(src)s, %(dst)s)' | |
| 95 | |
| 96 return val % sub | |
| 97 | |
| 98 def GetIncludePath(self): | |
| 99 return '#include "tools/json_schema_compiler/util.h"' | |
| OLD | NEW |