home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tlx501.zip / TEMPLATE / DICTION.CPP < prev    next >
C/C++ Source or Header  |  1996-01-05  |  3KB  |  84 lines

  1. /****************************************************************************
  2.     $Id: diction.cpp 501.0 1995/03/07 12:26:56 RON Exp $
  3.  
  4.     Copyright (c) 1991-95 Tarma Software Research. All rights reserved.
  5.  
  6.     Project:    Tarma Library for C++ V5.0
  7.     Author:    Ron van der Wal
  8.  
  9.     Implementation of class TLDictionary<K,V>.
  10.  
  11.     $Log: diction.cpp $
  12.     Revision 501.0  1995/03/07 12:26:56  RON
  13.     Updated for TLX 5.01
  14.     Revision 1.2  1995/01/31 16:30:42  RON
  15.     Update for release 012
  16.     Added partial support for SunPro C++ compiler
  17.     Revision 1.1  1994/10/12  10:10:07  ron
  18.     Initial revision
  19.  
  20. ****************************************************************************/
  21.  
  22. #ifndef _TLX_DICTION_CPP
  23. #define _TLX_DICTION_CPP
  24.  
  25. #ifndef _TLX_ASSOC_H
  26. #include <tlx\501\assoc.h>
  27. #endif
  28.  
  29. #ifndef _TLX_VALITER_CPP
  30. #include <tlx\501\template\valiter.cpp>
  31. #endif
  32.  
  33. //-----    TLDictionary<K,V>
  34.  
  35. template<class K, class V>
  36. TLDictionary<K,V>::TLDictionary(size_t size, size_t delta)
  37.     : mKeys(size, delta), mValues(size, delta) {}
  38.  
  39. template<class K, class V> size_t TLDictionary<K,V>::Count() const
  40.     { return mKeys.Count(); }
  41.  
  42. template<class K, class V> bool TLDictionary<K,V>::Contains(const K &key) const
  43.     { return mKeys.Contains(key); }
  44.  
  45. template<class K, class V>
  46. void TLDictionary<K,V>::Insert(const K &key, const V &value)
  47.     { mKeys.Append(key); mValues.Append(value); }
  48.  
  49. template<class K, class V> void TLDictionary<K,V>::RemoveAll()
  50.     { mKeys.RemoveAll(); mValues.RemoveAll(); }
  51.  
  52. template<class K, class V> V &TLDictionary<K,V>::operator [](const K &key)
  53.     { return mValues[mKeys.IndexOf(key)]; }
  54.  
  55. template<class K, class V>
  56. const V &TLDictionary<K,V>::operator [](const K &k) const
  57.     { return mValues[mKeys.IndexOf(k)]; }
  58.  
  59. //-----    TLDictIter<K,V>
  60.  
  61. template<class K, class V>
  62. TLDictIter<K,V>::TLDictIter(TLDictionary<K,V> &aDict)
  63.     : mDict(aDict) { mPos = 0; }
  64.  
  65. template<class K, class V> K &TLDictIter<K,V>::PeekKey() const
  66.     { return mDict.mKeys[mPos]; }
  67.  
  68. template<class K, class V> V &TLDictIter<K,V>::Peek() const
  69.     { return mDict.mValues[mPos]; }
  70.  
  71. template<class K, class V> size_t TLDictIter<K,V>::Count() const
  72.     { return mDict.Count(); }
  73.  
  74. template<class K, class V> bool TLDictIter<K,V>::Contains(V &aValue)
  75.     { return mDict.mValues.Contains(aValue); }
  76.  
  77. template<class K, class V> bool TLDictIter<K,V>::FirstPos()
  78.     { mPos = mDict.mKeys.Mini(); return mPos <= mDict.mKeys.Maxi(); }
  79.  
  80. template<class K, class V> bool TLDictIter<K,V>::NextPos()
  81.     { return ++mPos <= mDict.mKeys.Maxi(); }
  82.  
  83. #endif    // _TLX_DICTION_CPP
  84.