4 * Copyright (C) 2009 Red Hat Inc.
7 * Luiz Capitulino <lcapitulino@redhat.com>
9 * This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
10 * See the COPYING.LIB file in the top-level directory.
16 #include "qapi/qmp/qobject.h"
17 #include "qapi/qmp/qlist.h"
18 #include "qapi/qmp/qnum.h"
19 #include "qemu/queue.h"
21 #define QDICT_BUCKET_MAX 512
23 typedef struct QDictEntry
{
26 QLIST_ENTRY(QDictEntry
) next
;
29 typedef struct QDict
{
32 QLIST_HEAD(,QDictEntry
) table
[QDICT_BUCKET_MAX
];
36 QDict
*qdict_new(void);
37 const char *qdict_entry_key(const QDictEntry
*entry
);
38 QObject
*qdict_entry_value(const QDictEntry
*entry
);
39 size_t qdict_size(const QDict
*qdict
);
40 void qdict_put_obj(QDict
*qdict
, const char *key
, QObject
*value
);
41 void qdict_del(QDict
*qdict
, const char *key
);
42 int qdict_haskey(const QDict
*qdict
, const char *key
);
43 QObject
*qdict_get(const QDict
*qdict
, const char *key
);
44 QDict
*qobject_to_qdict(const QObject
*obj
);
45 void qdict_iter(const QDict
*qdict
,
46 void (*iter
)(const char *key
, QObject
*obj
, void *opaque
),
48 const QDictEntry
*qdict_first(const QDict
*qdict
);
49 const QDictEntry
*qdict_next(const QDict
*qdict
, const QDictEntry
*entry
);
50 void qdict_destroy_obj(QObject
*obj
);
52 /* Helper to qdict_put_obj(), accepts any object */
53 #define qdict_put(qdict, key, obj) \
54 qdict_put_obj(qdict, key, QOBJECT(obj))
56 /* Helpers for int, bool, and string */
57 #define qdict_put_int(qdict, key, value) \
58 qdict_put(qdict, key, qnum_from_int(value))
59 #define qdict_put_bool(qdict, key, value) \
60 qdict_put(qdict, key, qbool_from_bool(value))
61 #define qdict_put_str(qdict, key, value) \
62 qdict_put(qdict, key, qstring_from_str(value))
64 /* High level helpers */
65 double qdict_get_double(const QDict
*qdict
, const char *key
);
66 int64_t qdict_get_int(const QDict
*qdict
, const char *key
);
67 bool qdict_get_bool(const QDict
*qdict
, const char *key
);
68 QList
*qdict_get_qlist(const QDict
*qdict
, const char *key
);
69 QDict
*qdict_get_qdict(const QDict
*qdict
, const char *key
);
70 const char *qdict_get_str(const QDict
*qdict
, const char *key
);
71 int64_t qdict_get_try_int(const QDict
*qdict
, const char *key
,
73 bool qdict_get_try_bool(const QDict
*qdict
, const char *key
, bool def_value
);
74 const char *qdict_get_try_str(const QDict
*qdict
, const char *key
);
76 void qdict_copy_default(QDict
*dst
, QDict
*src
, const char *key
);
77 void qdict_set_default_str(QDict
*dst
, const char *key
, const char *val
);
79 QDict
*qdict_clone_shallow(const QDict
*src
);
80 void qdict_flatten(QDict
*qdict
);
82 void qdict_extract_subqdict(QDict
*src
, QDict
**dst
, const char *start
);
83 void qdict_array_split(QDict
*src
, QList
**dst
);
84 int qdict_array_entries(QDict
*src
, const char *subqdict
);
85 QObject
*qdict_crumple(const QDict
*src
, Error
**errp
);
87 void qdict_join(QDict
*dest
, QDict
*src
, bool overwrite
);