/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
/************************************************************
* File name: List.chf
*            member functions of class List
************************************************************/

/******************** Public Functions ********************/
List::List(){
    void *fptr;

    fptr = dlsym(g_sample_dlhandle, "List_List_chdl");
    if(fptr == NULL)  {
        printf("Error: %s(): dlsym(): %s\n", __class_func__, dlerror());
        return;
    };
    dlrunfun(fptr, NULL, NULL);
}

List::~List(){
    void *fptr;
    fptr = dlsym(g_sample_dlhandle, "List_dList_chdl");
    if(fptr == NULL)  {
        printf("Error: %s(): dlsym(): %s\n", __class_func__, dlerror());
        return;
    };
    dlrunfun(fptr, NULL, NULL, this);
}


void List::prepend (struct Data data) {
    void *fptr;

    fptr = dlsym(g_sample_dlhandle, "List_prepend_chdl");
    if(fptr == NULL)  {
        printf("Error: %s(): dlsym(): %s\n", __class_func__, dlerror());
    };
    dlrunfun(fptr, NULL, prepend, this, data);
}

void List::append(struct Data data) {
    void *fptr;

    fptr = dlsym(g_sample_dlhandle, "List_append_chdl");
    if(fptr == NULL)  {
        printf("Error: %s(): dlsym(): %s\n", __class_func__, dlerror());
    };
    dlrunfun(fptr, NULL, append, this, data);
}

void List::insert(struct Data data, int pos) {
    void *fptr;

    fptr = dlsym(g_sample_dlhandle, "List_insert_chdl");
    if(fptr == NULL)  {
        printf("Error: %s(): dlsym(): %s\n", __class_func__, dlerror());
    };
    dlrunfun(fptr, NULL, insert, this, data, pos);
}

void List::printList() {
    void *fptr;

    fptr = dlsym(g_sample_dlhandle, "List_printList_chdl");
    if(fptr == NULL)  {
        printf("Error: %s(): dlsym(): %s\n", __class_func__, dlerror());
        return;
    };
    dlrunfun(fptr, NULL, printList, this);
}

int List::printName(char *name) {
    void *fptr;
    int retval;

    fptr = dlsym(g_sample_dlhandle, "List_printName_chdl");
    if(fptr == NULL)  {
        printf("Error: %s(): dlsym(): %s\n", __class_func__, dlerror());
        return -1;
    };
    dlrunfun(fptr, &retval, printName, this, name);
    return retval;
}

void List::removeElement (int id) {
    void *fptr;

    fptr = dlsym(g_sample_dlhandle, "List_removeElement_chdl");
    if(fptr == NULL)  {
        printf("Error: %s(): dlsym(): %s\n", __class_func__, dlerror());
        return;
    };
    dlrunfun(fptr, NULL, removeElement, this, id);
    return;
}

void List::clear() {
    void *fptr;

    fptr = dlsym(g_sample_dlhandle, "List_clear_chdl");
    if(fptr == NULL)  {
        printf("Error: %s(): dlsym(): %s\n", __class_func__, dlerror());
        return;
    };
    dlrunfun(fptr, NULL, clear, this);
    return;
}

void createData(struct Data *newData, int id, char *name) {
    void *fptr;

    fptr = dlsym(g_sample_dlhandle, "createData_chdl");
    if(fptr == NULL)  {
        printf("Error: %s(): dlsym(): %s\n", __func__, dlerror());
        return;
    };
    dlrunfun(fptr, NULL, createData, newData, id, name);
}

void freeMem(struct Data *elem) {
    void *fptr;

    fptr = dlsym(g_sample_dlhandle, "freeMem_chdl");
    if(fptr == NULL)  {
        printf("Error: %s(): dlsym(): %s\n", __func__, dlerror());
        return;
    };
    dlrunfun(fptr, NULL, freeMem, elem);
}
