//----------------------------------------------------------------------
//  IMPLEMENTATION FILE (intlist.cpp)
//  This module exports IntList, an ADT for maintaining lists of
//  integers.
//  GenList is a private base class of IntList.
//----------------------------------------------------------------------
#include "intlist.h"

// Additional private members of class:
//     None

IntList::IntList()
    //..................................................................
    // POST: New list created via implicit call
    //       to base class constructor
    //..................................................................
{
    // Nothing to do after base class constructor called
}

IntList::IntList( const IntList& otherList ) : GenList(otherList)
    //..................................................................
    // POST: New list created via call to base class copy-constructor
    //       (Incoming parameter otherList is passed as a parameter to
    //        base class's copy-constructor)
    //..................................................................
{
    // Nothing to do after base class copy-constructor called
}

IntList::~IntList()
    //..................................................................
    // POST: List destroyed via implicit call to base class destructor
    //..................................................................
{
    // Nothing to do before base class destructor called
}

int IntList::CurrentItem() const
    //..............................................................
    // PRE:  NOT IsEmpty()  &&  NOT EndOfList()
    // POST: FCTVAL == integer pointed to by item at list cursor
    //..................................................................
{
    int* itemPtr = (int*) GenList::CurrentItem();
    return *itemPtr;
}

void IntList::InsertBefore( /* in */ int someInt )
    //..................................................................
    // PRE:  Assigned(someInt)  &&  NOT IsFull()
    // POST: Memory dynamically allocated for a copy of someInt
    //    && Its address has been inserted before list cursor
    //    && This is the new current item
    //..................................................................
{
    int* itemPtr = new int;
    *itemPtr = someInt;
    GenList::InsertBefore(itemPtr);
}

void IntList::InsertAfter( /* in */ int someInt )
    //..................................................................
    // PRE:  Assigned(someInt)  &&  NOT IsEmpty()
    //   &&  NOT IsFull()  &&  NOT EndOfList()
    // POST: Memory dynamically allocated for a copy of someInt
    //    && Its address has been inserted after list cursor
    //    && This is the new current item
    //..................................................................
{
    int* itemPtr = new int;
    *itemPtr = someInt;
    GenList::InsertAfter(itemPtr);
}

void IntList::Delete()
    //..................................................................
    // PRE:  NOT IsEmpty()  &&  NOT EndOfList()
    // POST: Integer pointed to by item at list cursor
    //       deleted from free store
    //    && GenList::Delete() invoked
    //..................................................................
{
    int* itemPtr = (int*) GenList::CurrentItem();
    delete itemPtr;
    GenList::Delete();
}


