/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
/* list.h */
#ifndef LIST_H_
#define LIST_H_

#include <iostream>
#include <stdlib.h>
using namespace std;

struct Data {
  int id;             /* id number */
  char *name;         /* name */
};

struct Element {
  struct Data data;
  struct Element *next;
};

void createData(struct Data *newData, int id, char *name);
void freeMem(struct Data *elem);

#ifdef _CH_
#include <dlfcn.h>
void *g_sample_dlhandle = dlopen("liblist.dl", RTLD_LAZY);
if(g_sample_dlhandle == NULL) {
   fprintf(_stderr, "Error: dlopen(): %s\n", dlerror());
   fprintf(_stderr, "       cannot get g_sample_dlhandle in sampclass.h\n");
   exit(-1);
}
void _dlclose_sampclass(void) {
   dlclose(g_sample_dlhandle);
}
atexit(_dlclose_sampclass);

class List {
  public:
    List();
    ~List();                //remove memory
    void prepend(struct Data data);   //prepend to the list at the beginning
    void append(struct Data data);   //append to the list at end
    void insert(struct Data data, int pos);   //insert to the list at pos
    void printList();   //print out the list
    int printName(char *name);   //print nodes with the same lname
    void removeElement(int id);   //delete first node with id = id
    void clear();   //delete all nodes attached to the list
};

/* get member functions of class List*/
#pragma importf <List.chf>
#else
class List {
  private:
    static int totnum;
    Element *head;
  public:
    List();
    ~List();   //remove memory
    void prepend(struct Data data);   //prepend to the list at the beginning
    void append(struct Data data);   //append to the list at end
    void insert(struct Data data, int pos);   //insert to the list at pos
    void printList();   //print out the list
    int printName(char *name);   //print nodes with the same lname
    void removeElement(int id);   //delete first node with id = id
    void clear();   //delete all nodes attached to the list
};
#endif

#endif /* LIST_H_ */
