home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / mesaaiok.zip / source / range.cpp < prev    next >
C/C++ Source or Header  |  1995-10-15  |  2KB  |  93 lines

  1. #include "range.h"
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. Range :: Range(const Address &ul,const Address &lr)
  6. {
  7.     count = 1;
  8.     _ul = (Address *)malloc(sizeof(Address) * count);
  9.     _lr = (Address *)malloc(sizeof(Address) * count);
  10.  
  11.     _ul[0] = ul;
  12.     _lr[0] = lr;
  13. }
  14.  
  15.  
  16. Range :: Range(const Range &rng)
  17. {
  18.     count = rng.count;
  19.     _ul = (Address *)malloc(sizeof(Address) * count);
  20.     _lr = (Address *)malloc(sizeof(Address) * count);
  21.  
  22.     for (int x = 0; x < count ; x++) {
  23.        _ul[x] = rng._ul[x];
  24.        _lr[x] = rng._lr[x];
  25.     } /* endfor */
  26. }
  27.  
  28. Range :: ~Range()
  29. {
  30.     if (count) {
  31.         free(_ul);
  32.         free(_lr);
  33.     } /* endif */
  34. }
  35.  
  36. void Range :: getItem(int x, Address &ul, Address & lr) const
  37. {
  38.     if (x >= count) {
  39.         ul.makeNull();
  40.         lr.makeNull();
  41.     } else {
  42.         ul = _ul[x];
  43.         lr = _lr[x];
  44.     } /* endif */
  45. }
  46.  
  47. void Range :: setItem(int x, Address &ul, Address & lr)
  48. {
  49.     if (x >= count) {
  50.         add(ul,lr);
  51.     } else {
  52.         ul = _ul[x];
  53.         lr = _lr[x];
  54.     } /* endif */
  55.     
  56. }
  57.  
  58. void Range :: add(Address &ul, Address & lr)
  59. {
  60.     count++;
  61.     _ul = (Address *)realloc(_ul,sizeof(Address) * count);
  62.     _lr = (Address *)realloc(_lr,sizeof(Address) * count);
  63.  
  64.     _ul[count-1] = ul;
  65.     _lr[count-1] = lr;
  66. }
  67.     
  68. Range & Range :: operator = (const Range & rg)
  69. {
  70.     count = rg.count;
  71.     _ul = (Address *)malloc(sizeof(Address) * count);
  72.     _lr = (Address *)malloc(sizeof(Address) * count);
  73.  
  74.     for (int x = 0; x < count ; x++) {
  75.        _ul[x] = rg._ul[x];
  76.        _lr[x] = rg._lr[x];
  77.     } /* endfor */   
  78.  
  79.     return *this;
  80. }
  81.     
  82. void Range :: zap()
  83. {
  84.     if (count) {
  85.         free(_ul);
  86.         free(_lr);
  87.         count = 0;
  88.         _ul = NULL;
  89.         _lr = NULL;
  90.     } /* endif */
  91. }
  92.  
  93.