11#include <initializer_list>
30 Value(std::string
k, std::unique_ptr<ValueNode> &&v)
31 : key(std::move(
k)), value(std::move(v))
35 std::unique_ptr<ValueNode> value;
38 using ValueContainer = std::vector<Value>;
42 template<
typename Derived,
typename ContainerIterator>
46 using difference_type = std::ptrdiff_t;
47 using iterator_category = std::forward_iterator_tag;
57 return *
static_cast<Derived *
>(
this);
69 return a.it_ == b.it_;
74 return a.it_ != b.it_;
81 template<
typename Iterator,
typename Container>
104 template<
typename Value,
typename ContainerIterator>
113 using value_type = Value;
114 using pointer = value_type *;
115 using reference = value_type &;
119 return *Base::it_->value.get();
122 pointer operator->()
const
124 return Base::it_->value.get();
128 template<
typename Value,
typename ContainerIterator>
137 using value_type = std::pair<const std::string &, Value &>;
138 using pointer = value_type *;
139 using reference = value_type &;
143 return { Base::it_->key, *Base::it_->value.get() };
148 ValueContainer::iterator>,
156 ValueContainer::iterator>,
162 ValueContainer::const_iterator>,
163 const ValueContainer>
170 ValueContainer::const_iterator>,
171 const ValueContainer>
182 set(std::forward<T>(value));
189 return type_ == Type::Value;
193 return type_ == Type::List;
197 return type_ == Type::Dictionary;
201 return type_ == Type::Empty;
205 return type_ != Type::Empty;
208 std::size_t
size()
const;
211 std::optional<T>
get()
const
216 template<
typename T,
typename U>
226 .set(*
this, std::forward<T>(value));
237 bool contains(std::string_view key)
const;
244 ValueNode *
add(std::initializer_list<std::string_view> path,
245 std::unique_ptr<ValueNode> &&
child);
247 void erase(std::string_view key);
248 void erase(std::initializer_list<std::string_view> path);
254 friend struct Accessor;
263 template<
typename T,
typename Enable =
void>
265 std::optional<T>
get(
const ValueNode &
obj)
const;
266 void set(ValueNode &
obj,
T value);
272 ValueContainer list_;
273 std::map<std::string, ValueNode *, std::less<>> dictionary_;
Utilities to help constructing class interfaces.
#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass)
Disable copy and move construction and assignment of the klass.
Definition class.h:29
A class representing a tree structure of values.
Definition value_node.h:27
DictAdapter asDict()
Wrap a dictionary ValueNode in an adapter that exposes iterators.
Definition value_node.h:229
bool isValue() const
Return whether the ValueNode is a value.
Definition value_node.h:187
ValueNode * at(std::size_t index)
Retrieve the element from list ValueNode by index.
Definition value_node.cpp:404
ConstDictAdapter asDict() const
Wrap a dictionary ValueNode in an adapter that exposes iterators.
Definition value_node.h:231
const ValueNode & operator[](std::size_t index) const
Retrieve the element from list ValueNode by index.
Definition value_node.cpp:423
ValueNode * add(std::unique_ptr< ValueNode > &&child)
Add a child node to a list.
Definition value_node.cpp:528
std::optional< T > get() const
Parse the ValueNode as a T value.
Definition value_node.h:211
void set(T &&value)
Set the value of a ValueNode.
Definition value_node.h:223
bool isDictionary() const
Return whether the ValueNode is a dictionary.
Definition value_node.h:195
T get(U &&defaultValue) const
Parse the ValueNode as a T value.
Definition value_node.h:217
void erase(std::string_view key)
Erase a child node in a dictionary.
Definition value_node.cpp:633
bool isList() const
Return whether the ValueNode is a list.
Definition value_node.h:191
ValueNode(T &&value)
Construct a ValueNode instance with a value.
Definition value_node.h:179
bool isEmpty() const
Return whether the ValueNode is an empty.
Definition value_node.h:199
ListAdapter asList()
Wrap a list ValueNode in an adapter that exposes iterators.
Definition value_node.h:230
bool contains(std::string_view key) const
Check if an element of a dictionary exists.
Definition value_node.cpp:442
std::size_t size() const
Retrieve the number of elements in a dictionary or list ValueNode.
Definition value_node.cpp:106
ConstListAdapter asList() const
Wrap a list ValueNode in an adapter that exposes iterators.
Definition value_node.h:232
Top-level libcamera namespace.
Definition backtrace.h:17
bool operator==(const ColorSpace &lhs, const ColorSpace &rhs)
Compare color spaces for equality.
Definition color_space.cpp:506
bool operator!=(const Vector< T, Rows > &lhs, const Vector< T, Rows > &rhs)
Compare vectors for inequality.
Definition vector.h:326
Matrix< U, Rows, Cols > operator*(T d, const Matrix< U, Rows, Cols > &m)
Multiply the matrix by a scalar.
Definition matrix.h:133