-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathobject.h
52 lines (38 loc) · 900 Bytes
/
object.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
#include <stdbool.h>
#pragma once
typedef struct Object Object;
typedef struct ObjectType ObjectType;
typedef struct OString OString;
typedef struct OInt OInt;
typedef unsigned int hash_t;
typedef bool (*equalifier)(Object *obj, Object *other);
typedef void (*freeer)(Object *obj);
#define OBJECTTYPEHEADER \
equalifier equal; \
freeer free;
#define OBJECTHEADER(type) \
type *class; \
hash_t hash; \
unsigned int refcount;
struct ObjectType {
OBJECTTYPEHEADER
};
struct Object {
OBJECTHEADER(ObjectType)
};
struct OString {
OBJECTHEADER(ObjectType)
char * str;
};
struct OInt {
OBJECTHEADER(ObjectType)
int n;
};
#define OSTRLEN(o) strlen(OSTR2CSTR(o))
#define OSTR2CSTR(o) ((OString*)(o))->str
#define OINT2INT(i) ((OInt*)(i))->n
OString *new_ostring(char *str);
OInt *new_oint(int n);
hash_t hash(void *obj, int size);
void retain(Object *obj);
void release(Object *obj);