00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00024
00025 #if !defined(AFX_CELLRANGE_H__F86EF761_725A_11D1_ABBA_00A0243D1382__INCLUDED_)
00026 #define AFX_CELLRANGE_H__F86EF761_725A_11D1_ABBA_00A0243D1382__INCLUDED_
00027
00028 #if _MSC_VER >= 1000
00029 #pragma once
00030 #endif // _MSC_VER >= 1000
00031
00032
00033
00034
00035
00036
00037 class CCellID
00038 {
00039
00040 public:
00041 int row, col;
00042
00043
00044 public:
00045 explicit CCellID(int nRow = -1, int nCol = -1) : row(nRow), col(nCol) {}
00046
00047 int IsValid() const { return (row >= 0 && col >= 0); }
00048 int operator==(const CCellID& rhs) const { return (row == rhs.row && col == rhs.col); }
00049 int operator!=(const CCellID& rhs) const { return !operator==(rhs); }
00050 };
00051
00052 class CCellRange
00053 {
00054 public:
00055
00056 CCellRange(int nMinRow = -1, int nMinCol = -1, int nMaxRow = -1, int nMaxCol = -1)
00057 {
00058 Set(nMinRow, nMinCol, nMaxRow, nMaxCol);
00059 }
00060
00061 void Set(int nMinRow = -1, int nMinCol = -1, int nMaxRow = -1, int nMaxCol = -1);
00062
00063 int IsValid() const;
00064 int InRange(int row, int col) const;
00065 int InRange(const CCellID& cellID) const;
00066 int Count() { return (m_nMaxRow - m_nMinRow + 1) * (m_nMaxCol - m_nMinCol + 1); }
00067
00068 CCellID GetTopLeft() const;
00069 CCellRange Intersect(const CCellRange& rhs) const;
00070
00071 int GetMinRow() const {return m_nMinRow;}
00072 void SetMinRow(int minRow) {m_nMinRow = minRow;}
00073
00074 int GetMinCol() const {return m_nMinCol;}
00075 void SetMinCol(int minCol) {m_nMinCol = minCol;}
00076
00077 int GetMaxRow() const {return m_nMaxRow;}
00078 void SetMaxRow(int maxRow) {m_nMaxRow = maxRow;}
00079
00080 int GetMaxCol() const {return m_nMaxCol;}
00081 void SetMaxCol(int maxCol) {m_nMaxCol = maxCol;}
00082
00083 int GetRowSpan() const {return m_nMaxRow - m_nMinRow + 1;}
00084 int GetColSpan() const {return m_nMaxCol - m_nMinCol + 1;}
00085
00086 void operator=(const CCellRange& rhs);
00087 int operator==(const CCellRange& rhs);
00088 int operator!=(const CCellRange& rhs);
00089
00090 protected:
00091 int m_nMinRow;
00092 int m_nMinCol;
00093 int m_nMaxRow;
00094 int m_nMaxCol;
00095 };
00096
00097 inline void CCellRange::Set(int minRow, int minCol, int maxRow, int maxCol)
00098 {
00099 m_nMinRow = minRow;
00100 m_nMinCol = minCol;
00101 m_nMaxRow = maxRow;
00102 m_nMaxCol = maxCol;
00103 }
00104
00105 inline void CCellRange::operator=(const CCellRange& rhs)
00106 {
00107 if (this != &rhs) Set(rhs.m_nMinRow, rhs.m_nMinCol, rhs.m_nMaxRow, rhs.m_nMaxCol);
00108 }
00109
00110 inline int CCellRange::operator==(const CCellRange& rhs)
00111 {
00112 return ((m_nMinRow == rhs.m_nMinRow) && (m_nMinCol == rhs.m_nMinCol) &&
00113 (m_nMaxRow == rhs.m_nMaxRow) && (m_nMaxCol == rhs.m_nMaxCol));
00114 }
00115
00116 inline int CCellRange::operator!=(const CCellRange& rhs)
00117 {
00118 return !operator==(rhs);
00119 }
00120
00121 inline int CCellRange::IsValid() const
00122 {
00123 return (m_nMinRow >= 0 && m_nMinCol >= 0 && m_nMaxRow >= 0 && m_nMaxCol >= 0 &&
00124 m_nMinRow <= m_nMaxRow && m_nMinCol <= m_nMaxCol);
00125 }
00126
00127 inline int CCellRange::InRange(int row, int col) const
00128 {
00129 return (row >= m_nMinRow && row <= m_nMaxRow && col >= m_nMinCol && col <= m_nMaxCol);
00130 }
00131
00132 inline int CCellRange::InRange(const CCellID& cellID) const
00133 {
00134 return InRange(cellID.row, cellID.col);
00135 }
00136
00137 inline CCellID CCellRange::GetTopLeft() const
00138 {
00139 return CCellID(m_nMinRow, m_nMinCol);
00140 }
00141
00142 inline CCellRange CCellRange::Intersect(const CCellRange& rhs) const
00143 {
00144 return CCellRange(max(m_nMinRow,rhs.m_nMinRow), max(m_nMinCol,rhs.m_nMinCol),
00145 min(m_nMaxRow,rhs.m_nMaxRow), min(m_nMaxCol,rhs.m_nMaxCol));
00146 }
00147
00148 #endif // !defined(AFX_CELLRANGE_H__F86EF761_725A_11D1_ABBA_00A0243D1382__INCLUDED_)