bigpoint_cclass.c
1.3 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
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <json/json.h>
#include "bigpoint/bigpoint_cclass.h"
void *
new(const void * _class, ...)
{
const struct BIGPOINT_CCLASS * class = _class;
void * object = calloc(1, class->size);
* (const struct BIGPOINT_CCLASS **) object = class;
if (class->__construct) {
va_list params;
va_start(params, _class);
class->__construct(object, ¶ms);
va_end(params);
}
return object;
}
void *
newFromJson(const void * _class, struct json_object * json)
{
const struct BIGPOINT_CCLASS * class = _class;
void * object = calloc(1, class->size);
* (const struct BIGPOINT_CCLASS **) object = class;
if (class->__jsonConst && json) {
class->__jsonConst(object, json);
}
return object;
}
void
delete(void * _object)
{
const struct BIGPOINT_CCLASS ** class = _object;
if (_object && *class && (*class)->__destruct) {
(*class)->__destruct(_object);
}
free(_object);
}
struct json_object *
toJson(void * _object)
{
const struct BIGPOINT_CCLASS ** class = _object;
if (_object && *class && (*class)->__toJson) {
return (*class)->__toJson(_object);
}
return NULL;
}
// vim: set et ts=4 sw=4: