1
0
mirror of https://gitlab.com/klmp200/LO27.git synced 2024-11-23 02:23:20 +00:00
LO27/LibMatrix/CellElement.h

214 lines
4.2 KiB
C
Raw Normal View History

2016-12-29 15:09:39 +00:00
/*
* 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
2016-12-31 19:19:49 +00:00
/**
* An essential basic type, added an ERROR for out of bounds
*
2017-01-01 15:47:49 +00:00
* @param true 1
* @param false 0
* @param ERROR -1
2016-12-31 19:19:49 +00:00
*
*/
typedef enum Bool{
2016-12-10 04:04:13 +00:00
true = 1,
2016-12-24 12:53:04 +00:00
false = 0,
ERROR = -1
} bool;
2016-12-31 19:19:49 +00:00
/**
* A cell of the matrix
*
2016-12-31 19:19:49 +00:00
* @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
*
2017-01-01 23:37:47 +00:00
* @see createCellElem to allocate one and freeCellElement to free one
*/
struct cellElement {
2016-12-10 20:11:46 +00:00
int colIndex;
int rowIndex;
struct cellElement * nextCol;
struct cellElement * nextRow;
};
2016-12-10 20:11:46 +00:00
typedef struct cellElement cellElement;
2016-12-31 19:19:49 +00:00
/**
* Allocates a cellElement and returns it
2016-12-10 23:33:02 +00:00
*
2016-12-31 19:19:49 +00:00
* @return pointer on the allocated cellElement
2016-12-10 23:33:02 +00:00
*
*/
2017-01-01 23:37:47 +00:00
cellElement * createCellElem();
2016-12-10 20:11:46 +00:00
2016-12-10 23:33:02 +00:00
2016-12-31 19:19:49 +00:00
/**
* Allocates a cellElement and sets it as the NextCol of the tree
2016-12-10 23:33:02 +00:00
*
2016-12-31 19:19:49 +00:00
* @param tree is a pointer on an allocated cellElement
2016-12-11 03:01:27 +00:00
*
2016-12-31 19:19:49 +00:00
* @return int error codes
2016-12-10 23:33:02 +00:00
*
*/
2017-01-01 23:37:47 +00:00
int addNextCol(cellElement* tree);
2016-12-10 23:33:02 +00:00
2016-12-31 19:19:49 +00:00
/**
* Allocates a cellElement and sets it as the NextRow of the tree
2016-12-10 23:33:02 +00:00
*
2016-12-31 19:19:49 +00:00
* @param tree is a pointer on an allocated cellElement
2016-12-11 03:01:27 +00:00
*
2016-12-31 19:19:49 +00:00
* @return int error codes
2016-12-10 23:33:02 +00:00
*
*/
2017-01-01 23:37:47 +00:00
int addNextRow(cellElement* tree);
2016-12-10 20:11:46 +00:00
2016-12-31 19:19:49 +00:00
/**
* Free the nextCol cellElement of the tree
2016-12-10 23:33:02 +00:00
*
2016-12-31 19:19:49 +00:00
* @param tree is a pointer on an allocated cellElement
2016-12-10 23:33:02 +00:00
*
*/
void removeNextCol(cellElement* tree);
2016-12-31 19:19:49 +00:00
/**
* Free the nextRow cellElement of the tree
2016-12-10 23:33:02 +00:00
*
2016-12-31 19:19:49 +00:00
* @param tree is a pointer on an allocated cellElement
2016-12-10 23:33:02 +00:00
*
*/
void removeNextRow(cellElement* tree);
2016-12-10 23:33:02 +00:00
2016-12-31 19:19:49 +00:00
/**
* Frees a cellElement and returns it
2016-12-10 23:33:02 +00:00
*
2016-12-31 19:19:49 +00:00
* @param element is pointer on the allocated cellElement
*
2016-12-10 23:33:02 +00:00
*/
2017-01-01 23:37:47 +00:00
void freeCellElement(cellElement* element);
2016-12-11 02:25:21 +00:00
2016-12-31 19:19:49 +00:00
/**
* Checks is the tree is a leaf
2016-12-11 03:01:27 +00:00
*
2016-12-31 19:19:49 +00:00
* @param tree is a pointer on an allocated cellElement
2016-12-11 03:01:27 +00:00
*
2017-01-01 23:37:47 +00:00
* @return bool (true/false)
2016-12-11 03:01:27 +00:00
*
*/
2017-01-01 23:37:47 +00:00
bool isLeaf(cellElement* tree);
2016-12-11 03:01:27 +00:00
2016-12-31 19:19:49 +00:00
/**
* Allows you to set the colIndex and the rowIndex of the cellElement elem
2016-12-11 03:01:27 +00:00
*
2016-12-31 19:19:49 +00:00
* @param elem is a pointer on an allocated cellElement
* @param Col is the value for colIndex
* @param Row is the value for rowIndex
2016-12-11 03:01:27 +00:00
*
2016-12-31 19:19:49 +00:00
* @return int error codes
2016-12-11 03:01:27 +00:00
*
*/
2017-01-01 23:37:47 +00:00
int setPositionIndex(cellElement* elem,int Col,int Row);
2016-12-11 03:01:27 +00:00
2016-12-31 19:19:49 +00:00
/**
* Allows you to set the nextCol of the cellElement tree
2016-12-11 03:01:27 +00:00
*
2016-12-31 19:19:49 +00:00
* @param tree is a pointer on the element you want to set
* @param elem is a pointer on a cellElement
2016-12-11 03:01:27 +00:00
*
2016-12-31 19:19:49 +00:00
* @return int error codes
2016-12-11 03:01:27 +00:00
*
*/
2017-01-01 23:37:47 +00:00
int setNextCol(cellElement* tree,cellElement* elem);
2016-12-11 03:01:27 +00:00
2016-12-31 19:19:49 +00:00
/**
* Allows you to set the nextRow of the cellElement elem
2016-12-11 03:01:27 +00:00
*
2016-12-31 19:19:49 +00:00
* @param tree is a pointer on the element you want to set
* @param elem is a pointer on a cellElement
2016-12-11 03:01:27 +00:00
*
2016-12-31 19:19:49 +00:00
* @return int error codes
2016-12-11 03:01:27 +00:00
*
*/
2017-01-01 23:37:47 +00:00
int setNextRow(cellElement* tree,cellElement* elem);
2016-12-11 02:25:21 +00:00
2016-12-31 19:19:49 +00:00
/**
* 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
*
*/
2016-12-11 02:25:21 +00:00
void recursivePrint(cellElement * tree);
2016-12-26 17:16:37 +00:00
/**
2016-12-31 19:19:49 +00:00
* Apply OR operator to a bool a and a bool b*
*
2016-12-26 17:16:37 +00:00
* @param a a bool
* @param b a bool
2016-12-31 19:19:49 +00:00
*
2017-01-01 23:37:47 +00:00
* @return bool
2016-12-26 17:16:37 +00:00
*/
bool OR(bool a, bool b);
/**
* Apply AND operator to a bool a and a bool b
2016-12-31 19:19:49 +00:00
*
2016-12-26 17:16:37 +00:00
* @param a a bool
* @param b a bool
2016-12-31 19:19:49 +00:00
*
2017-01-01 23:37:47 +00:00
* @return bool
2016-12-26 17:16:37 +00:00
*/
bool AND(bool a, bool b);
2016-12-28 01:38:48 +00:00
/**
* Apply XOR operator to a bool a and a bool b
2016-12-31 19:19:49 +00:00
*
2016-12-28 01:38:48 +00:00
* @param a a bool
* @param b a bool
2016-12-31 19:19:49 +00:00
*
2017-01-01 23:37:47 +00:00
* @return bool
2016-12-28 01:38:48 +00:00
*/
bool XOR(bool a, bool b);
/**
* Return false if the bool is ERROR
2016-12-31 19:19:49 +00:00
*
2016-12-28 01:38:48 +00:00
* @param x a bool
2016-12-31 19:19:49 +00:00
*
2017-01-01 23:37:47 +00:00
* @return bool
2016-12-28 01:38:48 +00:00
*/
2017-01-01 23:37:47 +00:00
bool errorToFalse(bool x);
2016-12-28 01:38:48 +00:00
2016-12-10 04:04:13 +00:00
#endif