aboutsummaryrefslogtreecommitdiffstats
path: root/Object.h
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2020-12-07 10:26:01 +0100
committerDaniel Lange <DLange@git.local>2020-12-07 10:26:01 +0100
commit65357c8c46154de4e4eca14075bfe5523bb5fc14 (patch)
tree8f430ee5a0d5de377c4e7c94e47842a27c70d7e8 /Object.h
parentf80394a20254938142011855f2954b3f63fe5909 (diff)
downloaddebian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.tar.gz
debian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.tar.bz2
debian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.zip
New upstream version 3.0.3upstream/3.0.3
Diffstat (limited to 'Object.h')
-rw-r--r--Object.h43
1 files changed, 26 insertions, 17 deletions
diff --git a/Object.h b/Object.h
index 50a5f12..2c3ba9f 100644
--- a/Object.h
+++ b/Object.h
@@ -4,41 +4,50 @@
htop - Object.h
(C) 2004-2012 Hisham H. Muhammad
(C) 2020 Red Hat, Inc. All Rights Reserved.
-Released under the GNU GPL, see the COPYING file
+Released under the GNU GPLv2, see the COPYING file
in the source distribution for its full text.
*/
+#include "config.h" // IWYU pragma: keep
+
+#include <assert.h>
+
#include "RichString.h"
-#include "XAlloc.h"
-#include "Macros.h"
+#include "XUtils.h" // IWYU pragma: keep
+
+#ifndef NDEBUG
+#include <stdbool.h>
+#endif
+
+struct Object_;
typedef struct Object_ Object;
-typedef void(*Object_Display)(Object*, RichString*);
+typedef void(*Object_Display)(const Object*, RichString*);
typedef long(*Object_Compare)(const void*, const void*);
typedef void(*Object_Delete)(Object*);
-#define Object_getClass(obj_) ((Object*)(obj_))->klass
-#define Object_setClass(obj_, class_) Object_getClass(obj_) = (ObjectClass*) class_
+#define Object_getClass(obj_) ((const Object*)(obj_))->klass
+#define Object_setClass(obj_, class_) (((Object*)(obj_))->klass = (const ObjectClass*) (class_))
-#define Object_delete(obj_) Object_getClass(obj_)->delete((Object*)(obj_))
+#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_) Object_getClass(obj_)->display((Object*)(obj_), str_)
-#define Object_compare(obj_, other_) Object_getClass(obj_)->compare((const void*)(obj_), other_)
+#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_) ((ObjectClass*)(&(class_ ## _class)))
+#define Class(class_) ((const ObjectClass*)(&(class_ ## _class)))
-#define AllocThis(class_) (class_*) xMalloc(sizeof(class_)); Object_setClass(this, Class(class_));
+#define AllocThis(class_) (class_*) xMalloc(sizeof(class_)); Object_setClass(this, Class(class_))
typedef struct ObjectClass_ {
- const void* extends;
+ const void* const extends;
const Object_Display display;
const Object_Delete delete;
const Object_Compare compare;
} ObjectClass;
struct Object_ {
- ObjectClass* klass;
+ const ObjectClass* klass;
};
typedef union {
@@ -46,12 +55,12 @@ typedef union {
void* v;
} Arg;
-extern ObjectClass Object_class;
+extern const ObjectClass Object_class;
-#ifdef DEBUG
+#ifndef NDEBUG
-bool Object_isA(Object* o, const ObjectClass* klass);
+bool Object_isA(const Object* o, const ObjectClass* klass);
-#endif
+#endif /* NDEBUG */
#endif

© 2014-2024 Faster IT GmbH | imprint | privacy policy