/*
 * Template definitions for RWTPtrSortedVector<TP>
 *
 * $Id: tpsrtvec.cc,v 7.11 1996/03/16 19:13:53 kevinj 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: tpsrtvec.cc,v $
 * Revision 7.11  1996/03/16 19:13:53  kevinj
 * Changed ctor from T** to T*const*.
 *
 * Revision 7.10  1996/02/19 12:34:12  jims
 * Port to Stdlib 1.2
 *
 * Revision 7.9  1996/02/12 21:03:06  kevinj
 * Switched stream and class args in rw*Guts.
 *
 * Revision 7.8  1996/02/07 06:04:13  jims
 * Remove devnotes (#2555)
 *
 * Revision 7.7  1996/01/25 01:51:32  kevinj
 * Improved ETP macros.
 *
 * Revision 7.6  1996/01/15 17:56:06  kevinj
 * Fixed bug in ETP.
 *
 * Revision 7.5  1996/01/14 00:10:18  kevinj
 * Simple External Template Persistence (ETP).
 *
 * Revision 7.4  1995/09/17 07:53:04  jims
 * Remove "pointless comparison" from postcondition
 * Check first for less than 2 elements before checking if sorted
 *
 * Revision 7.3  1995/09/05  20:55:29  jims
 * Use new copyright macro
 *
 * Revision 7.2  1995/06/26  22:31:22  griswolf
 * Scopus 1351: Partition RWPOSTCONDITION into two parts for method
 * insert(). Also add isSorted() RWPRECONDITION to bsearch().
 *
 * Revision 7.1  1994/10/16  03:18:52  josh
 * Merged 6.1 and 7.0 development trees
 *
 * Revision 6.2  1994/07/12  20:04:35  vriezen
 * Updated Copyright.
 *
 * Revision 6.1  1994/04/15  19:48:03  vriezen
 * Move all files to 6.1
 *
 * Revision 1.6  1994/01/12  03:09:17  jims
 * Add constness to T* parameters where appropriate
 *
 * Revision 1.5  1993/09/10  02:56:53  keffer
 * Switched RCS idents to avoid spurious diffs
 *
 * Revision 1.4  1993/07/08  03:42:18  keffer
 * Corrected logic error in RWDEBUG version of bsearch().
 *
 * Revision 1.3  1993/04/09  19:35:45  keffer
 * Indexing is now done using size_t
 *
 * Revision 1.1  1993/01/29  03:06:18  keffer
 * Initial revision
 *
 *
 ***************************************************************************
 */


#include "rw/epersist.h"

template <class T, class C>
RWTPtrSortedVector<T,C>::RWTPtrSortedVector(T*const* first, T*const* last) {
  container_type::iterator it = impl_.begin();
  while(first != last)
    it = insertSorted(it,*first++);
}


RWDEFINE_PERSISTABLE_TEMPLATE_2(RWTPtrSortedVector)

template <class T, class C, class S>
void rwSaveGuts(S& str, const RWTPtrSortedVector<T,C>& c)
{
  str << c.entries();
  for (size_t i=0; i < c.entries(); ++i)
    str << *c[i];
}

template <class T, class C, class S>
void rwRestoreGuts(S& str, RWTPtrSortedVector<T,C>& c)
{
  typedef RWTPtrSortedVector<T,C>::size_type size_type;
  size_type count;
  str >> count;
  c.clear();
  for (size_type i=0; i < count; ++i) {
    T* p;
    str >> p;
    c.insert(p);
  }
}

