NSMBW-Decomp
A decompilation of New Super Mario Bros. Wii
Loading...
Searching...
No Matches
ut_list.h
1#ifndef NW4R_UT_LINKLIST_H
2#define NW4R_UT_LINKLIST_H
3#include <nw4r/types_nw4r.h>
4
5namespace nw4r {
6namespace ut {
7
8struct List {
9 void* headObject; // at 0x0
10 void* tailObject; // at 0x4
11 u16 numObjects; // at 0x8
12 u16 offset; // at 0xA
13};
14
15struct Link {
16 void* prevObject; // at 0x0
17 void* nextObject; // at 0x4
18};
19
20void List_Init(List* pList, u16 offset);
21
22void List_Append(List* pList, void* pObject);
23void List_Prepend(List* pList, void* pObject);
24
25void List_Insert(List* pList, void* pTarget, void* pObject);
26void List_Remove(List* pList, void* pObject);
27
28void* List_GetNext(const List* pList, const void* pObject);
29inline const void* List_GetNextConst(const List* pList, const void* pObject) {
30 return List_GetNext(pList, pObject);
31}
32
33void* List_GetPrev(const List* pList, const void* pObject);
34inline const void* List_GetPrevConst(const List* pList, const void* pObject) {
35 return List_GetPrev(pList, pObject);
36}
37
38void* List_GetNth(const List* pList, u16 n);
39inline const void* List_GetNthConst(const List* pList, u16 n) {
40 return List_GetNth(pList, n);
41}
42
43inline void* List_GetFirst(const List* pList) {
44 return List_GetNext(pList, NULL);
45}
46inline const void* List_GetFirstConst(const List* pList) {
47 return List_GetFirst(pList);
48}
49
50inline void* List_GetLast(const List* pList) {
51 return List_GetPrev(pList, NULL);
52}
53inline const void* List_GetLastConst(const List* pList) {
54 return List_GetLast(pList);
55}
56
57inline u16 List_GetSize(const List* pList) {
58 return pList->numObjects;
59}
60
61/******************************************************************************
62 *
63 * Macros
64 *
65 ******************************************************************************/
66/**
67 * Declares a member Link.
68 */
69#define NW4R_UT_LIST_LINK_DECL() nw4r::ut::Link link
70
71/**
72 * Initializes a List object for use with the specified type.
73 *
74 * @param LIST Reference to list
75 * @param T List element type
76 */
77#define NW4R_UT_LIST_INIT(LIST, T) \
78 nw4r::ut::List_Init(&(LIST), offsetof(T, link))
79
80/**
81 * Gets the underlying Link within the specified object.
82 *
83 * @param LIST Reference to list
84 * @param OBJ Pointer to list object
85 */
86#define NW4R_UT_LIST_GET_LINK(LIST, OBJ) \
87 reinterpret_cast<nw4r::ut::Link*>((u8*)(OBJ) + (LIST).offset)
88
89/**
90 * List for-each macro.
91 *
92 * @param TYPE Element type
93 * @param NAME Element name
94 * @param LIST Reference to list
95 * @param ... Statement(s) to execute
96 */
97#define NW4R_UT_LIST_FOREACH(TYPE, NAME, LIST, ...) \
98 { \
99 TYPE* NAME = NULL; \
100 \
101 while ((NAME = static_cast<TYPE*>( \
102 nw4r::ut::List_GetNext(&(LIST), NAME))) != NULL) { \
103 \
104 __VA_ARGS__; \
105 } \
106 }
107/**
108 * List for-each macro (reverse order).
109 *
110 * @param TYPE Element type
111 * @param NAME Element name
112 * @param LIST Reference to list
113 * @param ... Statement(s) to execute
114 */
115#define NW4R_UT_LIST_FOREACH_REV(TYPE, NAME, LIST, ...) \
116 { \
117 TYPE* NAME = NULL; \
118 \
119 while ((NAME = static_cast<TYPE*>( \
120 nw4r::ut::List_GetPrev(&(LIST), NAME))) != NULL) { \
121 \
122 __VA_ARGS__; \
123 } \
124 }
125
126/**
127 * List for-each macro, with robust iteration.
128 *
129 * @param TYPE Element type
130 * @param NAME Element name
131 * @param LIST Reference to list
132 * @param ... Statement(s) to execute
133 */
134#define NW4R_UT_LIST_FOREACH_SAFE(TYPE, NAME, LIST, ...) \
135 { \
136 TYPE* NAME; \
137 TYPE* __next__; \
138 \
139 for (NAME = static_cast<TYPE*>(nw4r::ut::List_GetFirst(&(LIST))); \
140 NAME != NULL; NAME = __next__) { \
141 \
142 __next__ = \
143 static_cast<TYPE*>(nw4r::ut::List_GetNext(&(LIST), NAME)); \
144 \
145 __VA_ARGS__; \
146 } \
147 }
148
149} // namespace ut
150} // namespace nw4r
151
152#endif
Debugging library which includes various utilities used by the rest of nw4r.
Definition ut_list.cpp:4