/* gencodeGeneClass.c was originally generated by the autoSql program, which also 
 * generated gencodeGeneClass.h and gencodeGeneClass.sql.  This module links the database and
 * the RAM representation of objects. */

/* Copyright (C) 2014 The Regents of the University of California 
 * See kent/LICENSE or http://genome.ucsc.edu/license/ for licensing information. */

#include "common.h"
#include "linefile.h"
#include "dystring.h"
#include "jksql.h"
#include "gencodeGeneClass.h"


void gencodeGeneClassStaticLoad(char **row, struct gencodeGeneClass *ret)
/* Load a row from gencodeGeneClass table into ret.  The contents of ret will
 * be replaced at the next call to this function. */
{

ret->geneId = row[0];
ret->name = row[1];
ret->transcriptType = row[2];
ret->level = sqlSigned(row[3]);
ret->class = row[4];
ret->ottGeneId = row[5];
ret->ottTranscriptId = row[6];
}

struct gencodeGeneClass *gencodeGeneClassLoad(char **row)
/* Load a gencodeGeneClass from row fetched with select * from gencodeGeneClass
 * from database.  Dispose of this with gencodeGeneClassFree(). */
{
struct gencodeGeneClass *ret;

AllocVar(ret);
ret->geneId = cloneString(row[0]);
ret->name = cloneString(row[1]);
ret->transcriptType = cloneString(row[2]);
ret->level = sqlSigned(row[3]);
ret->class = cloneString(row[4]);
ret->ottGeneId = cloneString(row[5]);
ret->ottTranscriptId = cloneString(row[6]);
return ret;
}

struct gencodeGeneClass *gencodeGeneClassLoadAll(char *fileName) 
/* Load all gencodeGeneClass from a whitespace-separated file.
 * Dispose of this with gencodeGeneClassFreeList(). */
{
struct gencodeGeneClass *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[7];

while (lineFileRow(lf, row))
    {
    el = gencodeGeneClassLoad(row);
    slAddHead(&list, el);
    }
lineFileClose(&lf);
slReverse(&list);
return list;
}

struct gencodeGeneClass *gencodeGeneClassLoadAllByChar(char *fileName, char chopper) 
/* Load all gencodeGeneClass from a chopper separated file.
 * Dispose of this with gencodeGeneClassFreeList(). */
{
struct gencodeGeneClass *list = NULL, *el;
struct lineFile *lf = lineFileOpen(fileName, TRUE);
char *row[7];

while (lineFileNextCharRow(lf, chopper, row, ArraySize(row)))
    {
    el = gencodeGeneClassLoad(row);
    slAddHead(&list, el);
    }
lineFileClose(&lf);
slReverse(&list);
return list;
}

struct gencodeGeneClass *gencodeGeneClassCommaIn(char **pS, struct gencodeGeneClass *ret)
/* Create a gencodeGeneClass out of a comma separated string. 
 * This will fill in ret if non-null, otherwise will
 * return a new gencodeGeneClass */
{
char *s = *pS;

if (ret == NULL)
    AllocVar(ret);
ret->geneId = sqlStringComma(&s);
ret->name = sqlStringComma(&s);
ret->transcriptType = sqlStringComma(&s);
ret->level = sqlSignedComma(&s);
ret->class = sqlStringComma(&s);
ret->ottGeneId = sqlStringComma(&s);
ret->ottTranscriptId = sqlStringComma(&s);
*pS = s;
return ret;
}

void gencodeGeneClassFree(struct gencodeGeneClass **pEl)
/* Free a single dynamically allocated gencodeGeneClass such as created
 * with gencodeGeneClassLoad(). */
{
struct gencodeGeneClass *el;

if ((el = *pEl) == NULL) return;
freeMem(el->geneId);
freeMem(el->name);
freeMem(el->transcriptType);
freeMem(el->class);
freeMem(el->ottGeneId);
freeMem(el->ottTranscriptId);
freez(pEl);
}

void gencodeGeneClassFreeList(struct gencodeGeneClass **pList)
/* Free a list of dynamically allocated gencodeGeneClass's */
{
struct gencodeGeneClass *el, *next;

for (el = *pList; el != NULL; el = next)
    {
    next = el->next;
    gencodeGeneClassFree(&el);
    }
*pList = NULL;
}

void gencodeGeneClassOutput(struct gencodeGeneClass *el, FILE *f, char sep, char lastSep) 
/* Print out gencodeGeneClass.  Separate fields with sep. Follow last field with lastSep. */
{
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->geneId);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->name);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->transcriptType);
if (sep == ',') fputc('"',f);
fputc(sep,f);
fprintf(f, "%d", el->level);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->class);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ottGeneId);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ottTranscriptId);
if (sep == ',') fputc('"',f);
fputc(lastSep,f);
}

/* -------------------------------- End autoSql Generated Code -------------------------------- */

