From b25556c691965c10b61586af8d2679acce6e39dd Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Fri, 17 Oct 2025 21:53:34 +0300 Subject: [PATCH] libcamera: value_node: Add mutable adapters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ValueNode class was initially designed to store read-only property trees. It is useful to also provide mutable access. Add non-const adapters and iterators and adapters. This allows obtaining a mutable ValueNode instance when traversing a tree. Signed-off-by: Laurent Pinchart Reviewed-by: Barnabás Pőcze Reviewed-by: Isaac Scott --- include/libcamera/internal/value_node.h | 32 ++++++++++++++++++------- src/libcamera/value_node.cpp | 10 ++++++++ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/include/libcamera/internal/value_node.h b/include/libcamera/internal/value_node.h index 16e6660e..b51d2f4b 100644 --- a/include/libcamera/internal/value_node.h +++ b/include/libcamera/internal/value_node.h @@ -143,17 +143,31 @@ public: } }; - class DictAdapter : public Adapter, - const ValueContainer> + class DictAdapter : public Adapter, + ValueContainer> { public: using key_type = std::string; }; - class ListAdapter : public Adapter, - const ValueContainer> + class ListAdapter : public Adapter, + ValueContainer> + { + }; + + class ConstDictAdapter : public Adapter, + const ValueContainer> + { + public: + using key_type = std::string; + }; + + class ConstListAdapter : public Adapter, + const ValueContainer> { }; #endif /* __DOXYGEN__ */ @@ -211,8 +225,10 @@ public: .set(*this, std::forward(value)); } - DictAdapter asDict() const { return DictAdapter{ list_ }; } - ListAdapter asList() const { return ListAdapter{ list_ }; } + DictAdapter asDict() { return DictAdapter{ list_ }; } + ListAdapter asList() { return ListAdapter{ list_ }; } + ConstDictAdapter asDict() const { return ConstDictAdapter{ list_ }; } + ConstListAdapter asList() const { return ConstListAdapter{ list_ }; } const ValueNode &operator[](std::size_t index) const; diff --git a/src/libcamera/value_node.cpp b/src/libcamera/value_node.cpp index cb43fa9c..6221a22a 100644 --- a/src/libcamera/value_node.cpp +++ b/src/libcamera/value_node.cpp @@ -337,6 +337,11 @@ template struct ValueNode::Accessor>; template struct ValueNode::Accessor>; #endif /* __DOXYGEN__ */ +/** + * \fn ValueNode::asDict() + * \copydoc ValueNode::asDict() const + */ + /** * \fn ValueNode::asDict() const * \brief Wrap a dictionary ValueNode in an adapter that exposes iterators @@ -357,6 +362,11 @@ template struct ValueNode::Accessor>; * \return An adapter of unspecified type compatible with range-based for loops */ +/** + * \fn ValueNode::asList() + * \copydoc ValueNode::asList() const + */ + /** * \fn ValueNode::asList() const * \brief Wrap a list ValueNode in an adapter that exposes iterators