Loading [MathJax]/extensions/tex2jax.js
Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
linklist.h
Go to the documentation of this file.
1#ifndef LINKLIST_H
2#define LINKLIST_H
3
5
6namespace JGadget {
9 mNext = NULL;
10 mPrev = NULL;
11 }
12
14
15 TLinkListNode* getNext() const { return mNext; }
16 TLinkListNode* getPrev() const { return mPrev; }
17
18public:
19 /* 0x0 */ TLinkListNode* mNext;
20 /* 0x4 */ TLinkListNode* mPrev;
21}; // Size: 0x8
22
24 struct iterator {
25 iterator() { node = NULL; }
26 explicit iterator(TLinkListNode* pNode) { node = pNode; }
27 iterator& operator=(const iterator& other) { node = other.node; return *this; }
28
29 iterator& operator++() { node = node->getNext(); return *this; }
30 iterator& operator--() { node = node->getPrev(); return *this; }
31 iterator operator++(int) { const iterator old(*this); (void)++*this; return old; }
32 iterator operator--(int) { const iterator old(*this); (void)--*this; return old; }
33 friend bool operator==(iterator a, iterator b) { return a.node == b.node; }
34 friend bool operator!=(iterator a, iterator b) { return !(a == b); }
35
36 TLinkListNode* operator->() const { return node; }
37 TLinkListNode& operator*() const { return *node; }
38
39 public:
40 /* 0x00 */ TLinkListNode* node;
41 };
42
44 explicit const_iterator(TLinkListNode* pNode) { node = pNode; }
45 explicit const_iterator(iterator it) { node = it.node; }
46
47 const_iterator& operator++() { node = node->getNext(); return *this; }
48 const_iterator& operator--() { node = node->getPrev(); return *this; }
49 const_iterator operator++(int) { const const_iterator old(*this); (void)++*this; return old; }
50 const_iterator operator--(int) { const const_iterator old(*this); (void)--*this; return old; }
51 friend bool operator==(const_iterator a, const_iterator b) { return a.node == b.node; }
52 friend bool operator!=(const_iterator a, const_iterator b) { return !(a == b); }
53
54 friend bool operator==(const_iterator a, iterator b) { return a.node == b.node; }
55 friend bool operator!=(const_iterator a, iterator b) { return !(a == b); }
56
57 const TLinkListNode* operator->() const { return node; }
58 const TLinkListNode& operator*() const { return *node; }
59
60 public:
61 /* 0x00 */ TLinkListNode* node;
62 };
63
66
67 void Initialize_() {
68 count = 0;
71 }
72
77 u32 size() { return count; }
78 bool empty() { return size() == 0; }
79 iterator pop_front() { return erase(begin()); }
80
89
90 bool Iterator_isEnd_(const_iterator it) const { return it.node == &ocObject_; }
91 template <typename Predicate>
92 void Remove_if(Predicate predicate, TNodeLinkList& tList) {
93 iterator it = begin();
94
96 if (predicate(*it)) {
97 iterator itPrev = it;
98 ++it;
99 tList.splice(tList.end(), *this, itPrev);
100 } else {
101 ++it;
102 }
103 }
104 }
105
106 template <typename Predicate>
107 void remove_if(Predicate predicate) {
109 Remove_if(predicate, list);
110 }
111
112public:
113 /* 0x00 */ u32 count;
115}; // Size: 0xC
116
117template <typename T, int I>
118struct TLinkList : public TNodeLinkList {
120
121 struct iterator {
123 explicit iterator(TNodeLinkList::iterator iter) : base(iter) {}
124
126 ++base;
127 return *this;
128 }
130 --base;
131 return *this;
132 }
134 const iterator old(*this);
135 ++*this;
136 return old;
137 }
139 const iterator old(*this);
140 --*this;
141 return old;
142 }
143 friend bool operator==(iterator a, iterator b) { return a.base == b.base; }
144 friend bool operator!=(iterator a, iterator b) { return !(a == b); }
145
146 T* operator->() const { return Element_toValue(base.operator->()); }
147 T& operator*() const { return *operator->(); }
148
149 public:
151 };
152
155 explicit const_iterator(iterator iter) : base(iter.base) {}
156
158 ++base;
159 return *this;
160 }
162 --base;
163 return *this;
164 }
166 const const_iterator old(*this);
167 ++*this;
168 return old;
169 }
171 const const_iterator old(*this);
172 --*this;
173 return old;
174 }
175 friend bool operator==(const_iterator a, const_iterator b) { return a.base == b.base; }
176 friend bool operator!=(const_iterator a, const_iterator b) { return !(a == b); }
177
178 const T* operator->() const { return Element_toValue(base.operator->()); }
179 const T& operator*() const { return *operator->(); }
180
181 public:
183 };
184
186 JUT_ASSERT(0x2F1, p!=0);
187 return reinterpret_cast<TLinkListNode*>(reinterpret_cast<char*>(p) - I);
188 }
189 static const TLinkListNode* Element_toNode(const T* p) {
190 JUT_ASSERT(0x2F6, p!=0);
191 return reinterpret_cast<const TLinkListNode*>(reinterpret_cast<const char*>(p) - I);
192 }
194 JUT_ASSERT(0x2FB, p!=0);
195 return reinterpret_cast<T*>(reinterpret_cast<char*>(p) + I);
196 }
197 static const T* Element_toValue(const TLinkListNode* p) {
198 JUT_ASSERT(0x300, p!=0);
199 return reinterpret_cast<const T*>(reinterpret_cast<const char*>(p) + I);
200 }
201
202 iterator Insert(iterator iter, T* element) {
203 return iterator(TNodeLinkList::Insert(iter.base, Element_toNode(element)));
204 }
205 iterator Erase(T* element) { return iterator(TNodeLinkList::Erase(Element_toNode(element))); }
206
208 const_iterator begin() const { return const_iterator(const_cast<TLinkList*>(this)->begin()); }
210 const_iterator end() const { return const_iterator(const_cast<TLinkList*>(this)->end()); }
211 T& front() { return *begin(); }
212 T& back() { return *--end(); }
214 void Push_front(T* element) { Insert(begin(), element); }
215 void Push_back(T* element) { Insert(end(), element); }
216 iterator Find(const T* element) {
218 }
219 void Remove(T* element) { TNodeLinkList::Remove(Element_toNode(element)); }
220};
221
222template <typename T, int I>
223struct TLinkList_factory : public TLinkList<T, I> {
225 virtual T* Do_create() = 0;
226 virtual void Do_destroy(T*) = 0;
228 while (!this->empty()) {
229 T* item = &this->front();
230 this->pop_front();
231 Do_destroy(item);
232 }
233 }
234};
235
236template <typename T>
238 inline TEnumerator(T _current, T _end)
239 : current(_current), end(_end) {}
240
241 bool isEnd() const { return current != end; }
242 operator bool() const { return isEnd(); }
244 T rv = current;
245 ++current;
246 return rv;
247 }
248
251};
252
253// TEnumerator2 should be the same but there are two issues:
254// 1. How to derive the iterator return type for operator* (the debug makes it seem like operator* is called
255// so the return value should be what the iterator points to)
256// 2. Calling the * operator seems to make functions using TEnumerator<T*> not work. See
257// JStudio::TAdaptor::adaptor_setVariableValue_n
258// Perhaps template specialization?
259template <typename Iterator, typename T>
261 inline TEnumerator2(Iterator _current, Iterator _end)
262 : current(_current), end(_end) {}
263
264 bool isEnd() const { return current != end; }
265 operator bool() const { return isEnd(); }
267 T& rv = *current;
268 ++current;
269 return rv;
270 }
271
272 Iterator current;
273 Iterator end;
274};
275
276template <typename T, int I>
277struct TContainerEnumerator : public TEnumerator2<typename TLinkList<T, I>::iterator, T> {
279 : TEnumerator2<typename TLinkList<T, I>::iterator, T>(param_0->begin(), param_0->end()) {}
280};
281
282
283template <typename T, int I>
284struct TContainerEnumerator_const : public TEnumerator2<typename TLinkList<T, I>::const_iterator, const T> {
286 : TEnumerator2<typename TLinkList<T, I>::const_iterator, const T>(param_0->begin(), param_0->end()) {}
287};
288
289}; // namespace JGadget
290
291#endif /* LINKLIST_H */
p
Definition e_acos.c:98
a
Definition k_cos.c:89
Definition functionvalue.cpp:19
va_list list
Definition os.h:192
Definition linklist.h:284
TContainerEnumerator_const(const TLinkList< T, I > *param_0)
Definition linklist.h:285
Definition linklist.h:277
TContainerEnumerator(TLinkList< T, I > *param_0)
Definition linklist.h:278
Definition linklist.h:260
TEnumerator2(Iterator _current, Iterator _end)
Definition linklist.h:261
Iterator end
Definition linklist.h:273
bool isEnd() const
Definition linklist.h:264
T & operator*()
Definition linklist.h:266
Iterator current
Definition linklist.h:272
Definition linklist.h:237
TEnumerator(T _current, T _end)
Definition linklist.h:238
T operator*()
Definition linklist.h:243
T end
Definition linklist.h:250
bool isEnd() const
Definition linklist.h:241
T current
Definition linklist.h:249
Definition linklist.h:7
TLinkListNode * mNext
Definition linklist.h:19
TLinkListNode * getPrev() const
Definition linklist.h:16
TLinkListNode * mPrev
Definition linklist.h:20
~TLinkListNode()
Definition linklist.h:13
TLinkListNode * getNext() const
Definition linklist.h:15
TLinkListNode()
Definition linklist.h:8
unsigned long u32
Definition types.h:9