qemu/include/qapi/qmp/qdict.h
<<
>>
Prefs
   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#include <stdbool.h>
  20#include <stdint.h>
  21
  22#define QDICT_BUCKET_MAX 512
  23
  24typedef struct QDictEntry {
  25    char *key;
  26    QObject *value;
  27    QLIST_ENTRY(QDictEntry) next;
  28} QDictEntry;
  29
  30typedef struct QDict {
  31    QObject_HEAD;
  32    size_t size;
  33    QLIST_HEAD(,QDictEntry) table[QDICT_BUCKET_MAX];
  34} QDict;
  35
  36/* Object API */
  37QDict *qdict_new(void);
  38const char *qdict_entry_key(const QDictEntry *entry);
  39QObject *qdict_entry_value(const QDictEntry *entry);
  40size_t qdict_size(const QDict *qdict);
  41void qdict_put_obj(QDict *qdict, const char *key, QObject *value);
  42void qdict_del(QDict *qdict, const char *key);
  43int qdict_haskey(const QDict *qdict, const char *key);
  44QObject *qdict_get(const QDict *qdict, const char *key);
  45QDict *qobject_to_qdict(const QObject *obj);
  46void qdict_iter(const QDict *qdict,
  47                void (*iter)(const char *key, QObject *obj, void *opaque),
  48                void *opaque);
  49const QDictEntry *qdict_first(const QDict *qdict);
  50const QDictEntry *qdict_next(const QDict *qdict, const QDictEntry *entry);
  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/* High level helpers */
  57double qdict_get_double(const QDict *qdict, const char *key);
  58int64_t qdict_get_int(const QDict *qdict, const char *key);
  59bool qdict_get_bool(const QDict *qdict, const char *key);
  60QList *qdict_get_qlist(const QDict *qdict, const char *key);
  61QDict *qdict_get_qdict(const QDict *qdict, const char *key);
  62const char *qdict_get_str(const QDict *qdict, const char *key);
  63int64_t qdict_get_try_int(const QDict *qdict, const char *key,
  64                          int64_t def_value);
  65bool qdict_get_try_bool(const QDict *qdict, const char *key, bool def_value);
  66const char *qdict_get_try_str(const QDict *qdict, const char *key);
  67
  68void qdict_copy_default(QDict *dst, QDict *src, const char *key);
  69void qdict_set_default_str(QDict *dst, const char *key, const char *val);
  70
  71QDict *qdict_clone_shallow(const QDict *src);
  72void qdict_flatten(QDict *qdict);
  73
  74void qdict_extract_subqdict(QDict *src, QDict **dst, const char *start);
  75void qdict_array_split(QDict *src, QList **dst);
  76int qdict_array_entries(QDict *src, const char *subqdict);
  77
  78void qdict_join(QDict *dest, QDict *src, bool overwrite);
  79
  80#endif /* QDICT_H */
  81