/**********************************************************
 * This file has been automatically created by "typemaker2"
 * from the file "userqueue.xml".
 * Please do not edit this file, all changes will be lost.
 * Better edit the mentioned source file instead.
 **********************************************************/

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include "./userqueue_p.h"

#include <gwenhywfar/misc.h>
#include <gwenhywfar/debug.h>

/* code headers */

/* macro functions */
GWEN_LIST_FUNCTIONS(AB_USERQUEUE, AB_UserQueue)
GWEN_INHERIT_FUNCTIONS(AB_USERQUEUE)


AB_USERQUEUE *AB_UserQueue_new(void) {
  AB_USERQUEUE *p_struct;

  GWEN_NEW_OBJECT(AB_USERQUEUE, p_struct)
  p_struct->_refCount=1;
  GWEN_INHERIT_INIT(AB_USERQUEUE, p_struct)
  GWEN_LIST_INIT(AB_USERQUEUE, p_struct)
  /* members */
  p_struct->userId=0;
  p_struct->user=NULL;
  p_struct->accountQueueList=AB_AccountQueue_List_new();
  /* virtual functions */

  return p_struct;
}

void AB_UserQueue_free(AB_USERQUEUE *p_struct) {
  if (p_struct) {
  assert(p_struct->_refCount);
  if (p_struct->_refCount==1) {
    GWEN_INHERIT_FINI(AB_USERQUEUE, p_struct)
    GWEN_LIST_FINI(AB_USERQUEUE, p_struct)
  /* members */
    AB_AccountQueue_List_free(p_struct->accountQueueList); p_struct->accountQueueList=NULL;
    p_struct->_refCount=0;
    GWEN_FREE_OBJECT(p_struct);
  }
  else
    p_struct->_refCount--;
  }
}

void AB_UserQueue_Attach(AB_USERQUEUE *p_struct) {
  assert(p_struct);
  assert(p_struct->_refCount);
  p_struct->_refCount++;
}

AB_USERQUEUE *AB_UserQueue_dup(const AB_USERQUEUE *p_src) {
  AB_USERQUEUE *p_struct;

  assert(p_src);
  p_struct=AB_UserQueue_new();
  /* member "userId" */
    p_struct->userId=p_src->userId;


  /* member "user" */
    p_struct->user=p_src->user;


  /* member "accountQueueList" */
  if (p_struct->accountQueueList) {
    AB_AccountQueue_List_free(p_struct->accountQueueList); p_struct->accountQueueList=NULL;
    p_struct->accountQueueList=NULL;
  }
  if (p_src->accountQueueList) {
    p_struct->accountQueueList=AB_AccountQueue_List_dup(p_src->accountQueueList);
  }


  return p_struct;
}

uint32_t AB_UserQueue_GetUserId(const AB_USERQUEUE *p_struct){
  assert(p_struct);
  return p_struct->userId;
}

AB_USER *AB_UserQueue_GetUser(const AB_USERQUEUE *p_struct){
  assert(p_struct);
  return p_struct->user;
}

AB_ACCOUNTQUEUE_LIST *AB_UserQueue_GetAccountQueueList(const AB_USERQUEUE *p_struct){
  assert(p_struct);
  return p_struct->accountQueueList;
}

void AB_UserQueue_SetUserId(AB_USERQUEUE *p_struct, uint32_t p_src){
  assert(p_struct);
  p_struct->userId=p_src;
}

void AB_UserQueue_SetUser(AB_USERQUEUE *p_struct, AB_USER *p_src){
  assert(p_struct);
  p_struct->user=p_src;
}

void AB_UserQueue_SetAccountQueueList(AB_USERQUEUE *p_struct, AB_ACCOUNTQUEUE_LIST *p_src){
  assert(p_struct);
  if (p_struct->accountQueueList) {
    AB_AccountQueue_List_free(p_struct->accountQueueList); p_struct->accountQueueList=NULL;
    p_struct->accountQueueList=NULL;
  }
  p_struct->accountQueueList=p_src;
}

AB_USERQUEUE_LIST *AB_UserQueue_List_dup(const AB_USERQUEUE_LIST *p_src) {
  AB_USERQUEUE_LIST *p_dest;
  AB_USERQUEUE *p_elem;

  assert(p_src);
  p_dest=AB_UserQueue_List_new();
  p_elem=AB_UserQueue_List_First(p_src);
  while(p_elem) {
    AB_USERQUEUE *p_cpy;

    p_cpy=AB_UserQueue_dup(p_elem);
    AB_UserQueue_List_Add(p_cpy, p_dest);
    p_elem=AB_UserQueue_List_Next(p_elem);
  }

  return p_dest;
}

AB_USERQUEUE *AB_UserQueue_List_GetByUserId(const AB_USERQUEUE_LIST *p_list, uint32_t p_cmp){
  AB_USERQUEUE *p_struct;

  assert(p_list);
  p_struct = AB_UserQueue_List_First(p_list);
  while(p_struct) {
    int p_rv;

    if (p_struct->userId==p_cmp) p_rv=0; else if (p_cmp<p_struct->userId) p_rv=-1; else p_rv=1;
    if (p_rv == 0)
      return p_struct;
    p_struct = AB_UserQueue_List_Next(p_struct);
  }
  return NULL;
}

AB_ACCOUNTQUEUE *AB_UserQueue_FindAccountQueue(const AB_USERQUEUE *uq, AB_ACCOUNT *acc) { AB_ACCOUNTQUEUE *aq; aq=AB_AccountQueue_List_First(uq->accountQueueList); while(aq) { if (AB_AccountQueue_GetAccount(aq)==acc) return aq; aq=AB_AccountQueue_List_Next(aq); } return NULL; }
void AB_UserQueue_AddAccountQueue(AB_USERQUEUE *up, AB_ACCOUNTQUEUE *aq) { if (up->accountQueueList==NULL) up->accountQueueList=AB_AccountQueue_List_new(); AB_AccountQueue_List_Add(aq, up->accountQueueList); }
AB_ACCOUNTQUEUE *AB_UserQueue_GetFirstAccountQueue(const AB_USERQUEUE *up) { if (up->accountQueueList==NULL) return NULL; return AB_AccountQueue_List_First(up->accountQueueList); }

/* code headers */

