UFO: Alien Invasion
Loading...
Searching...
No Matches
list.h File Reference

LINKED LIST interface. More...

Include dependency graph for list.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  linkedList_t

Macros

#define LIST_Foreach(list, type, var)
 Iterates over a linked list, it's safe to delete the returned entry from the list while looping over it.
#define LIST_ForeachSorted(list, type, var, sorter, userdata, sortedlist)
 Will sort the list before loop over the sorted list. Make sure to free the sortedList after you are done with the loop.

Typedefs

typedef int(* linkedListSort_t) (linkedList_t *entry1, linkedList_t *entry2, const void *userData)

Functions

void LIST_PrependString (linkedList_t **listDest, const char *data)
 Adds a string as first entry to a linked list.
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.
void LIST_AddStringSorted (linkedList_t **listDest, const char *data)
void LIST_AddPointer (linkedList_t **listDest, void *data)
 Adds just a pointer to a new or to an already existing linked list.
linkedList_tLIST_Add (linkedList_t **list, void const *data, size_t length)
 Adds an entry to a new or to an already existing linked list.
const linkedList_tLIST_ContainsString (const linkedList_t *list, const char *string)
 Searches for the first occurrence of a given string.
linkedList_tLIST_GetPointer (linkedList_t *list, const void *data)
 Searches for the first occurrence of a given pointer.
void LIST_Delete (linkedList_t **list)
bool LIST_RemoveEntry (linkedList_t **list, linkedList_t *entry)
 Removes one entry from the linked list.
bool LIST_IsEmpty (const linkedList_t *list)
 Checks whether the given list is empty.
int LIST_Count (const linkedList_t *list)
linkedList_tLIST_CopyStructure (linkedList_t *src)
 Copies the list structure data - but not the content from the original list. We are only using pointers here.
voidLIST_GetByIdx (linkedList_t *list, int index)
 Get an entry of a linked list by its index in the list.
bool LIST_Remove (linkedList_t **list, const void *data)
void LIST_Sort (linkedList_t **list, linkedListSort_t sorter, const void *userData)
voidLIST_GetRandom (linkedList_t *list)
template<typename T>
T & LIST_Add (linkedList_t **const list, T const &data)

Detailed Description

LINKED LIST interface.

Definition in file list.h.

Macro Definition Documentation

◆ LIST_Foreach

#define LIST_Foreach ( list,
type,
var )
Value:
for (bool var##__break = false, var##__once = true; var##__once; var##__once = false) \
for (linkedList_t const* var##__iter = (list); !var##__break && var##__iter;) \
for (type* const var = (var##__break = var##__once = true, static_cast<type*>(var##__iter->data)); var##__once; var##__break = var##__once = false) \
if (var##__iter = var##__iter->next, false) {} else
QGL_EXTERN GLint GLenum type
Definition r_gl.h:94

Iterates over a linked list, it's safe to delete the returned entry from the list while looping over it.

Note
var must be a simple variable name, because it is declared in the loop macro and is also used to create the name of the internal variables.
Don't try to use the internal loop variable. This variable is most likely not at the position you would expect it to be.

Definition at line 41 of file list.h.

Referenced by AC_Init_f(), AC_KillAll_f(), AC_KillExceeding_f(), AC_KillOne_f(), AlienCargo::add(), ItemCargo::add(), AII_CollectingItems(), AIR_DestroyAircraft(), AIR_GetStorageRoom(), AIR_MoveAircraftIntoNewHomebase(), AIR_MoveEmployeeInventoryIntoStorage(), AIR_RemoveEmployees(), AIR_SaveAircraftXML(), AL_AddAliens(), AlienCargo::AlienCargo(), AM_FillTeamFromAircraft(), AM_UpdateSurivorsAfterBattle(), B_BuildBuilding(), B_InitialEquipment(), B_IsBuildingDestroyable(), B_SellOrAddItems(), B_SetUpFirstBase(), CHAR_UpdateData(), CITY_GetById(), CITY_GetByPos(), CL_ActorGetChr(), CL_ActorUpdate_f(), CL_ChangeSkinForWholeTeam_f(), CL_GetEventMail(), CL_SwapSkills(), CLMN_Mods_f(), Com_AddObjectLinks(), Com_GetBodyTemplateByID(), Com_GetNameListByID(), Com_ParseActorNames(), Com_ParseBodyTemplate(), ItemCargo::count(), CP_CleanupAircraftTeam(), CP_EndRescueMission(), CP_IsAlienEquipmentSelectable(), CP_SpawnRescueMission(), CP_TEAM_FillEquipSoldierList_f(), Destroy_Breakable(), uiLineChartNode::draw(), E_GetHiredRobot(), FS_BuildFileList(), GAME_ActorSelect_f(), GAME_ChangeEquip(), GAME_CP_InitializeBattlescape(), GAME_CP_Spawn(), GAME_GetCGameAPI(), GAME_GetSelectedChr(), GAME_InitializeBattlescape(), GAME_SaveTeamInfo(), GAME_SaveTeamState_f(), GAME_SendCurrentTeamSpawningInfo(), GAME_Spawn(), GAME_ToggleActorForTeam_f(), GAME_UpdateTeamMenuParameters_f(), ItemCargo::get(), AlienCargo::getAlive(), AlienCargo::getDead(), ItemCargo::ItemCargo(), AlienCargo::list(), ItemCargo::list(), LIST_CopyStructure(), NAT_ScriptSanityCheck(), AlienCargo::save(), ItemCargo::save(), ItemCargo::size(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), GameTest::testCountSpawnpointsForMap(), GameTest::testCountSpawnpointsForMapInMultiplayerMode(), GameTest::testCountSpawnpointsForMapWithAssembly(), GameTest::testCountSpawnpointsForMapWithAssemblyAndAircraft(), TR_Add_f(), TR_CargoList(), TR_CountAircraftInList(), TR_EmptyTransferCargo(), TR_FillAliens(), TR_List_f(), TR_TransferStart(), UI_AddLineChartCoord(), UI_AddLineChartLine(), UI_ClearLineChart(), UI_CvarChangeListener(), UI_ExecuteLuaEventScript_ParamList(), UI_ShowChartDots(), and UI_ShowChartLine().

◆ LIST_ForeachSorted

#define LIST_ForeachSorted ( list,
type,
var,
sorter,
userdata,
sortedlist )
Value:
sortedlist = LIST_CopyStructure(list); \
LIST_Sort(&sortedlist, sorter, userdata); \
LIST_Foreach(sortedlist, type, var)
linkedList_t * LIST_CopyStructure(linkedList_t *src)

Will sort the list before loop over the sorted list. Make sure to free the sortedList after you are done with the loop.

Definition at line 50 of file list.h.

Typedef Documentation

◆ linkedListSort_t

typedef int(* linkedListSort_t) (linkedList_t *entry1, linkedList_t *entry2, const void *userData)

Definition at line 36 of file list.h.

Function Documentation

◆ LIST_Add() [1/2]

template<typename T>
T & LIST_Add ( linkedList_t **const list,
T const & data )
inline

Add a copy of data to list and return a reference to the copied data.

Definition at line 75 of file list.h.

References data, linkedList_t::data, and LIST_Add().

◆ LIST_Add() [2/2]

◆ LIST_AddPointer()

void LIST_AddPointer ( linkedList_t ** listDest,
void * data )

Adds just a pointer to a new or to an already existing linked list.

See also
LIST_Add
LIST_RemoveEntry
Todo
Optimize this to not allocate memory for every entry - but use a hunk

Definition at line 153 of file list.cpp.

References data, LIST_AllocateEntry(), LIST_AppendEntry(), and linkedList_t::ptr.

Referenced by GAME_AppendTeamMember(), GAME_GetImportData(), GAME_LoadTeamInfo(), GAME_Spawn(), HUD_PopupFiremodeReservation(), LIST_CopyStructure(), and UI_CvarListenerNodeBind().

◆ LIST_AddString()

◆ LIST_AddStringSorted()

void LIST_AddStringSorted ( linkedList_t ** listDest,
const char * data )

◆ LIST_ContainsString()

const linkedList_t * LIST_ContainsString ( const linkedList_t * list,
const char * string )

Searches for the first occurrence of a given string.

Returns
the linkedList_t pointer if the string is found, otherwise nullptr
Note
if string is nullptr, the function returns nullptr
See also
LIST_AddString

Definition at line 73 of file list.cpp.

References linkedList_t::data, linkedList_t::next, and Q_streq.

Referenced by _AddToListBlock(), GAME_ChangeEquip(), GAME_GetImportData(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), UI_AddCvarListener_f(), UI_RemoveCvarListener_f(), and UI_UpdateInvisOptions().

◆ LIST_CopyStructure()

linkedList_t * LIST_CopyStructure ( linkedList_t * src)

Copies the list structure data - but not the content from the original list. We are only using pointers here.

Definition at line 52 of file cl_game_campaign.cpp.

References cgi, data, dest, LIST_AddPointer(), and LIST_Foreach.

Referenced by GAME_GetImportData(), and TEST_F().

◆ LIST_Count()

◆ LIST_Delete()

◆ LIST_GetByIdx()

void * LIST_GetByIdx ( linkedList_t * list,
int index )

Get an entry of a linked list by its index in the list.

Parameters
[in]listLinked list to get the entry from.
[in]indexThe index of the entry in the linked list.
Returns
A void pointer of the content in the list-entry.

Definition at line 362 of file list.cpp.

References linkedList_t::data, i, index, LIST_IsEmpty(), and linkedList_t::next.

Referenced by CL_ChangeSkin_f(), GAME_GetImportData(), HUD_ShotReserve_f(), LIST_GetRandom(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), UI_ExecuteLuaMethod(), and UI_GetTextFromList().

◆ LIST_GetPointer()

linkedList_t * LIST_GetPointer ( linkedList_t * list,
const void * data )

Searches for the first occurrence of a given pointer.

Returns
the linkedList_t pointer if the string is found, otherwise nullptr
Note
if data is nullptr, the function returns nullptr
O(n)
Only use this for small linked lists

Definition at line 91 of file list.cpp.

References data, linkedList_t::data, and linkedList_t::next.

Referenced by GAME_GetImportData(), LIST_Remove(), and UI_CvarListenerNodeBind().

◆ LIST_GetRandom()

void * LIST_GetRandom ( linkedList_t * list)

Definition at line 381 of file list.cpp.

References LIST_Count(), and LIST_GetByIdx().

Referenced by GAME_GetImportData(), TEST_F(), and UI_MapInfo().

◆ LIST_IsEmpty()

◆ LIST_PrependString()

void LIST_PrependString ( linkedList_t ** listDest,
const char * data )

Adds a string as first entry to a linked list.

Parameters
listDestThe linked list to add the string, too. If this is nullptr, a new list is created
dataThe string to add to the list
See also
LIST_AddString
Todo
Optimize this to not allocate memory for every entry - but use a hunk

Definition at line 127 of file list.cpp.

References data, and LIST_AllocateString().

Referenced by GAME_GetImportData(), and TEST_F().

◆ LIST_Remove()

bool LIST_Remove ( linkedList_t ** list,
const void * data )

◆ LIST_RemoveEntry()

bool LIST_RemoveEntry ( linkedList_t ** list,
linkedList_t * entry )

Removes one entry from the linked list.

See also
LIST_AddString
LIST_Add
LIST_AddPointer
LIST_Delete
Returns
true if the removal was successful, false otherwise.

Definition at line 172 of file list.cpp.

References linkedList_t::data, Mem_Free, linkedList_t::next, and linkedList_t::ptr.

Referenced by cgame_import_t::bool(), GAME_GetImportData(), LIST_Remove(), TEST_F(), and UI_RemoveCvarListener_f().

◆ LIST_Sort()

void LIST_Sort ( linkedList_t ** list,
linkedListSort_t sorter,
const void * userData )

Definition at line 48 of file cl_game_campaign.cpp.

References _LIST_Sort(), cgi, and LIST_IsEmpty().

Referenced by GAME_GetImportData(), and TEST_F().