On Wed, May 07, 2025 at 04:14:33PM -0700, Pierrick Bouvier wrote:
> 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.

IMHO this feels like a somewhat dubious concept to have in the
qobject code, as it is quite specialized to a single use case.
A more general purpose approach would be to have some mechanism
for cloning while applying a data filter, though I admit that
may be more tedious to actually use.

> 
> 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
> 

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Reply via email to