Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.01 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. #ifndef CMATRIX_H
  4. #define CMATRIX_H
  5.  
  6. class CMatrix {
  7. private:
  8.   // data structure related stuff - this could change if i use a different data structure
  9.   float **data;                   // internat data structure
  10.   void allocateData(int x, int y);// allocate the data structure of a X x Y matrix
  11.   void deleteData();              // delete the data structure
  12.  
  13.   // abstract stuff - if i ever change the data structure, these'll remain
  14.   int             sizeX,  sizeY;          // size of the matrix
  15.   void checkBounds(int x, int y) const;   // check if X,Y are vaild elements
  16.   float getElemCon(int x, int y) const;   // get element X,Y
  17.   float&   getElem(int x, int y);         // get reference to element X,Y
  18.   void     setElem(int x, int y, float v);// set element X,Y to V
  19.   void setAllElems(float v);              // set all elements to V
  20.  
  21. public:
  22.   // constructors
  23.   CMatrix();                          // default: 2x2 CMatrix
  24.   CMatrix(int x, int y);              // new CMatrix with these dims
  25.   CMatrix(int x, int y, float v);     // new CMatrix with default value V
  26.   CMatrix(int x, int y, float **mat); // new CMatrix with defaults
  27.   CMatrix(const CMatrix&);            // copy constructor
  28.   ~CMatrix();                         // destructor (most important piece of code, lol)
  29.  
  30.   // public accessors
  31.   float get(int x, int y) const;   // get a copy of X,Y
  32.   void  set(int x, int y, float v);// set X,Y to V
  33.   int height() const;              // get the height of the matrix (
  34.   int width() const;              // get the matrix's length
  35.  
  36.   // matrix related things
  37.   bool square() const;        // return true if this is a square matrix
  38.   float determinant() const;  // get the determinant
  39.   void resize(int x, int y);  // resize this matrix to an XxY matrix
  40.   void escape();              // escape this matrix
  41.   void invert();              // invert this matrix
  42.   CMatrix escaped() const;    // return an escaped version of this matrix
  43.   CMatrix inverse() const;    // return an inverted version of this matrix
  44.  
  45.   // operators
  46.   // element access
  47.   float& operator()(int x, int y);
  48.  
  49.   // comparing
  50.   bool operator==(const CMatrix&) const;
  51.   bool operator!=(const CMatrix&) const;
  52.  
  53.   // copy / assignment / math
  54.   CMatrix& operator= (const CMatrix&);
  55.   CMatrix& operator+=(const float);
  56.   CMatrix& operator+=(const CMatrix&);
  57.   CMatrix& operator++();
  58.   CMatrix& operator-=(const float);
  59.   CMatrix& operator-=(const CMatrix&);
  60.   CMatrix& operator--();
  61.   CMatrix& operator*=(const float);
  62.   CMatrix& operator*=(const CMatrix&);
  63.  
  64.   // math
  65.   CMatrix operator+(const float) const;
  66.   CMatrix operator+(const CMatrix&) const;
  67.   CMatrix operator-(const float) const;
  68.   CMatrix operator-(const CMatrix&) const;
  69.   CMatrix operator*(const float) const;
  70.   CMatrix operator*(const CMatrix&) const;
  71.   friend CMatrix operator+(const float, const CMatrix&);
  72.   friend CMatrix operator-(const float, const CMatrix&);
  73.   friend CMatrix operator*(const float, const CMatrix&);
  74.  
  75.   // stream
  76.   friend std::ostream& operator<<(std::ostream&, const CMatrix&);
  77. };
  78.  
  79. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement