ObjFW  Diff

Differences From Artifact [a404ee9968]:

To Artifact [1af8420b56]:


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
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







-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-



















-
+
-
-
-
-

+


















+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







 * the packaging of this file.
 */

#import <objc/Object.h>

#include <stdint.h>

/**
 * The OFObject class is the base class for all other classes inside ObjFW.
 */
@interface OFObject: Object
{
	void   **__memchunks;
	size_t __memchunks_size;
	size_t __retain_count;
}

@protocol OFRetainRelease
/**
 * Initialize the already allocated object.
 * Also sets up the memory pool for the object.
 *
 * \return An initialized object
 */
- init;

/**
 * Increases the retain count.
 */
- retain;

/**
 * Decreases the retain cound and frees the object if it reaches 0.
 */
- (void)release;

/**
 * Adds the object to the autorelease pool that is on top of the thread's stack.
 */
- autorelease;

/**
 * \return The retain count
 */
- (size_t)retainCount;

@end
/**
 * Frees the object and also frees all memory allocated via its memory pool.
 */
- free;

@protocol OFHashable
/**
 * Compare two objects.
 * Classes containing data (like strings, arrays, lists etc.) should reimplement
 * this!
 *
 * \param obj The object which is tested for equality
 * \return A boolean whether the object is equal to the other object
 */
- (BOOL)isEqual: (id)obj;

/**
 * Calculate a hash for the object.
 * Classes containing data (like strings, arrays, lists etc.) should reimplement
 * this!
 *
 * \return A 24 bit hash for the object
 */
- (uint32_t)hash;
@end

/**
 * The OFObject class is the base class for all other classes inside ObjFW.
 */
@interface OFObject: Object <OFRetainRelease, OFHashable>
{
	void   **__memchunks;
	size_t __memchunks_size;
	size_t __retain_count;
}

/**
 * Initialize the already allocated object.
 * Also sets up the memory pool for the object.
 *
 * \return An initialized object
 */
- init;

/**
 * Frees the object and also frees all memory allocated via its memory pool.
 */
- free;

/**
 * Adds a pointer to the memory pool.
 * This is useful to add memory allocated by functions such as asprintf to the
 * pool so it gets freed automatically when the object is freed.
 *
 * \param ptr A pointer to add to the memory pool