From 00b324bfc162030b575e03795dcfcaac56bd0b4d Mon Sep 17 00:00:00 2001 From: Hisham Muhammad Date: Wed, 5 Dec 2012 15:12:20 +0000 Subject: Changes in object model: separate class objects to store vtable. Also, nicer UTF-8 display of big numbers. --- ListItem.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'ListItem.c') diff --git a/ListItem.c b/ListItem.c index af50ca95..677707f0 100644 --- a/ListItem.c +++ b/ListItem.c @@ -26,12 +26,6 @@ typedef struct ListItem_ { }*/ -#ifdef DEBUG -char* LISTITEM_CLASS = "ListItem"; -#else -#define LISTITEM_CLASS NULL -#endif - static void ListItem_delete(Object* cast) { ListItem* this = (ListItem*)cast; free(this->value); @@ -49,11 +43,13 @@ static void ListItem_display(Object* cast, RichString* out) { RichString_write(out, CRT_colors[DEFAULT_COLOR], this->value/*buffer*/); } +ObjectClass ListItem_class = { + .display = ListItem_display, + .delete = ListItem_delete +}; + ListItem* ListItem_new(const char* value, int key) { - ListItem* this = malloc(sizeof(ListItem)); - Object_setClass(this, LISTITEM_CLASS); - ((Object*)this)->display = ListItem_display; - ((Object*)this)->delete = ListItem_delete; + ListItem* this = AllocThis(ListItem); this->value = strdup(value); this->key = key; return this; -- cgit v1.2.3