CoreFW  Diff

Differences From Artifact [36ac9401ba]:

To Artifact [13f417b3bd]:


32
33
34
35
36
37
38
39

40
41
42
43
44
45
46
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46







-
+







cfw_new(CFWClass *class, ...)
{
	CFWObject *obj;

	if ((obj = malloc(class->size)) == NULL)
		return NULL;

	obj->clsptr = class;
	obj->cls = class;
	obj->ref_cnt = 1;

	if (class->ctor != NULL) {
		va_list args;
		va_start(args, class);

		if (!class->ctor(obj, args)) {
74
75
76
77
78
79
80
81
82


83
84
85
86
87
88
89
90
91
92
93


94
95
96
97
98
99
100
101
102
103
104


105
106
107
108
109
110
111
112
113
74
75
76
77
78
79
80


81
82
83
84
85
86
87
88
89
90
91


92
93
94
95
96
97
98
99
100
101
102


103
104
105
106
107
108
109
110
111
112
113







-
-
+
+









-
-
+
+









-
-
+
+









}

void
cfw_free(void *ptr)
{
	CFWObject *obj = ptr;

	if (obj->clsptr->dtor != NULL)
		obj->clsptr->dtor(obj);
	if (obj->cls->dtor != NULL)
		obj->cls->dtor(obj);

	free(obj);
}

bool
cfw_equal(void *ptr1, void *ptr2)
{
	CFWObject *obj1 = ptr1, *obj2 = ptr2;

	if (obj1->clsptr->equal != NULL) {
		return obj1->clsptr->equal(obj1, obj2);
	if (obj1->cls->equal != NULL) {
		return obj1->cls->equal(obj1, obj2);
	} else
		return (obj1 == obj2);
}

void*
cfw_copy(void *ptr)
{
	CFWObject *obj = ptr;

	if (obj->clsptr->copy != NULL)
		return obj->clsptr->copy(obj);
	if (obj->cls->copy != NULL)
		return obj->cls->copy(obj);
	else
		return NULL;
}

static CFWClass class = {
	.name = "CFWObject",
	.size = sizeof(CFWObject),
};
CFWClass *cfw_object = &class;