]> granicus.if.org Git - json-c/commitdiff
Added array_list_del_idx and json_object_array_del_idx
authorMark Swoope <markswoope0@gmail.com>
Thu, 2 Apr 2015 21:05:27 +0000 (14:05 -0700)
committerMark Swoope <markswoope0@gmail.com>
Thu, 2 Apr 2015 21:05:27 +0000 (14:05 -0700)
arraylist.c
arraylist.h
json_object.c
json_object.h

index 8efe006eb6de4ac7ccddeb21840481793029876f..1e5ff1c0b8da974c3e0f54ecf1912cde677fb2f6 100644 (file)
@@ -106,3 +106,18 @@ array_list_length(struct array_list *arr)
 {
   return arr->length;
 }
+
+int
+array_list_del_idx( struct array_list *arr, int idx, int count )
+{
+       int i, stop;
+
+       stop = idx + count;
+       if ( idx >= arr->length || stop > arr->length ) return -1;
+       for ( i = idx; i < stop; ++i ) {
+               if ( arr->array[i] ) arr->free_fn( arr->array[i] );
+       }
+       memmove( arr->array + idx, arr->array + stop, (arr->length - stop) * sizeof(void*) );
+       arr->length -= count;
+       return 0;
+}
index caecdfa5c3a95e91a272b4a3c536c3475d62cbcb..9d2db5b8c56b70119f430aff8003cd8f06c8bcc0 100644 (file)
@@ -53,6 +53,8 @@ extern void* array_list_bsearch(const void **key,
                struct array_list *arr,
                int (*sort_fn)(const void *, const void *));
 
+extern int 
+array_list_del_idx(struct array_list *arr, int i, int count);
 
 #ifdef __cplusplus
 }
index 9b89bb7673ac2798cbb2a33bfc319214d03203f1..d09518f1a1fe2b1443399a39db37a7660c714ca6 100644 (file)
@@ -926,3 +926,7 @@ struct json_object* json_object_array_get_idx(struct json_object *jso,
        return (struct json_object*)array_list_get_idx(jso->o.c_array, idx);
 }
 
+int json_object_array_del_idx(struct json_object *jso, int idx, int count)
+{
+       return array_list_del_idx(jso->o.c_array, idx, count);
+}
index 2bdfd5f9d6851c00ec72f92a1230f4dfb8f6edf9..ad6af8e7439629fcd3c726965576d722ec2b5999 100644 (file)
@@ -464,6 +464,19 @@ extern int json_object_array_put_idx(struct json_object *obj, int idx,
 extern struct json_object* json_object_array_get_idx(struct json_object *obj,
                                                     int idx);
 
+/** Delete an elements from a specified index in an array (a json_object of type json_type_array)
+ *
+ * The reference count will be decremented for each of the deleted objects.  If there
+ * are no more owners of an element that is being deleted, then the value is 
+ * freed.  Otherwise, the reference to the value will remain in memory.
+ *
+ * @param obj the json_object instance
+ * @param idx the index to start deleting elements at
+ * @param count the number of elements to delete
+ * @returns 0 if the elements were successfully deleted
+ */
+extern int json_object_array_del_idx(struct json_object *obj, int idx, int count);
+
 /* json_bool type methods */
 
 /** Create a new empty json_object of type json_type_boolean