taisei/src/list.h

55 lines
1.5 KiB
C
Raw Normal View History

/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
* ---
2017-09-12 03:28:15 +02:00
* Copyright (c) 2011-2017, Lukas Weber <laochailan@web.de>.
* Copyright (c) 2012-2017, Andrei Alexeyev <akari@alienslab.net>.
*/
2017-09-27 14:14:53 +02:00
#pragma once
/* I got annoyed of the code doubling caused by simple linked lists,
* so i do some void-magic here to save the lines.
*/
#include <stdlib.h>
void* create_element(void **dest, size_t size);
2017-10-03 17:25:38 +02:00
void* create_element_at_end(void **dest, size_t size);
void* create_element_at_priority(void **list_head, size_t size, int prio, int (*prio_func)(void*));
void delete_element(void **dest, void *e);
void delete_all_elements(void **dest, void (callback)(void **, void *));
void delete_all_elements_witharg(void **dest, void (callback)(void **, void *, void *), void *arg);
typedef struct List {
struct List *next;
struct List *prev;
} List;
typedef struct ListContainer {
struct ListContainer *next;
struct ListContainer *prev;
void *data;
} ListContainer;
ListContainer* create_container(ListContainer **dest);
ListContainer* create_container_at_priority(ListContainer **list_head, int prio, int (*prio_func)(void*));
typedef struct {
void *ptr;
int refs;
} Reference;
typedef struct {
Reference *ptrs;
int count;
} RefArray;
extern void *_FREEREF;
#define FREEREF &_FREEREF
#define REF(p) (global.refs.ptrs[(int)(p)].ptr)
int add_ref(void *ptr);
void del_ref(void *ptr);
void free_ref(int i);
void free_all_refs(void);