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 "qapi/qmp/qlist.h" 18 #include "qemu/queue.h" 19 20 #define QDICT_BUCKET_MAX 512 21 22 typedef struct QDictEntry { 23 char *key; 24 QObject *value; 25 QLIST_ENTRY(QDictEntry) next; 26 } QDictEntry; 27 28 struct QDict { 29 QObject base; 30 size_t size; 31 QLIST_HEAD(,QDictEntry) table[QDICT_BUCKET_MAX]; 32 }; 33 34 /* Object API */ 35 QDict *qdict_new(void); 36 const char *qdict_entry_key(const QDictEntry *entry); 37 QObject *qdict_entry_value(const QDictEntry *entry); 38 size_t qdict_size(const QDict *qdict); 39 void qdict_put_obj(QDict *qdict, const char *key, QObject *value); 40 void qdict_del(QDict *qdict, const char *key); 41 int qdict_haskey(const QDict *qdict, const char *key); 42 QObject *qdict_get(const QDict *qdict, const char *key); 43 QDict *qobject_to_qdict(const QObject *obj); 44 bool qdict_is_equal(const QObject *x, const QObject *y); 45 void qdict_iter(const QDict *qdict, 46 void (*iter)(const char *key, QObject *obj, void *opaque), 47 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); 51 52 /* Helper to qdict_put_obj(), accepts any object */ 53 #define qdict_put(qdict, key, obj) \ 54 qdict_put_obj(qdict, key, QOBJECT(obj)) 55 56 void qdict_put_bool(QDict *qdict, const char *key, bool value); 57 void qdict_put_int(QDict *qdict, const char *key, int64_t value); 58 void qdict_put_null(QDict *qdict, const char *key); 59 void qdict_put_str(QDict *qdict, const char *key, const char *value); 60 61 double qdict_get_double(const QDict *qdict, const char *key); 62 int64_t qdict_get_int(const QDict *qdict, const char *key); 63 bool qdict_get_bool(const QDict *qdict, const char *key); 64 QList *qdict_get_qlist(const QDict *qdict, const char *key); 65 QDict *qdict_get_qdict(const QDict *qdict, const char *key); 66 const char *qdict_get_str(const QDict *qdict, const char *key); 67 int64_t qdict_get_try_int(const QDict *qdict, const char *key, 68 int64_t def_value); 69 bool qdict_get_try_bool(const QDict *qdict, const char *key, bool def_value); 70 const char *qdict_get_try_str(const QDict *qdict, const char *key); 71 72 void qdict_copy_default(QDict *dst, QDict *src, const char *key); 73 void qdict_set_default_str(QDict *dst, const char *key, const char *val); 74 75 QDict *qdict_clone_shallow(const QDict *src); 76 void qdict_flatten(QDict *qdict); 77 78 void qdict_extract_subqdict(QDict *src, QDict **dst, const char *start); 79 void qdict_array_split(QDict *src, QList **dst); 80 int qdict_array_entries(QDict *src, const char *subqdict); 81 QObject *qdict_crumple(const QDict *src, Error **errp); 82 83 void qdict_join(QDict *dest, QDict *src, bool overwrite); 84 85 #endif /* QDICT_H */ 86