Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ static {{classname}}_t *{{classname}}_create_internal(
{{/isPrimitiveType}}
{{#isPrimitiveType}}
{{#isNumeric}}
{{datatype}} {{name}}{{^-last}},{{/-last}}
{{datatype}} *{{name}}{{^-last}},{{/-last}}
{{/isNumeric}}
{{#isBoolean}}
{{datatype}} {{name}}{{^-last}},{{/-last}}
{{datatype}} *{{name}}{{^-last}},{{/-last}}
{{/isBoolean}}
{{#isEnum}}
{{#isString}}
Expand Down Expand Up @@ -243,10 +243,10 @@ __attribute__((deprecated)) {{classname}}_t *{{classname}}_create(
{{/isPrimitiveType}}
{{#isPrimitiveType}}
{{#isNumeric}}
{{datatype}} {{name}}{{^-last}},{{/-last}}
{{datatype}} *{{name}}{{^-last}},{{/-last}}
{{/isNumeric}}
{{#isBoolean}}
{{datatype}} {{name}}{{^-last}},{{/-last}}
{{datatype}} *{{name}}{{^-last}},{{/-last}}
{{/isBoolean}}
{{#isEnum}}
{{#isString}}
Expand Down Expand Up @@ -344,6 +344,18 @@ void {{classname}}_free({{classname}}_t *{{classname}}) {
{{/isFreeFormObject}}
{{/isPrimitiveType}}
{{#isPrimitiveType}}
{{#isNumeric}}
if ({{{classname}}}->{{{name}}}) {
free({{{classname}}}->{{{name}}});
{{classname}}->{{name}} = NULL;
}
{{/isNumeric}}
{{#isBoolean}}
if ({{{classname}}}->{{{name}}}) {
free({{{classname}}}->{{{name}}});
{{classname}}->{{name}} = NULL;
}
{{/isBoolean}}
{{^isEnum}}
{{#isString}}
if ({{{classname}}}->{{{name}}}) {
Expand Down Expand Up @@ -454,12 +466,12 @@ cJSON *{{classname}}_convertToJSON({{classname}}_t *{{classname}}) {
{{^isContainer}}
{{#isPrimitiveType}}
{{#isNumeric}}
if(cJSON_AddNumberToObject(item, "{{{baseName}}}", {{{classname}}}->{{{name}}}) == NULL) {
if(cJSON_AddNumberToObject(item, "{{{baseName}}}", *{{{classname}}}->{{{name}}}) == NULL) {
goto fail; //Numeric
}
{{/isNumeric}}
{{#isBoolean}}
if(cJSON_AddBoolToObject(item, "{{{baseName}}}", {{{classname}}}->{{{name}}}) == NULL) {
if(cJSON_AddBoolToObject(item, "{{{baseName}}}", *{{{classname}}}->{{{name}}}) == NULL) {
goto fail; //Bool
}
{{/isBoolean}}
Expand Down Expand Up @@ -700,6 +712,18 @@ fail:
{{/isFreeFormObject}}
{{/isModel}}
{{/isPrimitiveType}}
{{#isPrimitiveType}}
{{#isNumeric}}
// define the local variable for {{{classname}}}->{{{name}}}
{{datatype}} *{{name}}_local_var = NULL;

{{/isNumeric}}
{{#isBoolean}}
// define the local variable for {{{classname}}}->{{{name}}}
{{datatype}} *{{name}}_local_var = NULL;

{{/isBoolean}}
{{/isPrimitiveType}}
{{/isContainer}}
{{/vars}}
{{#vars}}
Expand All @@ -722,13 +746,31 @@ fail:
{
goto end; //Numeric
}
{{name}}_local_var = malloc(sizeof({{datatype}}));
if(!{{name}}_local_var)
{
goto end;
}
*{{name}}_local_var = {{{name}}}->valuedouble;
{{^required}}
}
{{/required}}
{{/isNumeric}}
{{#isBoolean}}
{{^required}}if ({{{name}}}) { {{/required}}
if(!cJSON_IsBool({{{name}}}))
{
goto end; //Bool
}
{{name}}_local_var = malloc(sizeof({{datatype}}));
if(!{{name}}_local_var)
{
goto end;
}
*{{name}}_local_var = {{{name}}}->valueint;
{{^required}}
}
{{/required}}
{{/isBoolean}}
{{#isEnum}}
{{#isString}}
Expand Down Expand Up @@ -977,10 +1019,10 @@ fail:
{{/isPrimitiveType}}
{{#isPrimitiveType}}
{{#isNumeric}}
{{^required}}{{{name}}} ? {{/required}}{{{name}}}->valuedouble{{^required}} : 0{{/required}}{{^-last}},{{/-last}}
{{name}}_local_var{{^-last}},{{/-last}}
{{/isNumeric}}
{{#isBoolean}}
{{^required}}{{{name}}} ? {{/required}}{{{name}}}->valueint{{^required}} : 0{{/required}}{{^-last}},{{/-last}}
{{name}}_local_var{{^-last}},{{/-last}}
{{/isBoolean}}
{{#isEnum}}
{{#isString}}
Expand Down Expand Up @@ -1046,6 +1088,20 @@ end:
{{/isFreeFormObject}}
{{/isModel}}
{{/isPrimitiveType}}
{{#isPrimitiveType}}
{{#isNumeric}}
if ({{{name}}}_local_var) {
free({{{name}}}_local_var);
{{{name}}}_local_var = NULL;
}
{{/isNumeric}}
{{#isBoolean}}
if ({{{name}}}_local_var) {
free({{{name}}}_local_var);
{{{name}}}_local_var = NULL;
}
{{/isBoolean}}
{{/isPrimitiveType}}
{{/isContainer}}
{{#isContainer}}
{{#isArray}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ typedef struct {{classname}}_t {
{{/isPrimitiveType}}
{{#isPrimitiveType}}
{{#isNumeric}}
{{datatype}} {{name}}; //numeric
{{datatype}} *{{name}}; //numeric
{{/isNumeric}}
{{#isBoolean}}
{{datatype}} {{name}}; //boolean
{{datatype}} *{{name}}; //boolean
{{/isBoolean}}
{{#isEnum}}
{{#isString}}
Expand Down Expand Up @@ -191,10 +191,10 @@ __attribute__((deprecated)) {{classname}}_t *{{classname}}_create(
{{/isPrimitiveType}}
{{#isPrimitiveType}}
{{#isNumeric}}
{{datatype}} {{name}}{{^-last}},{{/-last}}
{{datatype}} *{{name}}{{^-last}},{{/-last}}
{{/isNumeric}}
{{#isBoolean}}
{{datatype}} {{name}}{{^-last}},{{/-last}}
{{datatype}} *{{name}}{{^-last}},{{/-last}}
{{/isBoolean}}
{{#isEnum}}
{{#isString}}
Expand Down
Loading