/* * This is a cellular automaton library * * Copyright (C) 2016-2017 Antoine BARTUCCIO, Jean POREE DE RIDDER * * Licensed under the MIT License,(the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * hhttps://opensource.org/licenses/MIT * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * */ #ifndef CELLELMNT_H #define CELLELMNT_H /*---bool--- *@true : 1 *@false : 0 */ typedef enum Bool{ true = 1, false = 0, ERROR = -1 } bool; /*---cellElement--- *A cell of the matrix * *@colIndex : index (int) of the column of this cell *@rowIndex : index (int) of the row of this cell * *@value : a boolean that is the content of the cell * *@nextCol : pointer on the next cellElement in the same column *@nextRow : pointer on the next cellElement in the same row * */ struct cellElement { int colIndex; int rowIndex; struct cellElement * nextCol; struct cellElement * nextRow; }; typedef struct cellElement cellElement; /*---CreateCellElem--- *Allocates a cellElement and returns it * *@return : pointer on the allocated cellElement * */ cellElement * CreateCellElem(); /*---AddNextCol--- *Allocates a cellElement and sets it as the NextCol of the tree * *@tree : pointer on an allocated cellElement * *@return ; error codes * */ int AddNextCol(cellElement* tree); /*---AddNextRow--- *Allocates a cellElement and sets it as the NextRow of the tree * *@tree : a pointer on an allocated cellElement * *@return : error codes * */ int AddNextRow(cellElement* tree); /*---removeNextCol--- *Free the nextCol cellElement of the tree * *@tree : a pointer on an allocated cellElement * */ void removeNextCol(cellElement* tree); /*---removeNextRow--- *Free the nextRow cellElement of the tree * *@tree : a pointer on an allocated cellElement * */ void removeNextRow(cellElement* tree); /*---FreeCellElem--- *Frees a cellElement and returns it * *@element : pointer on the allocated cellElement * */ void FreeCellElement(cellElement* element); /*---is_leaf--- *Checks is the tree is a leaf * *@tree : a pointer on an allocated cellElement * *@return : a bool * */ bool is_leaf(cellElement* tree); /*---SetPositionIndex--- *Allows you to set the colIndex and the rowIndex of the cellElement elem * *@elem : a pointer on an allocated cellElement *@Col : the value for colIndex *@Row : the value for rowIndex * *@return : error codes * */ int SetPositionIndex(cellElement* elem,int Col,int Row); /*---SetNextCol--- *Allows you to set the nextCol of the cellElement tree * *@tree : a pointer on the element you want to set *@elem : a pointer on a cellElement * *@return : error codes * */ int SetNextCol(cellElement* tree,cellElement* elem); /*---SetNextRow--- *Allows you to set the nextRow of the cellElement elem * *@tree : a pointer on the element you want to set *@elem : a pointer on a cellElement * *@return : error codes * */ int SetNextRow(cellElement* tree,cellElement* elem); void recursivePrint(cellElement * tree); /** * Apply OR operator to a bool a and a bool b * @param a a bool * @param b a bool * @return result a or b */ bool OR(bool a, bool b); /** * Apply AND operator to a bool a and a bool b * @param a a bool * @param b a bool * @return result a and b */ bool AND(bool a, bool b); /** * Apply XOR operator to a bool a and a bool b * @param a a bool * @param b a bool * @return result a and b */ bool XOR(bool a, bool b); /** * Return false if the bool is ERROR * @param x a bool * @return result a bool */ bool ErrorToFalse(bool x); #endif