You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.3 KiB
67 lines
1.3 KiB
#include "bigpoint_cclass.h"
|
|
|
|
#include <stdarg.h>
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <json/json.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:
|