#ifndef __RWEP_MCNTN_H__
#define __RWEP_MCNTN_H__

/***************************************************************************
 *
 * ep_mcntn.h - RW_PMapCntnr<StdColl,RWColl,DataTypes>
 *   
 *     : pointer-based Key/Data interface components for STL Containers
 * 
 * $Id: ep_mcntn.h,v 7.17 1996/05/08 00:18:44 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: ep_mcntn.h,v $
 * Revision 7.17  1996/05/08 00:18:44  kyle
 * Added export pragma for Mac code fragments
 *
 * Revision 7.16  1996/02/18 01:40:45  griswolf
 * Replace tabs with spaces, per Rogue Wave standard.
 *
 * Revision 7.15  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.14  1995/12/20 23:19:20  kevinj
 * External template persistence using RW*Persistor.
 *
 * Revision 7.13  1995/12/15 10:23:55  jims
 * Work around 'no default args in function templates' problem
 *
 * Revision 7.12  1995/12/14 18:01:21  jims
 * saveOn, restoreFrom now global instead of member functions
 *
 * Revision 7.11  1995/12/12 00:03:06  jims
 * Add RWTExport
 *
 * Revision 7.10  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.9  1995/10/20 06:50:08  jims
 * include rw/ep_mcntn.cc for compile-time instantiation
 *
 * Revision 7.8  1995/09/05  21:42:02  jims
 * Change tlyrs.h to tlyrs.str
 *
 * Revision 7.7  1995/08/24  00:21:36  kevinj
 * Changed saveOn and restoreFrom to return bool.
 *
 * Revision 7.6  1995/08/14  06:11:08  jims
 * include rw/edefs.h, add forward declarations for RWFile, RWv[io]stream
 *
 * Revision 7.5  1995/08/12  00:23:12  kevinj
 * restoreFrom and saveOn for RWFile.
 *
 * Revision 7.4  1995/08/10  23:42:13  kevinj
 * Moved inline functions out of line.
 *
 * Revision 7.4  1995/08/10  23:42:13  kevinj
 * Moved inline functions out of line.
 *
 * Revision 7.3  1995/07/27  22:02:33  jims
 * Add header with file name, short description, $Id and $Log
 * 
 ****************************************************************************/

#include "rw/ep_cntnr.h"
#include "rw/epersist.h"
#include "rw/rwerr.h"
#include "rw/toolerr.h"
#include "rw/edefs.h"

class RWExport RWFile;
class RWExport RWvistream;
class RWExport RWvostream;

#ifdef RW_PRAGMA_EXPORT
#pragma export on
#endif

template <class StdColl, class RWColl, class Key, class T>
class RWTExport RW_PMapCntnr : public RW_PBase<StdColl,RWColl>
{
public:
  typedef RW_PBase<StdColl,RWColl> base_type;

  typedef StdColl::value_type        value_type;
  typedef StdColl::size_type         size_type;
  typedef StdColl::iterator          iterator;
  typedef StdColl::const_iterator    const_iterator;
  typedef StdColl::reference         reference;
  typedef StdColl::const_reference   const_reference;

  typedef Key*              value_type_key;
  typedef const Key*        const_value_key;
  typedef Key*&             reference_key;
  typedef const Key*const&  const_reference_key;

  typedef T*                value_type_data;
  typedef const T*          const_value_data;
  typedef T*&               reference_data;
  typedef const T*const&    const_reference_data;

  typedef rw_deref_pair_less<Key,T>    deref_less;
  typedef rw_deref_pair_equal<Key,T>   deref_equal;

  bool  operator==(const RWColl& rwc)   const
  { return entries() == rwc.entries() &&
      equal(begin(), end(), rwc.begin(), deref_equal()); }

  bool  operator<(const RWColl& rwc)   const
  { return lexicographical_compare(std().begin(), std().end(), rwc.begin(),
                                   rwc.end(), deref_less()); }

  bool  contains(const_value_key key) const {
    const_iterator iter = begin();
    while(iter != end()) {
      if(*((*iter).first) == *key) break;
      ++iter;
    }
    return iter != end();
  }

  bool  contains(bool(*fn)(value_type,void*),void* x) const
    { return base_type::contains(fn,x); }

  value_type nilValue() const { return value_type(0,0); }
  value_type find(const_reference key) const;
  value_type find(bool (*fn)(value_type,void*), void* x) const;

  StdColl::
  size_type     index(bool (*fn)(value_type, void*), void* x)
    { return base_type::index(fn,x); }

  StdColl::
  size_type     index(const_reference key) const;

  StdColl::
  size_type     occurrencesOf(const_value_key key) const {
    size_type ret = 0;
    const_iterator iter = begin();
    while(iter != end()) {
      if (*((*iter).first) == *key) break;
      ++iter;
    }
    while(iter != end()) {
      if(*((*iter).first) == *key) ++ret;
      ++iter;
    }
    return ret;
  }

  StdColl::
  size_type   occurrencesOf(bool (*fn)(value_type,void*),void* x) const
    { return base_type::occurrencesOf(fn,x);  }

};

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

#ifdef RW_PRAGMA_EXPORT
#pragma export off
#endif

#endif /* __RWEP_MCNTN_H__ */

