//----------------------------------------------------------------------
//  SPECIFICATION FILE (vector.h)
//  This module exports an integer vector class that allows:
//    1. Run-time specification of vector size
//    2. Trapping of invalid subscripts
//    3. Aggregate vector assignment
//    4. Aggregate vector initialization (for parameter passage by
//       value, function value return, initialization in a declaration)
//----------------------------------------------------------------------

#ifndef vector_h
#define vector_h 1

#include <iostream.h>

class IntVec {
  // ABSTRACTLY: a sequence of integer cells, with a fixed size (once created)
  //             a sequence <i0,...,in-1> has size n and indexes 0..n,
  //             these are refered to as the legal indexes of the sequence.
  
public:
  IntVec( int numElements );
    // MODIFIES: self, cerr
    // POST: IF numElements >= 1 THEN self is an sequence of size numElements
    //                                with unitialized values.
    //       ELSE an error message is printed and the program halted.
  
  IntVec( const IntVec& anotherVec );  // a "copy-constructor"
    // MODIFIES: self
    // POST: self has the same abstract value as anotherVec,
    // but does not share storage with it.
    // NOTE: This constructor is implicitly invoked whenever an
    //       IntVec is passed by value, is returned as a
    //       function value, or is initialized by another
    //       IntVec in a declaration.

  ~IntVec();      // Destructor
    // MODIFIES: self
    // POST: all of the cells in self are returned to the free store,
    // so the abstract value is undefined

  IntVec & operator = ( const IntVec & vec2 );
    // MODIFIES: self, cerr
    // POST: FCTVAL == the object self
    // && IF size of self == size of vec2
    //    THEN for each legal index i, self[i] == vec2[i]
    //         and cerr is unchanged
    //    ELSE an error message is printed and the program halted.
  
  int& operator[] ( int i ) const;
    // MODIFIES: cerr
    // POST: IF i is a legal index THEN FCTVAL == address of element i
    //       ELSE an error message is printed and the program halted.
    // NOTE: Because return type is "int&", not "int*", the result
    //       is automatically dereferenced in the calling code.
    //       Caller uses   someVec[6] = 943;
    //              not    *(someVec[6]) = 943;

  int Size () const;
    // POST: FCTVAL is the size of self

#include "vector.pri"
};
#endif
