diff --git a/LibAutomaton/CellElement.h b/LibAutomaton/CellElement.h index d9557ce..60b27e9 100644 --- a/LibAutomaton/CellElement.h +++ b/LibAutomaton/CellElement.h @@ -9,7 +9,8 @@ typedef enum Bool{ true = 1, - false = 0 + false = 0, + ERROR = -1 } bool; diff --git a/LibAutomaton/matrix.c b/LibAutomaton/matrix.c index 6896a18..6a584aa 100644 --- a/LibAutomaton/matrix.c +++ b/LibAutomaton/matrix.c @@ -30,13 +30,21 @@ Matrix CreateMatrix(){ return matrix; } -void CreateMatrixElem(Matrix matrix, int ColPos, int RowPos){ +void SetMatrixDim(Matrix matrix,int nbCols,int nbRows){ + matrix.colCount = nbCols; + matrix.rowCount = nbRows; +} + +bool CreateMatrixElem(Matrix matrix, int ColPos, int RowPos){ ListElement * Row = NULL; ListElement * Col = NULL; int error = 0; cellElement * elem = NULL; cellElement * tmp = NULL; + if (matrix.colCount < ColPos || matrix.rowCount < RowPos){ + return ERROR; + } elem = CreateCellElem(); SetPositionIndex(elem,ColPos,RowPos); @@ -95,7 +103,11 @@ void CreateMatrixElem(Matrix matrix, int ColPos, int RowPos){ if (error != 0){ free(elem); + return true; + }else{ + return false; } + } cellElement * FindMatrixElem(Matrix matrix, int ColPos, int RowPos){ @@ -186,21 +198,28 @@ int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos){ } bool GetCellValue(Matrix matrix, int ColPos, int RowPos){ + if (matrix.colCount < ColPos || matrix.rowCount < RowPos){ + return ERROR; + } + if (FindMatrixElem(matrix,ColPos,RowPos) == NULL){ return false; } return true; } -void SetCellValue(Matrix matrix, int ColPos, int RowPos,bool value){ +bool SetCellValue(Matrix matrix, int ColPos, int RowPos,bool value){ if (value == true){ - CreateMatrixElem(matrix,ColPos,RowPos); + return CreateMatrixElem(matrix,ColPos,RowPos); }else{ - SupprMatrixElem(matrix,ColPos,RowPos); + if ( SupprMatrixElem(matrix,ColPos,RowPos) >= 0 ){ + return true; + }else{ + return false; + } } } /* todos: -*gerer bornes matrice *print matrice */ \ No newline at end of file diff --git a/LibAutomaton/matrix.h b/LibAutomaton/matrix.h index 1916bce..bfdd828 100644 --- a/LibAutomaton/matrix.h +++ b/LibAutomaton/matrix.h @@ -67,12 +67,15 @@ cellElement * FindMatrixElem(Matrix matrix, int ColPos, int RowPos); *@return void * */ -void CreateMatrixElem(Matrix matrix, int ColPos, int RowPos); +bool CreateMatrixElem(Matrix matrix, int ColPos, int RowPos); int SupprMatrixElem(Matrix matrix, int ColPos, int RowPos); -void SetCellValue(Matrix matrix, int ColPos, int RowPos,bool value); +bool SetCellValue(Matrix matrix, int ColPos, int RowPos, bool value); bool GetCellValue(Matrix matrix, int ColPos, int RowPos); + +void SetMatrixDim(Matrix matrix,int nbCols,int nbRows); + #endif