/// @file /// @author Alejandro Valenzuela /// //! Generic double-linked list structure with minor lookup optimizations /*! * Generic double-linked list structure with minor lookup optimizations. */ /* * Copyright (C) 2006-2008 Alejandro Valenzuela Roca, * * http://mexinetica.com/~lanjoe9 * * This file is part of MotorJ, a free framework for videogame development. * * * * MotorJ is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * MotorJ is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with MotorJ. If not, see . */ /* NOTICE: Candidate to C++ Class Objectification */ #ifndef DATA_STRUCTS_H #define DATA_STRUCTS_H #include typedef struct list_node list_node; //! Node data structure struct list_node { //! Numerical ID; general purpose int type; //! Pointer to data. Can be NULL if only the numerical ID is useful void * data; //! Pointer to next node list_node * nxt; //! Pointer to previous node list_node * prv; }; //! Double-linked list structure typedef struct { //! Pointer to first node list_node * first; //! Pointer to middle node list_node * mid; //! Pointer to last node list_node * last; //! Number of nodes currently in list unsigned count; } list_header; //! List initialisation void list_init(list_header * header); //! Get node at specific position list_node * node_at(unsigned index, list_header * header); //! Add a node at the end of the list list_node * list_append(int type, void * data, list_header * header); //! Remove the last node list_node * list_pop(list_header * header); //! Remove a specific node; bridge surrounding nodes list_node * list_yank_node(list_node * node, list_header * header); //! Remove a node at a specific index; bridge surrounding nodes list_node * list_yank(unsigned index, list_header * header); //! Delete all the nodes without deleting their contents (the data field is intact) void list_delete(list_header * header, bool deleteHeader); //! Delete all the nodes as well as their contents (the data field is deleted by data_empty) void list_empty(void * data_empty(void * data), list_header * header); //! Find a node with a specific value in the "type" field list_node * list_find_type(int type, unsigned offset, list_header * header); //! Find a node situated after the offset node, with a specific value in the "type" field list_node * list_find_type_noffset(int type, list_node * offset); //! Interchange node positions void node_swap(list_node * node0, list_node * node1); #endif