blob: 929d8d22f50bde2370d89060b29fb083a548d814 [file] [log] [blame]
Luiz Capitulino41836a92010-05-12 16:34:42 -03001/*
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
Luiz Capitulinofb08dde2009-08-28 15:27:07 -030013#ifndef QDICT_H
14#define QDICT_H
15
16#include "qobject.h"
Luiz Capitulinof2e17502009-12-10 17:15:54 -020017#include "qlist.h"
Blue Swirl72cf2d42009-09-12 07:36:22 +000018#include "qemu-queue.h"
Luiz Capitulinofb08dde2009-08-28 15:27:07 -030019#include <stdint.h>
20
Luiz Capitulinoc8bc3cd2010-06-07 15:45:22 -030021#define QDICT_BUCKET_MAX 512
Luiz Capitulinofb08dde2009-08-28 15:27:07 -030022
23typedef struct QDictEntry {
24 char *key;
25 QObject *value;
Blue Swirl72cf2d42009-09-12 07:36:22 +000026 QLIST_ENTRY(QDictEntry) next;
Luiz Capitulinofb08dde2009-08-28 15:27:07 -030027} QDictEntry;
28
29typedef struct QDict {
30 QObject_HEAD;
31 size_t size;
Luiz Capitulinoc8bc3cd2010-06-07 15:45:22 -030032 QLIST_HEAD(,QDictEntry) table[QDICT_BUCKET_MAX];
Luiz Capitulinofb08dde2009-08-28 15:27:07 -030033} QDict;
34
35/* Object API */
36QDict *qdict_new(void);
Luiz Capitulino0d078b22010-06-07 16:53:51 -030037const char *qdict_entry_key(const QDictEntry *entry);
38QObject *qdict_entry_value(const QDictEntry *entry);
Luiz Capitulinofb08dde2009-08-28 15:27:07 -030039size_t qdict_size(const QDict *qdict);
40void qdict_put_obj(QDict *qdict, const char *key, QObject *value);
41void qdict_del(QDict *qdict, const char *key);
42int qdict_haskey(const QDict *qdict, const char *key);
43QObject *qdict_get(const QDict *qdict, const char *key);
44QDict *qobject_to_qdict(const QObject *obj);
Luiz Capitulino21f800d2009-10-13 13:56:58 -030045void qdict_iter(const QDict *qdict,
46 void (*iter)(const char *key, QObject *obj, void *opaque),
47 void *opaque);
Luiz Capitulinof2b07f32010-06-07 16:07:29 -030048const QDictEntry *qdict_first(const QDict *qdict);
49const QDictEntry *qdict_next(const QDict *qdict, const QDictEntry *entry);
Luiz Capitulinofb08dde2009-08-28 15:27:07 -030050
51/* Helper to qdict_put_obj(), accepts any object */
52#define qdict_put(qdict, key, obj) \
53 qdict_put_obj(qdict, key, QOBJECT(obj))
54
55/* High level helpers */
Markus Armbrusteracc3b032010-01-27 17:16:38 +010056double qdict_get_double(const QDict *qdict, const char *key);
Luiz Capitulinofb08dde2009-08-28 15:27:07 -030057int64_t qdict_get_int(const QDict *qdict, const char *key);
Luiz Capitulinocd4dde32009-12-10 17:15:53 -020058int qdict_get_bool(const QDict *qdict, const char *key);
Luiz Capitulinof2e17502009-12-10 17:15:54 -020059QList *qdict_get_qlist(const QDict *qdict, const char *key);
Luiz Capitulinodf10ce62010-01-21 19:15:39 -020060QDict *qdict_get_qdict(const QDict *qdict, const char *key);
Luiz Capitulinofb08dde2009-08-28 15:27:07 -030061const char *qdict_get_str(const QDict *qdict, const char *key);
62int64_t qdict_get_try_int(const QDict *qdict, const char *key,
Luiz Capitulino83aba692010-06-04 19:20:54 -030063 int64_t def_value);
Luiz Capitulino35006ac2010-06-07 17:25:04 -030064int qdict_get_try_bool(const QDict *qdict, const char *key, int def_value);
Luiz Capitulinofb08dde2009-08-28 15:27:07 -030065const char *qdict_get_try_str(const QDict *qdict, const char *key);
66
67#endif /* QDICT_H */