'Generates output class with a given name for a given set of tables.'

def _GenerateOutputClass(self, class_name, tables):

    output_class = type(utils.SmartStr(class_name), (rdf_structs.RDFProtoStruct,), {})
    if (not tables):
        raise RuntimeError("Can't    generate    output    class    without    Rekall    table    definition.")
    field_number = 1
    output_class.AddDescriptor(rdf_structs.ProtoEmbedded(name='metadata', field_number=field_number, nested=ExportedMetadata))
    field_number += 1
    output_class.AddDescriptor(rdf_structs.ProtoString(name='section_name', field_number=field_number))
    field_number += 1
    output_class.AddDescriptor(rdf_structs.ProtoString(name='text', field_number=field_number))
    used_names = set()
    for table in tables:
        for column_header in table:
            column_name = None
            try:
                column_name = column_header['cname']
            except KeyError:
                pass
            if (not column_name):
                column_name = column_header['name']
            if (not column_name):
                raise RuntimeError("Can't    determine    column    name    in    table    header.")
            if (column_name in used_names):
                continue
            field_number += 1
            used_names.add(column_name)
            output_class.AddDescriptor(rdf_structs.ProtoString(name=column_name, field_number=field_number))
    return output_class
