/*
  WVector.h - Vector library for Wiring & Arduino
  Copyright (c) 2009 Hernando Barragan.  All right reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef Vector_h
#define Vector_h

#include "WConstants.h"
#include <ctype.h>

template <class Element>
class Vector {
  public:
    // constructors
    Vector( unsigned int initialCapacity = 10, unsigned int capacityIncrement = 10 );
    Vector( const Vector& rhv );
    virtual ~Vector();

    // methods
    unsigned int capacity() const;
    boolean contains( const Element& elem ) const;
    const Element& firstElement() const;
    int indexOf( const Element& elem ) const;
    boolean isEmpty() const;
    const Element& lastElement() const;
    int lastIndexOf( const Element& elem ) const;
    unsigned int size() const;
    void copyInto( Element* array ) const;
    inline boolean add( const Element& obj ) { addElement(obj);  return true; }
    void addElement( const Element& obj );
    inline void clear() { removeAllElements(); }
    void ensureCapacity( unsigned int minCapacity );
    void removeAllElements();
    boolean removeElement( const Element& obj );
    void setSize( unsigned int newSize );
    void trimToSize();
    const Element& elementAt( unsigned int index ) const;
    void insertElementAt( const Element& obj, unsigned int index );
    const Element& remove( unsigned int index );
    void removeElementAt( unsigned int index );
    void setElementAt( const Element& obj, unsigned int index );
    inline const Element& get( unsigned int index ) const
      { return elementAt(index); }

    const Element& operator[]( unsigned int index ) const;
    Element& operator[]( unsigned int index );

  protected:
    unsigned int _size;
    unsigned int _capacity;
    unsigned int _increment;
    Element** _data;
  };

#include "WVector.cpp"

#endif
