home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dokpr1.zip / range.h < prev    next >
C/C++ Source or Header  |  1995-09-15  |  4KB  |  110 lines

  1. /**************************************************************************
  2.  *                                                                        *
  3.  *                                                                        *
  4.  *          This code is copyright (c)              1994                  *
  5.  *                     Athena Design, Inc.                                *
  6.  *                                                                        *
  7.  *                                                                        *
  8.  *                ALL RIGHTS RESERVED                                     *
  9.  *                                                                        *
  10.  *                                                                        *
  11.  *                                                                        *
  12.  *                                                                        *
  13.  *                                                                        *
  14.  **************************************************************************/
  15.  
  16. #ifndef _mh_TAG_RANGE__
  17.  
  18. #define _mh_TAG_RANGE__
  19.  
  20. #include "address.h"
  21.  
  22. // 94-08-23 dpp added methods to check whether a row or column on a give layer intersects the range
  23. // 94-09-19 dpp added methods to copy a set of ranges
  24.  
  25. class MSheet;
  26. class MStream;
  27.  
  28. const int COUNTMASK = 0xffff;        // the max number od discontiguous ranges
  29. const int AUTOGROWBIT = 0x10000;    // the bit that determines if we're autogrow
  30.  
  31.  
  32. class MRange {
  33.  
  34.     public:
  35.     void init() { r2.ads = 0 ; count = 0;};
  36.     void init(const MRange *mr) {init(); if (mr) *this = *mr;};
  37.     void zap() {if ((count & COUNTMASK) > 1) _free(); init();};
  38.     void free() {if ((count & COUNTMASK) > 1) _free(); count = 0;};
  39.     int getCount() const {return count & COUNTMASK;};
  40.     
  41.     void init(const MAddress *,const MAddress *);
  42.     void init(const MAddress *);
  43.     void init(MStream *);
  44.     void write(MStream *) const;
  45.     void addRange(const MAddress *,const MAddress *);
  46.     void addAndSortRange(const MAddress *,const MAddress *);
  47.     void addRange(const MAddress *);
  48.     void addRange(const MRange *);
  49.     void sortRange();
  50.  
  51.     int inRange(const MAddress *) const;
  52.     int inRange(const MRange *) const;
  53.  
  54.     // do the two ranges overlap or intersect?
  55.     // 94-09-16 dpp
  56.     int overlapRange(const MRange *) const;
  57.  
  58.     int inWhichRange(const MAddress *,MAddress &,MAddress &) const;
  59.     void set(const MAddress *);
  60.     void set(const MRange *ra) {free(); init(ra);};
  61.     void set(const MAddress *,const MAddress *);
  62.     void getItem(int,MAddress &,MAddress &) const;
  63.     void setItem(int,const MAddress *,const MAddress *);
  64.     void doMerge(const MAddress *);
  65.     // void offset(int,int,int);
  66.     MRange &operator=(const MRange &);
  67.     int operator==(const MRange &) const;
  68.     int getTotalCells() const;
  69.     void setAndSort(const MAddress *,const MAddress *);
  70.     void offset(int,int,int);
  71.     void offsetBy(const MAddress *);
  72.     void makeAbs();
  73.      void setAbs( int );
  74.      int getAbs();
  75.  
  76.     int isRowInRange(int,int) const;
  77.         // pass a row and a layer, returns 1 if that row intersects the rng
  78.     int isColInRange(int,int) const;
  79.         // pass a col and a layer, returns 1 if that col intersects the rng
  80.  
  81.     // copy a set of range pairs from the source to *this
  82.     // 94-09-19 dpp
  83.     void copySelectedRanges(const MRange *,int,int);
  84.  
  85.     // get and set the autogrow bit
  86.     int isAutoGrow() const {return (count & AUTOGROWBIT) ? 1 : 0;};
  87.     int isAtLowerEdge(const MAddress *) const;
  88.     int growFrom(const MAddress *);
  89.     void setAutoGrow(int i) {if (i) count |= AUTOGROWBIT; else count &= ~AUTOGROWBIT;};
  90.     void setCount(int i) {count = (count & ~COUNTMASK) | i;};
  91.  
  92.  
  93.     private:
  94.  
  95.     void _free();
  96.  
  97.     int count;
  98.     union {
  99.         MAddress ul;
  100.         int max;
  101.         } r1;
  102.     union {
  103.         MAddress lr;
  104.         MAddress *ads;
  105.         } r2;
  106.     };
  107.  
  108. #endif
  109.  
  110.