mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-18 06:51:47 +00:00
Move the QF object system into it's own library, fix up the standard
classes.
This commit is contained in:
parent
c3e7832d85
commit
7598ab35fb
26 changed files with 1232 additions and 207 deletions
|
@ -2084,6 +2084,7 @@ AC_OUTPUT(
|
||||||
include/QF/Makefile
|
include/QF/Makefile
|
||||||
include/QF/GL/Makefile
|
include/QF/GL/Makefile
|
||||||
include/QF/plugin/Makefile
|
include/QF/plugin/Makefile
|
||||||
|
include/QF/classes/Makefile
|
||||||
|
|
||||||
libs/Makefile
|
libs/Makefile
|
||||||
libs/audio/Makefile
|
libs/audio/Makefile
|
||||||
|
@ -2103,6 +2104,7 @@ AC_OUTPUT(
|
||||||
libs/net/Makefile
|
libs/net/Makefile
|
||||||
libs/net/nc/Makefile
|
libs/net/nc/Makefile
|
||||||
libs/net/nm/Makefile
|
libs/net/nm/Makefile
|
||||||
|
libs/object/Makefile
|
||||||
libs/util/Makefile
|
libs/util/Makefile
|
||||||
libs/video/Makefile
|
libs/video/Makefile
|
||||||
libs/video/renderer/Makefile
|
libs/video/renderer/Makefile
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
AUTOMAKE_OPTIONS = foreign
|
AUTOMAKE_OPTIONS = foreign
|
||||||
SUBDIRS = GL plugin
|
SUBDIRS = GL plugin classes
|
||||||
includedir = $(prefix)/include/QF
|
includedir = $(prefix)/include/QF
|
||||||
include_HEADERS = bspfile.h cbuf.h cdaudio.h checksum.h clip_hull.h cmd.h \
|
include_HEADERS = bspfile.h cbuf.h cdaudio.h checksum.h clip_hull.h cmd.h \
|
||||||
console.h crc.h csqc.h cvar.h dstring.h draw.h gib.h hash.h hl.h \
|
console.h crc.h csqc.h cvar.h dstring.h draw.h gib.h hash.h hl.h \
|
||||||
|
|
51
include/QF/classes/ArrayList.h
Normal file
51
include/QF/classes/ArrayList.h
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
ArrayList.h
|
||||||
|
|
||||||
|
Implements List by storing elements in a dynamic array
|
||||||
|
|
||||||
|
Copyright (C) 2003 Brian Koropoff
|
||||||
|
|
||||||
|
Author: Brian Koropoff
|
||||||
|
Date: December 03, 2003
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ArrayList_h
|
||||||
|
#define __ArrayList_h
|
||||||
|
|
||||||
|
#include "QF/classes/List.h"
|
||||||
|
|
||||||
|
classDecl (ArrayList, List,
|
||||||
|
unsigned int realsize;
|
||||||
|
Object **elements;
|
||||||
|
);
|
||||||
|
#define ARRAYLIST(o) ((ArrayList *)(o))
|
||||||
|
|
||||||
|
classDecl (ArrayListIterator, Iterator,
|
||||||
|
ArrayList *list;
|
||||||
|
unsigned int pos;
|
||||||
|
unsigned int smods;
|
||||||
|
qboolean alive;
|
||||||
|
);
|
||||||
|
#define ARRAYLISTITERATOR(o) ((ArrayListIterator *)(o))
|
||||||
|
|
||||||
|
#endif
|
49
include/QF/classes/Collection.h
Normal file
49
include/QF/classes/Collection.h
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
Collection.h
|
||||||
|
|
||||||
|
Abstract class for collections of objects
|
||||||
|
|
||||||
|
Copyright (C) 2003 Brian Koropoff
|
||||||
|
|
||||||
|
Author: Brian Koropoff
|
||||||
|
Date: December 03, 2003
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "QF/object.h"
|
||||||
|
|
||||||
|
#ifndef __Collection_h
|
||||||
|
#define __Collection_h
|
||||||
|
|
||||||
|
#include "QF/classes/Iterator.h"
|
||||||
|
|
||||||
|
classDecl (Collection, Object,
|
||||||
|
unsigned int count;
|
||||||
|
Class *type;
|
||||||
|
qboolean methodDecl (Collection, add, Object *o);
|
||||||
|
Object * methodDecl (Collection, remove, Object *o);
|
||||||
|
qboolean methodDecl (Collection, contains, Object *o);
|
||||||
|
Iterator * methodDecl (Collection, iterator);
|
||||||
|
);
|
||||||
|
#define COLLECTION(o) ((Collection *)(o))
|
||||||
|
|
||||||
|
#endif
|
42
include/QF/classes/Double.h
Normal file
42
include/QF/classes/Double.h
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
Double.h
|
||||||
|
|
||||||
|
Class for double values
|
||||||
|
|
||||||
|
Copyright (C) 2003 Brian Koropoff
|
||||||
|
|
||||||
|
Author: Brian Koropoff
|
||||||
|
Date: December 06, 2003
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __Double_h
|
||||||
|
#define __Double_h
|
||||||
|
|
||||||
|
#include "QF/classes/Number.h"
|
||||||
|
|
||||||
|
classDecl (Double, Number,
|
||||||
|
double value;
|
||||||
|
);
|
||||||
|
#define DOUBLE(o) ((Double *)(o))
|
||||||
|
|
||||||
|
#endif
|
42
include/QF/classes/Exception.h
Normal file
42
include/QF/classes/Exception.h
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
Exception.h
|
||||||
|
|
||||||
|
Class for signaling exceptional conditions
|
||||||
|
|
||||||
|
Copyright (C) 2003 Brian Koropoff
|
||||||
|
|
||||||
|
Author: Brian Koropoff
|
||||||
|
Date: December 03, 2003
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __Exception_h
|
||||||
|
#define __Exception_h
|
||||||
|
|
||||||
|
#include "QF/object.h"
|
||||||
|
|
||||||
|
classDecl (Exception, Object,
|
||||||
|
String * methodDecl (Exception, getDescription);
|
||||||
|
);
|
||||||
|
#define EXCEPTION(o) ((Exception *)(o))
|
||||||
|
|
||||||
|
#endif
|
42
include/QF/classes/Integer.h
Normal file
42
include/QF/classes/Integer.h
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
Integer.h
|
||||||
|
|
||||||
|
Class for integer values
|
||||||
|
|
||||||
|
Copyright (C) 2003 Brian Koropoff
|
||||||
|
|
||||||
|
Author: Brian Koropoff
|
||||||
|
Date: December 03, 2003
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __Integer_h
|
||||||
|
#define __Integer_h
|
||||||
|
|
||||||
|
#include "QF/classes/Number.h"
|
||||||
|
|
||||||
|
classDecl (Integer, Number,
|
||||||
|
int value;
|
||||||
|
);
|
||||||
|
#define INTEGER(o) ((Integer *)(o))
|
||||||
|
|
||||||
|
#endif
|
43
include/QF/classes/Iterator.h
Normal file
43
include/QF/classes/Iterator.h
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
Iterator.h
|
||||||
|
|
||||||
|
Abstract class for Collection iterators
|
||||||
|
|
||||||
|
Copyright (C) 2003 Brian Koropoff
|
||||||
|
|
||||||
|
Author: Brian Koropoff
|
||||||
|
Date: December 03, 2003
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "QF/object.h"
|
||||||
|
|
||||||
|
#ifndef __Iterator_h
|
||||||
|
#define __Iterator_h
|
||||||
|
|
||||||
|
classDecl (Iterator, Object,
|
||||||
|
Object * methodDecl (Iterator, next);
|
||||||
|
qboolean methodDecl (Iterator, hasNext);
|
||||||
|
);
|
||||||
|
#define ITERATOR(o) ((Iterator *)(o))
|
||||||
|
|
||||||
|
#endif
|
46
include/QF/classes/List.h
Normal file
46
include/QF/classes/List.h
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
List.h
|
||||||
|
|
||||||
|
Abstract class for lists
|
||||||
|
|
||||||
|
Copyright (C) 2003 Brian Koropoff
|
||||||
|
|
||||||
|
Author: Brian Koropoff
|
||||||
|
Date: December 03, 2003
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __List_h
|
||||||
|
#define __List_h
|
||||||
|
|
||||||
|
#include "QF/classes/Collection.h"
|
||||||
|
|
||||||
|
classDecl (List, Collection,
|
||||||
|
unsigned int smods;
|
||||||
|
qboolean methodDecl (List, set, unsigned int index, Object *o);
|
||||||
|
Object * methodDecl (List, get, unsigned int index);
|
||||||
|
qboolean methodDecl (List, insertAt, unsigned int index, Object *o);
|
||||||
|
Object * methodDecl (List, removeAt, unsigned int index);
|
||||||
|
);
|
||||||
|
#define LIST(o) ((List *)(o))
|
||||||
|
|
||||||
|
#endif
|
4
include/QF/classes/Makefile.am
Normal file
4
include/QF/classes/Makefile.am
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
AUTOMAKE_OPTIONS = foreign
|
||||||
|
includedir = $(prefix)/include/QF/classes
|
||||||
|
include_HEADERS = ArrayList.h Collection.h Double.h Exception.h Integer.h \
|
||||||
|
Iterator.h List.h Number.h String.h
|
43
include/QF/classes/Number.h
Normal file
43
include/QF/classes/Number.h
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
Number.h
|
||||||
|
|
||||||
|
Abstract class for numeric values
|
||||||
|
|
||||||
|
Copyright (C) 2003 Brian Koropoff
|
||||||
|
|
||||||
|
Author: Brian Koropoff
|
||||||
|
Date: December 03, 2003
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __Number_h
|
||||||
|
#define __Number_h
|
||||||
|
|
||||||
|
#include "QF/object.h"
|
||||||
|
|
||||||
|
classDecl (Number, Object,
|
||||||
|
int methodDecl (Number, intValue);
|
||||||
|
double methodDecl (Number, doubleValue);
|
||||||
|
);
|
||||||
|
#define NUMBER(o) ((Number *)(o))
|
||||||
|
|
||||||
|
#endif
|
42
include/QF/classes/String.h
Normal file
42
include/QF/classes/String.h
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
String.h
|
||||||
|
|
||||||
|
Class for containing immutable strings
|
||||||
|
|
||||||
|
Copyright (C) 2003 Brian Koropoff
|
||||||
|
|
||||||
|
Author: Brian Koropoff
|
||||||
|
Date: December 03, 2003
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __String_h
|
||||||
|
#define __String_h
|
||||||
|
|
||||||
|
#include "QF/object.h"
|
||||||
|
|
||||||
|
classDecl (String, Object,
|
||||||
|
const char *str;
|
||||||
|
);
|
||||||
|
#define STRING(o) ((String *)(o))
|
||||||
|
|
||||||
|
#endif
|
|
@ -52,17 +52,29 @@
|
||||||
#define methodDecl(type, name, ...) (* name) (struct type##_s *self, ##__VA_ARGS__)
|
#define methodDecl(type, name, ...) (* name) (struct type##_s *self, ##__VA_ARGS__)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define classDecl(name,extends,def) typedef struct name##_s {struct extends##_s base; def} name; extern Class * name##_class
|
#define classObj(name) name##_class
|
||||||
|
#define classDecl(name,extends,def) typedef struct name##_s {struct extends##_s base; def} name; extern Class * classObj(name); void __class_##name##_init (void)
|
||||||
|
#define classInitFunc(name) Class * classObj(name); void __class_##name##_init (void)
|
||||||
|
#define classInit(name) __class_##name##_init()
|
||||||
#define retain(obj) (Object_Retain((Object *)obj))
|
#define retain(obj) (Object_Retain((Object *)obj))
|
||||||
#define release(obj) (Object_Release((Object *)obj))
|
#define release(obj) (Object_Release((Object *)obj))
|
||||||
|
|
||||||
#define instanceOf(obj, cl) (Object_InstaceOf((Object *)obj, cl##_class))
|
#define instanceOf(obj, cl) (Object_InstaceOf((Object *)obj, cl##_class))
|
||||||
|
|
||||||
|
struct Object_s;
|
||||||
|
struct Class_s;
|
||||||
|
struct List_s;
|
||||||
|
|
||||||
|
typedef void (*ReplyHandler_t) (struct Object_s *retValue);
|
||||||
|
|
||||||
typedef struct Object_s {
|
typedef struct Object_s {
|
||||||
struct Class_s *cl;
|
struct Class_s *cl;
|
||||||
int refs;
|
int refs;
|
||||||
struct String_s *(*toString)(struct Object_s *obj);
|
struct String_s * methodDecl(Object, toString);
|
||||||
|
void methodDecl(Object, message, const char *name, struct List_s *args, struct Object_s *sender, ReplyHandler_t *reply);
|
||||||
|
void *data;
|
||||||
} Object;
|
} Object;
|
||||||
|
extern struct Class_s * Object_class;
|
||||||
#define OBJECT(o) ((Object *)(o))
|
#define OBJECT(o) ((Object *)(o))
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,34 +91,6 @@ classDecl (Class, Object,
|
||||||
);
|
);
|
||||||
#define CLASS(o) ((Class *)(o))
|
#define CLASS(o) ((Class *)(o))
|
||||||
|
|
||||||
classDecl (String, Object,
|
|
||||||
const char *str;
|
|
||||||
);
|
|
||||||
#define STRING(o) ((String *)(o))
|
|
||||||
|
|
||||||
classDecl (List, Object,
|
|
||||||
unsigned int count;
|
|
||||||
Object * methodDecl (List, get, unsigned int index);
|
|
||||||
qboolean methodDecl (List, add, Object *o);
|
|
||||||
);
|
|
||||||
#define LIST(o) ((List *)(o))
|
|
||||||
|
|
||||||
classDecl (ArrayList, List,
|
|
||||||
Object **elements;
|
|
||||||
);
|
|
||||||
#define ARRAYLIST(o) ((ArrayList *)(o))
|
|
||||||
|
|
||||||
classDecl (Number, Object,
|
|
||||||
int methodDecl (Number, intValue);
|
|
||||||
double methodDecl (Number, doubleValue);
|
|
||||||
);
|
|
||||||
#define NUMBER(o) ((Number *)(o))
|
|
||||||
|
|
||||||
classDecl (Integer, Number,
|
|
||||||
int value;
|
|
||||||
);
|
|
||||||
#define INTEGER(o) ((Integer *)(o))
|
|
||||||
|
|
||||||
Object *Object_Create (Class *cl);
|
Object *Object_Create (Class *cl);
|
||||||
void Object_Delete (Object *obj);
|
void Object_Delete (Object *obj);
|
||||||
Object *Object_Retain (Object *obj);
|
Object *Object_Retain (Object *obj);
|
||||||
|
@ -114,4 +98,7 @@ Object *Object_Release (Object *obj);
|
||||||
qboolean Object_InstanceOf (Object *obj, Class *cl);
|
qboolean Object_InstanceOf (Object *obj, Class *cl);
|
||||||
void Object_Init (void);
|
void Object_Init (void);
|
||||||
|
|
||||||
|
#include "QF/classes/List.h"
|
||||||
|
#include "QF/classes/String.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
AUTOMAKE_OPTIONS= foreign
|
AUTOMAKE_OPTIONS= foreign
|
||||||
|
|
||||||
SUBDIRS= audio console gamecode gib image models net video util
|
SUBDIRS= audio console gamecode gib image models net object video util
|
||||||
|
|
234
libs/object/ArrayList.c
Normal file
234
libs/object/ArrayList.c
Normal file
|
@ -0,0 +1,234 @@
|
||||||
|
/*
|
||||||
|
ArrayList.c
|
||||||
|
|
||||||
|
Implements List by storing elements in a dynamic array
|
||||||
|
|
||||||
|
Copyright (C) 2003 Brian Koropoff
|
||||||
|
|
||||||
|
Author: Brian Koropoff
|
||||||
|
Date: December 03, 2003
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static __attribute__ ((unused)) const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
|
|
||||||
|
#ifdef HAVE_STRING_H
|
||||||
|
# include <string.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_STRINGS_H
|
||||||
|
# include <strings.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "QF/classes/ArrayList.h"
|
||||||
|
|
||||||
|
static Object *
|
||||||
|
ArrayListIterator_Next_f (Iterator *self)
|
||||||
|
{
|
||||||
|
/* Was list structurally modified while we are iterating? */
|
||||||
|
if (ARRAYLISTITERATOR(self)->smods != LIST(ARRAYLISTITERATOR(self)->list)->smods) {
|
||||||
|
ARRAYLISTITERATOR(self)->alive = false;
|
||||||
|
// FIXME: Throw an exception or something
|
||||||
|
}
|
||||||
|
if (ARRAYLISTITERATOR(self)->alive) {
|
||||||
|
Object *o = ARRAYLISTITERATOR(self)->list->elements[ARRAYLISTITERATOR(self)->pos++];
|
||||||
|
if (ARRAYLISTITERATOR(self)->pos >= COLLECTION(ARRAYLISTITERATOR(self)->list)->count)
|
||||||
|
ARRAYLISTITERATOR(self)->alive = false;
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static qboolean
|
||||||
|
ArrayListIterator_HasNext_f (Iterator *self)
|
||||||
|
{
|
||||||
|
if (ARRAYLISTITERATOR(self)->smods != LIST(ARRAYLISTITERATOR(self)->list)->smods)
|
||||||
|
ARRAYLISTITERATOR(self)->alive = false;
|
||||||
|
return ARRAYLISTITERATOR(self)->alive;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Object *
|
||||||
|
ArrayListIterator_Init_f (Object *self, ArrayList *list)
|
||||||
|
{
|
||||||
|
superInit (ArrayListIterator, self);
|
||||||
|
ITERATOR(self)->next = ArrayListIterator_Next_f;
|
||||||
|
ITERATOR(self)->hasNext = ArrayListIterator_HasNext_f;
|
||||||
|
ARRAYLISTITERATOR(self)->list = ARRAYLIST(retain(list));
|
||||||
|
ARRAYLISTITERATOR(self)->smods = LIST(list)->smods;
|
||||||
|
ARRAYLISTITERATOR(self)->pos = 0;
|
||||||
|
ARRAYLISTITERATOR(self)->alive = COLLECTION(list)->count ? true : false;
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ArrayListIterator_Deinit_f (Object *self)
|
||||||
|
{
|
||||||
|
release(ARRAYLISTITERATOR(self)->list);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ArrayList_EnsureCapacity (ArrayList *list, unsigned int size)
|
||||||
|
{
|
||||||
|
if (list->realsize < size) {
|
||||||
|
unsigned int newsize = size | (list->realsize + list->realsize/2);
|
||||||
|
list->elements = realloc (list->elements, newsize);
|
||||||
|
memset (list->elements + list->realsize, 0, newsize - list->realsize);
|
||||||
|
list->realsize = newsize;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static qboolean
|
||||||
|
ArrayList_Set_f (List *self, unsigned int index, Object *o)
|
||||||
|
{
|
||||||
|
ArrayList *list = ARRAYLIST(self);
|
||||||
|
if (o) {
|
||||||
|
if (!Object_InstanceOf (o, COLLECTION(list)->type))
|
||||||
|
return false;
|
||||||
|
ArrayList_EnsureCapacity (list, index+1);
|
||||||
|
retain(o);
|
||||||
|
if (list->elements[index])
|
||||||
|
release (list->elements[index]);
|
||||||
|
list->elements[index] = o;
|
||||||
|
} else if (index < COLLECTION(list)->count) {
|
||||||
|
if (list->elements[index])
|
||||||
|
release (list->elements[index]);
|
||||||
|
list->elements[index] = NULL;
|
||||||
|
}
|
||||||
|
if (COLLECTION(list)->count < index+1)
|
||||||
|
COLLECTION(list)->count = index+1;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Object *
|
||||||
|
ArrayList_Get_f (List *self, unsigned int index)
|
||||||
|
{
|
||||||
|
ArrayList *list = ARRAYLIST(self);
|
||||||
|
if (index >= COLLECTION(list)->count || index >= list->realsize)
|
||||||
|
return NULL;
|
||||||
|
else
|
||||||
|
return list->elements[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ArrayList_MakeRoomAt (ArrayList *list, unsigned int index)
|
||||||
|
{
|
||||||
|
ArrayList_EnsureCapacity(list, ++COLLECTION(list)->count);
|
||||||
|
memmove(list->elements+index+1, list->elements+index, sizeof(Object *) * (COLLECTION(list)->count-index-1));
|
||||||
|
LIST(list)->smods++;
|
||||||
|
}
|
||||||
|
|
||||||
|
static qboolean
|
||||||
|
ArrayList_InsertAt_f (List *self, unsigned int index, Object *o)
|
||||||
|
{
|
||||||
|
ArrayList *list = ARRAYLIST(self);
|
||||||
|
if (index >= COLLECTION(list)->count)
|
||||||
|
return ArrayList_Set_f (self, index, o);
|
||||||
|
else if (o && !Object_InstanceOf(o, COLLECTION(list)->type))
|
||||||
|
return false;
|
||||||
|
else {
|
||||||
|
ArrayList_MakeRoomAt (list, index);
|
||||||
|
retain(o);
|
||||||
|
list->elements[index] = o;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Object *
|
||||||
|
ArrayList_RemoveAt_f (List *self, unsigned int index)
|
||||||
|
{
|
||||||
|
ArrayList *list = ARRAYLIST(self);
|
||||||
|
if (index >= COLLECTION(list)->count)
|
||||||
|
return NULL;
|
||||||
|
else {
|
||||||
|
Object *o = list->elements[index];
|
||||||
|
if (o)
|
||||||
|
release(o);
|
||||||
|
COLLECTION(list)->count--;
|
||||||
|
memmove(list->elements+index, list->elements+index+1, sizeof(Object *) * (COLLECTION(list)->count-index));
|
||||||
|
LIST(list)->smods++;
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static qboolean
|
||||||
|
ArrayList_Add_f (Collection *self, Object *o)
|
||||||
|
{
|
||||||
|
ArrayList *list = ARRAYLIST(self);
|
||||||
|
if (o && !Object_InstanceOf(o, COLLECTION(list)->type))
|
||||||
|
return false;
|
||||||
|
else {
|
||||||
|
ArrayList_EnsureCapacity (list, ++COLLECTION(list)->count);
|
||||||
|
list->elements[COLLECTION(list)->count-1] = o;
|
||||||
|
if (o)
|
||||||
|
retain(o);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static Iterator *
|
||||||
|
ArrayList_Iterator_f (Collection *self)
|
||||||
|
{
|
||||||
|
return newFloat(ArrayListIterator, ARRAYLIST(self));
|
||||||
|
}
|
||||||
|
|
||||||
|
static Object *
|
||||||
|
ArrayList_Init_f (Object *self, Class *type, Collection *source)
|
||||||
|
{
|
||||||
|
ARRAYLIST(self)->realsize = 32;
|
||||||
|
ARRAYLIST(self)->elements = calloc(32, sizeof(Object *));
|
||||||
|
LIST(self)->set = ArrayList_Set_f;
|
||||||
|
LIST(self)->get = ArrayList_Get_f;
|
||||||
|
LIST(self)->insertAt = ArrayList_InsertAt_f;
|
||||||
|
LIST(self)->removeAt = ArrayList_RemoveAt_f;
|
||||||
|
COLLECTION(self)->add = ArrayList_Add_f;
|
||||||
|
COLLECTION(self)->iterator = ArrayList_Iterator_f;
|
||||||
|
superInit(List, self, type, source);
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ArrayList_Deinit_f (Object *self)
|
||||||
|
{
|
||||||
|
unsigned int i;
|
||||||
|
for (i = COLLECTION(self)->count; --i > 0;)
|
||||||
|
if (ARRAYLIST(self)->elements[i])
|
||||||
|
release(ARRAYLIST(self)->elements[i]);
|
||||||
|
free(ARRAYLIST(self)->elements);
|
||||||
|
}
|
||||||
|
|
||||||
|
classInitFunc(ArrayListIterator) {
|
||||||
|
classObj (ArrayListIterator) = new (Class,
|
||||||
|
"ArrayListIterator", sizeof(ArrayListIterator), classObj(Iterator),
|
||||||
|
ArrayListIterator_Init_f, ArrayListIterator_Deinit_f, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
classInitFunc(ArrayList) {
|
||||||
|
classInit (ArrayListIterator);
|
||||||
|
classObj (ArrayList) = new (Class,
|
||||||
|
"ArrayList", sizeof(ArrayList), classObj(List),
|
||||||
|
ArrayList_Init_f, ArrayList_Deinit_f, false);
|
||||||
|
}
|
106
libs/object/Collection.c
Normal file
106
libs/object/Collection.c
Normal file
|
@ -0,0 +1,106 @@
|
||||||
|
/*
|
||||||
|
Collection.c
|
||||||
|
|
||||||
|
Abstract class for collections of objects
|
||||||
|
|
||||||
|
Copyright (C) 2003 Brian Koropoff
|
||||||
|
|
||||||
|
Author: Brian Koropoff
|
||||||
|
Date: December 03, 2003
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static __attribute__ ((unused)) const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
|
|
||||||
|
#include "QF/dstring.h"
|
||||||
|
#include "QF/classes/Collection.h"
|
||||||
|
|
||||||
|
static String *
|
||||||
|
Collection_ToString_f (Object *self)
|
||||||
|
{
|
||||||
|
Iterator *iter = methodCall(COLLECTION(self), iterator);
|
||||||
|
dstring_t *dstr = dstring_newstr();
|
||||||
|
Object *o;
|
||||||
|
String *ret;
|
||||||
|
|
||||||
|
dstring_appendstr (dstr, "[");
|
||||||
|
|
||||||
|
while ((o = methodCall(iter, next))) {
|
||||||
|
String *s = methodCall(o, toString);
|
||||||
|
dstring_appendstr (dstr, s->str);
|
||||||
|
if (methodCall(iter, hasNext))
|
||||||
|
dstring_appendstr (dstr, ", ");
|
||||||
|
}
|
||||||
|
|
||||||
|
dstring_appendstr (dstr, "]");
|
||||||
|
|
||||||
|
ret = newFloat(String, dstr->str);
|
||||||
|
dstring_delete (dstr);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static qboolean
|
||||||
|
Collection_Contains_f (Collection *self, Object *test)
|
||||||
|
{
|
||||||
|
Iterator *iter = methodCall(self, iterator);
|
||||||
|
Object *o;
|
||||||
|
|
||||||
|
while ((o = methodCall(iter, next)))
|
||||||
|
if (o == test)
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Object *
|
||||||
|
Collection_Init_f (Object *self, Class *type, Collection *source)
|
||||||
|
{
|
||||||
|
superInit(Collection, self);
|
||||||
|
COLLECTION(self)->contains = Collection_Contains_f;
|
||||||
|
COLLECTION(self)->count = 0;
|
||||||
|
COLLECTION(self)->type = type;
|
||||||
|
self->toString = Collection_ToString_f;
|
||||||
|
// FIXME allow for subclasses too
|
||||||
|
if (source && source->type == type) {
|
||||||
|
Iterator *iter = methodCall(source, iterator);
|
||||||
|
Object *o;
|
||||||
|
|
||||||
|
while ((o = methodCall(iter, next)))
|
||||||
|
methodCall(COLLECTION(self), add, o);
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
Collection_Deinit_f (Object *self)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
classInitFunc(Collection) {
|
||||||
|
classObj (Collection) = new (Class,
|
||||||
|
"Collection", sizeof(Collection), classObj(Object),
|
||||||
|
Collection_Init_f, Collection_Deinit_f, true);
|
||||||
|
}
|
80
libs/object/Double.c
Normal file
80
libs/object/Double.c
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
/*
|
||||||
|
Double.c
|
||||||
|
|
||||||
|
Class for double values
|
||||||
|
|
||||||
|
Copyright (C) 2003 Brian Koropoff
|
||||||
|
|
||||||
|
Author: Brian Koropoff
|
||||||
|
Date: December 06, 2003
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static __attribute__ ((unused)) const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "QF/classes/Double.h"
|
||||||
|
#include "QF/va.h"
|
||||||
|
|
||||||
|
static String *
|
||||||
|
Double_ToString_f (Object *self)
|
||||||
|
{
|
||||||
|
return new (String, va("%f", DOUBLE(self)->value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
Double_IntValue_f (Number *self)
|
||||||
|
{
|
||||||
|
return DOUBLE(self)->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double
|
||||||
|
Double_DoubleValue_f (Number *self)
|
||||||
|
{
|
||||||
|
return (int) DOUBLE(self)->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Object *
|
||||||
|
Double_Init_f (Object *self, double value)
|
||||||
|
{
|
||||||
|
superInit(Double, self);
|
||||||
|
DOUBLE(self)->value = value;
|
||||||
|
NUMBER(self)->intValue = Double_IntValue_f;
|
||||||
|
NUMBER(self)->doubleValue = Double_DoubleValue_f;
|
||||||
|
self->toString = Double_ToString_f;
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
Double_Deinit_f (Object *self)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
classInitFunc(Double)
|
||||||
|
{
|
||||||
|
classObj(Double) = new(Class, "Double", sizeof(Double), classObj(Number), Double_Init_f, Double_Deinit_f, false);
|
||||||
|
}
|
80
libs/object/Integer.c
Normal file
80
libs/object/Integer.c
Normal file
|
@ -0,0 +1,80 @@
|
||||||
|
/*
|
||||||
|
Integer.c
|
||||||
|
|
||||||
|
Class for integer values
|
||||||
|
|
||||||
|
Copyright (C) 2003 Brian Koropoff
|
||||||
|
|
||||||
|
Author: Brian Koropoff
|
||||||
|
Date: December 06, 2003
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static __attribute__ ((unused)) const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "QF/classes/Integer.h"
|
||||||
|
#include "QF/va.h"
|
||||||
|
|
||||||
|
static String *
|
||||||
|
Integer_ToString_f (Object *self)
|
||||||
|
{
|
||||||
|
return new (String, va("%i", INTEGER(self)->value));
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
Integer_IntValue_f (Number *self)
|
||||||
|
{
|
||||||
|
return INTEGER(self)->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static double
|
||||||
|
Integer_DoubleValue_f (Number *self)
|
||||||
|
{
|
||||||
|
return (double) INTEGER(self)->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Object *
|
||||||
|
Integer_Init_f (Object *self, int value)
|
||||||
|
{
|
||||||
|
superInit(Integer, self);
|
||||||
|
INTEGER(self)->value = value;
|
||||||
|
NUMBER(self)->intValue = Integer_IntValue_f;
|
||||||
|
NUMBER(self)->doubleValue = Integer_DoubleValue_f;
|
||||||
|
self->toString = Integer_ToString_f;
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
Integer_Deinit_f (Object *self)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
classInitFunc(Integer)
|
||||||
|
{
|
||||||
|
classObj(Integer) = new(Class, "Integer", sizeof(Integer), classObj(Number), Integer_Init_f, Integer_Deinit_f, false);
|
||||||
|
}
|
56
libs/object/Iterator.c
Normal file
56
libs/object/Iterator.c
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
Iterator.c
|
||||||
|
|
||||||
|
Abstract class for Collection iterators
|
||||||
|
|
||||||
|
Copyright (C) 2003 Brian Koropoff
|
||||||
|
|
||||||
|
Author: Brian Koropoff
|
||||||
|
Date: December 03, 2003
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static __attribute__ ((unused)) const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
|
|
||||||
|
#include "QF/classes/Iterator.h"
|
||||||
|
|
||||||
|
static Object *
|
||||||
|
Iterator_Init_f (Object *self)
|
||||||
|
{
|
||||||
|
superInit(Iterator, self);
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
Iterator_Deinit_f (Object *self)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
classInitFunc(Iterator) {
|
||||||
|
classObj (Iterator) = new (Class,
|
||||||
|
"Iterator", sizeof(Iterator), classObj(Object),
|
||||||
|
Iterator_Init_f, Iterator_Deinit_f, true);
|
||||||
|
}
|
75
libs/object/List.c
Normal file
75
libs/object/List.c
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
List.c
|
||||||
|
|
||||||
|
Abstract class for lists
|
||||||
|
|
||||||
|
Copyright (C) 2003 Brian Koropoff
|
||||||
|
|
||||||
|
Author: Brian Koropoff
|
||||||
|
Date: December 03, 2003
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static __attribute__ ((unused)) const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
|
|
||||||
|
#include "QF/classes/List.h"
|
||||||
|
|
||||||
|
static Object *
|
||||||
|
List_Remove_f (Collection *self, Object *o)
|
||||||
|
{
|
||||||
|
unsigned int i = 0;
|
||||||
|
Object *test;
|
||||||
|
Iterator *iter = methodCall(self, iterator);
|
||||||
|
|
||||||
|
while ((test = methodCall(iter, next))) {
|
||||||
|
if (test == o) {
|
||||||
|
methodCall(LIST(self), removeAt, i);
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Object *
|
||||||
|
List_Init_f (Object *self, Class *type, Collection *source)
|
||||||
|
{
|
||||||
|
superInit(List, self, type, source);
|
||||||
|
COLLECTION(self)->remove = List_Remove_f;
|
||||||
|
LIST(self)->smods = 0;
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
List_Deinit_f (Object *self)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
classInitFunc(List) {
|
||||||
|
classObj (List) = new (Class,
|
||||||
|
"List", sizeof(List), classObj(Collection),
|
||||||
|
List_Init_f, List_Deinit_f, true);
|
||||||
|
}
|
10
libs/object/Makefile.am
Normal file
10
libs/object/Makefile.am
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
AUTOMAKE_OPTIONS= foreign
|
||||||
|
AM_CFLAGS= @PREFER_PIC@
|
||||||
|
INCLUDES= -I$(top_srcdir)/include
|
||||||
|
|
||||||
|
lib_LTLIBRARIES= libQFobject.la
|
||||||
|
|
||||||
|
libQFobject_la_LDFLAGS= -version-info 1:0:0
|
||||||
|
libQFobject_la_SOURCES= \
|
||||||
|
ArrayList.c Collection.c Double.c Integer.c Iterator.c \
|
||||||
|
List.c Number.c String.c object.c
|
57
libs/object/Number.c
Normal file
57
libs/object/Number.c
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
Number.c
|
||||||
|
|
||||||
|
Abstract class for numeric values
|
||||||
|
|
||||||
|
Copyright (C) 2003 Brian Koropoff
|
||||||
|
|
||||||
|
Author: Brian Koropoff
|
||||||
|
Date: December 06, 2003
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static __attribute__ ((unused)) const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "QF/classes/Number.h"
|
||||||
|
|
||||||
|
static Object *
|
||||||
|
Number_Init_f (Object *self)
|
||||||
|
{
|
||||||
|
superInit(String, self);
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
Number_Deinit_f (Object *self)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
classInitFunc(Number)
|
||||||
|
{
|
||||||
|
classObj(Number) = new(Class, "Number", sizeof(Number), classObj(Object), Number_Init_f, Number_Deinit_f, true);
|
||||||
|
}
|
73
libs/object/String.c
Normal file
73
libs/object/String.c
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
/*
|
||||||
|
String.c
|
||||||
|
|
||||||
|
Class for containing immutable strings
|
||||||
|
|
||||||
|
Copyright (C) 2003 Brian Koropoff
|
||||||
|
|
||||||
|
Author: Brian Koropoff
|
||||||
|
Date: December 03, 2003
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU General Public License
|
||||||
|
as published by the Free Software Foundation; either version 2
|
||||||
|
of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
|
||||||
|
See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program; if not, write to:
|
||||||
|
|
||||||
|
Free Software Foundation, Inc.
|
||||||
|
59 Temple Place - Suite 330
|
||||||
|
Boston, MA 02111-1307, USA
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
# include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static __attribute__ ((unused)) const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
|
|
||||||
|
#ifdef HAVE_STRING_H
|
||||||
|
# include <string.h>
|
||||||
|
#endif
|
||||||
|
#ifdef HAVE_STRINGS_H
|
||||||
|
# include <strings.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "QF/classes/String.h"
|
||||||
|
|
||||||
|
static String *
|
||||||
|
String_ToString_f (Object *self)
|
||||||
|
{
|
||||||
|
return STRING(self);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Object *
|
||||||
|
String_Init_f (Object *self, const char *value)
|
||||||
|
{
|
||||||
|
superInit(String, self);
|
||||||
|
self->toString = String_ToString_f;
|
||||||
|
STRING(self)->str = strdup (value);
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
String_Deinit_f (Object *self)
|
||||||
|
{
|
||||||
|
free((void *)STRING(self)->str);
|
||||||
|
}
|
||||||
|
|
||||||
|
classInitFunc(String)
|
||||||
|
{
|
||||||
|
classObj(String) = new(Class, "String", sizeof(String), classObj(Object), String_Init_f, String_Deinit_f, false);
|
||||||
|
}
|
|
@ -52,6 +52,11 @@ static __attribute__ ((unused)) const char rcsid[] =
|
||||||
#include "QF/sys.h"
|
#include "QF/sys.h"
|
||||||
#include "QF/object.h"
|
#include "QF/object.h"
|
||||||
#include "QF/va.h"
|
#include "QF/va.h"
|
||||||
|
#include "QF/object.h"
|
||||||
|
|
||||||
|
#include "QF/classes/ArrayList.h"
|
||||||
|
#include "QF/classes/Integer.h"
|
||||||
|
#include "QF/classes/Double.h"
|
||||||
|
|
||||||
static String *
|
static String *
|
||||||
Object_ToString_f (Object *self)
|
Object_ToString_f (Object *self)
|
||||||
|
@ -98,26 +103,6 @@ Class_Deinit_f (Object *self) {
|
||||||
free ((void *)CLASS(self)->name);
|
free ((void *)CLASS(self)->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static String *
|
|
||||||
String_ToString_f (Object *self)
|
|
||||||
{
|
|
||||||
return STRING(self);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Object *
|
|
||||||
String_Init_f (Object *self, const char *value)
|
|
||||||
{
|
|
||||||
superInit(String, self);
|
|
||||||
self->toString = String_ToString_f;
|
|
||||||
STRING(self)->str = strdup (value);
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
String_Deinit_f (Object *self)
|
|
||||||
{
|
|
||||||
free((void *)STRING(self)->str);
|
|
||||||
}
|
|
||||||
|
|
||||||
Object *
|
Object *
|
||||||
Object_Create (Class *cl)
|
Object_Create (Class *cl)
|
||||||
|
@ -168,158 +153,29 @@ Object_InstanceOf (Object *obj, Class *cl)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static String *
|
|
||||||
List_ToString_f (Object *self)
|
|
||||||
{
|
|
||||||
List *list = LIST(self);
|
|
||||||
String *str;
|
|
||||||
unsigned int i;
|
|
||||||
dstring_t *dstr = dstring_newstr();
|
|
||||||
|
|
||||||
dstring_appendstr (dstr, "{");
|
|
||||||
|
|
||||||
for (i = 0; i < list->count; i++) {
|
|
||||||
str = methodCall(methodCall(list, get, i), toString);
|
|
||||||
retain(str);
|
|
||||||
dstring_appendstr (dstr, str->str);
|
|
||||||
release(str);
|
|
||||||
if (i < list->count - 1)
|
|
||||||
dstring_appendstr (dstr, ", ");
|
|
||||||
}
|
|
||||||
dstring_appendstr (dstr, "}");
|
|
||||||
str = newFloat(String, dstr->str);
|
|
||||||
dstring_delete (dstr);
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Object *
|
|
||||||
List_Init_f (Object *self)
|
|
||||||
{
|
|
||||||
superInit(List, self);
|
|
||||||
LIST(self)->count = 0;
|
|
||||||
LIST(self)->get = NULL;
|
|
||||||
LIST(self)->add = NULL;
|
|
||||||
self->toString = List_ToString_f;
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
List_Deinit_f (Object *self)
|
Object_Test (void)
|
||||||
{
|
{
|
||||||
}
|
String *liststr;
|
||||||
|
Collection *list = newFloat(ArrayList, classObj(Object), NULL);
|
||||||
|
|
||||||
static Object *
|
methodCall(list, add, newFloat(String, "Testing..."));
|
||||||
ArrayList_Get_f (List *self, unsigned int index)
|
methodCall(list, add, newFloat(String, "One"));
|
||||||
{
|
methodCall(list, add, newFloat(Integer, 2));
|
||||||
if (index >= self->count)
|
methodCall(list, add, newFloat(Double, 3.0));
|
||||||
return NULL;
|
|
||||||
return ARRAYLIST(self)->elements[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
static qboolean
|
liststr = methodCall(OBJECT(list), toString);
|
||||||
ArrayList_Add_f (List *self, Object *o)
|
Sys_DPrintf("List: %s\n", liststr->str);
|
||||||
{
|
methodCall(LIST(list), removeAt, 2);
|
||||||
self->count++;
|
liststr = methodCall(OBJECT(list), toString);
|
||||||
ARRAYLIST(self)->elements = realloc (ARRAYLIST(self)->elements, self->count);
|
Sys_DPrintf("List: %s\n", liststr->str);
|
||||||
ARRAYLIST(self)->elements[self->count-1] = o;
|
methodCall(LIST(list), insertAt, 2, newFloat(String, "Mr. Two!"));
|
||||||
retain (o);
|
liststr = methodCall(OBJECT(list), toString);
|
||||||
return true;
|
Sys_DPrintf("List: %s\n", liststr->str);
|
||||||
}
|
|
||||||
|
|
||||||
static Object *
|
|
||||||
ArrayList_Init_f (Object *self)
|
|
||||||
{
|
|
||||||
superInit (ArrayList, self);
|
|
||||||
ARRAYLIST(self)->elements = NULL;
|
|
||||||
LIST(self)->get = ArrayList_Get_f;
|
|
||||||
LIST(self)->add = ArrayList_Add_f;
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
ArrayList_Deinit_f (Object *self)
|
|
||||||
{
|
|
||||||
unsigned int i;
|
|
||||||
Object **elements = ARRAYLIST(self)->elements;
|
|
||||||
|
|
||||||
for (i = 0; i < LIST(self)->count; i++)
|
|
||||||
release (elements[i]);
|
|
||||||
if (elements)
|
|
||||||
free (elements);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Object *
|
|
||||||
Number_Init_f (Object *self)
|
|
||||||
{
|
|
||||||
superInit (Number, self);
|
|
||||||
NUMBER(self)->intValue = NULL;
|
|
||||||
NUMBER(self)->doubleValue = NULL;
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
Number_Deinit_f (Object *self)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static String *
|
|
||||||
Integer_ToString_f (Object *self)
|
|
||||||
{
|
|
||||||
return newFloat(String, va("%i", INTEGER(self)->value));
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
Integer_IntValue_f (Number *self)
|
|
||||||
{
|
|
||||||
return INTEGER(self)->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static double
|
|
||||||
Integer_DoubleValue_f (Number *self)
|
|
||||||
{
|
|
||||||
return (double) INTEGER(self)->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Object *
|
|
||||||
Integer_Init_f (Object *self, int value)
|
|
||||||
{
|
|
||||||
superInit (Integer, self);
|
|
||||||
INTEGER(self)->value = value;
|
|
||||||
NUMBER(self)->intValue = Integer_IntValue_f;
|
|
||||||
NUMBER(self)->doubleValue = Integer_DoubleValue_f;
|
|
||||||
self->toString = Integer_ToString_f;
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
Integer_Deinit_f (Object *self)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Class *Object_class;
|
Class *Object_class;
|
||||||
Class *Class_class;
|
Class *Class_class;
|
||||||
Class *String_class;
|
|
||||||
Class *List_class;
|
|
||||||
Class *ArrayList_class;
|
|
||||||
Class *Number_class;
|
|
||||||
Class *Integer_class;
|
|
||||||
|
|
||||||
static void
|
|
||||||
Object_Test (void)
|
|
||||||
{
|
|
||||||
List *l = new(ArrayList);
|
|
||||||
String *str;
|
|
||||||
|
|
||||||
methodCall(l, add, newFloat(Integer, 5));
|
|
||||||
methodCall(l, add, newFloat(String, "Daisy"));
|
|
||||||
methodCall(l, add, newFloat(Integer, 42));
|
|
||||||
|
|
||||||
str = methodCall(OBJECT(l), toString);
|
|
||||||
retain(str);
|
|
||||||
Sys_DPrintf("List: %s\n", str->str);
|
|
||||||
release(str);
|
|
||||||
release(l);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Object_Init (void)
|
Object_Init (void)
|
||||||
|
@ -343,14 +199,18 @@ Object_Init (void)
|
||||||
Class
|
Class
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Create String class normally */
|
/* Initialize standard classes */
|
||||||
String_class = new(Class, "String", sizeof(String), Object_class, String_Init_f, String_Deinit_f, false);
|
classInit(String);
|
||||||
/* Etc... */
|
classInit(Number);
|
||||||
List_class = new(Class, "List", sizeof(List), Object_class, List_Init_f, List_Deinit_f, true);
|
classInit(Integer);
|
||||||
ArrayList_class = new(Class, "ArrayList", sizeof(ArrayList), List_class, ArrayList_Init_f, ArrayList_Deinit_f, false);
|
classInit(Double);
|
||||||
Number_class = new(Class, "Number", sizeof(Number), Object_class, Number_Init_f, Number_Deinit_f, true);
|
classInit(Iterator);
|
||||||
Integer_class = new(Class, "Integer", sizeof(Integer), Number_class, Integer_Init_f, Integer_Deinit_f, false);
|
classInit(Collection);
|
||||||
|
classInit(List);
|
||||||
|
classInit(ArrayList);
|
||||||
|
|
||||||
/* Run a test! */
|
|
||||||
|
|
||||||
|
/* Run test */
|
||||||
Object_Test();
|
Object_Test();
|
||||||
}
|
}
|
|
@ -28,7 +28,7 @@ libQFutil_la_DEPENDENCIES= libasm.la
|
||||||
libQFutil_la_SOURCES= \
|
libQFutil_la_SOURCES= \
|
||||||
bspfile.c buildnum.c cbuf.c checksum.c cmd.c crc.c cvar.c dstring.c \
|
bspfile.c buildnum.c cbuf.c checksum.c cmd.c crc.c cvar.c dstring.c \
|
||||||
fendian.c getopt.c getopt1.c hash.c idparse.c info.c link.c llist.c \
|
fendian.c getopt.c getopt1.c hash.c idparse.c info.c link.c llist.c \
|
||||||
mathlib.c mdfour.c msg.c object.c pakfile.c plugin.c qargs.c qendian.c \
|
mathlib.c mdfour.c msg.c pakfile.c plugin.c qargs.c qendian.c \
|
||||||
qfplist.c quakefs.c quakeio.c riff.c sizebuf.c string.c sys.c \
|
qfplist.c quakefs.c quakeio.c riff.c sizebuf.c string.c sys.c \
|
||||||
va.c ver_check.c wad.c zone.c $(fnmatch)
|
va.c ver_check.c wad.c zone.c $(fnmatch)
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,7 @@ qf_server_LIBS= \
|
||||||
$(top_builddir)/libs/gamecode/builtins/libQFgamecode_builtins.la \
|
$(top_builddir)/libs/gamecode/builtins/libQFgamecode_builtins.la \
|
||||||
$(top_builddir)/libs/gamecode/engine/libQFgamecode.la \
|
$(top_builddir)/libs/gamecode/engine/libQFgamecode.la \
|
||||||
$(top_builddir)/libs/console/libQFconsole.la \
|
$(top_builddir)/libs/console/libQFconsole.la \
|
||||||
|
$(top_builddir)/libs/object/libQFobject.la \
|
||||||
$(top_builddir)/libs/gib/libQFgib.la \
|
$(top_builddir)/libs/gib/libQFgib.la \
|
||||||
$(top_builddir)/libs/util/libQFutil.la
|
$(top_builddir)/libs/util/libQFutil.la
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue