[26/36] libcamera: value_node: Rework templates to prepare for mutable views
diff mbox series

Message ID 20260113000808.15395-27-laurent.pinchart@ideasonboard.com
State New
Headers show
Series
  • libcamera: Global configuration file improvements
Related show

Commit Message

Laurent Pinchart Jan. 13, 2026, 12:07 a.m. UTC
ValueNode provides adapter classes to expose the object as an iteratable
list or dictionary. The Iterator and Adapter classes hardcode the
assumption that the ValueNode is const. To prepare for mutable views,
move the const specifier to the top-level DictAdapter and ListAdapter
class templates.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 include/libcamera/internal/value_node.h | 54 ++++++++++++++++---------
 1 file changed, 35 insertions(+), 19 deletions(-)

Patch
diff mbox series

diff --git a/include/libcamera/internal/value_node.h b/include/libcamera/internal/value_node.h
index eb509d855810..dd45859f3501 100644
--- a/include/libcamera/internal/value_node.h
+++ b/include/libcamera/internal/value_node.h
@@ -38,14 +38,14 @@  private:
 
 public:
 #ifndef __DOXYGEN__
-	template<typename Derived>
+	template<typename Derived, typename ContainerIterator>
 	class Iterator
 	{
 	public:
 		using difference_type = std::ptrdiff_t;
 		using iterator_category = std::forward_iterator_tag;
 
-		Iterator(typename ValueContainer::const_iterator it)
+		Iterator(ContainerIterator it)
 			: it_(it)
 		{
 		}
@@ -74,14 +74,14 @@  public:
 		}
 
 	protected:
-		ValueContainer::const_iterator it_;
+		ContainerIterator it_;
 	};
 
-	template<typename Iterator>
+	template<typename Iterator, typename Container>
 	class Adapter
 	{
 	public:
-		Adapter(const ValueContainer &container)
+		Adapter(Container &container)
 			: container_(container)
 		{
 		}
@@ -97,47 +97,63 @@  public:
 		}
 
 	protected:
-		const ValueContainer &container_;
+		Container &container_;
 	};
 
-	class ListIterator : public Iterator<ListIterator>
+	template<typename Value, typename ContainerIterator>
+	class ListIterator : public Iterator<ListIterator<Value, ContainerIterator>,
+					     ContainerIterator>
 	{
-	public:
-		using value_type = const ValueNode &;
-		using pointer = const ValueNode *;
-		using reference = value_type;
+	private:
+		using Base = Iterator<ListIterator<Value, ContainerIterator>,
+				      ContainerIterator>;
 
-		value_type operator*() const
+	public:
+		using value_type = Value;
+		using pointer = value_type *;
+		using reference = value_type &;
+
+		reference operator*() const
 		{
-			return *it_->value.get();
+			return *Base::it_->value.get();
 		}
 
 		pointer operator->() const
 		{
-			return it_->value.get();
+			return Base::it_->value.get();
 		}
 	};
 
-	class DictIterator : public Iterator<DictIterator>
+	template<typename Value, typename ContainerIterator>
+	class DictIterator : public Iterator<DictIterator<Value, ContainerIterator>,
+					     ContainerIterator>
 	{
+	private:
+		using Base = Iterator<DictIterator<Value, ContainerIterator>,
+				      ContainerIterator>;
+
 	public:
-		using value_type = std::pair<const std::string &, const ValueNode &>;
+		using value_type = std::pair<const std::string &, Value &>;
 		using pointer = value_type *;
 		using reference = value_type &;
 
 		value_type operator*() const
 		{
-			return { it_->key, *it_->value.get() };
+			return { Base::it_->key, *Base::it_->value.get() };
 		}
 	};
 
-	class DictAdapter : public Adapter<DictIterator>
+	class DictAdapter : public Adapter<DictIterator<const ValueNode,
+							ValueContainer::const_iterator>,
+					   const ValueContainer>
 	{
 	public:
 		using key_type = std::string;
 	};
 
-	class ListAdapter : public Adapter<ListIterator>
+	class ListAdapter : public Adapter<ListIterator<const ValueNode,
+							ValueContainer::const_iterator>,
+					   const ValueContainer>
 	{
 	};
 #endif /* __DOXYGEN__ */