libcamera: value_node: Add mutable adapters
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 <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:
@@ -143,17 +143,31 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class DictAdapter : public Adapter<DictIterator<const ValueNode,
|
||||
ValueContainer::const_iterator>,
|
||||
const ValueContainer>
|
||||
class DictAdapter : public Adapter<DictIterator<ValueNode,
|
||||
ValueContainer::iterator>,
|
||||
ValueContainer>
|
||||
{
|
||||
public:
|
||||
using key_type = std::string;
|
||||
};
|
||||
|
||||
class ListAdapter : public Adapter<ListIterator<const ValueNode,
|
||||
ValueContainer::const_iterator>,
|
||||
const ValueContainer>
|
||||
class ListAdapter : public Adapter<ListIterator<ValueNode,
|
||||
ValueContainer::iterator>,
|
||||
ValueContainer>
|
||||
{
|
||||
};
|
||||
|
||||
class ConstDictAdapter : public Adapter<DictIterator<const ValueNode,
|
||||
ValueContainer::const_iterator>,
|
||||
const ValueContainer>
|
||||
{
|
||||
public:
|
||||
using key_type = std::string;
|
||||
};
|
||||
|
||||
class ConstListAdapter : public Adapter<ListIterator<const ValueNode,
|
||||
ValueContainer::const_iterator>,
|
||||
const ValueContainer>
|
||||
{
|
||||
};
|
||||
#endif /* __DOXYGEN__ */
|
||||
@@ -211,8 +225,10 @@ public:
|
||||
.set(*this, std::forward<T>(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;
|
||||
|
||||
|
||||
@@ -337,6 +337,11 @@ template struct ValueNode::Accessor<std::vector<uint32_t>>;
|
||||
template struct ValueNode::Accessor<std::vector<std::string>>;
|
||||
#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<std::vector<std::string>>;
|
||||
* \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
|
||||
|
||||
Reference in New Issue
Block a user