/* tfbsConsFactors.c was originally generated by the autoSql program, which also 
 * generated tfbsConsFactors.h and tfbsConsFactors.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 "tfbsConsFactors.h"


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

ret->name = row[0];
ret->ac = row[1];
safecpy(ret->species, sizeof(ret->species), row[2]);
safecpy(ret->factor, sizeof(ret->factor), row[3]);
safecpy(ret->id, sizeof(ret->id), row[4]);
}

struct tfbsConsFactors *tfbsConsFactorsLoad(char **row)
/* Load a tfbsConsFactors from row fetched with select * from tfbsConsFactors
 * from database.  Dispose of this with tfbsConsFactorsFree(). */
{
struct tfbsConsFactors *ret;

AllocVar(ret);
ret->name = cloneString(row[0]);
ret->ac = cloneString(row[1]);
safecpy(ret->species, sizeof(ret->species), row[2]);
safecpy(ret->factor, sizeof(ret->factor), row[3]);
safecpy(ret->id, sizeof(ret->id), row[4]);
return ret;
}

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

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

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

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

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

if (ret == NULL)
    AllocVar(ret);
ret->name = sqlStringComma(&s);
ret->ac = sqlStringComma(&s);
sqlFixedStringComma(&s, ret->species, sizeof(ret->species));
sqlFixedStringComma(&s, ret->factor, sizeof(ret->factor));
sqlFixedStringComma(&s, ret->id, sizeof(ret->id));
*pS = s;
return ret;
}

void tfbsConsFactorsFree(struct tfbsConsFactors **pEl)
/* Free a single dynamically allocated tfbsConsFactors such as created
 * with tfbsConsFactorsLoad(). */
{
struct tfbsConsFactors *el;

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

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

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

void tfbsConsFactorsOutput(struct tfbsConsFactors *el, FILE *f, char sep, char lastSep) 
/* Print out tfbsConsFactors.  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->ac);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->species);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->factor);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->id);
if (sep == ',') fputc('"',f);
fputc(lastSep,f);
}

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

