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

  1. /****************************************************************************
  2.     $Id: ptrset.cpp 501.0 1995/03/07 12:27:00 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 TLPtrSet<T>.
  10.  
  11.     $Log: ptrset.cpp $
  12.     Revision 501.0  1995/03/07 12:27:00  RON
  13.     Updated for TLX 5.01
  14.     Revision 1.5  1995/01/31 16:30:46  RON
  15.     Update for release 012
  16.     Added partial support for SunPro C++ compiler
  17.     Revision 1.4  1994/10/06  17:51:23  ron
  18.     Changed #defined name
  19.  
  20.     Revision 1.3  1994/09/27  20:27:24  ron
  21.     Changed path separator from / to \
  22.  
  23.     Revision 1.2  1994/09/26  15:33:18  ron
  24.     Implemented iterators
  25.  
  26.     Revision 1.1  1994/08/16  18:15:28  ron
  27.     Initial revision
  28.  
  29. ****************************************************************************/
  30.  
  31. #ifndef _TLX_PTRSET_CPP
  32. #define _TLX_PTRSET_CPP
  33.  
  34. //----- Project headers
  35.  
  36. #ifndef _TLX_PTRARRAY_H
  37. #include <tlx\501\debug.h>
  38. #endif
  39. #ifndef _TLX_PTRARRAY_H
  40. #include <tlx\501\ptrarray.h>
  41. #endif
  42.  
  43. #ifndef _TLX_PTRITER_CPP
  44. #include <tlx\501\template\ptriter.cpp>
  45. #endif
  46.  
  47. /*-------------------------------------------------------------------------*/
  48.     template<class T> TLPtrSetIter<T>::TLPtrSetIter(TLPtrSet<T> &aSet)
  49.  
  50. /*  Constructor. Links to the given set.
  51. ---------------------------------------------------------------------------*/
  52. : mSet(aSet)
  53. {
  54. }
  55.  
  56. /*-------------------------------------------------------------------------*/
  57.     template<class T> size_t TLPtrSetIter<T>::Count() const
  58.  
  59. /*  Returns the number of items in the associated collection
  60. ---------------------------------------------------------------------------*/
  61. {
  62.     return mSet.Count();
  63. }
  64.  
  65. /*-------------------------------------------------------------------------*/
  66.     template<class T> bool TLPtrSetIter<T>::FirstPos()
  67.  
  68. /*  Sets the iterator to the first position (if any), returning true
  69.     on success.
  70. ---------------------------------------------------------------------------*/
  71. {
  72.     mPos = mSet.Mini();
  73.     return mPos <= mSet.Maxi();
  74. }
  75.  
  76. /*-------------------------------------------------------------------------*/
  77.     template<class T> bool TLPtrSetIter<T>::NextPos()
  78.  
  79. /*  Advances the iterator to the next position (if any), returning true
  80.     on success.
  81. ---------------------------------------------------------------------------*/
  82. {
  83.     if (mPos < mSet.Maxi())    // Test first to avoid integer overflow
  84.     {
  85.     mPos++;
  86.     return true;
  87.     }
  88.     else
  89.     return false;
  90. }
  91.  
  92. /*-------------------------------------------------------------------------*/
  93.     template<class T> T *&TLPtrSetIter<T>::Peek() const
  94.  
  95. /*  Returns the current iteration element.
  96. ---------------------------------------------------------------------------*/
  97. {
  98.     TLX_ASSERT(IsValid());
  99.     return mSet.PeekAt(mPos);
  100. }
  101.  
  102. /*-------------------------------------------------------------------------*/
  103.     template<class T> TLPtrSetIterConst<T>::TLPtrSetIterConst
  104.         (TLPtrSet<T> &aSet)
  105.  
  106. /*  Constructor. Links to the given set.
  107. ---------------------------------------------------------------------------*/
  108. : mSet(aSet)
  109. {
  110. }
  111.  
  112. /*-------------------------------------------------------------------------*/
  113.     template<class T> size_t TLPtrSetIterConst<T>::Count() const
  114.  
  115. /*  Returns the number of items in the associated collection
  116. ---------------------------------------------------------------------------*/
  117. {
  118.     return mSet.Count();
  119. }
  120.  
  121. /*-------------------------------------------------------------------------*/
  122.     template<class T> bool TLPtrSetIterConst<T>::FirstPos()
  123.  
  124. /*  Sets the iterator to the first position (if any), returning true
  125.     on success.
  126. ---------------------------------------------------------------------------*/
  127. {
  128.     mPos = mSet.Mini();
  129.     return mPos <= mSet.Maxi();
  130. }
  131.  
  132. /*-------------------------------------------------------------------------*/
  133.     template<class T> bool TLPtrSetIterConst<T>::NextPos()
  134.  
  135. /*  Advances the iterator to the next position (if any), returning true
  136.     on success.
  137. ---------------------------------------------------------------------------*/
  138. {
  139.     if (mPos < mSet.Maxi())    // Test first to avoid integer overflow
  140.     {
  141.     mPos++;
  142.     return true;
  143.     }
  144.     else
  145.     return false;
  146. }
  147.  
  148. /*-------------------------------------------------------------------------*/
  149.     template<class T> T *TLPtrSetIterConst<T>::Peek() const
  150.  
  151. /*  Returns the current iteration element.
  152. ---------------------------------------------------------------------------*/
  153. {
  154.     TLX_ASSERT(IsValid());
  155.     return mSet.PeekAt(mPos);
  156. }
  157.  
  158. /*-------------------------------------------------------------------------*/
  159.     template<class T> TLPtrSet<T>::TLPtrSet(size_t aSize, size_t aDelta)
  160.  
  161. /*  Constructor to create set of specified size; also doubles as default
  162.     constructor.
  163. ---------------------------------------------------------------------------*/
  164. : TLVPSet(aSize, aDelta)
  165. {
  166.     SetDelete(DeleteT);
  167. }
  168.  
  169. /*-------------------------------------------------------------------------*/
  170.     template<class T> TLPtrSet<T>::TLPtrSet(T *aPtr)
  171.  
  172. /*  Constructor that initializes a set of 1 element.
  173. ---------------------------------------------------------------------------*/
  174. : TLVPSet(aPtr)
  175. {
  176.     SetDelete(DeleteT);
  177. }
  178.  
  179. /*-------------------------------------------------------------------------*/
  180.     template<class T> TLPtrSet<T>::TLPtrSet(const TLPtrSet<T> &aSet)
  181.  
  182. /*  Copy constructor.
  183. ---------------------------------------------------------------------------*/
  184. : TLVPSet(aSet)
  185. {
  186.     SetDelete(DeleteT);
  187. }
  188.  
  189. /*-------------------------------------------------------------------------*/
  190.     template<class T> void TLPtrSet<T>::DeleteT(void *aPtr)
  191.  
  192. /*  Deletes pointed to object, after the appropriate typecast.
  193. ---------------------------------------------------------------------------*/
  194. {
  195.     delete (T *)aPtr;
  196. }
  197.  
  198. #endif    // _TLX_PTRSET_CPP
  199.