htop/Object.h

67 lines
1.8 KiB
C
Raw Normal View History

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
(C) 2004-2012 Hisham H. Muhammad
(C) 2020 Red Hat, Inc. All Rights Reserved.
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 "config.h" // IWYU pragma: keep
#include <assert.h>
2006-03-04 18:16:49 +00:00
#include "RichString.h"
#include "XUtils.h" // IWYU pragma: keep
2020-10-14 22:56:22 +00:00
#ifndef NDEBUG
#include <stdbool.h>
#endif
struct Object_;
2006-03-04 18:16:49 +00:00
typedef struct Object_ Object;
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*);
#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_))
#define Object_delete(obj_) (assert(Object_getClass(obj_)->delete), Object_getClass(obj_)->delete((Object*)(obj_)))
#define Object_displayFn(obj_) Object_getClass(obj_)->display
#define Object_display(obj_, str_) (assert(Object_getClass(obj_)->display), Object_getClass(obj_)->display((const Object*)(obj_), str_))
#define Object_compare(obj_, other_) (assert(Object_getClass(obj_)->compare), Object_getClass(obj_)->compare((const void*)(obj_), other_))
#define Class(class_) ((const ObjectClass*)(&(class_ ## _class)))
#define AllocThis(class_) (class_*) xMalloc(sizeof(class_)); Object_setClass(this, Class(class_))
2019-10-31 16:39:12 +00:00
typedef struct ObjectClass_ {
const void* const extends;
const Object_Display display;
const Object_Delete delete;
const Object_Compare compare;
} ObjectClass;
2006-03-04 18:16:49 +00:00
struct Object_ {
const ObjectClass* klass;
2006-03-04 18:16:49 +00:00
};
typedef union {
int i;
void* v;
} Arg;
extern const ObjectClass Object_class;
#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
#endif /* NDEBUG */
2006-03-04 18:16:49 +00:00
#endif