// sequence.h (UNFINISHED)
// Glenn G. Chappell
// Version 2
// 31 Mar 2008
//
// For CS 311 Spring 2008
// Header for class Sequence
// Smart array class

#ifndef FILE_SEQUENCE_H_INCLUDED
#define FILE_SEQUENCE_H_INCLUDED

#include <cstdlib>    // for std::size_t


// ************************************************************************
// class Sequence - Class definition
// ************************************************************************


// class Sequence
// Smart array of ints
// Invariants:
//     capacity_ >= size_ >= 0.
//     capacity_ >= MINCAP.
//     data_ points to an int array, allocated with new [],
//      owned by *this, holding capacity_ ints.
class Sequence {

// ***** Sequence: types & constants *****
public:

    typedef std::size_t size_type;  // For array size & indices
    typedef int value_type;         // Type of data item in array
    typedef value_type * iterator;  // iterator types, as in the STL
    typedef const value_type * const_iterator;

private:

    enum { MINCAP = 20 };           // minimum value of capacity_

// ***** Sequence: ctors, dctor, op= *****
public:

    // Default ctor & ctor from size
    // Pre:
    // Post:
    // Strong Guarantee
    Sequence(size_type theSize = 0)
        :size_(theSize),
         capacity_(theSize >= MINCAP ? theSize : MINCAP),
         data_(new value_type[capacity_])
         // capacity_ must be declared before data_
    {}

    // copy ctor
    // Pre:
    // Post:
    // Strong Guarantee
    Sequence(const Sequence & other);

    // Copy assignment
    // Pre:
    // Post:
    // ??? Guarantee
    Sequence & operator=(const Sequence & rhs);

    // Dctor
    // Pre:
    // Post:
    // No-Throw Guarantee
    ~Sequence()
    { delete [] data_; }

// ***** Sequence: General public functions *****
public:

    // size
    // Pre:
    // Post:
    // No-Throw Guarantee
    size_type size() const
    { return size_; }

    // empty
    // Pre:
    // Post:
    // No-Throw Guarantee
    bool empty() const
    { return size() == 0; }

    // operator[] (non-const & const)
    // Pre:
    // Post:
    // No-Throw Guarantee
    value_type & operator[](size_type index)
    { return data_[index]; }
    const value_type & operator[](size_type index) const
    { return data_[index]; }

    // begin (non-const & const)
    // Pre:
    // Post:
    // No-Throw Guarantee
    iterator begin()
    { return data_; }
    const_iterator begin() const
    { return data_; }

    // end (non-const & const)
    // Pre:
    // Post:
    // No-Throw Guarantee
    iterator end()
    { return data_ + size(); }
    const_iterator end() const
    { return data_ + size(); }

    // resize
    // Pre:
    // Post:
    // ??? Guarantee
    void resize(size_type newSize);

    // insert
    // Pre:
    // Post:
    // ??? Guarantee
    iterator insert(iterator pos,
                    const value_type & item);

    // remove
    // Pre:
    // Post:
    // ??? Guarantee
    iterator remove(iterator pos);

    // swap
    // Pre:
    // Post:
    // ??? Guarantee
    void swap(Sequence & other);

// ***** Sequence: Data members *****
private:

    size_type size_;      // Size of our (logical) array
    size_type capacity_;  // Number of items allocated
    value_type * data_;   // Pointer to our array
    // capacity_ must be declared before data_, for initializers

};  // end class Sequence

#endif //#ifndef FILE_SEQUENCE_H_INCLUDED