Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef AGH_MATRIX
- #define AGH_MATRIX
- #include <cstdarg>
- #include <iostream>
- //------------------------------------------------
- template<typename T>
- class aghMatrix{
- private:
- T** matrix;
- int rows,cols;
- //-------------------------------------
- void resize(int x, int y){
- if(matrix != NULL){
- for(int i=0;i<x;i++)
- delete [] matrix[i];
- delete [] matrix;
- matrix = NULL;
- }
- T** matrix = new T*[x];
- for(int i=0;i<x;i++)
- matrix[i] = new T[y];
- rows = x;
- cols = y;
- }
- //-------------------------------
- public:
- void setItem(int x, int y, T n){
- if(matrix!=NULL) if(x<=rows && y<=cols && x>0 && y>0) matrix[x][y]=n;
- }
- //-----------------------------------
- void setItems(T* items){
- int x=0;
- for(int i=0; i<rows; i++) for (int j=0; j<cols; j++)
- { matrix[i][j]=items[x]; x++; }
- }
- //TODO: obsluga wyjatkow
- //-----------------------------------
- void setItems(int r, int c, ... ){
- va_list arg;
- va_start(arg, c);
- resize(r,c);
- for(int i=0; i<rows; i++)
- for(int j=0; j<cols; j++)
- matrix[i][j]=arg;
- va_end(arg);
- }
- //-----------------------------------
- aghMatrix():rows(0),cols(0),matrix(NULL){}
- //-----------------------------------
- aghMatrix(int x, int y){
- resize(x,y);
- for(int i=0; i<rows; i++)
- for(int j=0; j<cols; j++)
- matrix[i][j]=0;
- }
- //-----------------------------------
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement