// This class is a modification of the STL auto_ptr that works for
// arrays

#ifndef __AUTO_ARRAY_PTR_H__
#define __AUTO_ARRAY_PTR_H__

template<class T>
class auto_array_ptr
{
 private:
  T* m_ptr;

 public:
  explicit auto_array_ptr(T* ptr = 0) throw() : m_ptr(ptr) {}
  auto_array_ptr(auto_array_ptr& aap) throw() : m_ptr(aap.release()) {}
  ~auto_array_ptr() { delete [] m_ptr; }

  auto_array_ptr& operator=(T* ptr) throw()
    {
      reset(ptr);
      return *this;
    }
  auto_array_ptr& operator=(auto_array_ptr& aap) throw()
    {
      reset(aap.release());
      return *this;
    }

  T& operator[](int i) { return m_ptr[i]; }
  const T& operator[](int i) const { return m_ptr[i]; }

  T* get() const throw() { return m_ptr; }
  T* release() throw()
    {
      T* tmp = m_ptr;
      m_ptr = 0;
      return tmp;
    }
  void reset(T* ptr = 0) throw()
    {
      if (ptr != m_ptr)
        {
          delete [] m_ptr;
          m_ptr = ptr;
        }
    }
};

#endif  // __AUTO_ARRAY_PTR_H__
