| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- /************************************************************************/
- /* Copyright (C), 2016-2020, [Home], 保留所有权利;
- /* 模 块 名:;
- /* 描 述:;
- /*
- /* 版 本:[V];
- /* 作 者:[Home];
- /* 日 期:[1/29/2017];
- /*
- /*
- /* 注 意:;
- /*
- /* 修改记录:[Home];
- /* 修改日期:;
- /* 修改版本:;
- /* 修改内容:;
- /************************************************************************/
- #ifndef __CELL_RANGE__
- #define __CELL_RANGE__
- class CCellID
- {
- public:
- // 行,列号;
- int row, col;
- public:
- CCellID(int nRow = -1, int nCol = -1) : row(nRow), col(nCol) {}
- int IsValid() const { return (row >= 0 && col >= 0); }
- int operator==(const CCellID& rhs) { return (row == rhs.row && col == rhs.col); }
- int operator!=(const CCellID& rhs) { return !operator==(rhs); }
- };
- class CCellRange
- {
- public:
- CCellRange(int nMinRow = -1, int nMinCol = -1, int nMaxRow = -1, int nMaxCol = -1)
- {
- Set(nMinRow, nMinCol, nMaxRow, nMaxCol);
- }
- void Set(int nMinRow = -1, int nMinCol = -1, int nMaxRow = -1, int nMaxCol = -1);
- int IsValid() const;
- int InRange(int row, int col) const;
- int InRange(const CCellID& cellID) const;
- int Count() { return (m_nMaxRow - m_nMinRow + 1) * (m_nMaxCol - m_nMinCol + 1); }
- CCellID GetTopLeft() const;
- CCellRange Intersect(const CCellRange& rhs) const;
- int GetMinRow() const { return m_nMinRow; }
- void SetMinRow(int minRow) { m_nMinRow = minRow; }
- int GetMinCol() const { return m_nMinCol; }
- void SetMinCol(int minCol) { m_nMinCol = minCol; }
- int GetMaxRow() const { return m_nMaxRow; }
- void SetMaxRow(int maxRow) { m_nMaxRow = maxRow; }
- int GetMaxCol() const { return m_nMaxCol; }
- void SetMaxCol(int maxCol) { m_nMaxCol = maxCol; }
- int GetRowSpan() const { return m_nMaxRow - m_nMinRow + 1; }
- int GetColSpan() const { return m_nMaxCol - m_nMinCol + 1; }
- void operator=(const CCellRange& rhs);
- int operator==(const CCellRange& rhs);
- int operator!=(const CCellRange& rhs);
- protected:
- int m_nMinRow;
- int m_nMinCol;
- int m_nMaxRow;
- int m_nMaxCol;
- };
- inline void CCellRange::Set(int minRow, int minCol, int maxRow, int maxCol)
- {
- m_nMinRow = minRow;
- m_nMinCol = minCol;
- m_nMaxRow = maxRow;
- m_nMaxCol = maxCol;
- }
- inline void CCellRange::operator=(const CCellRange& rhs)
- {
- Set(rhs.m_nMinRow, rhs.m_nMinCol, rhs.m_nMaxRow, rhs.m_nMaxCol);
- }
- inline int CCellRange::operator==(const CCellRange& rhs)
- {
- return ((m_nMinRow == rhs.m_nMinRow) && (m_nMinCol == rhs.m_nMinCol) &&
- (m_nMaxRow == rhs.m_nMaxRow) && (m_nMaxCol == rhs.m_nMaxCol));
- }
- inline int CCellRange::operator!=(const CCellRange& rhs)
- {
- return !operator==(rhs);
- }
- /************************************************************************/
- /* 函数:IsValid[1/28/2017 Home];
- /* 描述:单元格有效范围是否正确;
- /* 参数:;
- /* [IN] :;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- inline int CCellRange::IsValid() const
- {
- //return (m_nMinRow >= 0 && m_nMinCol >= 0 && m_nMaxRow >= 0 && m_nMaxCol >= 0 && m_nMinRow <= m_nMaxRow && m_nMinCol <= m_nMaxCol);
- return (m_nMinRow >= 0 && m_nMinCol >= 0 && m_nMinRow <= m_nMaxRow && m_nMinCol <= m_nMaxCol);
- }
- /************************************************************************/
- /* 函数:InRange[1/28/2017 Home];
- /* 描述:单元格是否有范围内;
- /* 参数:;
- /* [IN] :;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- inline int CCellRange::InRange(int row, int col) const
- {
- return (row >= m_nMinRow && row <= m_nMaxRow && col >= m_nMinCol && col <= m_nMaxCol);
- }
- inline int CCellRange::InRange(const CCellID& cellID) const
- {
- return InRange(cellID.row, cellID.col);
- }
- /************************************************************************/
- /* 函数:GetTopLeft[1/28/2017 Home];
- /* 描述:获取左上角单元格;
- /* 参数:;
- /* [IN] :;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- inline CCellID CCellRange::GetTopLeft() const
- {
- return CCellID(m_nMinRow, m_nMinCol);
- }
- /************************************************************************/
- /* 函数:Intersect[1/28/2017 Home];
- /* 描述:两范围是否有相交;
- /* 参数:;
- /* [IN] :;
- /* [OUT] :;
- /* [IN/OUT] :;
- /* 返回:void;
- /* 注意:;
- /* 示例:;
- /*
- /* 修改:;
- /* 日期:;
- /* 内容:;
- /************************************************************************/
- inline CCellRange CCellRange::Intersect(const CCellRange& rhs) const
- {
- return CCellRange(max(m_nMinRow, rhs.m_nMinRow), max(m_nMinCol, rhs.m_nMinCol),
- min(m_nMaxRow, rhs.m_nMaxRow), min(m_nMaxCol, rhs.m_nMaxCol));
- }
- #endif // __CELL_RANGE__;
|