def gen_java_inner_class_assign(self, struct, prefix): content = '' inner_class_type = struct["options"][predef.PredefInnerTypeClass] inner_var_name = struct["options"][predef.PredefInnerTypeName] inner_fields = structutil.get_inner_class_struct_fields(struct) start, end, step = structutil.get_inner_class_range(struct) assert start > 0 and end > 0 and step > 1 content += ' for (int i = %s; i < %s; i += %s) \n' % (start, end, step) content += ' {\n' content += ' %s item = new %s();\n' % (inner_class_type, inner_class_type) for n in range(step): field = inner_fields[n] origin_type = field['original_type_name'] typename = lang.map_java_type(origin_type) valuetext = 'record.get(i + %d)' % n content += ' if (!record.get(i + %d).isEmpty()) \n' % n content += ' {\n' content += self.gen_field_assign_stmt("item." + field['name'], typename, valuetext, 4) content += ' }\n' content += ' %s%s.add(item);\n' % (prefix, inner_var_name) content += ' }\n' return content
def gen_cs_inner_class(struct): content = '' class_name = struct["options"][predef.PredefInnerTypeClass] inner_fields = structutil.get_inner_class_struct_fields(struct) content += 'public class %s \n' % class_name content += '{\n' max_name_len = strutil.max_field_length(inner_fields, 'name', None) max_type_len = strutil.max_field_length(inner_fields, 'original_type_name', lang.map_cs_type) for field in inner_fields: typename = lang.map_cs_type(field['original_type_name']) assert typename != "", field['original_type_name'] typename = strutil.pad_spaces(typename, max_type_len + 1) name = lang.name_with_default_cs_value(field, typename) name = strutil.pad_spaces(name, max_name_len + 8) content += ' public %s %s // %s\n' % (typename.strip(), name, field['comment']) content += '};\n\n' return content
def parse_row(self, struct): rows = struct["data_rows"] rows = rowutil.validate_unique_column(struct, rows) rows = rowutil.hide_skipped_row_fields(struct, rows) fields = structutil.enabled_fields(struct) # 嵌套类 inner_var_name = '' inner_fields = [] inner_field_names, mapped_inner_fields = structutil.get_inner_class_mapped_fields(struct) if len(mapped_inner_fields) > 0: inner_var_name = struct["options"][predef.PredefInnerTypeName] inner_fields = structutil.get_inner_class_struct_fields(struct) obj_list = [] for row in rows: obj = self.row_to_object(struct, row, fields, inner_field_names, inner_var_name, inner_fields) obj_list.append(obj) return obj_list
def gen_inner_class_field_assgin_stmt(struct, prefix): content = '' inner_class_type = struct["options"][predef.PredefInnerTypeClass] inner_var_name = struct["options"][predef.PredefInnerTypeName] inner_fields = structutil.get_inner_class_struct_fields(struct) start, end, step = structutil.get_inner_class_range(struct) assert start > 0 and end > 0 and step > 1 content += ' for (int i = %s; i < %s; i += %s) \n' % (start, end, step) content += ' {\n' content += ' %s item;\n' % inner_class_type for n in range(step): field = inner_fields[n] origin_type = field['original_type_name'] typename = lang.map_cpp_type(origin_type) content += ' item.%s = to<%s>(row[i + %d]);\n' % ( field['name'], typename, n) content += ' %s%s.push_back(item);\n' % (prefix, inner_var_name) content += ' }\n' return content
def gen_go_inner_struct(self, struct, go_json_tag): content = '' class_name = struct["options"][predef.PredefInnerTypeClass] inner_fields = structutil.get_inner_class_struct_fields(struct) content += 'type %s struct {\n' % class_name for field in inner_fields: typename = lang.map_go_type(field['original_type_name']) assert typename != "", field['original_type_name'] if go_json_tag: name = field['name'] if self.json_snake_case: name = strutil.camel_to_snake(name) content += ' %s %s `json:"%s"` // %s\n' % ( field['camel_case_name'], typename, name, field['comment']) else: content += ' %s %s // %s\n' % (field['camel_case_name'], typename, field['comment']) content += '}\n\n' return content
def gen_cs_inner_class_assign(self, struct, prefix): content = '' inner_class_type = struct["options"][predef.PredefInnerTypeClass] inner_var_name = struct["options"][predef.PredefInnerTypeName] inner_fields = structutil.get_inner_class_struct_fields(struct) start, end, step = structutil.get_inner_class_range(struct) assert start > 0 and end > 0 and step > 1 content += ' %s%s = new %s[%d];\n' % (prefix, inner_var_name, inner_class_type, (end-start)/step) content += ' for (int i = %s, j = 0; i < %s; i += %s, j++) \n' % (start, end, step) content += ' {\n' content += ' %s item = new %s();\n' % (inner_class_type, inner_class_type) for n in range(step): field = inner_fields[n] origin_type = field['original_type_name'] typename = lang.map_cs_type(origin_type) valuetext = 'row[i + %d]' % n content += ' if (row[i + %d].Length > 0) \n' % n content += ' {\n' content += self.gen_field_assign_stmt("item." + field['name'], typename, valuetext, 4) content += ' }\n' content += ' %s%s[j] = item;\n' % (prefix, inner_var_name) content += ' }\n' return content
def gen_inner_class_parse(self, struct, prefix): content = '' inner_class_type = struct["options"][predef.PredefInnerTypeClass] inner_var_name = struct["options"][predef.PredefInnerTypeName] inner_fields = structutil.get_inner_class_struct_fields(struct) start, end, step = structutil.get_inner_class_range(struct) assert start > 0 and end > 0 and step > 1 content += ' for i := %s; i < %s; i += %s {\n' % (start, end, step) content += ' var item %s;\n' % inner_class_type for n in range(step): field = inner_fields[n] origin_type = field['original_type_name'] typename = lang.map_go_type(origin_type) field_name = field['camel_case_name'] valuetext = 'row[i + %d]' % n content += ' if row[i + %d] != "" {\n' % n content += self.gen_field_assign_stmt('item.' + field_name, typename, valuetext, 2, 'row') content += ' }\n' content += ' %s%s = append(%s%s, item);\n' % ( prefix, inner_var_name, prefix, inner_var_name) content += ' }\n' return content