mirror of
https://github.com/UberGames/rpgxEF.git
synced 2025-02-19 10:31:06 +00:00
Modified list module and sublicensed it
This commit is contained in:
parent
bfe7d807e4
commit
f54a709f00
6 changed files with 229 additions and 94 deletions
|
@ -71,7 +71,57 @@ creators is not allowed. Feel free to use the source code included
|
||||||
in this file and/or git repository for your own mod as long as you
|
in this file and/or git repository for your own mod as long as you
|
||||||
give full credit to UberGamesi for our modification/code and as long
|
give full credit to UberGamesi for our modification/code and as long
|
||||||
as this does not conflict with the original license of the STVEF HM
|
as this does not conflict with the original license of the STVEF HM
|
||||||
gamecode.. The Ubergames and other conributers to the RPG-X Mod cannot
|
gamecode. The Ubergames and other conributers to the RPG-X Mod cannot
|
||||||
be held accountable for any damage that may have been caused by playing
|
be held accountable for any damage that may have been caused by playing
|
||||||
the game.
|
the game.
|
||||||
|
|
||||||
|
Lua License:
|
||||||
|
------------
|
||||||
|
/****************************************************************************
|
||||||
|
* Copyright (C) 1994-2013 Lua.org, PUC-Rio. All rights reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
* a copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
* permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
* the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be
|
||||||
|
* included in all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
Original List Module License (list.h, list.c):
|
||||||
|
----------------------------------------------
|
||||||
|
/*
|
||||||
|
Copyright (c) 2011 Zhehao Mao
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -519,13 +519,13 @@ static char *TimedMessage( void ){
|
||||||
}
|
}
|
||||||
|
|
||||||
if(iterTimedMessages == NULL) {
|
if(iterTimedMessages == NULL) {
|
||||||
iterTimedMessages = list_iterator(level.timedMessages, FRONT);
|
iterTimedMessages = list_iterator(level.timedMessages, LIST_FRONT);
|
||||||
if(iterTimedMessages == NULL) { // something went wrong
|
if(iterTimedMessages == NULL) { // something went wrong
|
||||||
return "^1RPG-X ERROR: No messages to display";
|
return "^1RPG-X ERROR: No messages to display";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
msg = (timedMessage_t *)list_cycl_next(iterTimedMessages);
|
msg = (timedMessage_t *)list_cycl_next(iterTimedMessages)->data;
|
||||||
message = msg->message;
|
message = msg->message;
|
||||||
|
|
||||||
return message;
|
return message;
|
||||||
|
|
|
@ -7450,20 +7450,20 @@ void addShaderToList(list_p list, char *shader) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
i = list_iterator(list, FRONT);
|
i = list_iterator(list, LIST_FRONT);
|
||||||
if(i == NULL) {
|
if(i == NULL) {
|
||||||
free(s->s);
|
free(s->s);
|
||||||
free(s);
|
free(s);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(t = (rShader_s *)list_next(i); t != NULL; t = (rShader_s *)list_next(i)) {
|
for(t = (rShader_s *)list_next(i)->data; t != NULL; t = (rShader_s *)list_next(i)->data) {
|
||||||
if(!strcmp(shader, t->s)) {
|
if(!strcmp(shader, t->s)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
list_add(list, s, sizeof(rShader_s));
|
list_add(list, s, LT_DATA, sizeof(rShader_s));
|
||||||
}
|
}
|
||||||
|
|
||||||
extern target_alert_Shaders_s alertShaders;
|
extern target_alert_Shaders_s alertShaders;
|
||||||
|
@ -7519,14 +7519,14 @@ void Cmd_GeneratePrecacheFile(gentity_t *ent) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
iter = list_iterator(shaders, FRONT);
|
iter = list_iterator(shaders, LIST_FRONT);
|
||||||
if(iter == NULL) {
|
if(iter == NULL) {
|
||||||
trap_FS_FCloseFile(f);
|
trap_FS_FCloseFile(f);
|
||||||
destroy_list(shaders);
|
destroy_list(shaders);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for(s = (rShader_s *)list_next(iter); s != NULL; s = (rShader_s *)list_next(iter)) {
|
for(s = (rShader_s *)list_next(iter)->data; s != NULL; s = (rShader_s *)list_next(iter)->data) {
|
||||||
G_Printf("\t%s\n", s->s);
|
G_Printf("\t%s\n", s->s);
|
||||||
if(first) {
|
if(first) {
|
||||||
trap_FS_Write("\"", 1, f);
|
trap_FS_Write("\"", 1, f);
|
||||||
|
|
|
@ -968,7 +968,7 @@ static void G_LoadTimedMessages(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
msg->message = strdup(token);
|
msg->message = strdup(token);
|
||||||
list_add(level.timedMessages, msg, sizeof(timedMessage_s));
|
list_add(level.timedMessages, msg, LT_DATA, sizeof(timedMessage_s));
|
||||||
} else {
|
} else {
|
||||||
if(token[0] == '}') {
|
if(token[0] == '}') {
|
||||||
break;
|
break;
|
||||||
|
|
190
code/game/list.c
190
code/game/list.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2011 Zhehao Mao
|
Copyright (c) 2013 Ubergames
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
@ -20,80 +20,102 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
list_p create_list(){
|
list_p create_list() {
|
||||||
list_p list = (list_p) malloc(sizeof(struct list));
|
list_p list = (list_p)malloc(sizeof(struct list));
|
||||||
|
|
||||||
|
if(list == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
list->length = 0;
|
list->length = 0;
|
||||||
list->first = NULL;
|
list->first = NULL;
|
||||||
list->last = NULL;
|
list->last = NULL;
|
||||||
list->destructor = free;
|
list->destructor = free;
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
list_iter_p list_iterator(list_p list, char init){
|
list_iter_p list_iterator(list_p list, char init) {
|
||||||
list_iter_p iter = (list_iter_p)malloc(sizeof(struct list_iter));
|
list_iter_p iter = (list_iter_p)malloc(sizeof(struct list_iter));
|
||||||
if(init==FRONT){
|
|
||||||
iter->current = list->first;
|
if(iter == NULL) {
|
||||||
}
|
|
||||||
else if(init==BACK){
|
|
||||||
iter->current = list->last;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(iter != NULL)
|
|
||||||
free(iter);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(init == LIST_FRONT) {
|
||||||
|
iter->current = list->first;
|
||||||
|
} else if(init == LIST_BACK) {
|
||||||
|
iter->current = list->last;
|
||||||
|
} else { // asume front
|
||||||
|
iter->current = list->first;
|
||||||
|
}
|
||||||
|
|
||||||
iter->list = list;
|
iter->list = list;
|
||||||
iter->started = 0;
|
iter->started = 0;
|
||||||
|
|
||||||
return iter;
|
return iter;
|
||||||
}
|
}
|
||||||
|
|
||||||
void list_add(list_p list, void* data, int size){
|
int list_add(list_p list, void* data, dataType_t type, int size) {
|
||||||
lnode_p node = (lnode_p)malloc(sizeof(struct linked_node));
|
lnode_p node = (lnode_p)malloc(sizeof(struct linked_node));
|
||||||
node->data = malloc(size);
|
|
||||||
memcpy(node->data, data, size);
|
|
||||||
|
|
||||||
if(list->first==NULL){
|
node->cont = (container_p)(sizeof(container));
|
||||||
|
if(node->cont == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
node->cont->data = malloc(size);
|
||||||
|
if(node->cont->data == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
memcpy(node->cont->data, data, size);
|
||||||
|
|
||||||
|
if(list->first == NULL) {
|
||||||
node->prev = NULL;
|
node->prev = NULL;
|
||||||
node->next = NULL;
|
node->next = NULL;
|
||||||
list->first = node;
|
list->first = node;
|
||||||
list->last = node;
|
list->last = node;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
list->last->next = node;
|
list->last->next = node;
|
||||||
node->prev = list->last;
|
node->prev = list->last;
|
||||||
node->next = NULL;
|
node->next = NULL;
|
||||||
list->last = node;
|
list->last = node;
|
||||||
}
|
}
|
||||||
list->length++;
|
list->length++;
|
||||||
|
|
||||||
|
return list->length;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* list_current(list_iter_p iter){
|
container_p list_current(list_iter_p iter){
|
||||||
if(iter->started&&iter->current!=NULL)
|
if(iter->started && iter->current != NULL) {
|
||||||
return iter->current->data;
|
return iter->current->cont;
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* list_next(list_iter_p iter){
|
container_p list_next(list_iter_p iter) {
|
||||||
if(!iter->started&&iter->current!=NULL){
|
if(!iter->started && iter->current != NULL) {
|
||||||
iter->started=1;
|
iter->started = 1;
|
||||||
return iter->current->data;
|
return iter->current->cont;
|
||||||
}
|
}
|
||||||
if(iter->current!=NULL){
|
|
||||||
|
if(iter->current != NULL) {
|
||||||
iter->current = iter->current->next;
|
iter->current = iter->current->next;
|
||||||
return list_current(iter);
|
return list_current(iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* list_cycl_next(list_iter_p iter){
|
container_p list_cycl_next(list_iter_p iter) {
|
||||||
if(!iter->started&&iter->current!=NULL){
|
if(!iter->started && iter->current != NULL) {
|
||||||
iter->started=1;
|
iter->started = 1;
|
||||||
return iter->current->data;
|
return iter->current->cont;
|
||||||
}
|
}
|
||||||
if(iter->current!=NULL){
|
if(iter->current != NULL) {
|
||||||
iter->current = iter->current->next;
|
iter->current = iter->current->next;
|
||||||
if(iter->current == NULL) {
|
if(iter->current == NULL) {
|
||||||
iter->current = iter->list->first;
|
iter->current = iter->list->first;
|
||||||
|
@ -103,90 +125,123 @@ void* list_cycl_next(list_iter_p iter){
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* list_prev(list_iter_p iter){
|
container_p list_prev(list_iter_p iter) {
|
||||||
if(!iter->started&&iter->current!=NULL){
|
if(!iter->started&&iter->current!=NULL) {
|
||||||
iter->started=1;
|
iter->started = 1;
|
||||||
return iter->current->data;
|
return iter->current->cont;
|
||||||
}
|
}
|
||||||
if(iter->current!=NULL){
|
if(iter->current!=NULL) {
|
||||||
iter->current = iter->current->prev;
|
iter->current = iter->current->prev;
|
||||||
return list_current(iter);
|
return list_current(iter);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* list_cycl_prev(list_iter_p iter){
|
container_p list_cycl_prev(list_iter_p iter){
|
||||||
if(!iter->started&&iter->current!=NULL){
|
if(!iter->started && iter->current != NULL) {
|
||||||
iter->started=1;
|
iter->started =1 ;
|
||||||
return iter->current->data;
|
return iter->current->cont;
|
||||||
}
|
}
|
||||||
if(iter->current!=NULL){
|
|
||||||
|
if(iter->current!=NULL) {
|
||||||
iter->current = iter->current->prev;
|
iter->current = iter->current->prev;
|
||||||
if(iter->current == NULL) {
|
if(iter->current == NULL) {
|
||||||
iter->current = iter->list->last;
|
iter->current = iter->list->last;
|
||||||
}
|
}
|
||||||
return list_current(iter);
|
return list_current(iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* list_first(list_p list){
|
container_p list_first(list_p list) {
|
||||||
return list->first->data;
|
return list->first->cont;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* list_last(list_p list){
|
container_p list_last(list_p list) {
|
||||||
return list->last->data;
|
return list->last->cont;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* list_pop(list_p list){
|
container_p list_pop(list_p list) {
|
||||||
|
container_p cont;
|
||||||
lnode_p last = list->last;
|
lnode_p last = list->last;
|
||||||
if(last == NULL) return NULL;
|
|
||||||
|
if(last == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
list->last = last->prev;
|
list->last = last->prev;
|
||||||
void* data = last->data;
|
cont = last->cont;
|
||||||
|
|
||||||
if(last->prev != NULL) {
|
if(last->prev != NULL) {
|
||||||
last->prev->next = NULL;
|
last->prev->next = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(last);
|
free(last);
|
||||||
list->length--;
|
list->length--;
|
||||||
|
|
||||||
if(list->length == 0) {
|
if(list->length == 0) {
|
||||||
list->last = list->first = NULL;
|
list->last = list->first = NULL;
|
||||||
}
|
}
|
||||||
return data;
|
|
||||||
|
return cont;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* list_poll(list_p list){
|
container_p list_poll(list_p list){
|
||||||
|
container_p cont;
|
||||||
lnode_p first = list->first;
|
lnode_p first = list->first;
|
||||||
if(first == NULL) return NULL;
|
|
||||||
|
if(first == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
list->first = first->next;
|
list->first = first->next;
|
||||||
void* data = first->data;
|
cont = first->cont;
|
||||||
|
|
||||||
if(first->next != NULL) {
|
if(first->next != NULL) {
|
||||||
first->next->prev = NULL;
|
first->next->prev = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(first);
|
free(first);
|
||||||
list->length--;
|
list->length--;
|
||||||
|
|
||||||
if(list->length == 0) {
|
if(list->length == 0) {
|
||||||
list->last = list->first = NULL;
|
list->last = list->first = NULL;
|
||||||
}
|
}
|
||||||
return data;
|
|
||||||
|
return cont;
|
||||||
}
|
}
|
||||||
|
|
||||||
void list_remove(list_p list, char end){
|
void list_remove(list_p list, char end) {
|
||||||
void * data;
|
container_p cont;
|
||||||
if(end == FRONT)
|
void (*destructor)(void*) = list->destructor;
|
||||||
data = list_poll(list);
|
|
||||||
else if (end == BACK)
|
if(end == LIST_FRONT) {
|
||||||
data = list_pop(list);
|
cont = list_poll(list);
|
||||||
else return;
|
} else if (end == LIST_BACK) {
|
||||||
list->destructor(data);
|
cont = list_pop(list);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cont != NULL) {
|
||||||
|
if(cont->data != NULL) {
|
||||||
|
destructor(cont->data);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(cont);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_list(list_p list){
|
void destroy_list(list_p list) {
|
||||||
lnode_p cur = list->first;
|
lnode_p cur = list->first;
|
||||||
lnode_p next;
|
lnode_p next;
|
||||||
|
|
||||||
while(cur!=NULL){
|
while(cur!=NULL){
|
||||||
next = cur->next;
|
next = cur->next;
|
||||||
if(list->destructor != NULL) { // only destroy data if there is a destructor set
|
if(list->destructor != NULL) { // only destroy data if there is a destructor set
|
||||||
list->destructor(cur->data);
|
list->destructor(cur->cont->data);
|
||||||
|
free(cur->cont);
|
||||||
}
|
}
|
||||||
free(cur);
|
free(cur);
|
||||||
cur = next;
|
cur = next;
|
||||||
|
@ -195,7 +250,10 @@ void destroy_list(list_p list){
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_iterator(list_iter_p iter) {
|
void destroy_iterator(list_iter_p iter) {
|
||||||
if(iter == NULL) return;
|
if(iter == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
free(iter);
|
free(iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2011 Zhehao Mao
|
Copyright (c) 2013 Ubergames
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
this software and associated documentation files (the "Software"), to deal in
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
@ -25,11 +25,37 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
/* A C implementation of a doubly-linked list. Contains void pointer values.
|
/* A C implementation of a doubly-linked list. Contains void pointer values.
|
||||||
Can be used as a LIFO stack of FIFO queue. */
|
Can be used as a LIFO stack of FIFO queue. */
|
||||||
|
|
||||||
#define FRONT 0
|
#include <stdlib.h>
|
||||||
#define BACK 1
|
|
||||||
|
|
||||||
struct linked_node{
|
#define LIST_FRONT 0
|
||||||
void* data;
|
#define LIST_BACK 1
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
LT_BOOLEAN,
|
||||||
|
LT_CHAR,
|
||||||
|
LT_UNSIGNED_CHAR,
|
||||||
|
LT_SHORT,
|
||||||
|
LT_UNSIGNED_SHORT,
|
||||||
|
LT_INT,
|
||||||
|
LT_UNSIGNED_INT,
|
||||||
|
LT_LONG,
|
||||||
|
LT_UNSIGNED_LONG,
|
||||||
|
LT_DOUBLE,
|
||||||
|
LT_STRING,
|
||||||
|
LT_DATA,
|
||||||
|
LT_MAX
|
||||||
|
} dataType_t;
|
||||||
|
|
||||||
|
struct container {
|
||||||
|
void* data;
|
||||||
|
size_t size;
|
||||||
|
dataType_t type;
|
||||||
|
} container;
|
||||||
|
|
||||||
|
typedef struct container* container_p;
|
||||||
|
|
||||||
|
struct linked_node {
|
||||||
|
container_p cont;
|
||||||
struct linked_node* next;
|
struct linked_node* next;
|
||||||
struct linked_node* prev;
|
struct linked_node* prev;
|
||||||
};
|
};
|
||||||
|
@ -61,41 +87,42 @@ list_p create_list(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a list_iter object for the linked_list list. The flag init can be
|
* Create a list_iter object for the linked_list list. The flag init can be
|
||||||
* either FRONT or BACK and indicates whether to start the iterator from the first
|
* either LIST_FRONT or LIST_BACK and indicates whether to start the iterator from the first
|
||||||
* or last item in the list
|
* or last item in the list
|
||||||
*/
|
*/
|
||||||
list_iter_p list_iterator(list_p list, char init);
|
list_iter_p list_iterator(list_p list, char init);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an item with the given value and size to the back of the list.
|
* Add an item with the given value, type, and size to the back of the list.
|
||||||
* The data is copied by value, so the original pointer must be freed if it
|
* The data is copied by value, so the original pointer must be freed if it
|
||||||
* was allocated on the heap.
|
* was allocated on the heap.
|
||||||
|
* Returns the length of the list if succesfull else returns 0.
|
||||||
*/
|
*/
|
||||||
void list_add(list_p list, void* data, int size);
|
int list_add(list_p list, void* data, dataType_t type, int size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the data stored in the first item of the list or NULL if the list is empty
|
* Gets the data stored in the first item of the list or NULL if the list is empty
|
||||||
*/
|
*/
|
||||||
void* list_first(list_p list);
|
container_p list_first(list_p list);
|
||||||
/**
|
/**
|
||||||
* Gets the data stored in the last item of the list or NULL if the list is empty
|
* Gets the data stored in the last item of the list or NULL if the list is empty
|
||||||
*/
|
*/
|
||||||
void* list_last(list_p list);
|
container_p list_last(list_p list);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the last item in the list (LIFO order) and returns the data stored
|
* Removes the last item in the list (LIFO order) and returns the data stored
|
||||||
* there. The data returned must be freed later in order to remain memory safe.
|
* there. The data returned must be freed later in order to remain memory safe.
|
||||||
*/
|
*/
|
||||||
void* list_pop(list_p list);
|
container_p list_pop(list_p list);
|
||||||
/**
|
/**
|
||||||
* Removes the first item in the list (FIFO order) and returns the data stored
|
* Removes the first item in the list (FIFO order) and returns the data stored
|
||||||
* there. The data return must be freed later in order to remain memory safe.
|
* there. The data return must be freed later in order to remain memory safe.
|
||||||
*/
|
*/
|
||||||
void* list_poll(list_p list);
|
container_p list_poll(list_p list);
|
||||||
/**
|
/**
|
||||||
* Convenience function for completely destroying an item in the list. If the end
|
* Convenience function for completely destroying an item in the list. If the end
|
||||||
* flag is FRONT, an item will be polled from the front of the list and its data
|
* flag is LIST_FRONT, an item will be polled from the front of the list and its data
|
||||||
* freed. If the end flag is set to BACK, an item will be popped off the end of
|
* freed. If the end flag is set to LIST_BACK, an item will be popped off the end of
|
||||||
* the list and the data freed.
|
* the list and the data freed.
|
||||||
*/
|
*/
|
||||||
void list_remove(list_p list, char end);
|
void list_remove(list_p list, char end);
|
||||||
|
@ -113,28 +140,28 @@ void destroy_iterator(list_iter_p iter);
|
||||||
/**
|
/**
|
||||||
* Return the data held by the current item pointed to by the iterator
|
* Return the data held by the current item pointed to by the iterator
|
||||||
*/
|
*/
|
||||||
void* list_current(list_iter_p list);
|
container_p list_current(list_iter_p list);
|
||||||
/**
|
/**
|
||||||
* Advances the iterator to the next item in the list and returns the data
|
* Advances the iterator to the next item in the list and returns the data
|
||||||
* stored there.
|
* stored there.
|
||||||
*/
|
*/
|
||||||
void* list_next(list_iter_p list);
|
container_p list_next(list_iter_p list);
|
||||||
/**
|
/**
|
||||||
* Advances the iterator to the previous item in the list and returns the data
|
* Advances the iterator to the previous item in the list and returns the data
|
||||||
* stored there.
|
* stored there.
|
||||||
*/
|
*/
|
||||||
void* list_prev(list_iter_p list);
|
container_p list_prev(list_iter_p list);
|
||||||
/**
|
/**
|
||||||
* Advances the iterator to the next item in the list and returns the data
|
* Advances the iterator to the next item in the list and returns the data
|
||||||
* stored there. If the end of the list is reached it continues with the first
|
* stored there. If the end of the list is reached it continues with the first
|
||||||
* element of the list.
|
* element of the list.
|
||||||
*/
|
*/
|
||||||
void* list_cycl_next(list_iter_p list);
|
container_p list_cycl_next(list_iter_p list);
|
||||||
/**
|
/**
|
||||||
* Advances the iterator to the previous item in the list and returns the data
|
* Advances the iterator to the previous item in the list and returns the data
|
||||||
* stored there. If the start of the list is reached it continues with the last
|
* stored there. If the start of the list is reached it continues with the last
|
||||||
* element of the list.
|
* element of the list.
|
||||||
*/
|
*/
|
||||||
void* list_cycl_prev(list_iter_p list);
|
container_p list_cycl_prev(list_iter_p list);
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in a new issue