// intarray.h
// Glenn G. Chappell
// VERSION 2
// 18 Sep 2009
//
// For CS 311 Fall 2009
// Header for class IntArray
// RAII class for dynamically allocated array of ints
// There is no associated source file

#ifndef FILE_INTARRAY_H_INCLUDED
#define FILE_INTARRAY_H_INCLUDED

#include <cstdlib>  // for std::size_t


// ************************************************************************
// class IntArray - Class definition
// ************************************************************************


// class IntArray
// Simple RAII class for dynamically allocated array of ints.
// A const IntArray does not allow modifications of the data items
//  in its array.
// Invariants:
//     arrayPtr_ points to an array of ints, allocated with new [],
//      owned by *this.
class IntArray {

// ***** IntArray: Types *****
public:

    typedef std::size_t size_type;  // Unsigned type for size of array
    typedef int value_type;         // Type for items in array

// ***** IntArray: Ctors, dctor, op= *****
public:

    // ctor from size
    // Not an implicit type conversion.
    // Pre:
    //     size >= 0.
    // Post:
    //     The array pointed to by arrayPtr_ has the given size.
    explicit IntArray(size_type size)
        :arrayPtr_(new value_type[size])
    {}

    // Dctor
    // Pre: None.
    // Post:
    //     (arrayPtr_ has been delete'd.)
    ~IntArray()
    { delete [] arrayPtr_; }

private:

    // Uncopyable class; do not define copy ctor, copy =
    IntArray(const IntArray &);
    IntArray & operator=(const IntArray &);
    

// ***** IntArray: General public operators *****
public:

    // Bracket operator (non-const & const)
    // Pre:
    //     0 <= index < size, where "size" means the size of the array.
    // Post:
    //     Return is reference to arrayPtr_[index].
    value_type & operator[](size_type index)
    { return arrayPtr_[index]; }
    const value_type & operator[](size_type index) const
    { return arrayPtr_[index]; }

// ***** IntArray: Data members *****
private:

    value_type * arrayPtr_;  // Pointer to our array.

};  // End class IntArray


#endif //#ifndef FILE_INTARRAY_H_INCLUDED

