home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / APR94_1.ZIP / GA.ZIP / SOURCE.ZIP / WMATRIX.H < prev   
C/C++ Source or Header  |  1994-01-10  |  2KB  |  89 lines

  1. //Copyright (C) Man Machine Interfaces 1994. All rights reserved.
  2.  
  3. //wmatrix.h
  4.  
  5. #ifndef  __WMATRIX_H__
  6. #define __WMATRIX_H__
  7.  
  8.  
  9. class CWordMatrix
  10. {
  11. public:
  12.     
  13.     //construct,destruct,copy,assign                              
  14.     CWordMatrix(int numRows, int numCols, WORD init=0) ;
  15.     CWordMatrix(const CWordMatrix &source) ;
  16.     ~CWordMatrix() ; 
  17.     CWordMatrix &  operator =(const CWordMatrix &source) ;
  18.     
  19.     //query
  20.     int GetNumRows() const ;
  21.     int GetNumCols() const ;
  22.     int GetNumCells() const ;
  23.     WORD GetAt(int row, int col) const ;
  24.     const CWordArray &GetRow(int row) const;
  25.     const CWordArray &operator [](int row) const ;        
  26.     
  27.     //modify
  28.     CWordArray &operator [](int row) ;        
  29.     void SetAt(int row, int col, WORD val) ;
  30.     BOOL Find(WORD item, int &row, int &col) ;
  31.     
  32. private:
  33.     
  34.     //facilitate matrix operator [] notation
  35.     class CArrayOfWordArray : public CObArray 
  36.     {
  37.     friend     CWordMatrix ;
  38.     
  39.         CArrayOfWordArray() ;
  40.         const CWordArray & operator[] (int nIndex) const ;        
  41.         CWordArray & operator[] (int nIndex) ;
  42.     };
  43.  
  44.     int m_NumRows, 
  45.          m_NumCols ;
  46.     CArrayOfWordArray m_Rows ;
  47. };                                            
  48.  
  49. // CArrayOfWordArray inlines
  50. inline CWordMatrix::CArrayOfWordArray::CArrayOfWordArray()
  51. {
  52.  
  53. inline const CWordArray & CWordMatrix::CArrayOfWordArray::operator[] (int nIndex) const 
  54. {
  55.     return *((CWordArray *) CObArray::GetAt(nIndex) ) ;
  56. }
  57.  
  58. inline CWordArray & CWordMatrix::CArrayOfWordArray::operator[] (int nIndex) 
  59. {
  60.     return *((CWordArray *) CObArray::ElementAt(nIndex)) ;
  61. }
  62.  
  63.  
  64. //CWordMatrix inlines
  65.  
  66. inline int CWordMatrix::GetNumRows() const 
  67. {                                                                               
  68.     return m_NumRows ;
  69. }
  70.  
  71. inline int CWordMatrix::GetNumCols() const 
  72. {
  73.     return m_NumCols ;
  74. }
  75.  
  76. inline int CWordMatrix::GetNumCells() const
  77. {  
  78.     return GetNumRows() * GetNumCols() ;
  79. }
  80.    
  81. inline const CWordArray & CWordMatrix::operator [](int row) const 
  82. {
  83.     return GetRow(row) ;
  84. }
  85.            
  86.            
  87. #endif
  88.