/***************************************************************************

    supportware
    Copyright (C) 2001-2008 by c.holzheuer
    c.holzheuer@sourceworx.org

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

***************************************************************************/


#ifndef DDSTACK_H
#define DDSTACK_H

#include <ddbaseobject.h>
#include <deque>
#include <stdexcept>

using namespace std;


/// ddstack is a templateted implementation of stack.
/**

 */

template<class T>
class ddstack : public ddbaseobject
{

public:

	/**
		Default constructor.
	*/

	ddstack()
	{

	}

	/**
		Copy constructor.
	*/

	ddstack( const ddstack& src )
	{
		*this=src;
	}

	/**
		Assignment operator.
	*/

	ddstack& operator=( const ddstack& src )
	{
		_data = src._data;
		return *this;
	}

	/**
		Destructor.
	*/

	virtual ~ddstack()
	{

	}

	/**
		Returns the number of elements on the stack.
	*/

	size_t size() const
	{
		return _data.size();
	}

	/**
		Returns true for an empty stack.
	*/

	bool empty() const
	{
		return _data.empty();
	}

	/**
		Removes all elements of the stack
	*/

	void clear()
	{
		_data.clear();
	}

	/**
		Returns the top most element of the stack without removing it.
	*/

	T& top()
	{
		return _data.back();
	}

	/**
		Adds an element on top of the stack.
	*/

	void push( const T& elem )
	{
		_data.push_back( elem );
	}

	/**
		Returns the top most element of the stack and removes it.
	*/

	T pop()
	{
		T elem = _data.back();
		_data.pop_back();
		return elem;
	}

	/**
		Prints all elements of the stack.
	*/

	void dump()
	{		
		throw runtime_error( "ddstack::dump(): not implemented!" );
	}

protected:

	deque<T> _data;

};


#endif
