We add a new .hidden field to qlit entries, which gets ignored when creating the associated QObject. By default .hidden is 0, so it means the entry is visible. This way, only potentially hidden elements need to be assigned.
Signed-off-by: Pierrick Bouvier <pierrick.bouv...@linaro.org> --- include/qobject/qlit.h | 12 ++++++++++++ qobject/qlit.c | 10 ++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/qobject/qlit.h b/include/qobject/qlit.h index c0676d5daf2..3b66c22013c 100644 --- a/include/qobject/qlit.h +++ b/include/qobject/qlit.h @@ -28,25 +28,37 @@ struct QLitObject { QLitDictEntry *qdict; QLitObject *qlist; } value; + bool hidden; }; struct QLitDictEntry { const char *key; QLitObject value; + bool hidden; }; #define QLIT_QNULL \ { .type = QTYPE_QNULL } #define QLIT_QBOOL(val) \ { .type = QTYPE_QBOOL, .value.qbool = (val) } +#define QLIT_QBOOL_HIDDEN(val, cond) \ + { .type = QTYPE_QBOOL, .value.qbool = (val), .hidden = (cond) } #define QLIT_QNUM(val) \ { .type = QTYPE_QNUM, .value.qnum = (val) } +#define QLIT_QNUM_HIDDEN(val, cond) \ + { .type = QTYPE_QNUM, .value.qnum = (val), .hidden = (cond) } #define QLIT_QSTR(val) \ { .type = QTYPE_QSTRING, .value.qstr = (val) } +#define QLIT_QSTR_HIDDEN(val, cond) \ + { .type = QTYPE_QSTRING, .value.qstr = (val), .hidden = (cond) } #define QLIT_QDICT(val) \ { .type = QTYPE_QDICT, .value.qdict = (val) } +#define QLIT_QDICT_HIDDEN(val, cond) \ + { .type = QTYPE_QDICT, .value.qdict = (val), .hidden = (cond) } #define QLIT_QLIST(val) \ { .type = QTYPE_QLIST, .value.qlist = (val) } +#define QLIT_QLIST_HIDDEN(val, cond) \ + { .type = QTYPE_QLIST, .value.qlist = (val), .hidden = (cond) } bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs); diff --git a/qobject/qlit.c b/qobject/qlit.c index a44f47eaa57..7b372c5ebaa 100644 --- a/qobject/qlit.c +++ b/qobject/qlit.c @@ -90,6 +90,8 @@ bool qlit_equal_qobject(const QLitObject *lhs, const QObject *rhs) QObject *qobject_from_qlit(const QLitObject *qlit) { + g_assert(!qlit->hidden); + switch (qlit->type) { case QTYPE_QNULL: return QOBJECT(qnull()); @@ -102,7 +104,9 @@ QObject *qobject_from_qlit(const QLitObject *qlit) QLitDictEntry *e; for (e = qlit->value.qdict; e->key; e++) { - qdict_put_obj(qdict, e->key, qobject_from_qlit(&e->value)); + if (!e->hidden) { + qdict_put_obj(qdict, e->key, qobject_from_qlit(&e->value)); + } } return QOBJECT(qdict); } @@ -111,7 +115,9 @@ QObject *qobject_from_qlit(const QLitObject *qlit) QLitObject *e; for (e = qlit->value.qlist; e->type != QTYPE_NONE; e++) { - qlist_append_obj(qlist, qobject_from_qlit(e)); + if (!e->hidden) { + qlist_append_obj(qlist, qobject_from_qlit(e)); + } } return QOBJECT(qlist); } -- 2.47.2