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

#include <aqebics/aqebics.h>
#include <aqbanking/job_be.h>


GWEN_LIST_FUNCTIONS(EBC_CONTEXT, EBC_Context)
GWEN_LIST2_FUNCTIONS(EBC_CONTEXT, EBC_Context)




EBC_CONTEXT *EBC_Context_new() {
  EBC_CONTEXT *st;

  GWEN_NEW_OBJECT(EBC_CONTEXT, st)
  st->_usage=1;
  GWEN_LIST_INIT(EBC_CONTEXT, st)
  st->jobs=AB_Job_List2_new();
  return st;
}


void EBC_Context_free(EBC_CONTEXT *st) {
  if (st) {
    assert(st->_usage);
    if (--(st->_usage)==0) {
  if (st->jobs)
    AB_Job_List2_free(st->jobs);
  GWEN_LIST_FINI(EBC_CONTEXT, st)
  GWEN_FREE_OBJECT(st);
    }
  }

}


EBC_CONTEXT *EBC_Context_dup(const EBC_CONTEXT *d) {
  EBC_CONTEXT *st;

  assert(d);
  st=EBC_Context_new();
  if (d->jobs)
    st->jobs=AB_Job_List2_dup(d->jobs);
  st->jobType=d->jobType;
  return st;
}


int EBC_Context_toDb(const EBC_CONTEXT *st, GWEN_DB_NODE *db) {
  assert(st);
  assert(db);
  if (GWEN_DB_SetIntValue(db, GWEN_DB_FLAGS_OVERWRITE_VARS, "jobType", st->jobType))
    return -1;
  return 0;
}


int EBC_Context_ReadDb(EBC_CONTEXT *st, GWEN_DB_NODE *db) {
  assert(st);
  assert(db);
  EBC_Context_SetJobType(st, GWEN_DB_GetIntValue(db, "jobType", 0, 0));
  return 0;
}


EBC_CONTEXT *EBC_Context_fromDb(GWEN_DB_NODE *db) {
  EBC_CONTEXT *st;

  assert(db);
  st=EBC_Context_new();
  EBC_Context_ReadDb(st, db);
  st->_modified=0;
  return st;
}




AB_JOB_LIST2 *EBC_Context_GetJobs(const EBC_CONTEXT *st) {
  assert(st);
  return st->jobs;
}


void EBC_Context_SetJobs(EBC_CONTEXT *st, AB_JOB_LIST2 *d) {
  assert(st);
  if (st->jobs)
    AB_Job_List2_free(st->jobs);
  if (d)
    st->jobs=AB_Job_List2_dup(d);
  else
    st->jobs=0;
  st->_modified=1;
}




AB_JOB_TYPE EBC_Context_GetJobType(const EBC_CONTEXT *st) {
  assert(st);
  return st->jobType;
}


void EBC_Context_SetJobType(EBC_CONTEXT *st, AB_JOB_TYPE d) {
  assert(st);
  st->jobType=d;
  st->_modified=1;
}




int EBC_Context_IsModified(const EBC_CONTEXT *st) {
  assert(st);
  return st->_modified;
}


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


void EBC_Context_Attach(EBC_CONTEXT *st) {
  assert(st);
  st->_usage++;
}



EBC_CONTEXT *EBC_Context_List2__freeAll_cb(EBC_CONTEXT *st, GWEN_UNUSED void *user_data) {
  EBC_Context_free(st);
return 0;
}


void EBC_Context_List2_freeAll(EBC_CONTEXT_LIST2 *stl) {
  if (stl) {
    EBC_Context_List2_ForEach(stl, EBC_Context_List2__freeAll_cb, 0);
    EBC_Context_List2_free(stl); 
  }
}


EBC_CONTEXT_LIST *EBC_Context_List_dup(const EBC_CONTEXT_LIST *stl) {
  if (stl) {
    EBC_CONTEXT_LIST *nl;
    EBC_CONTEXT *e;

    nl=EBC_Context_List_new();
    e=EBC_Context_List_First(stl);
    while(e) {
      EBC_CONTEXT *ne;

      ne=EBC_Context_dup(e);
      assert(ne);
      EBC_Context_List_Add(ne, nl);
      e=EBC_Context_List_Next(e);
    } /* while (e) */
    return nl;
  }
  else
    return 0;
}




