/*
 *  ZThreads, a platform-independant, multithreading and 
 *  synchroniation library
 *
 *  Copyright (C) 2000-2002, Eric Crahen, See LGPL.TXT for details
 *
 *  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 *  SUNY @ Buffalo, hereby disclaims all copyright interest in the
 *  ZThreads library written by Eric Crahen
 */

#ifndef __ZTQUEUE_H__
#define __ZTQUEUE_H__

#include "zthread/ZThread.h"
#include "zthread/Cancelable.h"
#include "zthread/SynchronizationExceptions.h"

namespace ZThread {

/**
 * @class Queue
 *
 * @author Eric Crahen <crahen@cse.buffalo.edu>
 * @date <2002-02-24T09:28:16-0500>
 * @version 1.3.0
 *
 * A Queue defines an important common interface for collections. It
 * can be implemented using different forms of protection and 
 * synchronization.
 */

template <class T>
class ZTHREAD_API Queue : public Cancelable {
public:

  /**
   * Add a new object to this Queue
   *
   * @param T object to add
   * 
   * @exception InterruptedException
   * @exception CancelationException - the queue has 
   * been canceled.
   */
  virtual void add(T)
    throw(Synchronization_Exception) = 0;

  /**
   * Get an object from this Queue
   *
   * @return T next available object
   * 
   * @exception InterruptedException 
   * @exception CancelationException - the queue is empty and has 
   * been canceled.
   */
  virtual T next()
    throw(Synchronization_Exception) = 0;

  /**
   * Get an object from this Queue within a given amount of time
   * 
   * @param unsigned long time limit 
   *
   * @return T next available object
   * 
   * @exception InterruptedException
   * @exception CancelationException - the queue is empty and has 
   * been canceled.
   * @exception Timeout_Exception - thrown if the given amount
   * of time has expired and the queue could not return an item
   */
  virtual T next(unsigned long)
    throw(Synchronization_Exception) = 0;


  /**
   * Cancel this queue. No more objects can be added to it
   *
   * @exception InterruptedException 
   *
   * @post - The next() method will continue to return objects until 
   * the queue has been emptied. After the queue is emptied, further 
   * calls to next() will throw CancelationException
   *
   * The add() method will begin to throw CancelationException and no
   * item will be accepted by this queue
   */
  virtual void cancel()
    throw(Synchronization_Exception) = 0;


  /**
   * Test this queue to see if it is empty. This method may or may not
   * block the caller, it is completely up to the implementation to decide
   * weather or not it is appropriate to block the caller.
   *
   * @return boolean - true if empty  
   * @exception InterruptedException 
   */
  virtual bool empty()
    throw(Synchronization_Exception) = 0;

  };

};


#endif
