xref: /openbmc/qemu/include/qapi/qmp/qdict.h (revision 89854803)
1 /*
2  * QDict Module
3  *
4  * Copyright (C) 2009 Red Hat Inc.
5  *
6  * Authors:
7  *  Luiz Capitulino <lcapitulino@redhat.com>
8  *
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.
11  */
12 
13 #ifndef QDICT_H
14 #define QDICT_H
15 
16 #include "qapi/qmp/qobject.h"
17 #include "qemu/queue.h"
18 
19 #define QDICT_BUCKET_MAX 512
20 
21 typedef struct QDictEntry {
22     char *key;
23     QObject *value;
24     QLIST_ENTRY(QDictEntry) next;
25 } QDictEntry;
26 
27 struct QDict {
28     struct QObjectBase_ base;
29     size_t size;
30     QLIST_HEAD(,QDictEntry) table[QDICT_BUCKET_MAX];
31 };
32 
33 /* Object API */
34 QDict *qdict_new(void);
35 const char *qdict_entry_key(const QDictEntry *entry);
36 QObject *qdict_entry_value(const QDictEntry *entry);
37 size_t qdict_size(const QDict *qdict);
38 void qdict_put_obj(QDict *qdict, const char *key, QObject *value);
39 void qdict_del(QDict *qdict, const char *key);
40 int qdict_haskey(const QDict *qdict, const char *key);
41 QObject *qdict_get(const QDict *qdict, const char *key);
42 bool qdict_is_equal(const QObject *x, const QObject *y);
43 void qdict_iter(const QDict *qdict,
44                 void (*iter)(const char *key, QObject *obj, void *opaque),
45                 void *opaque);
46 const QDictEntry *qdict_first(const QDict *qdict);
47 const QDictEntry *qdict_next(const QDict *qdict, const QDictEntry *entry);
48 void qdict_destroy_obj(QObject *obj);
49 
50 /* Helper to qdict_put_obj(), accepts any object */
51 #define qdict_put(qdict, key, obj) \
52         qdict_put_obj(qdict, key, QOBJECT(obj))
53 
54 void qdict_put_bool(QDict *qdict, const char *key, bool value);
55 void qdict_put_int(QDict *qdict, const char *key, int64_t value);
56 void qdict_put_null(QDict *qdict, const char *key);
57 void qdict_put_str(QDict *qdict, const char *key, const char *value);
58 
59 double qdict_get_double(const QDict *qdict, const char *key);
60 int64_t qdict_get_int(const QDict *qdict, const char *key);
61 bool qdict_get_bool(const QDict *qdict, const char *key);
62 QList *qdict_get_qlist(const QDict *qdict, const char *key);
63 QDict *qdict_get_qdict(const QDict *qdict, const char *key);
64 const char *qdict_get_str(const QDict *qdict, const char *key);
65 int64_t qdict_get_try_int(const QDict *qdict, const char *key,
66                           int64_t def_value);
67 bool qdict_get_try_bool(const QDict *qdict, const char *key, bool def_value);
68 const char *qdict_get_try_str(const QDict *qdict, const char *key);
69 
70 void qdict_copy_default(QDict *dst, QDict *src, const char *key);
71 void qdict_set_default_str(QDict *dst, const char *key, const char *val);
72 
73 QDict *qdict_clone_shallow(const QDict *src);
74 void qdict_flatten(QDict *qdict);
75 
76 void qdict_extract_subqdict(QDict *src, QDict **dst, const char *start);
77 void qdict_array_split(QDict *src, QList **dst);
78 int qdict_array_entries(QDict *src, const char *subqdict);
79 QObject *qdict_crumple(const QDict *src, Error **errp);
80 
81 void qdict_join(QDict *dest, QDict *src, bool overwrite);
82 
83 typedef struct QDictRenames {
84     const char *from;
85     const char *to;
86 } QDictRenames;
87 bool qdict_rename_keys(QDict *qdict, const QDictRenames *renames, Error **errp);
88 
89 #endif /* QDICT_H */
90