Example #1
0
 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 = genutil.get_inner_class_struct_fields(struct)
     start, end, step = genutil.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 = 'row[i + %d]' % n
         content += '            if (!row[i + %d].isEmpty()) \n' % n
         content += '            {\n'
         content += self.gen_field_assgin_stmt("item." + field['name'],
                                               typename, valuetext, 4)
         content += '            }\n'
     content += '            %s%s.add(item);\n' % (prefix, inner_var_name)
     content += '        }\n'
     return content
Example #2
0
 def gen_java_inner_class(self, struct):
     content = ''
     class_name = struct["options"][predef.PredefInnerTypeClass]
     inner_fields = genutil.get_inner_class_struct_fields(struct)
     content += '    public static 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_java_type)
     for field in inner_fields:
         typename = lang.map_java_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_java_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
Example #3
0
    def gen_go_inner_struct(self, struct, json_decorate):
        content = ''
        class_name = struct["options"][predef.PredefInnerTypeClass]
        inner_fields = genutil.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 json_decorate:
                content += '    %s %s `json:"%s"` // %s\n' % (
                    field['camel_case_name'], typename, field['comment'],
                    field['name'])
            else:
                content += '    %s %s // %s\n' % (field['camel_case_name'],
                                                  typename, field['comment'])
        content += '};\n\n'

        return content
Example #4
0
 def gen_inner_class_field_assgin_stmt(self, struct, prefix):
     content = ''
     inner_class_type = struct["options"][predef.PredefInnerTypeClass]
     inner_var_name = struct["options"][predef.PredefInnerTypeName]
     inner_fields = genutil.get_inner_class_struct_fields(struct)
     start, end, step = genutil.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 = ParseValue<%s>(row[i + %d]);\n' % (field['name'], typename, n)
     content += '        %s%s.push_back(item);\n' % (prefix, inner_var_name)
     content += '    }\n'
     return content
Example #5
0
 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 = genutil.get_inner_class_struct_fields(struct)
     start, end, step = genutil.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_assgin_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
Example #6
0
    def parse_row(self, struct, params):
        rows = struct["data_rows"]
        fields = struct['fields']
        hiden_columns = self.parse_hiden_columns(struct, params)

        # 嵌套类
        inner_var_name = ''
        inner_fields = []
        inner_field_names, mapped_inner_fields = genutil.get_inner_class_mapped_fields(
            struct)
        if len(mapped_inner_fields) > 0:
            inner_var_name = struct["options"][predef.PredefInnerTypeName]
            inner_fields = genutil.get_inner_class_struct_fields(struct)

        obj_list = []
        for row in rows:
            obj = {}
            inner_class_done = False
            for field in fields:
                if field['column_index'] in hiden_columns:
                    continue
                if field['name'] in inner_field_names:
                    if not inner_class_done:
                        value = self.parse_row_inner_obj(
                            struct, row, inner_fields)
                        obj[inner_var_name] = value
                        inner_class_done = True
                else:
                    valuetext = row[field['column_index'] - 1]
                    value = self.parse_value(struct,
                                             field['original_type_name'],
                                             valuetext)
                    name = field['name']
                    obj[name] = value
            obj_list.append(obj)
        return obj_list