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

  1. /****************************************************************************
  2.     $Id: seqbase.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.     Imlementation of class TLSeqBase<T>.
  10.  
  11.     $Log: seqbase.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:50  RON
  15.     Update for release 012
  16.     Added partial support for SunPro C++ compiler
  17.     Revision 1.4  1994/09/28  14:42:11  ron
  18.     Removed Macintosh-style #include references
  19.  
  20.     Revision 1.3  1994/09/27  20:27:36  ron
  21.     Changed path separator from / to \
  22.  
  23.     Revision 1.2  1994/09/26  15:34:35  ron
  24.     Changed include file references
  25.     Renamed SetSize() to Resize()
  26.  
  27.     Revision 1.1  1994/08/16  18:15:32  ron
  28.     Initial revision
  29.  
  30. ****************************************************************************/
  31.  
  32. #ifndef _TLX_SEQBASE_CPP
  33. #define _TLX_SEQBASE_CPP
  34.  
  35. //----- Project headers
  36.  
  37. #ifndef _TLX_ARRAYS_H
  38. #include <tlx\501\arrays.h>
  39. #endif
  40. #ifndef _TLX_DEBUG_H
  41. #include <tlx\501\debug.h>
  42. #endif
  43. #ifndef _TLX_EXCEPT_H
  44. #include <tlx\501\except.h>
  45. #endif
  46.  
  47. #ifndef _TLX_VBASE_CPP
  48. #include <tlx\501\template\vbase.cpp>
  49. #endif
  50.  
  51. /*-------------------------------------------------------------------------*/
  52.     template<class T> TLSeqBase<T>::TLSeqBase(size_t size, size_t delta)
  53.  
  54. /*  Normal constructor for TLSeqBase<T>. It calls the TLVector<T>(size_t)
  55.     constructor to create a vector of the desired size, then it sets
  56.     mCount to 0 to indicate an empty sequence, and mDelta to the
  57.     delta parameter.
  58. ---------------------------------------------------------------------------*/
  59. : TLVBase<T>(size)
  60. {
  61.     mCount = 0;
  62.     mDelta = delta;
  63. }
  64.  
  65. /*-------------------------------------------------------------------------*/
  66.     template<class T> TLSeqBase<T>::TLSeqBase(const T &t)
  67.  
  68. /*  Constructor creating a single element sequence.
  69. ---------------------------------------------------------------------------*/
  70. : TLVBase<T>(t)
  71. {
  72.     mDelta = 0;
  73.     mCount = mSize;
  74. }
  75.  
  76. /*-------------------------------------------------------------------------*/
  77.     template<class T> TLSeqBase<T>::TLSeqBase(const T *tp, size_t sz)
  78.  
  79. /*  Constructor creating a sequence from a C-style vector of given size.
  80. ---------------------------------------------------------------------------*/
  81. : TLVBase<T>(tp, sz)
  82. {
  83.     mDelta = 0;
  84.     mCount = mSize;
  85. }
  86.  
  87. /*-------------------------------------------------------------------------*/
  88.     template<class T> void TLSeqBase<T>::CompactStorage()
  89.  
  90. /*  Adjusts the physical storage to fit the logical size of the sequence.
  91. ---------------------------------------------------------------------------*/
  92. {
  93.     Resize(Count());
  94. }
  95.  
  96. /*-------------------------------------------------------------------------*/
  97.     template<class T> void TLSeqBase<T>::Expand()
  98.  
  99. /*  Expands the storage for the sequence by mDelta elements. If mDelta is
  100.     0, or expansion fails otherwise, a TLXFull exception is thrown.
  101. ---------------------------------------------------------------------------*/
  102. {
  103.     if (mDelta < 1)
  104.     THROW(TLXFull(LOCUS));
  105.  
  106.     ExpandBy(mDelta);
  107. }
  108.  
  109. /*-------------------------------------------------------------------------*/
  110.     template<class T> TLSeqBase<T> &TLSeqBase<T>::operator =
  111.     (
  112.         const TLSeqBase<T> &s
  113.     )
  114.  
  115. /*  Overloading of assignment operator.
  116. ---------------------------------------------------------------------------*/
  117. {
  118.     if (this != &s)
  119.     {
  120.     TLVBase<T>::operator =(s);
  121.     mCount = s.mCount;
  122.     mDelta = s.mDelta;
  123.     }
  124.     return *this;
  125. }
  126.  
  127. /*-------------------------------------------------------------------------*/
  128.     template<class T> size_t TLSeqBase<T>::SetDelta(size_t dt)
  129.  
  130. /*  Sets the expansion parameter, returning its previous value.
  131. ---------------------------------------------------------------------------*/
  132. {
  133.     size_t del = mDelta;
  134.     mDelta = dt;
  135.     return del;
  136. }
  137.  
  138. #endif    // _TLX_SEQBASE_CPP
  139.  
  140.