summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjstebbins <[email protected]>2015-04-03 17:43:13 +0000
committerjstebbins <[email protected]>2015-04-03 17:43:13 +0000
commit5efc8273df8372d36819391a1700314bd052ce2c (patch)
tree71d09b609234f496ae630b9b17376188bdd13c8c
parentde17b2d007026cac6bc1aa7821126094e3c5e142 (diff)
hb_dict: add 'const' to a few prototypes and add a couple new helper funcs
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7045 b64f7644-9d1e-0410-96f1-a4d463321fa5
-rw-r--r--libhb/hb_dict.c24
-rw-r--r--libhb/hb_dict.h7
2 files changed, 27 insertions, 4 deletions
diff --git a/libhb/hb_dict.c b/libhb/hb_dict.c
index c3c17e380..7fd12b565 100644
--- a/libhb/hb_dict.c
+++ b/libhb/hb_dict.c
@@ -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()
{
diff --git a/libhb/hb_dict.h b/libhb/hb_dict.h
index 88b9dea1c..6d8057e09 100644
--- a/libhb/hb_dict.h
+++ b/libhb/hb_dict.h
@@ -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 */