/*----------------------------------------------------------------*/
/* This file can be saved to your machine (almost) as you see it  */
/* by doing a "Save As..." from the File menu of your browser.    */
/*                                                                */
/* For this to work, you must TYPE a filename with .txt as the    */
/* file extent.  (Simply selecting .txt as the file type          */
/* doesn't seem to be sufficient.)  Remove the .txt extension     */
/* once the file is saved.  (IE inserts the page title as the     */
/* first line, which must be removed also.)                       */
/*----------------------------------------------------------------*/

// Author: Hannah C. Tang (hctang@cs)
//
// Specification for a templated array class with bounds checking


#ifndef ARRAY_HH
#define ARRAY_HH

template< typename T >
class Array 
{
    //
    // Canonical form is the 4 standard functions which should be 
    // implemented for *any* class which uses dynamic memory:
    //  (1) default constructor, (2) copy constructor, (3) assignment op
    //  (4) destructor
    // 

private:
    // The default constructor will be private and unimplemented
    // because it's not supposed to be called
    Array( void );                                // (1) default constructor

public:
    Array( int initCapacity );                    // overloaded constructor
    Array( const Array& other );                  // (2) copy constructor
    const Array& operator=( const Array& other ); // (3) assign op
    ~Array( void );                               // (4) destructor

    // There are two versions of the indexing operator -- the const
    // version is for accessing data in const Arrays.
    const T&             operator[]( int index ) const;
    T&                   operator[]( int index );

    int                  GetCapacity( void );


private:
    // I follow a subset of the "hungarian" naming convention, where
    // data members are prefaced with a "m_" and pointers with a "p"
    // Hungarian is not required for this class, but some sort of 
    // consistant naming convention *is*.
    int                  m_capacity;
    T*                   m_pData;

    // Helper methods for canonical form
    void                 Copy( const Array& other );
    void                 Destroy( void );
};


#endif // ARRAY_HH