WinGui: Fix another instance of the Caliburn vs Json.net sillyness where objects...
[HandBrake.git] / libhb / hb_dict.h
blobac3a562b01c8fcfed705be7ea10d5203cc6b6b3d
1 /* hb_dict.h
3 Copyright (c) 2003-2015 HandBrake Team
4 This file is part of the HandBrake source code
5 Homepage: <http://handbrake.fr/>.
6 It may be used under the terms of the GNU General Public License v2.
7 For full terms see the file COPYING file or visit http://www.gnu.org/licenses/gpl-2.0.html
8 */
9 #if !defined(HB_DICT_H)
10 #define HB_DICT_H
12 #include <jansson.h>
14 #define HB_VALUE_TYPE_DICT JSON_OBJECT
15 #define HB_VALUE_TYPE_ARRAY JSON_ARRAY
16 #define HB_VALUE_TYPE_STRING JSON_STRING
17 #define HB_VALUE_TYPE_INT JSON_INTEGER
18 #define HB_VALUE_TYPE_DOUBLE JSON_REAL
19 #define HB_VALUE_TYPE_NULL JSON_NULL
20 #define HB_VALUE_TYPE_BOOL 0xff
22 #define HB_DICT_ITER_DONE NULL
24 typedef int hb_value_type_t;
25 typedef json_t hb_value_t;
26 typedef hb_value_t hb_dict_t;
27 typedef hb_value_t hb_value_array_t;
28 typedef void* hb_dict_iter_t;
30 /* A dictionary implementation.
32 * an hb_dict_t must be initialized with hb_dict_init() before use.
34 * "key" must be a string with non-zero length (NULL and "" are invalid keys).
35 * "value" must be an hb_value_t*
37 hb_dict_t * hb_dict_init(void);
38 /* free dictionary and release references to all values it contains */
39 void hb_dict_free(hb_dict_t ** dict_ptr);
40 /* add value to dictionary. dictionary takes ownership of value */
41 void hb_dict_set(hb_dict_t * dict, const char * key,
42 hb_value_t * value);
43 /* remove value from dictionary. releases reference to value */
44 int hb_dict_remove(hb_dict_t * dict, const char * key);
45 /* get value from dictionary. value has borrowed reference */
46 hb_value_t * hb_dict_get(const hb_dict_t * dict, const char * key);
48 /* dict iterator
49 * hb_dict_iter_init(dict) returns an iter to the first key/value in the dict
50 * hb_dict_iter_next(dict, iter) returns an iter to the next key/value
51 * HB_DICT_ITER_DONE if the end of the dictionary was reached.
53 hb_dict_iter_t hb_dict_iter_init(const hb_dict_t *dict);
54 hb_dict_iter_t hb_dict_iter_next(const hb_dict_t *dict, hb_dict_iter_t iter);
55 int hb_dict_iter_next_ex(const hb_dict_t *dict,
56 hb_dict_iter_t *iter,
57 const char **key, hb_value_t **val);
58 /* get key from iter */
59 const char * hb_dict_iter_key(const hb_dict_iter_t iter);
60 /* get value from iter. value has borrowed reference */
61 hb_value_t * hb_dict_iter_value(const hb_dict_iter_t iter);
63 /* hb_value_array_t */
64 hb_value_array_t * hb_value_array_init(void);
65 /* remove all elements of array */
66 void hb_value_array_clear(hb_value_array_t *array);
67 /* get value from array. value has borrowed reference */
68 hb_value_t * hb_value_array_get(const hb_value_array_t *array, int index);
69 /* replace value at index in array. array takes ownership of new value */
70 void hb_value_array_set(hb_value_array_t *array, int index,
71 hb_value_t *value);
72 /* insert value at index in array. values move up.
73 * array takes ownership of new value */
74 void hb_value_array_insert(hb_value_array_t *array, int index,
75 hb_value_t *value);
76 /* append value to array. array takes ownership of new value */
77 void hb_value_array_append(hb_value_array_t *array,
78 hb_value_t *value);
79 /* remove value from array. releases reference to value */
80 void hb_value_array_remove(hb_value_array_t *array, int index);
81 /* clears dst and performs a deep copy */
82 void hb_value_array_copy(hb_value_array_t *dst,
83 const hb_value_array_t *src, int count);
84 size_t hb_value_array_len(const hb_value_array_t *array);
86 /* hb_value_t */
87 int hb_value_type(const hb_value_t *value);
88 int hb_value_is_number(const hb_value_t *value);
89 hb_value_t * hb_value_dup(const hb_value_t *value);
90 hb_value_t * hb_value_incref(hb_value_t *value);
91 void hb_value_decref(hb_value_t *value);
92 void hb_value_free(hb_value_t **value);
94 /* Create new hb_value_t */
95 hb_value_t * hb_value_string(const char *value);
96 hb_value_t * hb_value_int(json_int_t value);
97 hb_value_t * hb_value_double(double value);
98 hb_value_t * hb_value_bool(int value);
99 hb_value_t * hb_value_json(const char *json);
100 hb_value_t * hb_value_read_json(const char *path);
102 /* Transform hb_value_t from one type to another */
103 hb_value_t * hb_value_xform(const hb_value_t *value, int type);
105 /* Extract values */
106 /* hb_value_t must be of type HB_VALUE_TYPE_STRING */
107 const char * hb_value_get_string(const hb_value_t *value);
108 /* hb_value_t may be of any type, automatic conversion performed */
109 json_int_t hb_value_get_int(const hb_value_t *value);
110 double hb_value_get_double(const hb_value_t *value);
111 int hb_value_get_bool(const hb_value_t *value);
112 /* converts value type and returns an allocated string representation.
113 * caller must free the returned string */
114 char * hb_value_get_string_xform(const hb_value_t *value);
115 /* converts value to json string */
116 char * hb_value_get_json(const hb_value_t *value);
117 /* write json representation to a file */
118 int hb_value_write_file_json(hb_value_t *value, FILE *file);
119 int hb_value_write_json(hb_value_t *value, const char *path);
121 /* specialized dict functions */
123 * hb_encopts_to_dict() converts an op1=val1:opt2=val2:opt3=val3 type string to
124 * an hb_dict_t dictionary. */
125 hb_dict_t * hb_encopts_to_dict(const char * encopts, int encoder);
126 char * hb_dict_to_encopts(const hb_dict_t * dict);
128 #endif // !defined(HB_DICT_H)