Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
Loading...
Searching...
No Matches
std-list.h
Go to the documentation of this file.
1#ifndef STD_LIST_H
2#define STD_LIST_H
3
7
8namespace JGadget {
9 template <typename T, typename Allocator = JGadget::TAllocator<T> >
10 struct TList {
11 struct TNode_ {
12 /* 0x00 */ TNode_* pNext_;
13 /* 0x04 */ TNode_* pPrev_;
14 };
15
16 struct iterator : public TIterator<std::bidirectional_iterator_tag, T, s32, T*, T&> {
17 iterator() {p_ = NULL; }
18 iterator(TNode_* pNode) { p_ = pNode; }
19
20 iterator& operator++() { p_ = p_->pNext_; return *this; }
21 iterator& operator--() { p_ = p_->pPrev_; return *this; }
22 iterator operator++(int) { const iterator old(*this); (void)++*this; return old; }
23 iterator operator--(int) { const iterator old(*this); (void)--*this; return old; }
24 friend bool operator==(iterator a, iterator b) { return a.p_ == b.p_; }
25 friend bool operator!=(iterator a, iterator b) { return !(a == b); }
26 T& operator*() const {
27 JUT_ASSERT(125, p_!=NULL);
28 return *(T*)&p_[1];
29 }
30
31 /* 0x00 */ TNode_* p_;
32 };
33
35 const_iterator(TNode_* pNode) { p_ = pNode; }
36
37 const_iterator& operator++() { p_ = p_->pNext_; return *this; }
38 const_iterator& operator--() { p_ = p_->pPrev_; return *this; }
39 friend bool operator==(const_iterator a, const_iterator b) { return a.p_ == b.p_; }
40 friend bool operator!=(const_iterator a, const_iterator b) { return !(a == b); }
41
42 /* 0x00 */ TNode_* p_;
43 };
44
45 TList(const Allocator& allocator = Allocator()) {
46 field_0x4 = 0;
48 }
50 int r30;
51 int r29;
53 int r27;
54 Confirm();
55 clear();
56 r30 = 0;
57 r29 = 1;
58 if (empty()) {
59 return;
60 }
61
63 r30 = 1;
64 r28 = &out;
65 *r28 << "empty()";
66 r27 = 0;
67 if (!r27) {
68 r29 = 0;
69 }
70 }
71
72 iterator push_front(const T& element) { return insert(begin(), element); }
73 iterator push_back(const T& element) { return insert(end(), element); }
74 iterator insert(iterator it, const T& element) {
75 TNode_* p = it.p_;
76 JUT_ASSERT(286, p!=NULL);
77 TNode_* prev = p->pPrev_;
78 TNode_* node = CreateNode_(p, prev, element);
79 if (!node) {
80 return end();
81 }
82 p->pPrev_ = node;
83 prev->pNext_ = node;
84 field_0x4++;
85 return iterator(node);
86 }
87
89 while (start != end) {
90 start = erase(start);
91 }
92 return start;
93 }
94
96 JUT_ASSERT(314, !empty());
97 TNode_* p = it.p_;
98 JUT_ASSERT(316, p!=NULL);
99 TNode_* next = p->pNext_;
100 p->pPrev_->pNext_ = next;
101 next->pPrev_ = p->pPrev_;
103 field_0x4--;
104 return iterator(next);
105 }
106
107 void clear() { erase(begin(), end()); }
108 BOOL empty() const { return size() == 0; }
109 int size() const { return field_0x4; }
111 iterator end() { return iterator(&oEnd_); }
116
117 void Initialize_() {
118 oEnd_.pNext_ = &oEnd_;
119 oEnd_.pPrev_ = &oEnd_;
120 }
121
122 BOOL Confirm() const {
123 u32 r28 = 0;
124 const_iterator local_24 = end();
125 if (local_24.p_ != &oEnd_) {
126 return FALSE;
127 }
128 const_iterator local_28 = begin();
129 if (local_28.p_ != oEnd_.pNext_) {
130 return FALSE;
131 }
132 for (; local_28 != local_24; ++local_28) {
133 TNode_* node = local_28.p_;
134 if (node->pNext_->pPrev_ != node) {
135 return FALSE;
136 }
137 if (node->pPrev_->pNext_ != node) {
138 return FALSE;
139 }
140 r28++;
141 }
142 if (local_28.p_ != &oEnd_) {
143 return FALSE;
144 }
145 if (r28 != size()) {
146 return FALSE;
147 }
148 return TRUE;
149 }
150
151 TNode_* CreateNode_(TNode_ *pNext, TNode_ *pPrev, const T& pObject) {
152 JUT_ASSERT(483, pNext!=NULL);
153 JUT_ASSERT(484, pPrev!=NULL);
154 TNode_* node = (TNode_*)mAllocator.AllocateRaw(sizeof(TNode_) + sizeof(T));
155 if (!node) {
156 JGADGET_WARNMSG(489, "can\'t allocate memory");
157 return NULL;
158 }
159 node->pNext_ = pNext;
160 node->pPrev_ = pPrev;
161 mAllocator.construct((T*)&node[1], pObject);
162 return node;
163 }
164
166 JUT_ASSERT(501, p!=NULL);
167 JUT_ASSERT(502, p!=&oEnd_);
168 JUT_ASSERT(503, p->pNext_->pPrev_!=p);
169 JUT_ASSERT(504, p->pPrev_->pNext_!=p);
170 mAllocator.destroy((T*)&p[1]);
171 mAllocator.DeallocateRaw((T*)p);
172 }
173
174 /* 0x00 */ Allocator mAllocator;
175 /* 0x04 */ int field_0x4;
176 /* 0x08 */ TNode_ oEnd_;
177 };
178}
179
180#endif /* STD_LIST_H */
Definition define.h:9
static void warning(const char *, int, const char *)
Definition define.cpp:70
static u32 next
Definition CARDUnlock.c:29
DVDCommandBlock * prev
Definition dvdqueue.c:8
p
Definition e_acos.c:103
int BOOL
Definition types.h:33
unsigned long u32
Definition types.h:12
a
Definition k_cos.c:89
Definition linklist.cpp:6
@ start
Definition strtold.c:23
Definition search.h:73
Definition search.h:69
Definition std-list.h:11
TNode_ * pPrev_
Definition std-list.h:13
TNode_ * pNext_
Definition std-list.h:12
Definition std-list.h:34
const_iterator & operator--()
Definition std-list.h:38
friend bool operator!=(const_iterator a, const_iterator b)
Definition std-list.h:40
TNode_ * p_
Definition std-list.h:42
const_iterator & operator++()
Definition std-list.h:37
friend bool operator==(const_iterator a, const_iterator b)
Definition std-list.h:39
const_iterator(TNode_ *pNode)
Definition std-list.h:35
Definition std-list.h:16
iterator operator--(int)
Definition std-list.h:23
friend bool operator!=(iterator a, iterator b)
Definition std-list.h:25
T & operator*() const
Definition std-list.h:26
TNode_ * p_
Definition std-list.h:31
iterator(TNode_ *pNode)
Definition std-list.h:18
iterator & operator--()
Definition std-list.h:21
iterator operator++(int)
Definition std-list.h:22
friend bool operator==(iterator a, iterator b)
Definition std-list.h:24
iterator & operator++()
Definition std-list.h:20
iterator()
Definition std-list.h:17
Definition std-list.h:10
~TList()
Definition std-list.h:49
const_iterator begin() const
Definition std-list.h:112
void Initialize_()
Definition std-list.h:117
iterator insert(iterator it, const T &element)
Definition std-list.h:74
TNode_ oEnd_
Definition std-list.h:176
TIterator_reverse< iterator > rend()
Definition std-list.h:115
BOOL Confirm() const
Definition std-list.h:122
TIterator_reverse< iterator > rbegin()
Definition std-list.h:114
iterator end()
Definition std-list.h:111
void clear()
Definition std-list.h:107
iterator erase(iterator it)
Definition std-list.h:95
int field_0x4
Definition std-list.h:175
iterator begin()
Definition std-list.h:110
int size() const
Definition std-list.h:109
iterator push_back(const T &element)
Definition std-list.h:73
void DestroyNode_(TNode_ *p)
Definition std-list.h:165
Allocator mAllocator
Definition std-list.h:174
iterator push_front(const T &element)
Definition std-list.h:72
iterator erase(iterator start, iterator end)
Definition std-list.h:88
const_iterator end() const
Definition std-list.h:113
TList(const Allocator &allocator=Allocator())
Definition std-list.h:45
TNode_ * CreateNode_(TNode_ *pNext, TNode_ *pPrev, const T &pObject)
Definition std-list.h:151
BOOL empty() const
Definition std-list.h:108