2006-03-04 18:16:49 +00:00
|
|
|
#ifndef HEADER_Object
|
|
|
|
#define HEADER_Object
|
|
|
|
/*
|
2011-12-26 21:35:57 +00:00
|
|
|
htop - Object.h
|
2012-12-05 15:12:20 +00:00
|
|
|
(C) 2004-2012 Hisham H. Muhammad
|
2020-08-19 23:35:24 +00:00
|
|
|
(C) 2020 Red Hat, Inc. All Rights Reserved.
|
2020-10-05 07:51:32 +00:00
|
|
|
Released under the GNU GPLv2, see the COPYING file
|
2006-03-04 18:16:49 +00:00
|
|
|
in the source distribution for its full text.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "RichString.h"
|
2016-02-02 14:53:02 +00:00
|
|
|
#include "XAlloc.h"
|
2020-09-09 06:56:04 +00:00
|
|
|
#include "Macros.h"
|
2006-07-11 06:13:32 +00:00
|
|
|
|
2006-03-04 18:16:49 +00:00
|
|
|
typedef struct Object_ Object;
|
|
|
|
|
2020-10-06 10:28:11 +00:00
|
|
|
typedef void(*Object_Display)(const Object*, RichString*);
|
2014-04-25 22:41:23 +00:00
|
|
|
typedef long(*Object_Compare)(const void*, const void*);
|
2006-03-04 18:16:49 +00:00
|
|
|
typedef void(*Object_Delete)(Object*);
|
|
|
|
|
2020-10-06 10:28:11 +00:00
|
|
|
#define Object_getClass(obj_) ((const Object*)(obj_))->klass
|
2020-10-13 12:39:12 +00:00
|
|
|
#define Object_setClass(obj_, class_) (((Object*)(obj_))->klass = (const ObjectClass*) (class_))
|
2012-12-05 15:12:20 +00:00
|
|
|
|
|
|
|
#define Object_delete(obj_) Object_getClass(obj_)->delete((Object*)(obj_))
|
|
|
|
#define Object_displayFn(obj_) Object_getClass(obj_)->display
|
2020-10-06 10:28:11 +00:00
|
|
|
#define Object_display(obj_, str_) Object_getClass(obj_)->display((const Object*)(obj_), str_)
|
2012-12-05 15:12:20 +00:00
|
|
|
#define Object_compare(obj_, other_) Object_getClass(obj_)->compare((const void*)(obj_), other_)
|
|
|
|
|
2020-10-04 15:55:08 +00:00
|
|
|
#define Class(class_) ((const ObjectClass*)(&(class_ ## _class)))
|
2012-12-05 15:12:20 +00:00
|
|
|
|
2016-02-02 14:53:02 +00:00
|
|
|
#define AllocThis(class_) (class_*) xMalloc(sizeof(class_)); Object_setClass(this, Class(class_));
|
2019-10-31 16:39:12 +00:00
|
|
|
|
2012-12-05 15:12:20 +00:00
|
|
|
typedef struct ObjectClass_ {
|
2020-10-04 15:55:08 +00:00
|
|
|
const void* const extends;
|
2012-12-05 15:12:20 +00:00
|
|
|
const Object_Display display;
|
|
|
|
const Object_Delete delete;
|
|
|
|
const Object_Compare compare;
|
|
|
|
} ObjectClass;
|
|
|
|
|
2006-03-04 18:16:49 +00:00
|
|
|
struct Object_ {
|
2020-10-04 15:55:08 +00:00
|
|
|
const ObjectClass* klass;
|
2006-03-04 18:16:49 +00:00
|
|
|
};
|
|
|
|
|
2020-08-19 23:35:24 +00:00
|
|
|
typedef union {
|
|
|
|
int i;
|
|
|
|
void* v;
|
|
|
|
} Arg;
|
|
|
|
|
2020-10-04 15:55:08 +00:00
|
|
|
extern const ObjectClass Object_class;
|
2006-07-11 06:13:32 +00:00
|
|
|
|
2020-09-17 20:27:33 +00:00
|
|
|
#ifndef NDEBUG
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2020-10-05 10:27:32 +00:00
|
|
|
bool Object_isA(const Object* o, const ObjectClass* klass);
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2020-09-17 20:27:33 +00:00
|
|
|
#endif /* NDEBUG */
|
2006-03-04 18:16:49 +00:00
|
|
|
|
|
|
|
#endif
|