blob: 2475be39741a38fdd2e1c87ad6a55be750b6253b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
#include <Paradox/Object.h>
#include <objc/objc.h>
#include <objc/runtime.h>
#include <objc/objc-arc.h>
#include <stdio.h>
@implementation PXObject
/* init and lifecycle */
+ (instancetype)alloc {
return class_createInstance(self, 0);
}
+ (instancetype) new {
return [[self alloc] init];
}
- (instancetype) retain {
return objc_retain_fast_np(self);
}
- (void) release {
objc_release_fast_np(self);
}
- (instancetype) autorelease {
return objc_autorelease(self);
}
- (instancetype)init {
return self;
}
- (void)dealloc {
object_dispose(self);
}
/* object introspection */
- (Class)class {
return object_getClass(self);
}
- (Class)superclass {
return class_getSuperclass([self class]);
}
+ (Class)class {
return self;
}
+ (Class)superclass {
return class_getSuperclass(self);
}
+ (const char *)className {
return class_getName(self);
}
- (const char *)className {
return class_getName([self class]);
}
- (BOOL)isKindOfClass:(Class)class {
Class current = [self class];
while (current != nil) {
if (current == class)
return YES;
current = class_getSuperclass(current);
}
return NO;
}
- (BOOL)isMemberOfClass:(Class)class {
return ([self class] == class);
}
/* selector stuff */
- (BOOL)respondsToSelector:(SEL)selector {
return class_respondsToSelector([self class], selector);
}
#ifdef PARADOX_DEBUG_FEATURES
- (void)healthCheck {
printf("PXObject health check: %p\n", (void*)self);
}
+ (instancetype)allocDebug {
printf("alloc: self = %p\n", (void*)self);
printf("alloc: instance size = %zu\n", class_getInstanceSize(self));
printf("alloc: sizeof(Class) = %zu\n", sizeof(Class));
id object = [self alloc];
printf("alloc: object = %p\n", (void*)object);
return object;
}
#endif
@end
|