Lines Matching refs:variant

44 static int json_variant_deep_copy(JsonVariant *ret, JsonVariant *variant) {
48 assert(variant);
50 ret->type = variant->type;
51 ret->size = variant->size;
53 if (variant->type == JSON_VARIANT_STRING) {
54 ret->string = memdup(variant->string, variant->size+1);
57 } else if (variant->type == JSON_VARIANT_ARRAY || variant->type == JSON_VARIANT_OBJECT) {
60 ret->objects = new0(JsonVariant, variant->size);
64 for (i = 0; i < variant->size; ++i) {
65 r = json_variant_deep_copy(&ret->objects[i], &variant->objects[i]);
70 ret->value = variant->value;
75 static JsonVariant *json_object_unref(JsonVariant *variant);
77 static JsonVariant *json_variant_unref_inner(JsonVariant *variant) {
78 if (!variant)
81 if (variant->type == JSON_VARIANT_ARRAY || variant->type == JSON_VARIANT_OBJECT)
82 return json_object_unref(variant);
83 else if (variant->type == JSON_VARIANT_STRING)
84 free(variant->string);
89 static JsonVariant *json_raw_unref(JsonVariant *variant, size_t size) {
90 if (!variant)
94 json_variant_unref_inner(&variant[i]);
96 free(variant);
100 static JsonVariant *json_object_unref(JsonVariant *variant) {
103 assert(variant);
105 if (!variant->objects)
108 for (i = 0; i < variant->size; ++i)
109 json_variant_unref_inner(&variant->objects[i]);
111 free(variant->objects);
115 static JsonVariant **json_variant_array_unref(JsonVariant **variant) {
119 if (!variant)
122 while((p = (variant[i++])) != NULL) {
128 free(variant);
135 JsonVariant *json_variant_unref(JsonVariant *variant) {
136 if (!variant)
139 if (variant->type == JSON_VARIANT_ARRAY || variant->type == JSON_VARIANT_OBJECT)
140 json_object_unref(variant);
141 else if (variant->type == JSON_VARIANT_STRING)
142 free(variant->string);
144 free(variant);
149 char *json_variant_string(JsonVariant *variant){
150 assert(variant);
151 assert(variant->type == JSON_VARIANT_STRING);
153 return variant->string;
156 bool json_variant_bool(JsonVariant *variant) {
157 assert(variant);
158 assert(variant->type == JSON_VARIANT_BOOLEAN);
160 return variant->value.boolean;
163 intmax_t json_variant_integer(JsonVariant *variant) {
164 assert(variant);
165 assert(variant->type == JSON_VARIANT_INTEGER);
167 return variant->value.integer;
170 double json_variant_real(JsonVariant *variant) {
171 assert(variant);
172 assert(variant->type == JSON_VARIANT_REAL);
174 return variant->value.real;
177 JsonVariant *json_variant_element(JsonVariant *variant, unsigned index) {
178 assert(variant);
179 assert(variant->type == JSON_VARIANT_ARRAY || variant->type == JSON_VARIANT_OBJECT);
180 assert(index < variant->size);
181 assert(variant->objects);
183 return &variant->objects[index];
186 JsonVariant *json_variant_value(JsonVariant *variant, const char *key) {
189 assert(variant);
190 assert(variant->type == JSON_VARIANT_OBJECT);
191 assert(variant->objects);
193 for (i = 0; i < variant->size; i += 2) {
194 JsonVariant *p = &variant->objects[i];
196 return &variant->objects[i + 1];