mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-18 15:01:41 +00:00
add a List class
This commit is contained in:
parent
5838cfb565
commit
ef1b68e697
4 changed files with 137 additions and 2 deletions
31
ruamoko/include/List.h
Normal file
31
ruamoko/include/List.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
#ifndef __ruamoko_List_h
|
||||
#define __ruamoko_List_h
|
||||
|
||||
#include "Object.h"
|
||||
|
||||
struct list_bucket_t = {
|
||||
list_bucket_t [] next;
|
||||
list_bucket_t [][] prev;
|
||||
id obj;
|
||||
};
|
||||
|
||||
@interface List: Object
|
||||
{
|
||||
integer count;
|
||||
list_bucket_t [] head;
|
||||
list_bucket_t [][] tail;
|
||||
}
|
||||
- (id) init;
|
||||
- (void) free;
|
||||
- (id) getItemAt: (integer) index;
|
||||
- (id) head;
|
||||
- (id) tail;
|
||||
- (void) addItemAtHead: (id) item;
|
||||
- (void) addItemAtTail: (id) item;
|
||||
- (void) removeItem: (id) item;
|
||||
- (integer) count;
|
||||
-(void)makeObjectsPerformSelector:(SEL)selector;
|
||||
-(void)makeObjectsPerformSelector:(SEL)selector withObject:(id)arg;
|
||||
@end
|
||||
|
||||
#endif//__ruamoko_List_h
|
|
@ -8,4 +8,4 @@ include_HEADERS= \
|
|||
draw.h key.h \
|
||||
\
|
||||
cbuf.h cmd.h cvar.h file.h gib.h hash.h plist.h \
|
||||
Object.h Array.h Entity.h InputLine.h Point.h Rect.h Size.h
|
||||
Object.h Array.h Entity.h InputLine.h List.h Point.h Rect.h Size.h
|
||||
|
|
104
ruamoko/lib/List.r
Normal file
104
ruamoko/lib/List.r
Normal file
|
@ -0,0 +1,104 @@
|
|||
#include "List.h"
|
||||
|
||||
@implementation List
|
||||
|
||||
- (id) init
|
||||
{
|
||||
count = 0;
|
||||
head = NIL;
|
||||
tail = &head;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) free
|
||||
{
|
||||
local list_bucket_t [] e, t = NIL; //FIXME t uninitialized
|
||||
|
||||
for (e = head; e; e = t) {
|
||||
t = e.next;
|
||||
[e.obj free];
|
||||
obj_free (e);
|
||||
}
|
||||
[super free];
|
||||
}
|
||||
|
||||
- (id) getItemAt: (integer) index
|
||||
{
|
||||
local list_bucket_t [] e;
|
||||
if (index < 0 || index >= count)
|
||||
return NIL;
|
||||
for (e = head; e && index; index--)
|
||||
e = e.next;
|
||||
return e.obj;
|
||||
}
|
||||
|
||||
-(id) head
|
||||
{
|
||||
if (!head)
|
||||
return NIL;
|
||||
return head.obj;
|
||||
}
|
||||
|
||||
-(id) tail
|
||||
{
|
||||
local list_bucket_t [] e = (list_bucket_t []) tail;
|
||||
if (!e)
|
||||
return NIL;
|
||||
return e.obj;
|
||||
}
|
||||
|
||||
-(void) addItemAtHead: (id) item
|
||||
{
|
||||
local list_bucket_t [] e = obj_malloc (@sizeof (list_bucket_t));
|
||||
e.obj = item;
|
||||
e.next = head;
|
||||
e.prev = &head;
|
||||
if (head)
|
||||
head.prev = &e.next;
|
||||
head = e;
|
||||
}
|
||||
|
||||
-(void) addItemAtTail: (id) item
|
||||
{
|
||||
local list_bucket_t [] e = obj_malloc (@sizeof (list_bucket_t));
|
||||
e.obj = item;
|
||||
e.next = NIL;
|
||||
e.prev = tail;
|
||||
tail[0] = e;
|
||||
tail = &e.next;
|
||||
}
|
||||
|
||||
- (void) removeItem: (id) item
|
||||
{
|
||||
local list_bucket_t [] e;
|
||||
|
||||
for (e = head; e; e = e.next) {
|
||||
if (e.obj == item) {
|
||||
e.prev[0] = e.next;
|
||||
if (e.next)
|
||||
e.next.prev = e.prev;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (integer) count
|
||||
{
|
||||
return count;
|
||||
}
|
||||
|
||||
-(void)makeObjectsPerformSelector:(SEL)selector
|
||||
{
|
||||
local list_bucket_t [] e;
|
||||
for (e = head; e; e = e.next)
|
||||
[e.obj perform:selector];
|
||||
}
|
||||
|
||||
-(void)makeObjectsPerformSelector:(SEL)selector withObject:(id)arg
|
||||
{
|
||||
local list_bucket_t [] e;
|
||||
for (e = head; e; e = e.next)
|
||||
[e.obj perform:selector withObject:arg];
|
||||
}
|
||||
|
||||
@end
|
|
@ -30,7 +30,7 @@ libr_a_SOURCES=\
|
|||
crudefile.r debug.r hash.r entities.r infokey.r math.r message.r \
|
||||
nq_message.r physics.r plist.r qfile.r qw_message.r qw_physics.r qw_sys.r \
|
||||
sound.r \
|
||||
string.r system.r Object.r Array.r Entity.r Point.r Size.r Rect.r
|
||||
string.r system.r Object.r Array.r Entity.r List.r Point.r Size.r Rect.r
|
||||
libr_a_AR=$(PAK) -cf
|
||||
|
||||
libgui_a_SOURCES=\
|
||||
|
|
Loading…
Reference in a new issue