/* This file is auto-generated from "textkeydescr.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 "textkeydescr_p.h"
#include <gwenhywfar/misc.h>
#include <gwenhywfar/db.h>
#include <gwenhywfar/debug.h>
#include <assert.h>
#include <stdlib.h>
#include <strings.h>

#include <aqbanking/error.h>


GWEN_LIST_FUNCTIONS(AB_TEXTKEY_DESCR, AB_TextKeyDescr)
GWEN_LIST2_FUNCTIONS(AB_TEXTKEY_DESCR, AB_TextKeyDescr)




AB_TEXTKEY_DESCR *AB_TextKeyDescr_new(void) {
  AB_TEXTKEY_DESCR *st;

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


void AB_TextKeyDescr_free(AB_TEXTKEY_DESCR *st) {
  if (st) {
    assert(st->_usage);
    if (--(st->_usage)==0) {
  if (st->name)
    free(st->name);
  if (st->descr)
    free(st->descr);
  GWEN_LIST_FINI(AB_TEXTKEY_DESCR, st)
  GWEN_FREE_OBJECT(st);
    }
  }

}


AB_TEXTKEY_DESCR *AB_TextKeyDescr_dup(const AB_TEXTKEY_DESCR *d) {
  AB_TEXTKEY_DESCR *st;

  assert(d);
  st=AB_TextKeyDescr_new();
  st->value=d->value;
  if (d->name)
    st->name=strdup(d->name);
  if (d->descr)
    st->descr=strdup(d->descr);
  return st;
}


int AB_TextKeyDescr_toDb(const AB_TEXTKEY_DESCR *st, GWEN_DB_NODE *db) {
  assert(st);
  assert(db);
  if (GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "value", st->value))
    return -1;
  if (st->name)
    if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "name", st->name))
      return -1;
  if (st->descr)
    if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "descr", st->descr))
      return -1;
  return 0;
}


int AB_TextKeyDescr_ReadDb(AB_TEXTKEY_DESCR *st, GWEN_DB_NODE *db) {
  assert(st);
  assert(db);
  AB_TextKeyDescr_SetValue(st, GWEN_DB_GetIntValue(db, "value", 0, 0));
  AB_TextKeyDescr_SetName(st, GWEN_DB_GetCharValue(db, "name", 0, 0));
  AB_TextKeyDescr_SetDescr(st, GWEN_DB_GetCharValue(db, "descr", 0, 0));
  return 0;
}


AB_TEXTKEY_DESCR *AB_TextKeyDescr_fromDb(GWEN_DB_NODE *db) {
  AB_TEXTKEY_DESCR *st;

  assert(db);
  st=AB_TextKeyDescr_new();
  AB_TextKeyDescr_ReadDb(st, db);
  st->_modified=0;
  return st;
}




int AB_TextKeyDescr_GetValue(const AB_TEXTKEY_DESCR *st) {
  assert(st);
  return st->value;
}


void AB_TextKeyDescr_SetValue(AB_TEXTKEY_DESCR *st, int d) {
  assert(st);
  st->value=d;
  st->_modified=1;
}




const char *AB_TextKeyDescr_GetName(const AB_TEXTKEY_DESCR *st) {
  assert(st);
  return st->name;
}


void AB_TextKeyDescr_SetName(AB_TEXTKEY_DESCR *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_TextKeyDescr_GetDescr(const AB_TEXTKEY_DESCR *st) {
  assert(st);
  return st->descr;
}


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




int AB_TextKeyDescr_IsModified(const AB_TEXTKEY_DESCR *st) {
  assert(st);
  return st->_modified;
}


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


void AB_TextKeyDescr_Attach(AB_TEXTKEY_DESCR *st) {
  assert(st);
  st->_usage++;
}
AB_TEXTKEY_DESCR *AB_TextKeyDescr_List2__freeAll_cb(AB_TEXTKEY_DESCR *st, void *user_data) {
  AB_TextKeyDescr_free(st);
return 0;
}


void AB_TextKeyDescr_List2_freeAll(AB_TEXTKEY_DESCR_LIST2 *stl) {
  if (stl) {
    AB_TextKeyDescr_List2_ForEach(stl, AB_TextKeyDescr_List2__freeAll_cb, 0);
    AB_TextKeyDescr_List2_free(stl); 
  }
}


AB_TEXTKEY_DESCR_LIST *AB_TextKeyDescr_List_dup(const AB_TEXTKEY_DESCR_LIST *stl) {
  if (stl) {
    AB_TEXTKEY_DESCR_LIST *nl;
    AB_TEXTKEY_DESCR *e;

    nl=AB_TextKeyDescr_List_new();
    e=AB_TextKeyDescr_List_First(stl);
    while(e) {
      AB_TEXTKEY_DESCR *ne;

      ne=AB_TextKeyDescr_dup(e);
      assert(ne);
      AB_TextKeyDescr_List_Add(ne, nl);
      e=AB_TextKeyDescr_List_Next(e);
    } /* while (e) */
    return nl;
  }
  else
    return 0;
}




