|
|
|
@ -15,7 +15,12 @@ __construct(struct BIGPOINT_DYNTYPE * _this, va_list * params) |
|
|
|
|
|
|
|
switch(_this->type) { |
|
|
|
case BIGPOINT_DYNTYPE_INT: |
|
|
|
(_this->data)._int = va_arg(* params, long); |
|
|
|
(_this->data)._int = va_arg(* params, int); |
|
|
|
break; |
|
|
|
|
|
|
|
case BIGPOINT_DYNTYPE_STRING: |
|
|
|
(_this->data)._string = calloc(_this->size + 1, sizeof(char)); |
|
|
|
memcpy((_this->data)._string, va_arg(* params, const char *), _this->size); |
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
@ -34,6 +39,18 @@ __jsonConst(struct BIGPOINT_DYNTYPE * _this, struct json_object * json) |
|
|
|
(_this->data)._int = (int)json_object_get_int(json); |
|
|
|
break; |
|
|
|
|
|
|
|
case json_type_string: |
|
|
|
{ |
|
|
|
const char * string = json_object_get_string(json); |
|
|
|
|
|
|
|
_this->type = BIGPOINT_DYNTYPE_STRING; |
|
|
|
_this->size = strlen(string); |
|
|
|
(_this->data)._string = calloc(_this->size + 1, sizeof(char)); |
|
|
|
memcpy((_this->data)._string, string, _this->size); |
|
|
|
// the json object handles the memory for string.... |
|
|
|
} |
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
_this->type = BIGPOINT_DYNTYPE_NULL; |
|
|
|
_this->size = 0; |
|
|
|
@ -45,8 +62,15 @@ static |
|
|
|
void |
|
|
|
__destruct(struct BIGPOINT_DYNTYPE * _this) |
|
|
|
{ |
|
|
|
if (_this && BIGPOINT_DYNTYPE_OBJECT == _this->type && (_this->data)._object) { |
|
|
|
free((_this->data)._object); |
|
|
|
if (_this) { |
|
|
|
switch(_this->type) { |
|
|
|
case BIGPOINT_DYNTYPE_STRING: |
|
|
|
free((_this->data)._string); |
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -61,6 +85,10 @@ __toJson(struct BIGPOINT_DYNTYPE * _this) |
|
|
|
json = json_object_new_int((_this->data)._int); |
|
|
|
break; |
|
|
|
|
|
|
|
case BIGPOINT_DYNTYPE_STRING: |
|
|
|
json = json_object_new_string((_this->data)._string); |
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
json = NULL; |
|
|
|
} |
|
|
|
|