-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathSub_Object.c
More file actions
55 lines (52 loc) · 1.26 KB
/
Sub_Object.c
File metadata and controls
55 lines (52 loc) · 1.26 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
#include "Sub_Object.h"
//--Implementations
//----Constructor/Destructor
Sub_Object * new_Sub_Object(int x, int y, int z) {
Sub_Object * o = malloc(sizeof(Sub_Object));
o->prop = malloc(sizeof(Sub_Properties));
o->methods = malloc(sizeof(Sub_Methods));
init_Sub_Object(o, x, y, z);
return o;
}
void delete_Sub_Object(Sub_Object * o) {
uninit_Sub_Properties(o->prop);
free(o->prop);
o->prop = 0;
init_Sub_Methods(o->methods);
free(o->methods);
o->methods = 0;
free(o);
o = 0;
}
void init_Sub_Object(Sub_Object * o, int x, int y, int z) {
o->super = (Object*) o;
init_Sub_Properties(o->prop, x, y, z);
init_Sub_Methods(o->methods);
}
//----Properties
void init_Sub_Properties(Sub_Properties * p, int x, int y, int z) {
init_Properties((Properties *)p, x, y);
p->z = z;
}
void uninit_Sub_Properties(Sub_Properties * p) {
uninit_Properties((Properties *)p);
p->z = 0;
}
//----Methods
void init_Sub_Methods(Sub_Methods * m) {
init_Methods((Methods *)m);
m->print = print;
m->delete = delete_Sub_Object;
}
void uninit_Sub_Methods(Sub_Methods * m) {
uninit_Methods((Methods *)m);
m->print = 0;
m->delete = 0;
}
//----Other
void print(Sub_Object * so) {
int a = so->super->prop->x;
int * b = so->super->prop->y;
int c = so->prop->z;
printf("%d, %d, %d\n", a, *b, c);
}