//Sequence.cpp
 *****************************************************************************
 * FILE: Sequence.cpp                                                        *
 * CLASS PROVIDED: sequence (part of namespace CS256_Asgn3)                  *
 *    See sequence.h for documentation                                       *
 *                                                                           *
 * LIBRARIES:  cassert for assert( )                                         *
 *                                                                           *
 * NAMESPACE  CS256_Asgn3                                                    *
 *                                                                           *
 *****************************************************************************/
#include <cassert>
#include "sequence.h"

using namespace std;

namespace CS256_Asgn3
{



   // CONSTRUCTOR
   
   /**************************************************************************
   * Function: sequence()																	  *
   * Constructor: creates an sequence.													  *
   * Preconditions: none.																	  *
   * Postcondition: The sequence has been initialized as an empty sequence.  *
   **************************************************************************/
   sequence::sequence( )
   {
      current_index = 0;
      used = 0;
          
   }
   
   // MODIFICATION MEMBER FUNCTIONS
   
   /**************************************************************************
   * Function: start()																		  *
   * The first item in the sequence becomes the new current item.            *
   * Preconditions: none.																	  *
   * Postcondition: The first item on the sequence becomes the current       *
   *     item (but if the sequence is empty, then there is no current item). *
   **************************************************************************/
   void sequence::start( )
   {
     if(used > 0)
     current_index = 0;
     else
     {
     	  current_index = NULL;
     }	   
     return;
   }
   
   /**************************************************************************
   * Function: advance()																	  *
   * The next item in the sequence becomes the current item                  *
   * Precondtions: Precondition: is_item returns true.                       *
   * Postcondition: If the current item was already the last item in the     *
   *   sequence, then there is no longer any current item. Otherwise, the    *
   *   new current item is the item immediately after the original current   *
   *   item.                                                                 *
   **************************************************************************/
   void sequence::advance( )
   {
      assert( is_item());
      if( current_index == used-1 )
      {
      	current_index = NULL;
      }
      else
      {
      	current_index++;	
      }	
      return;
   }
   
   /**************************************************************************
   * Function: insert(const value_type& entry)										  *
   * 'entry' is added to the sequence before the current item.               *
   * Precondition: size( ) < CAPACITY.                                       *
   * Postcondition: A new copy of entry has been inserted in the sequence    *
   *    before the current item. If there was no current item, then the new  *
   *    entry has been inserted at the front of the sequence. In either case,*
   *    the newly inserted item is now the current item of the sequence.     *
   **************************************************************************/
   void sequence::insert(const value_type& entry)
   {
      size_type i;
      assert( size() < CAPACITY);
      if(!is_item())
      {
         current_index = 0;
      }
      for( i = used; i > current_index; i--)
      {
         data[i]=data[i-1];
      }
      data[current_index]=entry;
      used++;   
      return;
   }
   
   /**************************************************************************
   * Function: attach(const value_type& entry)										  *
   * 'entry' is added to the sequence after the current item.                *
   * Precondition: size( ) < CAPACITY.                                       *
   * Postcondition: A new copy of entry has been attached in the sequence    *
   *    after the current item. If there was no current item, then the new   *
   *    entry has been attached to the end of the sequence.  In either case, *
   *    the newly inserted item is now the current item of the sequence.     *
   **************************************************************************/
   void squence::attach(const value_type& entry)
   {
      assert( size() < CAPACITY);
      size_type i;
      
      for( i = used; i > current_index+1; i--)
      {
         data[i]=data[i-1];
      }
      
      if(!is_item())
      {
         current_index = used;
      }
      else
      {
      	current_index = i;
      }	
      data[current_index]=entry;
      used++;
      return;
   }
   
   /**************************************************************************
   * Function: remove_current()															  *
   * The current item is taken out of the sequence                           *
   * Precondition: is_item returns true.                                     *
   * Postcondition: The current item has been removed from the sequence,     *
   *   and the item after this (if there is one) is now the new current item *
   **************************************************************************/ 
   void sequence::remove_current( )
   {
      assert(is_item());
      
      
      return;
   }
   
   
   // CONSTANT MEMBER FUNCTIONS
   
   /**************************************************************************
   * Function: size() const																  *
   * Returns how many items are in the sequence.									  *
   * Precondition: none.																	  *
   * Postcondition: Return value is the number of items in the sequence.     *
   **************************************************************************/
   size_type sequence::size( ) const
   {
      return used;
   }
   
   /**************************************************************************
   * Function: is_item()																	  *
   * True if current points to an item.												  *
   * Precondition: none.																	  *
   * Postcondition: A true return value indicates that there is a valid      *
   *   "current" item that may be retrieved by activating the current        *
   *   member function (listed below). A false return value indicates that   *
   **************************************************************************/
   bool sequence::is_item( ) const
   {
     if(current_index > used)
     {
        return true;
     }
     else
     {
     	  return false;
     }	  
   }
         
   /**************************************************************************
   * Function: current()																	  *
   * Returns what data type the current item is.  									  *
   * Precondition: is_item( ) returns true.                                  *
   * Postcondition: The item returned is the current item in the sequence.   *
   **************************************************************************/ 
   value_type sequence::current( ) const      
   {
      assert( is_item());
      return value_type;
   }         
         
         
         
         
}
