/*****************************************************************/
/**                                                             **/
/**             (C) Copyright 1992 the Regents of the           **/
/**        University of California.  All Rights Reserved.      **/
/**                                                             **/
/**        This work was produced under the sponsorship of      **/
/**         the U.S. Department of Energy.  The Government      **/
/**                retains certain rights therein.              **/
/**                                                             **/
/**                         Written by                          **/
/**         Distributed Programming Environments Project        **/
/**           Computer Software and Networking Division,        **/
/**                   Livermore Computer Center,                **/
/**            Lawrence Livermore National Laboratory           **/
/**                                                             **/
/*****************************************************************/

#ifndef LINK_H
#define LINK_H

static char sccsid_link_h[] = "@(#)list.h	1.3 10/19/92 13:34:09 LLNL ";


class link
    {
    friend class list;
    link *next;
    link *prev;

  public:

    inline link(link *n = 0, link *p = 0)
    {
      next = n; prev = p;
    }

    inline link(link &)
    {
      next = prev = 0;
    }

    inline void operator=(link &)
    {
      next = prev = 0;
    }

    inline ~link()
    {
      remove();
    }

    void insert(link *);
    void append(link *);
    void remove();
    };

class list
    {
    link *last;
    link *curr;
    int count;
  public:
    inline list()
    {
      last = curr = 0;
      count = 0;
    }

    inline list(link *a)
    {
      curr = 0;
      last = a;
      last->next = last->prev = last;
      count = 1;
    }

    inline ~list()
    {
      clear();
    }

    int isempty();
    void clear();

    // set current pointer to ends of the list

    void reset();

    // return the number of elements in the list

    int length();

    // set the curr pointer in the list

    inline void set_curr(link *l)
    { curr = l; }

    // return the curr pointer in the list

    inline link *get_curr()
    { return(curr); }

    // move around the list, leaving the links there

    int next(link *&e);
    int prev(link *&e);

    // move around the list, removing the links

    int getnext(link *&e);
    int getprev(link *&e);

    // manipulate around the beginning and end of the list

    void insert(link *);
    void append(link *);

    // manipulate around the current entry

    void inserthere(link *);
    void appendhere(link *);

    };

#endif

