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

  1. /****************************************************************************
  2.     $Id: array.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 TLArray<T>.
  10.  
  11.     $Log: array.cpp $
  12.     Revision 501.0  1995/03/07 12:26:56  RON
  13.     Updated for TLX 5.01
  14.     Revision 1.6  1995/01/31 16:30:40  RON
  15.     Update for release 012
  16.     Added partial support for SunPro C++ compiler
  17.     Revision 1.5  1994/10/07  17:09:29  ron
  18.     Implemented Array<T>::SetLimits()
  19.  
  20.     Revision 1.4  1994/09/28  14:40:05  ron
  21.     Removed Macintosh-style #include references
  22.  
  23.     Revision 1.3  1994/09/27  20:27:06  ron
  24.     Changed path separator from / to \
  25.  
  26.     Revision 1.2  1994/09/26  15:28:37  ron
  27.     Changed include file references
  28.  
  29.     Revision 1.1  1994/08/16  18:15:22  ron
  30.     Initial revision
  31.  
  32. ****************************************************************************/
  33.  
  34. #ifndef _TLX_ARRAY_CPP
  35. #define _TLX_ARRAY_CPP
  36.  
  37. //----- Project headers
  38.  
  39. #ifndef _TLX_ARRAYS_H
  40. #include <tlx\501\arrays.h>
  41. #endif
  42. #ifndef _TLX_DEBUG_H
  43. #include <tlx\501\debug.h>
  44. #endif
  45.  
  46. #ifndef _TLX_VBASE_CPP
  47. #include <tlx\501\template\vbase.cpp>
  48. #endif
  49.  
  50. /*-------------------------------------------------------------------------*/
  51.     template<class T> TLArray<T>::TLArray(size_t sz)
  52.  
  53. /*  Constructor, also doubling as the default constructor. Creates a
  54.     0-based array of the specified size.
  55. ---------------------------------------------------------------------------*/
  56. : TLVBase<T>(sz)
  57. {
  58.     mLower = 0;
  59. }
  60.  
  61. /*-------------------------------------------------------------------------*/
  62.     template<class T> TLArray<T>::TLArray(index_t lower, index_t upper)
  63.  
  64. /*  Constructor creating an array with the given lower and upper index
  65.     bounds.
  66. ---------------------------------------------------------------------------*/
  67. : TLVBase<T>((size_t)(lower <= upper ? upper - lower + 1: 0))
  68. {
  69.     mLower = lower;
  70. }
  71.  
  72. /*-------------------------------------------------------------------------*/
  73.     template<class T> TLArray<T>::TLArray(const T &t)
  74.  
  75. /*  Constructor creating a 1-element array with index base 0.
  76. ---------------------------------------------------------------------------*/
  77. : TLVBase<T>(t)
  78. {
  79.     mLower = 0;
  80. }
  81.  
  82. /*-------------------------------------------------------------------------*/
  83.     template<class T> TLArray<T>::TLArray(const T *t, size_t sz)
  84.  
  85. /*  Constructor creating an array from a C-style vector of a given size.
  86.     The resulting array is 0-based.
  87. ---------------------------------------------------------------------------*/
  88. : TLVBase<T>(t, sz)
  89. {
  90.     mLower = 0;
  91. }
  92.  
  93. /*-------------------------------------------------------------------------*/
  94.     template<class T> TLArray<T> &TLArray<T>::operator =(const TLArray<T> &t)
  95.  
  96. /*  Overloading of assignment operator.
  97. ---------------------------------------------------------------------------*/
  98. {
  99.     if (this != &t)
  100.     {
  101.     TLVBase<T>::operator =(t);
  102.     mLower = t.mLower;
  103.     }
  104.     return *this;
  105. }
  106.  
  107. /*-------------------------------------------------------------------------*/
  108.     template<class T> void TLArray<T>::SetLimits(index_t aLower, index_t aUpper)
  109.  
  110. /*  Changes the limits of the array.
  111. ---------------------------------------------------------------------------*/
  112. {
  113.     SetMini(aLower);
  114.     TLX_ASSERT(aUpper - aLower + 1 >= 0);
  115.     Resize(aUpper - aLower + 1);
  116. }
  117.  
  118. /*-------------------------------------------------------------------------*/
  119.     template<class T> index_t TLArray<T>::SetMini(index_t base)
  120.  
  121. /*  Sets index base, returning the previous base.
  122. ---------------------------------------------------------------------------*/
  123. {
  124.     index_t low = mLower;
  125.     mLower = base;
  126.     return low;
  127. }
  128.  
  129. #endif    // _TLX_ARRAY_CPP
  130.