Isle
Loading...
Searching...
No Matches
mxlist.h
Go to the documentation of this file.
1#ifndef MXLIST_H
2#define MXLIST_H
3
4#include "mxcollection.h"
5#include "mxcore.h"
6#include "mxtypes.h"
7
9template <class T>
10class MxList; // [AI] Used for type-safe linked list implementation.
11
13template <class T>
14class MxListCursor; // [AI] Iterator-like class for traversing/operating on MxList.
15
19template <class T>
21public:
24
29 MxListEntry(T p_obj, MxListEntry* p_prev)
30 {
31 m_obj = p_obj;
32 m_prev = p_prev;
33 m_next = NULL;
34 }
35
41 MxListEntry(T p_obj, MxListEntry* p_prev, MxListEntry* p_next)
42 {
43 m_obj = p_obj;
44 m_prev = p_prev;
45 m_next = p_next;
46 }
47
51 T GetValue() { return this->m_obj; }
52
56 MxListEntry* GetNext() { return m_next; }
57
61 MxListEntry* GetPrev() { return m_prev; }
62
66 void SetValue(T p_obj) { m_obj = p_obj; }
67
71 void SetNext(MxListEntry* p_next) { m_next = p_next; }
72
76 void SetPrev(MxListEntry* p_prev) { m_prev = p_prev; }
77
78private:
79 T m_obj;
80 MxListEntry* m_prev;
81 MxListEntry* m_next;
82};
83
84// SIZE 0x18
88template <class T>
89class MxList : protected MxCollection<T> {
90public:
93
95 ~MxList() override { DeleteAll(); }
96
100 void Append(T p_obj) { InsertEntry(p_obj, this->m_last, NULL); }
101
105 void Prepend(T p_obj) { InsertEntry(p_obj, NULL, this->m_first); }
106
109 void DeleteAll();
110
113 void Empty();
114
118 MxU32 GetNumElements() { return this->m_count; }
119
121 friend class MxListCursor<T>;
124
125protected:
128
133
141};
142
143// SIZE 0x18
147template <class T>
148class MxPtrList : public MxList<T*> {
149public:
153 MxPtrList(MxBool p_ownership) { SetOwnership(p_ownership); }
154
158 static void Destroy(T* p_obj) { delete p_obj; }
159
163 void SetOwnership(MxBool p_ownership)
164 {
166 }
167};
168
169// SIZE 0x10
173template <class T>
174class MxListCursor : public MxCore {
175public:
180 {
181 m_list = p_list;
182 m_match = NULL;
183 }
184
189 MxBool Find(T p_obj);
190
193 void Detach();
194
197 void Destroy();
198
203
208 MxBool Next(T& p_obj);
209
214
219 MxBool Prev(T& p_obj);
220
225 MxBool Current(T& p_obj);
226
231 MxBool First(T& p_obj);
232
237 MxBool Last(T& p_obj);
238
242 MxBool HasMatch() { return m_match != NULL; }
243
247 void SetValue(T p_obj);
248
253 {
254 m_match = m_list->m_first;
255 return m_match != NULL;
256 }
257
262 {
263 m_match = m_list->m_last;
264 return m_match != NULL;
265 }
266
269 void Reset() { m_match = NULL; }
270
274 void Prepend(T p_newobj);
275
276private:
277 MxList<T>* m_list;
278 MxListEntry<T>* m_match;
279};
280
281// SIZE 0x10
285template <class T>
286class MxPtrListCursor : public MxListCursor<T*> {
287public:
291 MxPtrListCursor(MxPtrList<T>* p_list) : MxListCursor<T*>(p_list) {}
292};
293
294#endif // MXLIST_H
[AI] Template class for a generic collection, providing fundamental storage and comparison facilities...
Definition: mxcollection.h:10
MxU32 m_count
[AI] Number of elements currently stored in the collection.
Definition: mxcollection.h:37
void SetDestroy(void(*p_customDestructor)(T))
[AI] Assigns a custom destructor function to be used for elements of this collection.
Definition: mxcollection.h:34
[AI] Base virtual class for all Mindscape engine (Mx) objects.
Definition: mxcore.h:15
[AI] Forward declaration for MxListCursor.
Definition: mxlist.h:174
MxBool Next()
[AI]
MxBool Prev()
[AI]
void Prepend(T p_newobj)
[AI]
MxBool Head()
[AI]
Definition: mxlist.h:252
void Detach()
[AI]
MxBool Last(T &p_obj)
[AI]
MxBool Tail()
[AI]
Definition: mxlist.h:261
MxBool Current(T &p_obj)
[AI]
void Reset()
[AI]
Definition: mxlist.h:269
void SetValue(T p_obj)
[AI]
MxBool HasMatch()
[AI]
Definition: mxlist.h:242
MxBool Find(T p_obj)
[AI]
MxBool Prev(T &p_obj)
[AI]
MxBool Next(T &p_obj)
[AI]
MxListCursor(MxList< T > *p_list)
[AI]
Definition: mxlist.h:179
MxBool First(T &p_obj)
[AI]
void Destroy()
[AI]
[AI]
Definition: mxlist.h:20
void SetNext(MxListEntry *p_next)
[AI]
Definition: mxlist.h:71
MxListEntry()
[AI] Default constructor.
Definition: mxlist.h:23
MxListEntry * GetPrev()
[AI]
Definition: mxlist.h:61
MxListEntry(T p_obj, MxListEntry *p_prev, MxListEntry *p_next)
[AI]
Definition: mxlist.h:41
void SetPrev(MxListEntry *p_prev)
[AI]
Definition: mxlist.h:76
void SetValue(T p_obj)
[AI]
Definition: mxlist.h:66
MxListEntry * GetNext()
[AI]
Definition: mxlist.h:56
MxListEntry(T p_obj, MxListEntry *p_prev)
[AI]
Definition: mxlist.h:29
T GetValue()
[AI]
Definition: mxlist.h:51
[AI] Forward declaration for MxList.
Definition: mxlist.h:89
void Prepend(T p_obj)
[AI]
Definition: mxlist.h:105
~MxList() override
[AI] Destructor. Deletes all entries in the list and manages resource ownership. [AI]
Definition: mxlist.h:95
void DeleteAll()
[AI]
void Empty()
[AI]
void Append(T p_obj)
[AI]
Definition: mxlist.h:100
MxList()
[AI] Constructor. Initializes the list pointers to null (empty list). [AI]
Definition: mxlist.h:92
MxListEntry< T > * m_first
[AI] Pointer to the first entry in the list. [AI]
Definition: mxlist.h:126
MxListEntry< T > * m_last
[AI] Pointer to the last entry in the list. [AI]
Definition: mxlist.h:127
MxListEntry< T > * InsertEntry(T, MxListEntry< T > *, MxListEntry< T > *)
[AI]
void DeleteEntry(MxListEntry< T > *)
[AI]
MxU32 GetNumElements()
[AI]
Definition: mxlist.h:118
MxPtrListCursor(MxPtrList< T > *p_list)
[AI]
Definition: mxlist.h:291
[AI]
Definition: mxlist.h:148
MxPtrList(MxBool p_ownership)
[AI]
Definition: mxlist.h:153
void SetOwnership(MxBool p_ownership)
[AI]
Definition: mxlist.h:163
static void Destroy(T *p_obj)
[AI]
Definition: mxlist.h:158
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
MxU8 MxBool
[AI]
Definition: mxtypes.h:124
unsigned int MxU32
[AI]
Definition: mxtypes.h:32