hb_dict: add 'const' to a few prototypes and add a couple new helper funcs
authorjstebbins <jstebbins.hb@gmail.com>
Fri, 3 Apr 2015 17:43:13 +0000 (17:43 +0000)
committerjstebbins <jstebbins.hb@gmail.com>
Fri, 3 Apr 2015 17:43:13 +0000 (17:43 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7045 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/hb_dict.c
libhb/hb_dict.h

index c3c17e3806e6322ffdf20144a117ba76ad464586..7fd12b56589a235a6f05c2bc08abef0f6eec50df 100644 (file)
@@ -7,6 +7,7 @@
    For full terms see the file COPYING file or visit http://www.gnu.org/licenses/gpl-2.0.html
  */
 
+#include <stdio.h>
 #include "hb.h"
 #include "hb_dict.h"
 
@@ -20,7 +21,7 @@ hb_value_type_t hb_value_type(const hb_value_t *value)
     return type;
 }
 
-hb_value_t * hb_value_dup(hb_value_t *value)
+hb_value_t * hb_value_dup(const hb_value_t *value)
 {
     if (value == NULL) return NULL;
     return json_deep_copy(value);
@@ -420,6 +421,11 @@ char * hb_value_get_json(hb_value_t *value)
     return json_dumps(value, JSON_INDENT(4) | JSON_SORT_KEYS);
 }
 
+int  hb_value_write_file_json(hb_value_t *value, FILE *file)
+{
+    return json_dumpf(value, file, JSON_INDENT(4) | JSON_SORT_KEYS);
+}
+
 int  hb_value_write_json(hb_value_t *value, const char *path)
 {
     return json_dump_file(value, path, JSON_INDENT(4) | JSON_SORT_KEYS);
@@ -445,7 +451,7 @@ int hb_dict_remove(hb_dict_t * dict, const char * key)
     return json_object_del(dict, key) == 0;
 }
 
-hb_value_t * hb_dict_get(hb_dict_t * dict, const char * key)
+hb_value_t * hb_dict_get(const hb_dict_t * dict, const char * key)
 {
     return json_object_get(dict, key);
 }
@@ -472,6 +478,20 @@ hb_value_t * hb_dict_iter_value(const hb_dict_iter_t iter)
     return json_object_iter_value(iter);
 }
 
+int
+hb_dict_iter_next_ex(hb_dict_t *dict, hb_dict_iter_t *iter,
+                     const char **key, hb_value_t **val)
+{
+    if (*iter == NULL)
+        return 0;
+    if (key != NULL)
+        *key = json_object_iter_key(*iter);
+    if (val != NULL)
+        *val = json_object_iter_value(*iter);
+    *iter = json_object_iter_next(dict, *iter);
+    return 1;
+}
+
 hb_value_array_t*
 hb_value_array_init()
 {
index 88b9dea1c1342d946e35a0274aa21c671245e266..6d8057e09a64fb0f226935516f877f85987c0d43 100644 (file)
@@ -43,7 +43,7 @@ void              hb_dict_set(hb_dict_t * dict, const char * key,
 /* remove value from dictionary.  releases reference to value */
 int               hb_dict_remove(hb_dict_t * dict, const char * key);
 /* get value from dictionary.  value has borrowed reference */
-hb_value_t *      hb_dict_get(hb_dict_t * dict, const char * key);
+hb_value_t *      hb_dict_get(const hb_dict_t * dict, const char * key);
 
 /* dict iterator
  * hb_dict_iter_init(dict) returns an iter to the first key/value in the dict
@@ -52,6 +52,8 @@ hb_value_t *      hb_dict_get(hb_dict_t * dict, const char * key);
  */
 hb_dict_iter_t    hb_dict_iter_init(const hb_dict_t *dict);
 hb_dict_iter_t    hb_dict_iter_next(const hb_dict_t *dict, hb_dict_iter_t iter);
+int               hb_dict_iter_next_ex(hb_dict_t *dict, hb_dict_iter_t *iter,
+                                       const char **key, hb_value_t **val);
 /* get key from iter */
 const char *      hb_dict_iter_key(const hb_dict_iter_t iter);
 /* get value from iter.  value has borrowed reference */
@@ -82,7 +84,7 @@ size_t             hb_value_array_len(const hb_value_array_t *array);
 
 /* hb_value_t */
 int          hb_value_type(const hb_value_t *value);
-hb_value_t * hb_value_dup(hb_value_t *value);
+hb_value_t * hb_value_dup(const hb_value_t *value);
 void         hb_value_incref(hb_value_t *value);
 void         hb_value_decref(hb_value_t *value);
 void         hb_value_free(hb_value_t **value);
@@ -111,6 +113,7 @@ char *       hb_value_get_string_xform(const hb_value_t *value);
 /* converts value to json string */
 char *       hb_value_get_json(hb_value_t *value);
 /* write json representation to a file */
+int          hb_value_write_file_json(hb_value_t *value, FILE *file);
 int          hb_value_write_json(hb_value_t *value, const char *path);
 
 /* specialized dict functions */