qdict.h (2322B)
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 21typedef struct QDictEntry { 22 char *key; 23 QObject *value; 24 QLIST_ENTRY(QDictEntry) next; 25} QDictEntry; 26 27struct QDict { 28 struct QObjectBase_ base; 29 size_t size; 30 QLIST_HEAD(,QDictEntry) table[QDICT_BUCKET_MAX]; 31}; 32 33/* Object API */ 34QDict *qdict_new(void); 35const char *qdict_entry_key(const QDictEntry *entry); 36QObject *qdict_entry_value(const QDictEntry *entry); 37size_t qdict_size(const QDict *qdict); 38void qdict_put_obj(QDict *qdict, const char *key, QObject *value); 39void qdict_del(QDict *qdict, const char *key); 40int qdict_haskey(const QDict *qdict, const char *key); 41QObject *qdict_get(const QDict *qdict, const char *key); 42const QDictEntry *qdict_first(const QDict *qdict); 43const QDictEntry *qdict_next(const QDict *qdict, const QDictEntry *entry); 44 45/* Helper to qdict_put_obj(), accepts any object */ 46#define qdict_put(qdict, key, obj) \ 47 qdict_put_obj(qdict, key, QOBJECT(obj)) 48 49void qdict_put_bool(QDict *qdict, const char *key, bool value); 50void qdict_put_int(QDict *qdict, const char *key, int64_t value); 51void qdict_put_null(QDict *qdict, const char *key); 52void qdict_put_str(QDict *qdict, const char *key, const char *value); 53 54double qdict_get_double(const QDict *qdict, const char *key); 55int64_t qdict_get_int(const QDict *qdict, const char *key); 56bool qdict_get_bool(const QDict *qdict, const char *key); 57QList *qdict_get_qlist(const QDict *qdict, const char *key); 58QDict *qdict_get_qdict(const QDict *qdict, const char *key); 59const char *qdict_get_str(const QDict *qdict, const char *key); 60int64_t qdict_get_try_int(const QDict *qdict, const char *key, 61 int64_t def_value); 62bool qdict_get_try_bool(const QDict *qdict, const char *key, bool def_value); 63const char *qdict_get_try_str(const QDict *qdict, const char *key); 64 65QDict *qdict_clone_shallow(const QDict *src); 66 67QObject *qdict_crumple(const QDict *src, Error **errp); 68void qdict_flatten(QDict *qdict); 69 70#endif /* QDICT_H */