Removed common type code.
This commit is contained in:
parent
7b0f930185
commit
f60178798f
|
@ -4,10 +4,8 @@ CFILES += \
|
||||||
common/areaevents.c \
|
common/areaevents.c \
|
||||||
common/control.c \
|
common/control.c \
|
||||||
common/matrix.c \
|
common/matrix.c \
|
||||||
common/menu.c \
|
|
||||||
common/ptrarray.c \
|
common/ptrarray.c \
|
||||||
common/shouldquit.c \
|
common/shouldquit.c
|
||||||
common/types.c
|
|
||||||
|
|
||||||
HFILES += \
|
HFILES += \
|
||||||
common/uipriv.h
|
common/uipriv.h
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
// 29 may 2015
|
|
||||||
#include "../ui.h"
|
|
||||||
|
|
||||||
static uintmax_t type_uiMenu = 0;
|
|
||||||
static uintmax_t type_uiMenuItem = 0;
|
|
||||||
|
|
||||||
uintmax_t uiMenuType(void)
|
|
||||||
{
|
|
||||||
if (type_uiMenu == 0)
|
|
||||||
type_uiMenu = uiRegisterType("uiMenu", 0, 0);
|
|
||||||
return type_uiMenu;
|
|
||||||
}
|
|
||||||
|
|
||||||
uintmax_t uiMenuItemType(void)
|
|
||||||
{
|
|
||||||
if (type_uiMenuItem == 0)
|
|
||||||
type_uiMenuItem = uiRegisterType("uiMenuItem", 0, 0);
|
|
||||||
return type_uiMenuItem;
|
|
||||||
}
|
|
|
@ -1,88 +0,0 @@
|
||||||
// 17 may 2015
|
|
||||||
#include "../ui.h"
|
|
||||||
#include "uipriv.h"
|
|
||||||
|
|
||||||
struct typeinfo {
|
|
||||||
const char *name;
|
|
||||||
uintmax_t parent;
|
|
||||||
size_t size;
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct ptrArray *types = NULL;
|
|
||||||
|
|
||||||
uintmax_t uiRegisterType(const char *name, uintmax_t parent, size_t size)
|
|
||||||
{
|
|
||||||
struct typeinfo *ti;
|
|
||||||
|
|
||||||
if (types == NULL) {
|
|
||||||
types = newPtrArray();
|
|
||||||
// reserve ID 0
|
|
||||||
ptrArrayAppend(types, NULL);
|
|
||||||
}
|
|
||||||
// TODO prevent our size from being smaller than our parent's
|
|
||||||
ti = uiNew(struct typeinfo);
|
|
||||||
ti->name = name;
|
|
||||||
ti->parent = parent;
|
|
||||||
ti->size = size;
|
|
||||||
ptrArrayAppend(types, ti);
|
|
||||||
return types->len - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void *uiIsA(void *p, uintmax_t id, int fail)
|
|
||||||
{
|
|
||||||
uiTyped *t;
|
|
||||||
struct typeinfo *ti, *ti2;
|
|
||||||
uintmax_t compareTo;
|
|
||||||
|
|
||||||
if (id == 0 || id >= types->len)
|
|
||||||
complain("invalid type ID given to uiIsA()");
|
|
||||||
t = (uiTyped *) p;
|
|
||||||
compareTo = t->Type;
|
|
||||||
if (compareTo == 0)
|
|
||||||
complain("object %p has no type in uiIsA()", t);
|
|
||||||
for (;;) {
|
|
||||||
if (compareTo >= types->len)
|
|
||||||
complain("invalid type ID in uiIsA()", t);
|
|
||||||
if (compareTo == id)
|
|
||||||
return t;
|
|
||||||
ti = ptrArrayIndex(types, struct typeinfo *, compareTo);
|
|
||||||
if (ti->parent == 0)
|
|
||||||
break;
|
|
||||||
compareTo = ti->parent;
|
|
||||||
}
|
|
||||||
if (fail) {
|
|
||||||
ti = ptrArrayIndex(types, struct typeinfo *, id);
|
|
||||||
ti2 = ptrArrayIndex(types, struct typeinfo *, t->Type);
|
|
||||||
complain("object %p not a %s in uiIsA() (is a %s)", t, ti->name, ti2->name);
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
void uninitTypes(void)
|
|
||||||
{
|
|
||||||
struct typeinfo *ti;
|
|
||||||
|
|
||||||
if (types == NULL) // never initialized; do nothing
|
|
||||||
return;
|
|
||||||
// the first entry is NULL; get rid of it directly
|
|
||||||
ptrArrayDelete(types, 0);
|
|
||||||
while (types->len != 0) {
|
|
||||||
ti = ptrArrayIndex(types, struct typeinfo *, 0);
|
|
||||||
ptrArrayDelete(types, 0);
|
|
||||||
uiFree(ti);
|
|
||||||
}
|
|
||||||
ptrArrayDestroy(types);
|
|
||||||
}
|
|
||||||
|
|
||||||
uiTyped *newTyped(uintmax_t type)
|
|
||||||
{
|
|
||||||
struct typeinfo *ti;
|
|
||||||
uiTyped *instance;
|
|
||||||
|
|
||||||
if (type == 0 || type >= types->len)
|
|
||||||
complain("invalid type ID given to newTyped()");
|
|
||||||
ti = ptrArrayIndex(types, struct typeinfo *, type);
|
|
||||||
instance = (uiTyped *) uiAlloc(ti->size, ti->name);
|
|
||||||
instance->Type = type;
|
|
||||||
return instance;
|
|
||||||
}
|
|
|
@ -38,10 +38,6 @@ void ptrArrayDelete(struct ptrArray *, uintmax_t);
|
||||||
// shouldquit.c
|
// shouldquit.c
|
||||||
extern int shouldQuit(void);
|
extern int shouldQuit(void);
|
||||||
|
|
||||||
// types.c
|
|
||||||
extern void uninitTypes(void);
|
|
||||||
extern uiTyped *newTyped(uintmax_t type);
|
|
||||||
|
|
||||||
// areaevents.c
|
// areaevents.c
|
||||||
typedef struct clickCounter clickCounter;
|
typedef struct clickCounter clickCounter;
|
||||||
// you should call Reset() to zero-initialize a new instance
|
// you should call Reset() to zero-initialize a new instance
|
||||||
|
|
|
@ -119,7 +119,6 @@ void uiUninit(void)
|
||||||
[realNSApp() setDelegate:nil];
|
[realNSApp() setDelegate:nil];
|
||||||
[appDelegate() release];
|
[appDelegate() release];
|
||||||
[realNSApp() release];
|
[realNSApp() release];
|
||||||
uninitTypes();
|
|
||||||
uninitAlloc();
|
uninitAlloc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ const char *uiInit(uiInitOptions *o)
|
||||||
void uiUninit(void)
|
void uiUninit(void)
|
||||||
{
|
{
|
||||||
uninitMenus();
|
uninitMenus();
|
||||||
uninitTypes();
|
|
||||||
uninitAlloc();
|
uninitAlloc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -151,7 +151,6 @@ void uiUninit(void)
|
||||||
unregisterWindowClass();
|
unregisterWindowClass();
|
||||||
// no need to delete the default icon or cursor; see http://stackoverflow.com/questions/30603077/
|
// no need to delete the default icon or cursor; see http://stackoverflow.com/questions/30603077/
|
||||||
uninitUtilWindow();
|
uninitUtilWindow();
|
||||||
uninitTypes();
|
|
||||||
uninitAlloc();
|
uninitAlloc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue