UFO: Alien Invasion
Loading...
Searching...
No Matches
list.h
Go to the documentation of this file.
1
5
6/*
7Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24*/
25
26#pragma once
27
28#include "../shared/ufotypes.h"
29
31 void* data;
33 bool ptr;
34};
35
36typedef int (*linkedListSort_t) (linkedList_t* entry1, linkedList_t* entry2, const void* userData);
37
41#define LIST_Foreach(list, type, var) \
42 for (bool var##__break = false, var##__once = true; var##__once; var##__once = false) \
43 for (linkedList_t const* var##__iter = (list); !var##__break && var##__iter;) \
44 for (type* const var = (var##__break = var##__once = true, static_cast<type*>(var##__iter->data)); var##__once; var##__break = var##__once = false) \
45 if (var##__iter = var##__iter->next, false) {} else
46
50#define LIST_ForeachSorted(list, type, var, sorter, userdata, sortedlist) \
51 sortedlist = LIST_CopyStructure(list); \
52 LIST_Sort(&sortedlist, sorter, userdata); \
53 LIST_Foreach(sortedlist, type, var)
54
55void LIST_PrependString(linkedList_t** listDest, const char* data);
56void LIST_AddString(linkedList_t** list, const char* data);
57void LIST_AddStringSorted(linkedList_t** listDest, const char* data);
58void LIST_AddPointer(linkedList_t** listDest, void* data);
59linkedList_t* LIST_Add(linkedList_t** list, void const* data, size_t length);
60const linkedList_t* LIST_ContainsString(const linkedList_t* list, const char* string);
62void LIST_Delete(linkedList_t** list);
63bool LIST_RemoveEntry(linkedList_t** list, linkedList_t* entry);
64bool LIST_IsEmpty(const linkedList_t* list);
65int LIST_Count(const linkedList_t* list);
67void* LIST_GetByIdx(linkedList_t* list, int index);
68bool LIST_Remove(linkedList_t** list, const void* data);
69void LIST_Sort(linkedList_t** list, linkedListSort_t sorter, const void* userData);
70void* LIST_GetRandom(linkedList_t* list);
71
75template<typename T> inline T& LIST_Add(linkedList_t** const list, T const& data)
76{
77 return *static_cast<T*>(LIST_Add(list, &data, sizeof(data))->data);
78}
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
linkedList_t * LIST_GetPointer(linkedList_t *list, const void *data)
Searches for the first occurrence of a given pointer.
Definition list.cpp:91
void LIST_AddStringSorted(linkedList_t **listDest, const char *data)
Definition list.cpp:107
linkedList_t * LIST_CopyStructure(linkedList_t *src)
Copies the list structure data - but not the content from the original list. We are only using pointe...
int(* linkedListSort_t)(linkedList_t *entry1, linkedList_t *entry2, const void *userData)
Definition list.h:36
void * LIST_GetRandom(linkedList_t *list)
Definition list.cpp:381
void LIST_Delete(linkedList_t **list)
Definition list.cpp:195
bool LIST_RemoveEntry(linkedList_t **list, linkedList_t *entry)
Removes one entry from the linked list.
Definition list.cpp:172
linkedList_t * LIST_Add(linkedList_t **list, void const *data, size_t length)
Adds an entry to a new or to an already existing linked list.
void LIST_Sort(linkedList_t **list, linkedListSort_t sorter, const void *userData)
void * LIST_GetByIdx(linkedList_t *list, int index)
Get an entry of a linked list by its index in the list.
Definition list.cpp:362
int LIST_Count(const linkedList_t *list)
Definition list.cpp:344
void LIST_AddPointer(linkedList_t **listDest, void *data)
Adds just a pointer to a new or to an already existing linked list.
Definition list.cpp:153
void LIST_AddString(linkedList_t **list, const char *data)
Adds an string to a new or to an already existing linked list. The string is copied here.
Definition list.cpp:139
bool LIST_Remove(linkedList_t **list, const void *data)
Definition list.cpp:213
bool LIST_IsEmpty(const linkedList_t *list)
Checks whether the given list is empty.
Definition list.cpp:335
const linkedList_t * LIST_ContainsString(const linkedList_t *list, const char *string)
Searches for the first occurrence of a given string.
Definition list.cpp:73
void LIST_PrependString(linkedList_t **listDest, const char *data)
Adds a string as first entry to a linked list.
Definition list.cpp:127
QGL_EXTERN GLsizei const GLvoid * data
Definition r_gl.h:89
QGL_EXTERN GLuint GLsizei GLsizei * length
Definition r_gl.h:110
QGL_EXTERN GLuint index
Definition r_gl.h:110
void * data
Definition list.h:31
linkedList_t * next
Definition list.h:32
bool ptr
Definition list.h:33
Cross-platform type definitions.