Skip to content

Commit

Permalink
Fix compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
RusJJ committed Aug 24, 2023
1 parent b80a4f0 commit 4514a7a
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ FodyWeavers.xsd
*.sln.iml

# Own
mod/
libs/
*.bak
build.ps1
Expand Down
73 changes: 73 additions & 0 deletions mod/listitem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#pragma once

#define LIST_START(__cls_name) class __cls_name { \
public: \
__cls_name *pPrev; \
__cls_name *pNext; \
unsigned int nCount; \
typedef __cls_name MyClass; \
\
unsigned int Count() { return First()->nCount; } \
__cls_name *First() \
{ \
__cls_name *first = this; \
while(first->pPrev != NULL) first = first->pPrev; \
return first; \
} \
__cls_name *Last() \
{ \
__cls_name *last = this; \
while(last->pNext != NULL) last = last->pNext; \
return last; \
} \
void Push(__cls_name **listPtr) \
{ \
if(pPrev || pNext) Remove(); \
__cls_name*& list = *listPtr; \
pPrev = NULL; \
if(list == NULL) { \
pNext = NULL; \
nCount = 1; \
} else { \
pNext = list; \
list->pPrev = this; \
nCount = list->nCount + 1; \
} \
list = this; \
} \
void Remove() /* risky removal! */ \
{ \
if(pPrev) { \
--(First()->nCount); \
pPrev->pNext = pNext; \
} else { \
pNext->nCount = nCount - 1; \
} \
if(pNext) pNext->pPrev = pPrev; \
} \
void Remove(__cls_name **listPtr) \
{ \
if(First() != *listPtr) return; \
if(First() == this && Last() == this) { *listPtr = NULL; return; } \
if(pPrev) { \
--(First()->nCount); \
pPrev->pNext = pNext; \
} else { \
pNext->nCount = nCount - 1; \
} \
if(pNext) pNext->pPrev = pPrev; \
}

#define LIST_END() \
};

#define LIST_INITSTART(__cls_name) \
__cls_name() {

#define LIST_INITEND() \
pPrev = NULL; \
pNext = NULL; \
nCount = 1; \
}

#define LIST_FOR(__list) for(auto item = __list; item != NULL; item = item->pNext)

0 comments on commit 4514a7a

Please sign in to comment.