libcamera: value_node: Add mutable children accessors

Add two at() functions that return mutable pointer to child nodes, based
on an index for lists and a key for dictionaries.

The API differs from const children accessors that use operator[] and
return a reference in order to allow better error handling: while the
const accessors return a reference to a global instance of an empty
ValueNode when the requested child doesn't exist, a mutable accessor
can't do the same without allowing modifying the empty global instance.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
Reviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>
This commit is contained in:
Laurent Pinchart
2025-10-17 21:53:34 +03:00
parent b25556c691
commit eafc366012
2 changed files with 44 additions and 0 deletions

View File

@@ -230,9 +230,11 @@ public:
ConstDictAdapter asDict() const { return ConstDictAdapter{ list_ }; }
ConstListAdapter asList() const { return ConstListAdapter{ list_ }; }
ValueNode *at(std::size_t index);
const ValueNode &operator[](std::size_t index) const;
bool contains(std::string_view key) const;
ValueNode *at(std::string_view key);
const ValueNode &operator[](std::string_view key) const;
ValueNode *add(std::unique_ptr<ValueNode> &&child);