-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathISObject.h
55 lines (39 loc) · 1.5 KB
/
ISObject.h
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
/* Created By: Justin Meiners (2013) */
#ifndef IS_OBJECT_H
#define IS_OBJECT_H
#include <stdlib.h>
#include <assert.h>
#include <string.h>
typedef const void* ISObjectRef;
typedef struct
{
/* this could also include functions for comparison, hashing,
or whatever core functionality objects required */
const char* _name;
void (*_deallocFunc)(ISObjectRef object);
ISObjectRef (*_copyFunc)(ISObjectRef object);
} ISObjectClass;
/* C Standard
A pointer to a structure object, suitably converted, points to its initial member and vice versa.
This allows the ISObjectBase to be accessible from any struct that contains it as the first member.
*/
typedef struct
{
/* this structure must be the first item in every ISObject */
int retainCount;
ISObjectClass* objectClass;
} ISObjectBase;
extern void ISObjectBaseInit(ISObjectBase* base, ISObjectClass* objClass);
extern int ISObjectRetainCount(ISObjectRef object);
/* +1 retain count */
extern ISObjectRef ISRetain(ISObjectRef object);
/* -1 retain count, calls objects dealloc method when retainCount < 1 */
extern void ISRelease(ISObjectRef object);
/* adds the object to the current autorelease pool, object will be released when the pool is destroyed */
extern ISObjectRef ISAutorelease(ISObjectRef object);
extern ISObjectRef ISCopy(ISObjectRef object);
/* adds a new pool to the stack */
extern void ISAutoreleasePoolPush();
/* removes a pool from the stack releasing all objects */
extern void ISAutoreleasePoolPop();
#endif