
/*
 *    10-Oct-1990 - created
 */

/***********************************************************
 *
 *    Module:   olist.h
 *
 *    Purpose:  Include file for ordered lists
 *
 *    (c) Copyright 1990 Kenneth L. Grogan Jr.
 *
 **********************************************************/


#ifndef OLIST_H
#define OLIST_H

#ifndef OLIST_X
#define OLIST_X
                                /* global error variable */
extern int      olist_errno;

#endif

#define OLIST_SUCCESS           0
#define OLIST_INVALID           1
#define OLIST_NO_MEMORY         2
#define OLIST_EMPTY             3
#define OLIST_INVALID_TYPE      4
#define OLIST_NOT_FOUND         5
#define OLIST_KEY_EXISTS        6
#define OLIST_NO_CURRENT        7
#define OLIST_END_OF_LIST       8

#define OLIST_INVALID_STR       "olist is invalid"
#define OLIST_NO_MEMORY_STR     "No more memory"
#define OLIST_EMPTY_STR         "This list is empty"
#define OLIST_INVALID_TYPE_STR  "Key type is invalid"
#define OLIST_NOT_FOUND_STR     "Key was not found"
#define OLIST_KEY_EXISTS_STR    "Key already exists in list"
#define OLIST_NO_CURRENT_STR    "No current node in this list"
#define OLIST_END_OF_LIST_STR   "End of the list"

                                /* olist type */
typedef void    *OLIST;
                                /* olist key type */
typedef int     OLIST_KEY_T;

                                /* olist key type values */
#define OLIST_KEY_1             0
#define OLIST_KEY_2             1
#define OLIST_KEY_3             2
#define OLIST_NUM_KEY_TYPES     3
#define OLIST_NO_KEY            4

#define OLIST_UINT      OLIST_KEY_1
#define OLIST_DBL       OLIST_KEY_2
#define OLIST_PTR       OLIST_KEY_3
                                /* olist with unsigned keys */
#define olistu_new()            (olist_new(OLIST_UINT, NULL))
#define olistu_kill(ol)         (olist_kill(ol))
#define olistu_size(ol)         (olist_size(ol)
#define olistu_key_type(ol)     (olist_key_type(ol))
#define olistu_insert(ol, inkey, data) \
    (olist_add((ol), OLIST_UINT, &(inkey), (data), FALSE))
#define olistu_replace(ol, inkey, data) \
    (olist_add((ol), OLIST_UINT, &(inkey), (data), TRUE))
#define olistu_remove(ol, inkey) \
    (olist_remove((ol), OLIST_UINT, &(inkey)))
#define olistu_remove_all(ol)   (olist_remove_all(ol))
#define olistu_find(ol, inkey)  (olist_find((ol), \
    OLIST_UINT, &(inkey)))
#define olistu_query(ol, inkey, outkey, before) \
    (olist_query((ol), OLIST_UINT, &(inkey), &(outkey), \
        (before)))
#define olistu_get_last(ol, outkey) \
    (olist_get_last((ol), OLIST_UINT, &(outkey)))
#define olistu_first(ol, outkey) \
    (olist_do_first((ol), OLIST_UINT, &(outkey), TRUE))
#define olistu_get_first(ol, outkey) \
    (olist_do_first((ol), OLIST_UINT, &(outkey), FALSE))
#define olistu_next(ol, outkey) \
    (olist_do_next((ol), OLIST_UINT, &(outkey), TRUE))
#define olistu_get_next(ol, outkey) \
    (olist_do_next((ol), OLIST_UINT, &(outkey), FALSE))
#define olistu_get_current(ol, outkey) \
    (olist_get_current((ol), OLIST_UINT, &(outkey)))
#define olistu_compares(ol, inkey) \
    (olist_compares((ol), OLIST_UINT, &(inkey)))

                                /* olist with double keys */
#define olistd_new()            (olist_new(OLIST_DBL, NULL))
#define olistd_kill(ol)         (olist_kill(ol))
#define olistd_size(ol)         (olist_size(ol)
#define olistd_key_type(ol)     (olist_key_type(ol))
#define olistd_insert(ol, inkey, data) \
    (olist_add((ol), OLIST_DBL, &(inkey), (data), FALSE))
#define olistd_replace(ol, inkey, data) \
    (olist_add((ol), OLIST_DBL, &(inkey), (data), TRUE))
#define olistd_remove(ol, inkey) \
    (olist_remove((ol), OLIST_DBL, &(inkey)))
#define olistd_remove_all(ol)   (olist_remove_all(ol))
#define olistd_find(ol, inkey) \
    (olist_find((ol), OLIST_DBL, &(inkey)))
#define olistd_query(ol, inkey, outkey, before) \
    (olist_query((ol), OLIST_DBL, &(inkey), &(outkey), (before)))
#define olistd_get_last(ol, outkey) \
    (olist_get_last((ol), OLIST_DBL, &(outkey)))
#define olistd_first(ol, outkey) \
    (olist_do_first((ol), OLIST_DBL, &(outkey), TRUE))
#define olistd_get_first(ol, outkey) \
    (olist_do_first((ol), OLIST_DBL, &(outkey), FALSE))
#define olistd_next(ol, outkey) \
    (olist_do_next((ol), OLIST_DBL, &(outkey), TRUE))
#define olistd_get_next(ol, outkey) \
    (olist_do_next((ol), OLIST_DBL, &(outkey), FALSE))
#define olistd_get_current(ol, outkey) \
    (olist_get_current((ol), OLIST_DBL, &(outkey)))
#define olistd_compares(ol, inkey) \
    (olist_compares((ol), OLIST_DBL, &(inkey)))

                                /* olist with pointer keys */
#define olistp_new(comp_func)   (olist_new(OLIST_PTR, comp_func))
#define olistp_kill(ol)         (olist_kill(ol))
#define olistp_size(ol)         (olist_size(ol)
#define olistp_key_type(ol)     (olist_key_type(ol))
#define olistp_insert(ol, inkey, data) \
    (olist_add((ol), OLIST_PTR, &(inkey), (data), FALSE))
#define olistp_replace(ol, inkey, data) \
    (olist_add((ol), OLIST_PTR, &(inkey), (data), TRUE))
#define olistp_remove(ol, inkey) \
    (olist_remove((ol), OLIST_PTR, &(inkey)))
#define olistp_remove_all(ol)   (olist_remove_all(ol))
#define olistp_find(ol, inkey) \
        (olist_find((ol), OLIST_PTR, &(inkey)))
#define olistp_query(ol, inkey, outkey, before) \
    (olist_query((ol), OLIST_PTR, &(inkey), &(outkey), (before)))
#define olistp_get_last(ol, outkey) \
    (olist_get_last((ol), OLIST_PTR, &(outkey)))
#define olistp_first(ol, outkey) \
    (olist_do_first((ol), OLIST_PTR, &(outkey), TRUE))
#define olistp_get_first(ol, outkey) \
    (olist_do_first((ol), OLIST_PTR, &(outkey), FALSE))
#define olistp_next(ol, outkey) \
    (olist_do_next((ol), OLIST_PTR, &(outkey), TRUE))
#define olistp_get_next(ol, outkey) \
    (olist_do_next((ol), OLIST_PTR, &(outkey), FALSE))
#define olistp_get_current(ol, outkey) \
    (olist_get_current((ol), OLIST_PTR, &(outkey)))
#define olistp_compares(ol, inkey) \
    (olist_compares((ol), OLIST_PTR, &(inkey)))

                                /* function prototypes */
#ifdef PROTO

OLIST olist_new (OLIST_KEY_T    key_type,
                 int            (*compare_func)());
bool olist_kill (OLIST  o_list);
size_t olist_size (OLIST        o_list);
OLIST_KEY_T olist_key_type (OLIST       o_list);
bool olist_add (OLIST           o_list,
                OLIST_KEY_T     key_type,
                void            *inkey,
                void            *client_data,
                bool            replace_data);
bool olist_remove (OLIST        o_list,
                   OLIST_KEY_T  key_type,
                   void         *inkey);
bool olist_remove_all (OLIST    o_list);
void *olist_find (OLIST         o_list,
                  OLIST_KEY_T   key_type,
                  void          *inkey);
void *olist_query (OLIST        o_list,
                   OLIST_KEY_T  key_type,
                   void         *inkey,
                   void         *outkey,
                   bool         find_before);
void *olist_get_last (OLIST             o_list,
                      OLIST_KEY_T       key_type,
                      void              *outkey);
void *olist_do_first (OLIST             o_list,
                      OLIST_KEY_T       key_type,
                      void              *outkey,
                      bool              set_current);
void *olist_do_next (OLIST              o_list,
                     OLIST_KEY_T        key_type,
                     void               *outkey,
                     bool               set_current);
void *olist_get_current (OLIST          o_list,
                         OLIST_KEY_T    key_type,
                         void           *outkey);
int olist_compares (OLIST       o_list,
                    OLIST_KEY_T key_type,
                    void        *inkey);
bool olist_report (OLIST        o_list);

#else

OLIST olist_new ();
bool olist_kill ();
size_t olist_size ();
OLIST_KEY_T olist_key_type ();
bool olist_add ();
bool olist_remove ();
bool olist_remove_all ();
void *olist_find ();
void *olist_query ();
void *olist_get_last ();
void *olist_do_first ();
void *olist_do_next ();
void *olist_get_current ();
int olist_compares ();
bool olist_report ();

#endif

#endif   /* OLIST_H */

/*
 *    end of file
 */
