Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
Loading...
Searching...
No Matches
JPAList.h
Go to the documentation of this file.
1#ifndef JPALIST_H
2#define JPALIST_H
3
4#include <dolphin/types.h>
5
10template <class T>
11struct JPANode {
12 JPANode() : mpPrev(NULL), mpNext(NULL) {
13 }
15 JPANode<T>* getPrev() const { return mpPrev; }
16 JPANode<T>* getNext() const { return mpNext; }
17 T* getObject() { return &mData; }
18
19 /* 0x00 */ JPANode<T>* mpPrev;
20 /* 0x04 */ JPANode<T>* mpNext;
21 /* 0x08 */ T mData;
22};
23
28template <class T>
29struct JPAList {
30 /* 0x00 */ JPANode<T>* mpFirst;
31 /* 0x04 */ JPANode<T>* mpLast;
32 /* 0x08 */ u32 mNum;
33
34 JPAList() : mpFirst(NULL), mpLast(NULL), mNum() {}
36
37 JPANode<T>* getEnd() { return NULL; }
38 JPANode<T>* getFirst() const { return mpFirst; }
39 JPANode<T>* getLast() const { return mpLast; }
40 u32 getNum() const { return mNum; }
41
42 void push_front(JPANode<T>* node) {
43 if (mpFirst != NULL) {
44 node->mpPrev = NULL;
45 node->mpNext = mpFirst;
46 mpFirst->mpPrev = node;
47 mpFirst = node;
48 } else {
49 mpLast = node;
50 mpFirst = node;
51 node->mpNext = node->mpPrev = NULL;
52 }
53
54 mNum++;
55 }
56
57 void push_back(JPANode<T>* node) {
58 if (mpLast != NULL) {
59 node->mpPrev = mpLast;
60 node->mpNext = NULL;
61 mpLast->mpNext = node;
62 mpLast = node;
63 } else {
64 mpFirst = node;
65 mpLast = node;
66 node->mpNext = node->mpPrev = NULL;
67 }
68
69 mNum++;
70 }
71
73 JPANode<T>* ret = NULL;
74
75 if (mNum == 1) {
76 ret = mpFirst;
77 mpFirst = mpLast = NULL;
78 mNum--;
79 } else if (mNum) {
80 ret = mpFirst;
81 ret->mpNext->mpPrev = NULL;
82 mpFirst = ret->mpNext;
83 mNum--;
84 }
85
86 return ret;
87 }
88
90 JPANode<T>* ret = NULL;
91
92 if (mNum == 1) {
93 ret = mpLast;
94 mpFirst = mpLast = NULL;
95 mNum--;
96 } else if (mNum) {
97 ret = mpLast;
98 ret->mpPrev->mpNext = NULL;
99 mpLast = ret->mpPrev;
100 mNum--;
101 }
102
103 return ret;
104 }
105
107 if (node->mpNext != NULL && node->mpPrev != NULL) {
108 node->mpPrev->mpNext = node->mpNext;
109 node->mpNext->mpPrev = node->mpPrev;
110 mNum--;
111 } else if (node->mpNext != NULL) {
112 node->mpNext->mpPrev = NULL;
113 mpFirst = node->mpNext;
114 mNum--;
115 } else if (node->mpPrev != NULL) {
116 node->mpPrev->mpNext = NULL;
117 mpLast = node->mpPrev;
118 mNum--;
119 } else {
120 mpFirst = mpLast = NULL;
121 mNum--;
122 }
123 return node;
124 }
125};
126
127#endif
unsigned long u32
Definition types.h:12
Definition JPAList.h:29
JPANode< T > * mpLast
Definition JPAList.h:31
JPANode< T > * getLast() const
Definition JPAList.h:39
void push_front(JPANode< T > *node)
Definition JPAList.h:42
JPANode< T > * getEnd()
Definition JPAList.h:37
JPANode< T > * pop_back()
Definition JPAList.h:89
JPAList()
Definition JPAList.h:34
void push_back(JPANode< T > *node)
Definition JPAList.h:57
~JPAList()
Definition JPAList.h:35
JPANode< T > * erase(JPANode< T > *node)
Definition JPAList.h:106
JPANode< T > * getFirst() const
Definition JPAList.h:38
JPANode< T > * pop_front()
Definition JPAList.h:72
u32 mNum
Definition JPAList.h:32
JPANode< T > * mpFirst
Definition JPAList.h:30
u32 getNum() const
Definition JPAList.h:40
Definition JPAList.h:11
JPANode< T > * getPrev() const
Definition JPAList.h:15
JPANode()
Definition JPAList.h:12
JPANode< T > * mpPrev
Definition JPAList.h:19
~JPANode()
Definition JPAList.h:14
JPANode< T > * mpNext
Definition JPAList.h:20
T * getObject()
Definition JPAList.h:17
JPANode< T > * getNext() const
Definition JPAList.h:16
T mData
Definition JPAList.h:21