This repository was archived by the owner on Dec 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtype.h
More file actions
75 lines (49 loc) · 1.6 KB
/
type.h
File metadata and controls
75 lines (49 loc) · 1.6 KB
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
#ifndef __TYPE_H_
#define __TYPE_H_
#define TYPE_INVALID (0)
#define TYPE_FROM_INSTANCE(i) (((TypeInstance *) i)->type)
#define TYPE_FROM_CLASS(c) (((TypeClass *) c)->type)
#define TYPE_CHECK_INSTANCE_TYPE(i, t) (type_is(TYPE_FROM_INSTANCE(i), t))
#define TYPE_CHECK_INSTANCE_CAST(i, t, ctype) (TYPE_CHECK_INSTANCE_TYPE(i, t) ? (ctype *) (i) : NULL)
#define TYPE_CHECK_CLASS_TYPE(c, t) (type_is(TYPE_FROM_CLASS(c), t))
#define TYPE_CHECK_CLASS_CAST(c, t, ctype) (TYPE_CHECK_CLASS_TYPE(c, t) ? (ctype *) (c) : NULL)
#define TYPE_INSTANCE_GET_CLASS(i, t, ctype) (TYPE_CHECK_CLASS_CAST(type_instance_get_class((TypeInstance *) (i)), t, ctype))
typedef unsigned int Type;
typedef enum _TypeFlags TypeFlags;
typedef struct _TypeClass TypeClass;
typedef struct _TypeInstance TypeInstance;
typedef void (* ClassInitFunc)(TypeClass * clazz);
enum _TypeFlags
{
TYPE_FLAGS_NONE = 0,
TYPE_FLAGS_ABSTRACT = 1 << 1,
};
struct _TypeClass
{
Type parent;
Type type;
char * name;
size_t class_size;
ClassInitFunc class_init;
size_t inst_size;
TypeFlags flags : 16;
int inited : 1;
};
struct _TypeInstance
{
Type type;
};
Type type_register(Type parent,
const char * name,
size_t class_size,
ClassInitFunc class_init,
size_t inst_size,
TypeFlags flags);
const char * type_get_name(Type type);
TypeClass * type_get_class(Type self);
int type_is_instantiatable(Type self);
TypeInstance * type_create_instance(Type self);
TypeClass * type_instance_get_class(TypeInstance * self);
Type type_get_parent(Type type);
int type_is(Type self, Type other);
#endif /* __TYPE_H_ */