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

/* Copyright (C) 2014 The Regents of the University of California 
 * See README in this or parent directory for licensing information. */

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


void bgiGeneInfoStaticLoad(char **row, struct bgiGeneInfo *ret)
/* Load a row from bgiGeneInfo table into ret.  The contents of ret will
 * be replaced at the next call to this function. */
{
ret->name = row[0];
ret->source = row[1];
ret->go = row[2];
ret->ipr = row[3];
}

struct bgiGeneInfo *bgiGeneInfoLoad(char **row)
/* Load a bgiGeneInfo from row fetched with select * from bgiGeneInfo
 * from database.  Dispose of this with bgiGeneInfoFree(). */
{
struct bgiGeneInfo *ret;

AllocVar(ret);
ret->name = cloneString(row[0]);
ret->source = cloneString(row[1]);
ret->go = cloneString(row[2]);
ret->ipr = cloneString(row[3]);
return ret;
}

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

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

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

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

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

if (ret == NULL)
    AllocVar(ret);
ret->name = sqlStringComma(&s);
ret->source = sqlStringComma(&s);
ret->go = sqlStringComma(&s);
ret->ipr = sqlStringComma(&s);
*pS = s;
return ret;
}

void bgiGeneInfoFree(struct bgiGeneInfo **pEl)
/* Free a single dynamically allocated bgiGeneInfo such as created
 * with bgiGeneInfoLoad(). */
{
struct bgiGeneInfo *el;

if ((el = *pEl) == NULL) return;
freeMem(el->name);
freeMem(el->source);
freeMem(el->go);
freeMem(el->ipr);
freez(pEl);
}

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

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

void bgiGeneInfoOutput(struct bgiGeneInfo *el, FILE *f, char sep, char lastSep) 
/* Print out bgiGeneInfo.  Separate fields with sep. Follow last field with lastSep. */
{
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->name);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->source);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->go);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->ipr);
if (sep == ',') fputc('"',f);
fputc(lastSep,f);
}

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

