summaryrefslogtreecommitdiff
path: root/src/core/Lists.h
diff options
context:
space:
mode:
authoraap <aap@papnet.eu>2019-07-07 13:09:11 +0200
committeraap <aap@papnet.eu>2019-07-07 13:09:11 +0200
commit53023eb65bdcde43e341c1ecb7cf0c7f8ee524fb (patch)
treefc65a6c40fa719f9d43be9e0e15be79c490135e0 /src/core/Lists.h
parent219a65b81a1141d6475fc48bdc6251bd20e44a70 (diff)
the great reorganization
Diffstat (limited to 'src/core/Lists.h')
-rw-r--r--src/core/Lists.h130
1 files changed, 130 insertions, 0 deletions
diff --git a/src/core/Lists.h b/src/core/Lists.h
new file mode 100644
index 00000000..7572e882
--- /dev/null
+++ b/src/core/Lists.h
@@ -0,0 +1,130 @@
+#pragma once
+
+class CPtrNode
+{
+public:
+ void *item;
+ CPtrNode *prev;
+ CPtrNode *next;
+
+ void *operator new(size_t);
+ void operator delete(void *p, size_t);
+};
+
+class CPtrList
+{
+public:
+ CPtrNode *first;
+
+ CPtrList(void) { first = nil; }
+ ~CPtrList(void) { Flush(); }
+ CPtrNode *FindItem(void *item){
+ CPtrNode *node;
+ for(node = first; node; node = node->next)
+ if(node->item == item)
+ return node;
+ return nil;
+ }
+ CPtrNode *InsertNode(CPtrNode *node){
+ node->prev = nil;
+ node->next = first;
+ if(first)
+ first->prev = node;
+ first = node;
+ return node;
+ }
+ CPtrNode *InsertItem(void *item){
+ CPtrNode *node = new CPtrNode;
+ node->item = item;
+ InsertNode(node);
+ return node;
+ }
+ void RemoveNode(CPtrNode *node){
+ if(node == first)
+ first = node->next;
+ if(node->prev)
+ node->prev->next = node->next;
+ if(node->next)
+ node->next->prev = node->prev;
+ }
+ void DeleteNode(CPtrNode *node){
+ RemoveNode(node);
+ delete node;
+ }
+ void RemoveItem(void *item){
+ CPtrNode *node, *next;
+ for(node = first; node; node = next){
+ next = node->next;
+ if(node->item == item)
+ DeleteNode(node);
+ }
+ }
+ void Flush(void){
+ CPtrNode *node, *next;
+ for(node = first; node; node = next){
+ next = node->next;
+ DeleteNode(node);
+ }
+ }
+};
+
+class CSector;
+
+// This records in which sector list a Physical is
+class CEntryInfoNode
+{
+public:
+ CPtrList *list; // list in sector
+ CPtrNode *listnode; // node in list
+ CSector *sector;
+
+ CEntryInfoNode *prev;
+ CEntryInfoNode *next;
+
+ void *operator new(size_t);
+ void operator delete(void *p, size_t);
+};
+
+class CEntryInfoList
+{
+public:
+ CEntryInfoNode *first;
+
+ CEntryInfoList(void) { first = nil; }
+ ~CEntryInfoList(void) { Flush(); }
+ CEntryInfoNode *InsertNode(CEntryInfoNode *node){
+ node->prev = nil;
+ node->next = first;
+ if(first)
+ first->prev = node;
+ first = node;
+ return node;
+ }
+ CEntryInfoNode *InsertItem(CPtrList *list, CPtrNode *listnode, CSector *sect){
+ CEntryInfoNode *node = new CEntryInfoNode;
+ node->list = list;
+ node->listnode = listnode;
+ node->sector = sect;
+ InsertNode(node);
+ return node;
+ }
+ void RemoveNode(CEntryInfoNode *node){
+ if(node == first)
+ first = node->next;
+ if(node->prev)
+ node->prev->next = node->next;
+ if(node->next)
+ node->next->prev = node->prev;
+ }
+ void DeleteNode(CEntryInfoNode *node){
+ RemoveNode(node);
+ delete node;
+ }
+ void Flush(void){
+ CEntryInfoNode *node, *next;
+ for(node = first; node; node = next){
+ next = node->next;
+ DeleteNode(node);
+ }
+ }
+};