/* ** $Id: array,v 1.1 2003/01/27 15:36:32 phf Exp $ ** ** Copyright (c) 2003 by Peter H. Froehlich . ** Freely distributable for educational purposes. */ #ifndef _CS14_ARRAY #define _CS14_ARRAY #include #include namespace cs14 { /* ** Interface class for ADT Array. */ template class Array { public: /* ** Member functions for C++ specifics. ** ** You also need to implement the constructor ** ** Array( int length, T initial ) ** ** the copy constructor ** ** Array( const Array &that ) ** ** and the assignment operator ** ** Array& operator=( const Array &that ) ** ** in derived classes! */ virtual ~Array() {} // Can't be made pure, although we would like to! virtual const T& operator[]( int index ) const throw (std::out_of_range) =0; virtual T& operator[]( int index ) throw (std::out_of_range) =0; /* ** Member functions for ADT Array operations. */ virtual T get( int index ) const throw (std::out_of_range) =0; virtual void put( int index, T t ) throw (std::out_of_range) =0; virtual int length() const = 0; }; template std::ostream& operator <<( std::ostream &o, const cs14::Array &a ) { int l = a.length(); o << "["; for (int i = 0; i < l; i++) { o << a.get(i) << (i == l-1 ? "" : ", "); } o << "]"; return o; } } // namespace cs14 #endif /* _CS14_ARRAY */