Object.c 1.03 KB
Newer Older
Hisham Muhammad's avatar
Hisham Muhammad committed
1
2
/*
htop
Hisham Muhammad's avatar
Hisham Muhammad committed
3
(C) 2004-2010 Hisham H. Muhammad
Hisham Muhammad's avatar
Hisham Muhammad committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/

#include "Object.h"
#include "RichString.h"
#include "CRT.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>

#include "debug.h"

/*{
18
19
20
21
22

#ifndef DEBUG
#define Object_setClass(obj, class)
#endif

Hisham Muhammad's avatar
Hisham Muhammad committed
23
24
25
typedef struct Object_ Object;

typedef void(*Object_Display)(Object*, RichString*);
26
typedef int(*Object_Compare)(const void*, const void*);
Hisham Muhammad's avatar
Hisham Muhammad committed
27
28
29
typedef void(*Object_Delete)(Object*);

struct Object_ {
30
   #ifdef DEBUG
Hisham Muhammad's avatar
Hisham Muhammad committed
31
   char* class;
32
   #endif
Hisham Muhammad's avatar
Hisham Muhammad committed
33
34
35
36
37
   Object_Display display;
   Object_Delete delete;
};
}*/

38
39
#ifdef DEBUG
char* OBJECT_CLASS = "Object";
Hisham Muhammad's avatar
Hisham Muhammad committed
40

41
42
43
#else
#define OBJECT_CLASS NULL
#endif
Hisham Muhammad's avatar
Hisham Muhammad committed
44

45
#ifdef DEBUG
Hisham Muhammad's avatar
Hisham Muhammad committed
46

47
48
void Object_setClass(void* this, char* class) {
   ((Object*)this)->class = class;
Hisham Muhammad's avatar
Hisham Muhammad committed
49
50
}

51
static void Object_display(Object* this, RichString* out) {
Hisham Muhammad's avatar
Hisham Muhammad committed
52
53
54
55
56
   char objAddress[50];
   sprintf(objAddress, "%s @ %p", this->class, (void*) this);
   RichString_write(out, CRT_colors[DEFAULT_COLOR], objAddress);
}

57
#endif