/* This file is auto-generated from "security.xml" by the typemaker
   tool of Gwenhywfar. 
   Do not edit this file -- all changes will be lost! */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include "security_p.h"
#include <gwenhywfar/misc.h>
#include <gwenhywfar/db.h>
#include <gwenhywfar/debug.h>
#include <assert.h>
#include <stdlib.h>
#include <strings.h>

#include <gwenhywfar/types.h>
#include <gwenhywfar/gwentime.h>
#include <aqbanking/value.h>


GWEN_LIST_FUNCTIONS(AB_SECURITY, AB_Security)
GWEN_LIST2_FUNCTIONS(AB_SECURITY, AB_Security)




AB_SECURITY *AB_Security_new(void) {
  AB_SECURITY *st;

  GWEN_NEW_OBJECT(AB_SECURITY, st)
  st->_usage=1;
  GWEN_LIST_INIT(AB_SECURITY, st)
  return st;
}


void AB_Security_free(AB_SECURITY *st) {
  if (st) {
    assert(st->_usage);
    if (--(st->_usage)==0) {
  if (st->name)
    free(st->name);
  if (st->uniqueId)
    free(st->uniqueId);
  if (st->nameSpace)
    free(st->nameSpace);
  if (st->tickerSymbol)
    free(st->tickerSymbol);
  if (st->units)
    AB_Value_free(st->units);
  if (st->unitPriceValue)
    AB_Value_free(st->unitPriceValue);
  if (st->unitPriceDate)
    GWEN_Time_free(st->unitPriceDate);
  GWEN_LIST_FINI(AB_SECURITY, st)
  GWEN_FREE_OBJECT(st);
    }
  }

}


AB_SECURITY *AB_Security_dup(const AB_SECURITY *d) {
  AB_SECURITY *st;

  assert(d);
  st=AB_Security_new();
  if (d->name)
    st->name=strdup(d->name);
  if (d->uniqueId)
    st->uniqueId=strdup(d->uniqueId);
  if (d->nameSpace)
    st->nameSpace=strdup(d->nameSpace);
  if (d->tickerSymbol)
    st->tickerSymbol=strdup(d->tickerSymbol);
  if (d->units)
    st->units=AB_Value_dup(d->units);
  if (d->unitPriceValue)
    st->unitPriceValue=AB_Value_dup(d->unitPriceValue);
  if (d->unitPriceDate)
    st->unitPriceDate=GWEN_Time_dup(d->unitPriceDate);
  return st;
}


int AB_Security_toDb(const AB_SECURITY *st, GWEN_DB_NODE *db) {
  assert(st);
  assert(db);
  if (st->name)
    if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "name", st->name))
      return -1;
  if (st->uniqueId)
    if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "uniqueId", st->uniqueId))
      return -1;
  if (st->nameSpace)
    if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "nameSpace", st->nameSpace))
      return -1;
  if (st->tickerSymbol)
    if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "tickerSymbol", st->tickerSymbol))
      return -1;
  if (st->units)
    if (AB_Value_toDb(st->units, GWEN_DB_GetGroup(db, GWEN_DB_FLAGS_DEFAULT, "units")))
      return -1;
  if (st->unitPriceValue)
    if (AB_Value_toDb(st->unitPriceValue, GWEN_DB_GetGroup(db, GWEN_DB_FLAGS_DEFAULT, "unitPriceValue")))
      return -1;
  if (st->unitPriceDate)
    if (GWEN_Time_toDb(st->unitPriceDate, GWEN_DB_GetGroup(db, GWEN_DB_FLAGS_DEFAULT, "unitPriceDate")))
      return -1;
  return 0;
}


int AB_Security_ReadDb(AB_SECURITY *st, GWEN_DB_NODE *db) {
  assert(st);
  assert(db);
  AB_Security_SetName(st, GWEN_DB_GetCharValue(db, "name", 0, 0));
  AB_Security_SetUniqueId(st, GWEN_DB_GetCharValue(db, "uniqueId", 0, 0));
  AB_Security_SetNameSpace(st, GWEN_DB_GetCharValue(db, "nameSpace", 0, 0));
  AB_Security_SetTickerSymbol(st, GWEN_DB_GetCharValue(db, "tickerSymbol", 0, 0));
  if (1) { /* for local vars */
    GWEN_DB_NODE *dbT;

    dbT=GWEN_DB_GetGroup(db, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "units");
    if (dbT) {
  if (st->units)
    AB_Value_free(st->units);
  st->units=AB_Value_fromDb(dbT);
}
  }
  if (1) { /* for local vars */
    GWEN_DB_NODE *dbT;

    dbT=GWEN_DB_GetGroup(db, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "unitPriceValue");
    if (dbT) {
  if (st->unitPriceValue)
    AB_Value_free(st->unitPriceValue);
  st->unitPriceValue=AB_Value_fromDb(dbT);
}
  }
  if (1) { /* for local vars */
    GWEN_DB_NODE *dbT;

    dbT=GWEN_DB_GetGroup(db, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "unitPriceDate");
    if (dbT) {
  if (st->unitPriceDate)
    GWEN_Time_free(st->unitPriceDate);
  st->unitPriceDate=GWEN_Time_fromDb(dbT);
}
  }
  return 0;
}


AB_SECURITY *AB_Security_fromDb(GWEN_DB_NODE *db) {
  AB_SECURITY *st;

  assert(db);
  st=AB_Security_new();
  AB_Security_ReadDb(st, db);
  st->_modified=0;
  return st;
}




const char *AB_Security_GetName(const AB_SECURITY *st) {
  assert(st);
  return st->name;
}


void AB_Security_SetName(AB_SECURITY *st, const char *d) {
  assert(st);
  if (st->name)
    free(st->name);
  if (d && *d)
    st->name=strdup(d);
  else
    st->name=0;
  st->_modified=1;
}




const char *AB_Security_GetUniqueId(const AB_SECURITY *st) {
  assert(st);
  return st->uniqueId;
}


void AB_Security_SetUniqueId(AB_SECURITY *st, const char *d) {
  assert(st);
  if (st->uniqueId)
    free(st->uniqueId);
  if (d && *d)
    st->uniqueId=strdup(d);
  else
    st->uniqueId=0;
  st->_modified=1;
}




const char *AB_Security_GetNameSpace(const AB_SECURITY *st) {
  assert(st);
  return st->nameSpace;
}


void AB_Security_SetNameSpace(AB_SECURITY *st, const char *d) {
  assert(st);
  if (st->nameSpace)
    free(st->nameSpace);
  if (d && *d)
    st->nameSpace=strdup(d);
  else
    st->nameSpace=0;
  st->_modified=1;
}




const char *AB_Security_GetTickerSymbol(const AB_SECURITY *st) {
  assert(st);
  return st->tickerSymbol;
}


void AB_Security_SetTickerSymbol(AB_SECURITY *st, const char *d) {
  assert(st);
  if (st->tickerSymbol)
    free(st->tickerSymbol);
  if (d && *d)
    st->tickerSymbol=strdup(d);
  else
    st->tickerSymbol=0;
  st->_modified=1;
}




const AB_VALUE *AB_Security_GetUnits(const AB_SECURITY *st) {
  assert(st);
  return st->units;
}


void AB_Security_SetUnits(AB_SECURITY *st, const AB_VALUE *d) {
  assert(st);
  if (st->units)
    AB_Value_free(st->units);
  if (d)
    st->units=AB_Value_dup(d);
  else
    st->units=0;
  st->_modified=1;
}




const AB_VALUE *AB_Security_GetUnitPriceValue(const AB_SECURITY *st) {
  assert(st);
  return st->unitPriceValue;
}


void AB_Security_SetUnitPriceValue(AB_SECURITY *st, const AB_VALUE *d) {
  assert(st);
  if (st->unitPriceValue)
    AB_Value_free(st->unitPriceValue);
  if (d)
    st->unitPriceValue=AB_Value_dup(d);
  else
    st->unitPriceValue=0;
  st->_modified=1;
}




const GWEN_TIME *AB_Security_GetUnitPriceDate(const AB_SECURITY *st) {
  assert(st);
  return st->unitPriceDate;
}


void AB_Security_SetUnitPriceDate(AB_SECURITY *st, const GWEN_TIME *d) {
  assert(st);
  if (st->unitPriceDate)
    GWEN_Time_free(st->unitPriceDate);
  if (d)
    st->unitPriceDate=GWEN_Time_dup(d);
  else
    st->unitPriceDate=0;
  st->_modified=1;
}




int AB_Security_IsModified(const AB_SECURITY *st) {
  assert(st);
  return st->_modified;
}


void AB_Security_SetModified(AB_SECURITY *st, int i) {
  assert(st);
  st->_modified=i;
}


void AB_Security_Attach(AB_SECURITY *st) {
  assert(st);
  st->_usage++;
}
AB_SECURITY *AB_Security_List2__freeAll_cb(AB_SECURITY *st, void *user_data) {
  AB_Security_free(st);
return 0;
}


void AB_Security_List2_freeAll(AB_SECURITY_LIST2 *stl) {
  if (stl) {
    AB_Security_List2_ForEach(stl, AB_Security_List2__freeAll_cb, 0);
    AB_Security_List2_free(stl); 
  }
}


AB_SECURITY_LIST *AB_Security_List_dup(const AB_SECURITY_LIST *stl) {
  if (stl) {
    AB_SECURITY_LIST *nl;
    AB_SECURITY *e;

    nl=AB_Security_List_new();
    e=AB_Security_List_First(stl);
    while(e) {
      AB_SECURITY *ne;

      ne=AB_Security_dup(e);
      assert(ne);
      AB_Security_List_Add(ne, nl);
      e=AB_Security_List_Next(e);
    } /* while (e) */
    return nl;
  }
  else
    return 0;
}




