| 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"'
|
|
|