1
0
mirror of https://gitlab.com/klmp200/LO27.git synced 2024-11-22 22:13:19 +00:00
LO27/LibMatrix/CellElement.h

214 lines
4.2 KiB
C

/*
* 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
/**
* An essential basic type, added an ERROR for out of bounds
*
* @param true 1
* @param false 0
* @param ERROR -1
*
*/
typedef enum Bool{
true = 1,
false = 0,
ERROR = -1
} bool;
/**
* A cell of the matrix
*
* @param colIndex is index (int) of the column of this cell
* @param rowIndex is index (int) of the row of this cell
*
* @param nextCol is pointer on the next cellElement in the same column
* @param nextRow is pointer on the next cellElement in the same row
*
* @see createCellElem to allocate one and freeCellElement to free one
*/
struct cellElement {
int colIndex;
int rowIndex;
struct cellElement * nextCol;
struct cellElement * nextRow;
};
typedef struct cellElement cellElement;
/**
* Allocates a cellElement and returns it
*
* @return pointer on the allocated cellElement
*
*/
cellElement * createCellElem();
/**
* Allocates a cellElement and sets it as the NextCol of the tree
*
* @param tree is a pointer on an allocated cellElement
*
* @return int error codes
*
*/
int addNextCol(cellElement* tree);
/**
* Allocates a cellElement and sets it as the NextRow of the tree
*
* @param tree is a pointer on an allocated cellElement
*
* @return int error codes
*
*/
int addNextRow(cellElement* tree);
/**
* Free the nextCol cellElement of the tree
*
* @param tree is a pointer on an allocated cellElement
*
*/
void removeNextCol(cellElement* tree);
/**
* Free the nextRow cellElement of the tree
*
* @param tree is a pointer on an allocated cellElement
*
*/
void removeNextRow(cellElement* tree);
/**
* Frees a cellElement and returns it
*
* @param element is pointer on the allocated cellElement
*
*/
void freeCellElement(cellElement* element);
/**
* Checks is the tree is a leaf
*
* @param tree is a pointer on an allocated cellElement
*
* @return bool (true/false)
*
*/
bool isLeaf(cellElement* tree);
/**
* Allows you to set the colIndex and the rowIndex of the cellElement elem
*
* @param elem is a pointer on an allocated cellElement
* @param Col is the value for colIndex
* @param Row is the value for rowIndex
*
* @return int error codes
*
*/
int setPositionIndex(cellElement* elem,int Col,int Row);
/**
* Allows you to set the nextCol of the cellElement tree
*
* @param tree is a pointer on the element you want to set
* @param elem is a pointer on a cellElement
*
* @return int error codes
*
*/
int setNextCol(cellElement* tree,cellElement* elem);
/**
* Allows you to set the nextRow of the cellElement elem
*
* @param tree is a pointer on the element you want to set
* @param elem is a pointer on a cellElement
*
* @return int error codes
*
*/
int setNextRow(cellElement* tree,cellElement* elem);
/**
* A debug function that recursively prints a tree, don't use it in not tree structured cellElements (may cause endless loops)
*
* @param tree a pointer on a cell element
*
*/
void recursivePrint(cellElement * tree);
/**
* Apply OR operator to a bool a and a bool b*
*
* @param a a bool
* @param b a bool
*
* @return bool
*/
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 bool
*/
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 bool
*/
bool XOR(bool a, bool b);
/**
* Return false if the bool is ERROR
*
* @param x a bool
*
* @return bool
*/
bool errorToFalse(bool x);
#endif