#ifndef __RWTPDEQUE_H__
#define __RWTPDEQUE_H__

/***************************************************************************
 *
 * tpdeque.h - RWTPtrDeque<T>
 *   
 *     : pointer-based double-ended queue wrapper for STL deque 
 * 
 * $Id: tpdeque.h,v 7.19 1996/05/07 21:04:37 kyle Exp $
 *
 * (c) Copyright 1989 - 1996 Rogue Wave Software, Inc.
 * ALL RIGHTS RESERVED
 *
 * The software and information contained herein are proprietary to, and
 * comprise valuable trade secrets of, Rogue Wave Software, Inc., which
 * intends to preserve as trade secrets such software and information.
 * This software is furnished pursuant to a written license agreement and
 * may be used, copied, transmitted, and stored only in accordance with
 * the terms of such license and with the inclusion of the above copyright
 * notice.  This software and information or any other copies thereof may
 * not be provided or otherwise made available to any other person.
 *
 * Notwithstanding any other lease or license that may pertain to, or
 * accompany the delivery of, this computer software and information, the
 * rights of the Government regarding its use, reproduction and disclosure
 * are as set forth in Section 52.227-19 of the FARS Computer
 * Software-Restricted Rights clause.
 * 
 * Use, duplication, or disclosure by the Government is subject to
 * restrictions as set forth in subparagraph (c)(1)(ii) of the Rights in
 * Technical Data and Computer Software clause at DFARS 252.227-7013.
 * Contractor/Manufacturer is Rogue Wave Software, Inc.,
 * P.O. Box 2328, Corvallis, Oregon 97339.
 *
 * This computer software and information is distributed with "restricted
 * rights."  Use, duplication or disclosure is subject to restrictions as
 * set forth in NASA FAR SUP 18-52.227-79 (April 1985) "Commercial
 * Computer Software-Restricted Rights (April 1985)."  If the Clause at
 * 18-52.227-74 "Rights in Data General" is specified in the contract,
 * then the "Alternate III" clause applies.
 *
 ****************************************************************************
 * 
 * $Log: tpdeque.h,v $
 * Revision 7.19  1996/05/07 21:04:37  kyle
 * Added export pragma for Mac code fragments
 *
 * Revision 7.18  1996/03/16 13:10:38  jims
 * Fix argument names in op= and ctors
 *
 * Revision 7.17  1996/02/19 12:34:12  jims
 * Port to Stdlib 1.2
 *
 * Revision 7.16  1996/02/18 01:47:25  griswolf
 * Replace tabs with spaces, per Rogue Wave standard.
 *
 * Revision 7.15  1996/02/13 12:14:17  jims
 * Small mods to the interface
 *
 * Revision 7.14  1996/01/25 01:51:32  kevinj
 * Improved ETP macros.
 *
 * Revision 7.13  1996/01/24 21:07:41  jims
 * Simplify implementation of otis-stl ptr-based collections
 * by using container<T*> impls instead of container<void*>
 *
 * Revision 7.12  1996/01/23 07:35:03  jims
 * Change ctor args from T** to T*const*
 *
 * Revision 7.11  1996/01/11 01:33:10  kevinj
 * RWFile external template persistence.
 *
 * Revision 7.10  1996/01/10 21:09:42  kevinj
 * RWDEFINE_PERSISTABLE_CONTAINER and RWDECLARE_PERSISTABLE_CONTAINER.
 *
 * Revision 7.9  1996/01/09 22:26:03  kevinj
 * Simpler external template persistence.
 *
 * Revision 7.8  1995/12/20 23:19:20  kevinj
 * External template persistence using RW*Persistor.
 *
 * Revision 7.7  1995/12/15 10:17:40  jims
 * Remove friend declaration for restoreFrom_ptr
 * Unify conditional-compilation constructors
 *
 * Revision 7.6  1995/12/14 18:01:21  jims
 * saveOn, restoreFrom now global instead of member functions
 *
 * Revision 7.5  1995/12/13 00:22:58  jims
 * Remove member functions saveOn and restoreFrom (now global)
 *
 * Revision 7.4  1995/12/12 00:03:06  jims
 * Add RWTExport
 *
 * Revision 7.3  1995/12/11 22:30:41  jims
 * Remove 'Sca' from interior class names
 * Add 'rw_' to global helper classes
 * Change 'muterator' to 'filterator'
 *
 * Revision 7.2  1995/12/01 18:09:30  jims
 * Rename to 6.1 style name
 *
 * Revision 7.1  1995/11/29 18:27:27  jims
 * Move to revision 7.1
 *
 * Revision 7.15  1995/10/20  06:46:20  jims
 * Port to msvc 4.0: don't use access adjustment for typedefs
 *
 * Revision 7.14  1995/09/25  11:09:35  jims
 * Add NO_CONST_INST version of T**,T** ctor
 *
 * Revision 7.13  1995/09/18  17:40:23  griswolf
 * Add method sort().
 *
 * Revision 7.12  1995/09/15  21:14:32  griswolf
 * Remove un-needed destructor, leaving it commented as documentation.
 *
 * Revision 7.11  1995/09/05  21:42:32  jims
 * Change tlyrs.h to tlyrs.str
 *
 * Revision 7.10  1995/08/18  16:45:33  kevinj
 * Removed edefs.h
 *
 * Revision 7.9  1995/07/27  22:02:33  jims
 * Add header with file name, short description, $Id and $Log
 *
 ****************************************************************************/

#include "rw/compiler.h"

#ifdef RW_NO_STL

#error RWTPtrDeque not available if RW_NO_STL is defined for your compiler

#endif

#include <deque>
#include "rw/ep_seq.h"

#ifdef RW_PRAGMA_EXPORT
#pragma export on
#endif

template <class T>
class RWTExport RWTPtrDeque : private RW_PSeq<deque<T*,allocator>, RWTPtrDeque<T>, T> {
public:
// typedefs
  typedef deque<T*,allocator>                       container_type;
  typedef RWTPtrDeque<T>                            this_type;
  typedef RW_PSeq<container_type,
                  RWTPtrDeque<T>, T> base_type;

  typedef container_type::iterator          iterator;
  typedef container_type::const_iterator    const_iterator;
  typedef container_type::size_type         size_type;
  typedef container_type::difference_type   difference_type;
  typedef container_type::value_type        value_type;
  typedef container_type::reference         reference;
  typedef container_type::const_reference   const_reference;

// STL-level access
  const container_type&  std() const { return impl_; }
  container_type&  std() { return impl_; }

// inherited interface components
  base_type::append;
  base_type::apply;
  base_type::at;
  base_type::begin;
  base_type::clear;
  base_type::contains;
  base_type::end;
  base_type::entries;
  base_type::find;
  base_type::first;
  base_type::index;
  base_type::insert;
  base_type::insertAt;
  base_type::isEmpty;
  base_type::minElement;
  base_type::maxElement;
  base_type::npos;
  base_type::occurrencesOf;
  base_type::operator();
  base_type::operator<;
  base_type::operator==;
  base_type::operator[];
  base_type::prepend;
  base_type::remove;
  base_type::removeAll;
  base_type::removeAt;
  base_type::removeFirst;
  base_type::replaceAll;

  void          sort()
    { ::sort(begin(),end(),rw_deref_compare<less<T>,T>()); }

  void  clearAndDestroy()
    { while(entries()) { delete *(begin()); impl_.pop_front();} }
                          
// additional interface components
  T*&       last()       { return impl_.back(); }
  T*const&  last() const { return impl_.back(); }

  void  pushBack(T* t)   { impl_.push_back(t); }
  void  pushFront(T* t)  { impl_.push_front(t); }
  T*    removeLast()     { T* ret = impl_.back();
                           impl_.pop_back();
                           return ret; }
  T*    popBack()        { return removeLast(); }
  T*    popFront()       { return removeFirst(); }

// assignment operators
  RWTPtrDeque<T>&   operator=(const RWTPtrDeque<T>& rwdeq)
    { impl_ = rwdeq.impl_; return *this; }
  RWTPtrDeque<T>&   operator=(const container_type& stddeq)
    { impl_ = stddeq; return *this; }

// constructors
  RWTPtrDeque()                                : impl_()            { }
  RWTPtrDeque(const container_type& deq)       : impl_(deq)         { }
  RWTPtrDeque(const this_type& rwdeq)          : impl_(rwdeq.impl_) { }
  RWTPtrDeque(size_type n, T* p)               : impl_(n, p)        { }
  RWTPtrDeque(T*const* first, T*const* last)   : impl_(first,last)  { }

//  ~RWTPtrDeque(); // handled by compiler-generated destructor

private:
  container_type impl_;         
  friend class  RW_PBase<container_type, this_type>;
};

RWDECLARE_PERSISTABLE_TEMPLATE(RWTPtrDeque)

#ifdef RW_COMPILE_INSTANTIATE
# include "rw/tpdeque.cc"
#endif

#ifdef RW_PRAGMA_EXPORT
#pragma export off
#endif

#endif /* __RWTPDEQUE_H__ */
