
//file: myVector.h
//written by: David Yang, Sean McMillan, Dominic Golab
//on: 12/6/09
//For: CSE 30331: Scrabble Gmae
//12/6/09
/*Description: This file contains the functionality of a Vector. It is a templated extension of the STL vector class that has resize ability and exception handling.*/

#include <vector>
#include <iostream>
#include <stdexcept>


using namespace std;

template<class T>
class Vector : public vector<T>{
  public:
  Vector(int n=0,T value=0); //constructor
  T& operator[]( int k); //overloads the bracket operator
  void resize(int n); //resizes the vector to the desired size

  private:
    
};

//constructor
template<class T>
Vector<T>::Vector(int n,T value): vector<T>(n,value){

}

//overloads the bracket operator
template<class T>
T& Vector<T>::operator[](int k){
  //try and catch block that determines whether a given address is invalid and changes it to 0 if it is and returns that value.
  try{
    if(k < 0 || k >= (int)this->size()){
      k =0;
      throw out_of_range("Improper address value given. Out of bounds of Vector. The address is changed to 0");
   

    }
  }	
  catch (out_of_range& oor) {
    cerr << "Out of Range error: " << oor.what() << endl;
      
  }
  return this->at(k); 
}

//resizes the vector to the desired size
template<class T>
void Vector<T>::resize(int n)
{
  //determines if the resize value is negative. if so, resizes the vector to 1.
  try{
    if(n < 0){
       n=1;
      throw out_of_range("Number provided to resize vector is negative. Resized to 1");

    }	
  }
  catch (out_of_range& oor) {
    cerr << "Out of Range error: " << oor.what() << endl;

  }

  std::vector<T>::resize(n);

}








