home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 6.ddi / MWHC.006 / F1 < prev    next >
Encoding:
Text File  |  1992-06-07  |  8.4 KB  |  263 lines

  1. #ifndef __RWGVECTOR_H__
  2. #define __RWGVECTOR_H__
  3. pragma push_align_members(64);
  4.  
  5. /*
  6.  * <generic.h> style macro for a generic vector.
  7.  *
  8.  * $Header:   E:/vcs/rw/gvector.h_v   1.4   18 Mar 1992 11:27:52   KEFFER  $
  9.  *
  10.  ****************************************************************************
  11.  *
  12.  * Rogue Wave 
  13.  * P.O. Box 2328
  14.  * Corvallis, OR 97339
  15.  * Voice: (503) 754-3010    FAX: (503) 757-6650
  16.  *
  17.  * Copyright (C) 1989, 1990, 1991. This software is subject to copyright 
  18.  * protection under the laws of the United States and other countries.
  19.  *
  20.  ***************************************************************************
  21.  *
  22.  * $Log:   E:/vcs/rw/gvector.h_v  $
  23.  * 
  24.  *    Rev 1.4   18 Mar 1992 11:27:52   KEFFER
  25.  * Implementation is now V2.1 aware.
  26.  * 
  27.  *    Rev 1.3   18 Feb 1992 19:23:04   KEFFER
  28.  * Now includes "rw/generic.h".
  29.  * Class tag is now RWExport instead of huge.
  30.  * 
  31.  *    Rev 1.2   28 Oct 1991 09:08:16   keffer
  32.  * Changed inclusions to <rw/xxx.h>
  33.  * 
  34.  *    Rev 1.1   09 Oct 1991 18:34:38   keffer
  35.  * Ported to Zortech V3.0
  36.  * 
  37.  *    Rev 1.0   28 Jul 1991 08:11:24   keffer
  38.  * Tools.h++ V4.0.5 PVCS baseline version
  39.  *
  40.  */
  41.  
  42. #include "rw/generic.h"
  43.  
  44. #define GVector(val) name2(val,GVector)
  45.  
  46. /************************************************
  47.  ************************************************
  48.  *                        *
  49.  *        GVector declaration        *
  50.  *                        *
  51.  ************************************************
  52.  ************************************************/
  53.  
  54. #ifdef CONST_OVERLOADS
  55.  
  56. #  ifdef CPPV21    /* V2.1 compliant does not allow delete [npts] syntax; V2.0 requires it! */
  57.  
  58. #define GVectordeclare(val)                            \
  59. GPT set_handler(GVector,val,GPT);                        \
  60. extern GPT errorhandler(GVector,val);                        \
  61. class RWExport GVector(val) {                            \
  62. protected:                                    \
  63.   unsigned    npts;                                \
  64.   val*        array;                                \
  65. public:                                        \
  66.   GVector(val)()                                \
  67.     {npts = 0; array = 0;}                            \
  68.   GVector(val)(unsigned n)                            \
  69.     {npts = n; array = new val[npts];}                        \
  70.   GVector(val)(unsigned n, val ival);                        \
  71.   ~GVector(val)()    { delete[] array; }                    \
  72.   GVector(val)(const GVector(val)&);                        \
  73.   GVector(val)&        operator=(const GVector(val)&);                \
  74.   const val*        data() const {return array;}                \
  75.   unsigned        length() const { return npts; }                \
  76.   void            resize(unsigned);                    \
  77.   val&            operator()(int i)       { return array[i]; }        \
  78.   val            operator()(int i) const { return array[i]; }        \
  79.   val&            operator[](int i)                    \
  80.   { if (i<0 || i>=npts) callerror(GVector,val,1,"GVector index out of range.");    \
  81.     return array[i]; }                                \
  82.   val            operator[](int i) const                    \
  83.   { if (i<0 || i>=npts) callerror(GVector,val,1,"GVector index out of range.");    \
  84.     return array[i]; }                                \
  85. };
  86.  
  87. #  else /* V2.0 compliant */
  88.  
  89. #define GVectordeclare(val)                            \
  90. GPT set_handler(GVector,val,GPT);                        \
  91. extern GPT errorhandler(GVector,val);                        \
  92. class RWExport GVector(val) {                            \
  93. protected:                                    \
  94.   unsigned    npts;                                \
  95.   val*        array;                                \
  96. public:                                        \
  97.   GVector(val)()                                \
  98.     {npts = 0; array = 0;}                            \
  99.   GVector(val)(unsigned n)                            \
  100.     {npts = n; array = new val[npts];}                        \
  101.   GVector(val)(unsigned n, val ival);                        \
  102.   ~GVector(val)()    { delete[npts] array; }                    \
  103.   GVector(val)(const GVector(val)&);                        \
  104.   GVector(val)&        operator=(const GVector(val)&);                \
  105.   const val*        data() const {return array;}                \
  106.   unsigned        length() const { return npts; }                \
  107.   void            resize(unsigned);                    \
  108.   val&            operator()(int i)       { return array[i]; }        \
  109.   val            operator()(int i) const { return array[i]; }        \
  110.   val&            operator[](int i)                    \
  111.   { if (i<0 || i>=npts) callerror(GVector,val,1,"GVector index out of range.");    \
  112.     return array[i]; }                                \
  113.   val            operator[](int i) const                    \
  114.   { if (i<0 || i>=npts) callerror(GVector,val,1,"GVector index out of range.");    \
  115.     return array[i]; }                                \
  116. };
  117. #  endif /* CPPV21 */
  118.  
  119. #else /* not CONST_OVERLOADS */
  120.  
  121. #define GVectordeclare(val)                            \
  122. GPT set_handler(GVector,val,GPT);                        \
  123. extern GPT errorhandler(GVector,val);                        \
  124. class RWExport GVector(val) {                            \
  125. protected:                                    \
  126.   unsigned    npts;                                \
  127.   val*        array;                                \
  128. public:                                        \
  129.   GVector(val)()                                \
  130.     {npts = 0; array = 0;}                            \
  131.   GVector(val)(unsigned n)                            \
  132.     {npts = n; array = new val[npts];}                        \
  133.   GVector(val)(unsigned n, val val);                        \
  134.   ~GVector(val)()    { delete[npts] array; }                    \
  135.   GVector(val)(const GVector(val)&);                        \
  136.   GVector(val)&        operator=(const GVector(val)&);                \
  137.   const val*        data() const {return array;}                \
  138.   unsigned        length() const { return npts; }                \
  139.   void            resize(unsigned);                    \
  140.   val&            operator()(int i) { return array[i]; }            \
  141.   val&            operator[](int i)                    \
  142.   { if (i<0 || i>=npts) callerror(GVector,val,1,"GVector index out of range.");    \
  143.     return array[i]; }                                \
  144. };
  145.  
  146. #endif /* CONST_OVERLOADS */
  147.  
  148.  
  149. /************************************************
  150.  ************************************************
  151.  *                        *
  152.  *        GVector implementation        *
  153.  *                        *
  154.  ************************************************
  155.  ************************************************/
  156.  
  157. #ifdef CPPV21
  158.  
  159. #define GVectorimplement(val)                            \
  160. GPT errorhandler(GVector,val) = genericerror;                    \
  161. GVector(val)::GVector(val)(unsigned n, val ival)                \
  162. {                                        \
  163.   register unsigned i = npts = n;                        \
  164.   register val* dst = array = new val[i];                    \
  165.   while(i--) *dst++ = ival;                            \
  166. }                                        \
  167.                                         \
  168. GVector(val)::GVector(val)(const GVector(val)& a)                \
  169. {                                        \
  170.   register unsigned i= npts = a.npts;                        \
  171.   register val* dst = array = new val[i];                    \
  172.   register val* src = a.array;                            \
  173.   while (i--) *dst++ = *src++;                            \
  174. }                                        \
  175.                                         \
  176. GVector(val)& GVector(val)::operator=(const GVector(val)& a)            \
  177. {                                        \
  178.   if(this != &a){                                \
  179.     delete[] array;    /* Disconnect from old array */                \
  180.     register unsigned i = npts = a.npts;                    \
  181.     register val* dst = array = new val[i];                    \
  182.     register val* src = a.array;                        \
  183.     while (i--) *dst++ = *src++;                        \
  184.   }                                        \
  185.   return *this;                                    \
  186. }                                        \
  187.                                         \
  188. void GVector(val)::resize(unsigned N)                        \
  189. {                                        \
  190.   if(N==npts)return;                                \
  191.   val* newArray = new val[N];                            \
  192.   register unsigned i = (N<=npts) ? N:npts;                    \
  193.   register val* src = array;                            \
  194.   register val* dst = newArray;                            \
  195.   while (i--) *dst++ = *src++;                            \
  196.   delete[] array;                                \
  197.   array = newArray;                                \
  198.   npts = N;                                    \
  199. }                                        \
  200.                                         \
  201. GPT set_handler(GVector,val, GPT newHandler)                    \
  202. {                                        \
  203.   GPT oldHandler = errorhandler(GVector,val);                    \
  204.   errorhandler(GVector,val) = newHandler;                    \
  205.   return oldHandler;                                \
  206. }
  207.  
  208. #else    /* Not V2.1 compliant */
  209.  
  210. #define GVectorimplement(val)                            \
  211. GPT errorhandler(GVector,val) = genericerror;                    \
  212. GVector(val)::GVector(val)(unsigned n, val ival)                \
  213. {                                        \
  214.   register unsigned i = npts = n;                        \
  215.   register val* dst = array = new val[i];                    \
  216.   while(i--) *dst++ = ival;                            \
  217. }                                        \
  218.                                         \
  219. GVector(val)::GVector(val)(const GVector(val)& a)                \
  220. {                                        \
  221.   register unsigned i= npts = a.npts;                        \
  222.   register val* dst = array = new val[i];                    \
  223.   register val* src = a.array;                            \
  224.   while (i--) *dst++ = *src++;                            \
  225. }                                        \
  226.                                         \
  227. GVector(val)& GVector(val)::operator=(const GVector(val)& a)            \
  228. {                                        \
  229.   if(this != &a){                                \
  230.     delete[npts] array;    /* Disconnect from old array */                \
  231.     register unsigned i = npts = a.npts;                    \
  232.     register val* dst = array = new val[i];                    \
  233.     register val* src = a.array;                        \
  234.     while (i--) *dst++ = *src++;                        \
  235.   }                                        \
  236.   return *this;                                    \
  237. }                                        \
  238.                                         \
  239. void GVector(val)::resize(unsigned N)                        \
  240. {                                        \
  241.   if(N==npts)return;                                \
  242.   val* newArray = new val[N];                            \
  243.   register unsigned i = (N<=npts) ? N:npts;                    \
  244.   register val* src = array;                            \
  245.   register val* dst = newArray;                            \
  246.   while (i--) *dst++ = *src++;                            \
  247.   delete[npts] array;                                \
  248.   array = newArray;                                \
  249.   npts = N;                                    \
  250. }                                        \
  251.                                         \
  252. GPT set_handler(GVector,val, GPT newHandler)                    \
  253. {                                        \
  254.   GPT oldHandler = errorhandler(GVector,val);                    \
  255.   errorhandler(GVector,val) = newHandler;                    \
  256.   return oldHandler;                                \
  257. }
  258.  
  259. #endif
  260.  
  261. pragma pop_align_members();
  262. #endif /* __RWGVECTOR_H__ */
  263.