/* This file is auto-generated from "cellphoneproduct.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 "cellphoneproduct_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 <aqbanking/error.h>
#include <aqbanking/value.h>


GWEN_LIST_FUNCTIONS(AB_CELLPHONE_PRODUCT, AB_CellPhoneProduct)
GWEN_LIST2_FUNCTIONS(AB_CELLPHONE_PRODUCT, AB_CellPhoneProduct)




AB_CELLPHONE_PRODUCT *AB_CellPhoneProduct_new(void) {
  AB_CELLPHONE_PRODUCT *st;

  GWEN_NEW_OBJECT(AB_CELLPHONE_PRODUCT, st)
  st->_usage=1;
  GWEN_LIST_INIT(AB_CELLPHONE_PRODUCT, st)
  st->values=AB_Value_List_new();
  return st;
}


void AB_CellPhoneProduct_free(AB_CELLPHONE_PRODUCT *st) {
  if (st) {
    assert(st->_usage);
    if (--(st->_usage)==0) {
  if (st->id)
    free(st->id);
  if (st->providerName)
    free(st->providerName);
  if (st->productName)
    free(st->productName);
  if (st->minimumValue)
    AB_Value_free(st->minimumValue);
  if (st->maximumValue)
    AB_Value_free(st->maximumValue);
  if (st->values)
    AB_Value_List_free(st->values);
  GWEN_LIST_FINI(AB_CELLPHONE_PRODUCT, st)
  GWEN_FREE_OBJECT(st);
    }
  }

}


AB_CELLPHONE_PRODUCT *AB_CellPhoneProduct_dup(const AB_CELLPHONE_PRODUCT *d) {
  AB_CELLPHONE_PRODUCT *st;

  assert(d);
  st=AB_CellPhoneProduct_new();
  if (d->id)
    st->id=strdup(d->id);
  if (d->providerName)
    st->providerName=strdup(d->providerName);
  if (d->productName)
    st->productName=strdup(d->productName);
  st->allowFreeValue=d->allowFreeValue;
  if (d->minimumValue)
    st->minimumValue=AB_Value_dup(d->minimumValue);
  if (d->maximumValue)
    st->maximumValue=AB_Value_dup(d->maximumValue);
  if (d->values)
    st->values=AB_Value_List_dup(d->values);
  return st;
}


int AB_CellPhoneProduct_toDb(const AB_CELLPHONE_PRODUCT *st, GWEN_DB_NODE *db) {
  assert(st);
  assert(db);
  if (st->id)
    if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "id", st->id))
      return -1;
  if (st->providerName)
    if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "providerName", st->providerName))
      return -1;
  if (st->productName)
    if (GWEN_DB_SetCharValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "productName", st->productName))
      return -1;
  if (GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "allowFreeValue", st->allowFreeValue))
    return -1;
  if (st->minimumValue)
    if (AB_Value_toDb(st->minimumValue, GWEN_DB_GetGroup(db, GWEN_DB_FLAGS_DEFAULT, "minimumValue")))
      return -1;
  if (st->maximumValue)
    if (AB_Value_toDb(st->maximumValue, GWEN_DB_GetGroup(db, GWEN_DB_FLAGS_DEFAULT, "maximumValue")))
      return -1;
  if (st->values)
  if (1) {
    GWEN_DB_NODE *dbT;
    AB_VALUE *e;

    dbT=GWEN_DB_GetGroup(db, GWEN_PATH_FLAGS_CREATE_GROUP, "values");
    assert(dbT);
    e=AB_Value_List_First(st->values);
    while(e) {
      if (AB_Value_toDb(e, GWEN_DB_GetGroup(dbT, GWEN_PATH_FLAGS_CREATE_GROUP, "element")))
        return -1;
      e=AB_Value_List_Next(e);
    } /* while */
  } /* if (1) */
  return 0;
}


int AB_CellPhoneProduct_ReadDb(AB_CELLPHONE_PRODUCT *st, GWEN_DB_NODE *db) {
  assert(st);
  assert(db);
  AB_CellPhoneProduct_SetId(st, GWEN_DB_GetCharValue(db, "id", 0, 0));
  AB_CellPhoneProduct_SetProviderName(st, GWEN_DB_GetCharValue(db, "providerName", 0, 0));
  AB_CellPhoneProduct_SetProductName(st, GWEN_DB_GetCharValue(db, "productName", 0, 0));
  AB_CellPhoneProduct_SetAllowFreeValue(st, GWEN_DB_GetIntValue(db, "allowFreeValue", 0, 0));
  if (1) { /* for local vars */
    GWEN_DB_NODE *dbT;

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

    dbT=GWEN_DB_GetGroup(db, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "maximumValue");
    if (dbT) {
  if (st->maximumValue)
    AB_Value_free(st->maximumValue);
  st->maximumValue=AB_Value_fromDb(dbT);
}
  }
  st->values=AB_Value_List_new();
  if (1) {/* just for local vars */
    GWEN_DB_NODE *dbT;
    AB_VALUE *e;

    dbT=GWEN_DB_GetGroup(db, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "values");
    if (dbT) {
      GWEN_DB_NODE *dbT2;

      dbT2=GWEN_DB_FindFirstGroup(dbT, "element");
      while(dbT2) {
        e=AB_Value_fromDb(dbT2);
        if (!e) {
          DBG_ERROR(0, "Bad element for type \"AB_VALUE\"");
          if (GWEN_Logger_GetLevel(0)>=GWEN_LoggerLevel_Debug)
            GWEN_DB_Dump(dbT2, 2);
          AB_CellPhoneProduct_free(st);
          return 0;
        }
        AB_Value_List_Add(e, st->values);    dbT2=GWEN_DB_FindNextGroup(dbT2, "element");
      } /* while */
    } /* if (dbT) */
  } /* if (1) */
  return 0;
}


AB_CELLPHONE_PRODUCT *AB_CellPhoneProduct_fromDb(GWEN_DB_NODE *db) {
  AB_CELLPHONE_PRODUCT *st;

  assert(db);
  st=AB_CellPhoneProduct_new();
  AB_CellPhoneProduct_ReadDb(st, db);
  st->_modified=0;
  return st;
}




const char *AB_CellPhoneProduct_GetId(const AB_CELLPHONE_PRODUCT *st) {
  assert(st);
  return st->id;
}


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




const char *AB_CellPhoneProduct_GetProviderName(const AB_CELLPHONE_PRODUCT *st) {
  assert(st);
  return st->providerName;
}


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




const char *AB_CellPhoneProduct_GetProductName(const AB_CELLPHONE_PRODUCT *st) {
  assert(st);
  return st->productName;
}


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




int AB_CellPhoneProduct_GetAllowFreeValue(const AB_CELLPHONE_PRODUCT *st) {
  assert(st);
  return st->allowFreeValue;
}


void AB_CellPhoneProduct_SetAllowFreeValue(AB_CELLPHONE_PRODUCT *st, int d) {
  assert(st);
  st->allowFreeValue=d;
  st->_modified=1;
}




const AB_VALUE *AB_CellPhoneProduct_GetMinimumValue(const AB_CELLPHONE_PRODUCT *st) {
  assert(st);
  return st->minimumValue;
}


void AB_CellPhoneProduct_SetMinimumValue(AB_CELLPHONE_PRODUCT *st, const AB_VALUE *d) {
  assert(st);
  if (st->minimumValue)
    AB_Value_free(st->minimumValue);
  if (d)
    st->minimumValue=AB_Value_dup(d);
  else
    st->minimumValue=0;
  st->_modified=1;
}




const AB_VALUE *AB_CellPhoneProduct_GetMaximumValue(const AB_CELLPHONE_PRODUCT *st) {
  assert(st);
  return st->maximumValue;
}


void AB_CellPhoneProduct_SetMaximumValue(AB_CELLPHONE_PRODUCT *st, const AB_VALUE *d) {
  assert(st);
  if (st->maximumValue)
    AB_Value_free(st->maximumValue);
  if (d)
    st->maximumValue=AB_Value_dup(d);
  else
    st->maximumValue=0;
  st->_modified=1;
}




AB_VALUE_LIST *AB_CellPhoneProduct_GetValues(const AB_CELLPHONE_PRODUCT *st) {
  assert(st);
  return st->values;
}


void AB_CellPhoneProduct_SetValues(AB_CELLPHONE_PRODUCT *st, AB_VALUE_LIST *d) {
  assert(st);
  if (st->values)
    AB_Value_List_free(st->values);
  if (d) {
    AB_VALUE *e;

  st->values=AB_Value_List_new();
    e=AB_Value_List_First(d);
    while(e) {
      AB_VALUE *ne;

      ne=AB_Value_dup(e);
      assert(ne);
      AB_Value_List_Add(ne, st->values);
      e=AB_Value_List_Next(e);
    } /* while (e) */
  } /* if LIST */
  else
    st->values=0;
  st->_modified=1;
}




int AB_CellPhoneProduct_IsModified(const AB_CELLPHONE_PRODUCT *st) {
  assert(st);
  return st->_modified;
}


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


void AB_CellPhoneProduct_Attach(AB_CELLPHONE_PRODUCT *st) {
  assert(st);
  st->_usage++;
}
AB_CELLPHONE_PRODUCT *AB_CellPhoneProduct_List2__freeAll_cb(AB_CELLPHONE_PRODUCT *st, void *user_data) {
  AB_CellPhoneProduct_free(st);
return 0;
}


void AB_CellPhoneProduct_List2_freeAll(AB_CELLPHONE_PRODUCT_LIST2 *stl) {
  if (stl) {
    AB_CellPhoneProduct_List2_ForEach(stl, AB_CellPhoneProduct_List2__freeAll_cb, 0);
    AB_CellPhoneProduct_List2_free(stl); 
  }
}


AB_CELLPHONE_PRODUCT_LIST *AB_CellPhoneProduct_List_dup(const AB_CELLPHONE_PRODUCT_LIST *stl) {
  if (stl) {
    AB_CELLPHONE_PRODUCT_LIST *nl;
    AB_CELLPHONE_PRODUCT *e;

    nl=AB_CellPhoneProduct_List_new();
    e=AB_CellPhoneProduct_List_First(stl);
    while(e) {
      AB_CELLPHONE_PRODUCT *ne;

      ne=AB_CellPhoneProduct_dup(e);
      assert(ne);
      AB_CellPhoneProduct_List_Add(ne, nl);
      e=AB_CellPhoneProduct_List_Next(e);
    } /* while (e) */
    return nl;
  }
  else
    return 0;
}




