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

/* Copyright (C) 2011 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 "bToBeCfg.h"


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

ret->factor = row[0];
ret->source = row[1];
ret->sourceId = row[2];
ret->dataSource = row[3];
ret->scoreCol = sqlSigned(row[4]);
ret->multiplier = sqlFloat(row[5]);
ret->dataTable = row[6];
}

struct bToBeCfg *bToBeCfgLoad(char **row)
/* Load a bToBeCfg from row fetched with select * from bToBeCfg
 * from database.  Dispose of this with bToBeCfgFree(). */
{
struct bToBeCfg *ret;

AllocVar(ret);
ret->factor = cloneString(row[0]);
ret->source = cloneString(row[1]);
ret->sourceId = cloneString(row[2]);
ret->dataSource = cloneString(row[3]);
ret->scoreCol = sqlSigned(row[4]);
ret->multiplier = sqlFloat(row[5]);
ret->dataTable = cloneString(row[6]);
return ret;
}

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

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

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

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

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

if (ret == NULL)
    AllocVar(ret);
ret->factor = sqlStringComma(&s);
ret->source = sqlStringComma(&s);
ret->sourceId = sqlStringComma(&s);
ret->dataSource = sqlStringComma(&s);
ret->scoreCol = sqlSignedComma(&s);
ret->multiplier = sqlFloatComma(&s);
ret->dataTable = sqlStringComma(&s);
*pS = s;
return ret;
}

void bToBeCfgFree(struct bToBeCfg **pEl)
/* Free a single dynamically allocated bToBeCfg such as created
 * with bToBeCfgLoad(). */
{
struct bToBeCfg *el;

if ((el = *pEl) == NULL) return;
freeMem(el->factor);
freeMem(el->source);
freeMem(el->sourceId);
freeMem(el->dataSource);
freeMem(el->dataTable);
freez(pEl);
}

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

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

void bToBeCfgOutput(struct bToBeCfg *el, FILE *f, char sep, char lastSep) 
/* Print out bToBeCfg.  Separate fields with sep. Follow last field with lastSep. */
{
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->factor);
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->sourceId);
if (sep == ',') fputc('"',f);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->dataSource);
if (sep == ',') fputc('"',f);
fputc(sep,f);
fprintf(f, "%d", el->scoreCol);
fputc(sep,f);
fprintf(f, "%g", el->multiplier);
fputc(sep,f);
if (sep == ',') fputc('"',f);
fprintf(f, "%s", el->dataTable);
if (sep == ',') fputc('"',f);
fputc(lastSep,f);
}

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

