Luiz Capitulino | 41836a9 | 2010-05-12 16:34:42 -0300 | [diff] [blame] | 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 | |
Luiz Capitulino | fb08dde | 2009-08-28 15:27:07 -0300 | [diff] [blame] | 13 | #ifndef QDICT_H |
| 14 | #define QDICT_H |
| 15 | |
| 16 | #include "qobject.h" |
Luiz Capitulino | f2e1750 | 2009-12-10 17:15:54 -0200 | [diff] [blame] | 17 | #include "qlist.h" |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 18 | #include "qemu-queue.h" |
Luiz Capitulino | fb08dde | 2009-08-28 15:27:07 -0300 | [diff] [blame] | 19 | #include <stdint.h> |
| 20 | |
Luiz Capitulino | c8bc3cd | 2010-06-07 15:45:22 -0300 | [diff] [blame] | 21 | #define QDICT_BUCKET_MAX 512 |
Luiz Capitulino | fb08dde | 2009-08-28 15:27:07 -0300 | [diff] [blame] | 22 | |
| 23 | typedef struct QDictEntry { |
| 24 | char *key; |
| 25 | QObject *value; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 26 | QLIST_ENTRY(QDictEntry) next; |
Luiz Capitulino | fb08dde | 2009-08-28 15:27:07 -0300 | [diff] [blame] | 27 | } QDictEntry; |
| 28 | |
| 29 | typedef struct QDict { |
| 30 | QObject_HEAD; |
| 31 | size_t size; |
Luiz Capitulino | c8bc3cd | 2010-06-07 15:45:22 -0300 | [diff] [blame] | 32 | QLIST_HEAD(,QDictEntry) table[QDICT_BUCKET_MAX]; |
Luiz Capitulino | fb08dde | 2009-08-28 15:27:07 -0300 | [diff] [blame] | 33 | } QDict; |
| 34 | |
| 35 | /* Object API */ |
| 36 | QDict *qdict_new(void); |
Luiz Capitulino | 0d078b2 | 2010-06-07 16:53:51 -0300 | [diff] [blame] | 37 | const char *qdict_entry_key(const QDictEntry *entry); |
| 38 | QObject *qdict_entry_value(const QDictEntry *entry); |
Luiz Capitulino | fb08dde | 2009-08-28 15:27:07 -0300 | [diff] [blame] | 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); |
Luiz Capitulino | 21f800d | 2009-10-13 13:56:58 -0300 | [diff] [blame] | 45 | void qdict_iter(const QDict *qdict, |
| 46 | void (*iter)(const char *key, QObject *obj, void *opaque), |
| 47 | void *opaque); |
Luiz Capitulino | f2b07f3 | 2010-06-07 16:07:29 -0300 | [diff] [blame] | 48 | const QDictEntry *qdict_first(const QDict *qdict); |
| 49 | const QDictEntry *qdict_next(const QDict *qdict, const QDictEntry *entry); |
Luiz Capitulino | fb08dde | 2009-08-28 15:27:07 -0300 | [diff] [blame] | 50 | |
| 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 Armbruster | acc3b03 | 2010-01-27 17:16:38 +0100 | [diff] [blame] | 56 | double qdict_get_double(const QDict *qdict, const char *key); |
Luiz Capitulino | fb08dde | 2009-08-28 15:27:07 -0300 | [diff] [blame] | 57 | int64_t qdict_get_int(const QDict *qdict, const char *key); |
Luiz Capitulino | cd4dde3 | 2009-12-10 17:15:53 -0200 | [diff] [blame] | 58 | int qdict_get_bool(const QDict *qdict, const char *key); |
Luiz Capitulino | f2e1750 | 2009-12-10 17:15:54 -0200 | [diff] [blame] | 59 | QList *qdict_get_qlist(const QDict *qdict, const char *key); |
Luiz Capitulino | df10ce6 | 2010-01-21 19:15:39 -0200 | [diff] [blame] | 60 | QDict *qdict_get_qdict(const QDict *qdict, const char *key); |
Luiz Capitulino | fb08dde | 2009-08-28 15:27:07 -0300 | [diff] [blame] | 61 | const char *qdict_get_str(const QDict *qdict, const char *key); |
| 62 | int64_t qdict_get_try_int(const QDict *qdict, const char *key, |
Luiz Capitulino | 83aba69 | 2010-06-04 19:20:54 -0300 | [diff] [blame] | 63 | int64_t def_value); |
Luiz Capitulino | 35006ac | 2010-06-07 17:25:04 -0300 | [diff] [blame] | 64 | int qdict_get_try_bool(const QDict *qdict, const char *key, int def_value); |
Luiz Capitulino | fb08dde | 2009-08-28 15:27:07 -0300 | [diff] [blame] | 65 | const char *qdict_get_try_str(const QDict *qdict, const char *key); |
| 66 | |
| 67 | #endif /* QDICT_H */ |