/* Vector.h, version 1.0
 *
 * Defines a Vector class that acts like a vector<string>.  This code
 * is NOT suitable for use in an actual C++ program.  We'll be building
 * it up toward a more robust, complete version over the next two weeks.
 */

#ifndef Vector_Included // Note the include guard to prevent problems with multiple inclusions.
#define Vector_Included

#include <string>
using namespace std;

class Vector
{
public:
	/* Constructor: Vector()
	 * Usage: Vector v;
	 * ------------------------------------------
	 * Constructs an empty Vector.
	 */
	Vector();

	/* Destructor: ~Vector()
	 * Usage: (implicit)
	 * ------------------------------------------
	 * Cleans up the resources used by this Vector.
	 */
	~Vector();
	
	/* string& at(size_t index);
	 * Usage: cout << v.at(0) << endl;
	 * ------------------------------------------
	 * Returns the element at the specified position
	 * in the Vector.  If the element is out of bounds,
	 * the behavior is undefined.
	 */
	string& at(size_t index);

	/* size_t size();
	 * bool   empty();
	 * Usages: for (size_t i = 0; i < v.size(); ++i)
	 *         if (v.empty())
	 * -------------------------------------------
	 * size returns the number of elements in the Vector.
	 * empty returns whether the Vector has no elements.
	 */
	size_t size();
	bool   empty();

	/* Type: iterator
	 * -------------------------------------------
	 * An STL-compatible iterator type that can
	 * traverse the elements of the Vector.
	 */
	typedef string* iterator;

	/* iterator begin();
	 * iterator end();
	 * Usages: for (Vector::iterator itr = v.begin(); itr != v.end(); ++itr);
	 * -------------------------------------------
	 * Returns iterators to the beginning and one-past-
	 * the-end of the Vector.
	 */
	iterator begin();
	iterator end();

	/* iterator insert(iterator where, string value);
	 * Usage: v.insert(v.begin(), "Hi!")
	 * -------------------------------------------
	 * Inserts the specified value at the location indicated
	 * by where.  All outstanding iterators are invalidated.
	 * The function then returns an iterator to the value.
	 */
	iterator insert(iterator where, string value);

	/* iterator erase(iterator where);
	 * Usage: v.erase(v.begin())
	 * -------------------------------------------
	 * Deletes the specified value from the location indicated
	 * by where.  All outstanding iterators after where are
	 * invalidated.  The function then returns an iterator
	 * to the element following the one that was erased.
	 */
	iterator erase(iterator where);

	/* void push_back(string value);
	 * Usage: v.push_back("137");
	 * -------------------------------------------
	 * Appends the specified value to the Vector.
	 */
	void push_back(string str);

	/* void pop_back();
	 * Usage: v.pop_back();
	 * -------------------------------------------
	 * Removes the last element of the Vector.
	 */
	void pop_back();

	/* size_t indexOf();
	 * Usage: cout << v.indexOf("137") << endl;
	 * -------------------------------------------
	 * Returns the index of the string in the Vector
	 * or a sentinel value otherwise.
	 */
	size_t indexOf(string str);

	/* size_t capacity();
	 * Usage: cout << v.capacity() << endl;
	 * -------------------------------------------
	 * Returns how many elements can be stored in the
	 * Vector before a reallocation will occur.
	 */
	size_t capacity();

	/* void reserve(size_t howMuch);
	 * Usage: v.reserve(137);
	 * --------------------------------------------
	 * Guarantees that space for at least howMuch
	 * elements is allocated in the Vector.  Use this
	 * if the estimated size of the Vector is known.
	 */
	void reserve(size_t howMuch);

private:
	string* elems;          // Pointer to dynamically-allocated array of elements.
	size_t logicalLength;   // Number of elements stored in the Vector.
	size_t allocatedLength; // Amount of space allocated by the Vector.
};

#endif





