Browse Source

change cclass so that the internal structure is no longer visible by the rest of the code

master
Georg Hopp 14 years ago
parent
commit
5b8db017e8
  1. 20
      src/cclass.c

20
src/cclass.c

@ -34,9 +34,10 @@ void *
_new(const CCLASS _class, ...)
{
const CCLASS class = _class;
void * object = calloc(1, class->size);
void * object = calloc(1, class->size + sizeof(CCLASS));
* (const struct _CCLASS **) object = class;
* (const struct _CCLASS **)object = class;
object += sizeof(CCLASS);
if (class->__construct) {
va_list params;
@ -53,9 +54,10 @@ void *
_newFromJson(const CCLASS _class, struct json_object * json)
{
const CCLASS class = _class;
void * object = calloc(1, class->size);
void * object = calloc(1, class->size + sizeof(CCLASS));
* (const struct _CCLASS **) object = class;
object += sizeof(CCLASS);
if (class->__jsonConst && json) {
class->__jsonConst(object, json);
@ -67,7 +69,7 @@ _newFromJson(const CCLASS _class, struct json_object * json)
int
_instanceOf(const CCLASS _class, void * _object)
{
const CCLASS * class = _object;
const CCLASS * class = _object - sizeof(CCLASS);
return (class && _class == *class);
}
@ -76,7 +78,7 @@ _instanceOf(const CCLASS _class, void * _object)
void
clear(void * _object)
{
const CCLASS * class = _object;
const CCLASS * class = _object - sizeof(CCLASS);
if (_object && *class && (*class)->__clear) {
(*class)->__clear(_object);
@ -86,20 +88,20 @@ clear(void * _object)
void
delete(void * _object)
{
const CCLASS * class = *(void**)_object;
const CCLASS * class = (*(void**)_object) - sizeof(CCLASS);
if (*(void**)_object && *class && (*class)->__destruct) {
(*class)->__destruct(*(void**)_object);
}
free(*(void**)_object);
free((void *)class);
*(void**)_object = NULL;
}
void
toJson(void * _object, struct json_object ** json)
{
const CCLASS * class = _object;
const CCLASS * class = _object - sizeof(CCLASS);
if (_object && *class && (*class)->__toJson) {
(*class)->__toJson(_object, json);
@ -109,7 +111,7 @@ toJson(void * _object, struct json_object ** json)
int
isObject(void * _object)
{
const CCLASS * class = _object;
const CCLASS * class = _object - sizeof(CCLASS);
return (_object && (*class) && CCLASS_MAGIC == (*class)->magic);
}

Loading…
Cancel
Save