//----------------------------------------------------------------------
//  SPECIFICATION FILE (genlist.h)
//  This module exports GenList, a generic list ADT.  Each item in the
//  list is a pointer to an actual data item.
//  It is intended that specialized classes be derived from GenList
//  and that GenList will be a private base class.
//----------------------------------------------------------------------
#ifndef GENLIST_H
#define GENLIST_H

#include "bool.h"

// DOMAIN: Each list is a collection of pointers, along with an
//         implicit list cursor in the range 1..n+1, where n is
//         the current length of the list

struct NodeType;   // Complete declaration hidden in
                   // implementation file

class GenList {
public:
    Boolean IsEmpty() const;
        // POST: FCTVAL == (list is empty)

    Boolean IsFull() const;
        // POST: FCTVAL == (list is full)

    void Reset();
        // PRE:  NOT IsEmpty()
        // POST: List cursor is at front of list

    Boolean EndOfList() const;
        // POST: FCTVAL == (list cursor is beyond end of list)

    void Advance();
        // PRE:  NOT IsEmpty()  &&  NOT EndOfList()
        // POST: List cursor has advanced to next item

    void* CurrentItem() const;
        // PRE:  NOT IsEmpty()  &&  NOT EndOfList()
        // POST: FCTVAL == item at list cursor

    void InsertBefore( /* in */ void* somePtr );
        // PRE:  Assigned(somePtr)  &&  NOT IsFull()
        // POST: somePtr inserted before list cursor
        //          (at back, if EndOfList())
        //    && This is the new current item

    void InsertAfter( /* in */ void* somePtr );
        // PRE:  Assigned(somePtr)  &&  NOT IsEmpty()
        //   &&  NOT IsFull()  &&  NOT EndOfList()
        // POST: somePtr inserted after list cursor
        //    && This is the new current item

    void Delete();
        // PRE:  NOT IsEmpty()  &&  NOT EndOfList()
        // POST: Item at list cursor deleted
        //    && Successor of deleted item is now the current item

    GenList();
        // POST: Created(list)  &&  IsEmpty()  &&  EndOfList()

    GenList( const GenList& otherList );
        // POST: Created(list)  &&  list == otherList  &&  EndOfList()

    ~GenList();
        // POST: List destroyed
private:
    NodeType* head;
    NodeType* currPtr;
};
#endif

