23 class YamlParserContext;
29 Value(std::string &&k, std::unique_ptr<YamlObject> &&v)
30 : key(std::move(k)), value(std::move(v))
34 std::unique_ptr<YamlObject> value;
37 using Container = std::vector<Value>;
38 using ListContainer = std::vector<std::unique_ptr<YamlObject>>;
42 template<
typename Derived>
46 using difference_type = std::ptrdiff_t;
47 using iterator_category = std::forward_iterator_tag;
49 Iterator(
typename Container::const_iterator it)
57 return *
static_cast<Derived *
>(
this);
60 Derived operator++(
int)
62 Derived it = *
static_cast<Derived *
>(
this);
67 friend bool operator==(
const Iterator &a,
const Iterator &b)
69 return a.it_ == b.it_;
72 friend bool operator!=(
const Iterator &a,
const Iterator &b)
74 return a.it_ != b.it_;
78 Container::const_iterator it_;
81 template<
typename Iterator>
85 Adapter(
const Container &container)
86 : container_(container)
90 Iterator begin()
const 92 return Iterator{ container_.begin() };
97 return Iterator{ container_.end() };
101 const Container &container_;
104 class ListIterator :
public Iterator<ListIterator>
109 using reference = value_type;
113 return *it_->value.get();
116 pointer operator->()
const 118 return it_->value.get();
122 class DictIterator :
public Iterator<DictIterator>
125 using value_type = std::pair<const std::string &, const YamlObject &>;
126 using pointer = value_type *;
127 using reference = value_type &;
131 return { it_->key, *it_->value.get() };
135 class DictAdapter :
public Adapter<DictIterator>
138 using key_type = std::string;
141 class ListAdapter :
public Adapter<ListIterator>
151 return type_ == Type::Value;
155 return type_ == Type::List;
159 return type_ == Type::Dictionary;
162 std::size_t
size()
const;
165 std::optional<T>
get()
const 167 return Getter<T>{}.get(*
this);
170 template<
typename T,
typename U>
171 T
get(U &&defaultValue)
const 173 return get<T>().value_or(std::forward<U>(defaultValue));
179 std::is_same_v<bool, T> ||
180 std::is_same_v<float, T> ||
181 std::is_same_v<double, T> ||
182 std::is_same_v<int8_t, T> ||
183 std::is_same_v<uint8_t, T> ||
184 std::is_same_v<int16_t, T> ||
185 std::is_same_v<uint16_t, T> ||
186 std::is_same_v<int32_t, T> ||
187 std::is_same_v<uint32_t, T> ||
188 std::is_same_v<std::string, T> ||
189 std::is_same_v<Size, T>> * =
nullptr>
193 std::optional<std::vector<T>>
getList()
const;
195 DictAdapter
asDict()
const {
return DictAdapter{ list_ }; }
196 ListAdapter
asList()
const {
return ListAdapter{ list_ }; }
200 bool contains(
const std::string &key)
const;
207 friend struct Getter;
208 friend class YamlParserContext;
218 std::optional<T>
get(
const YamlObject &obj)
const;
225 std::map<std::string, YamlObject *> dictionary_;
231 static std::unique_ptr<YamlObject> parse(
File &file);
Utilities to help constructing class interfaces.
bool operator==(const ColorSpace &lhs, const ColorSpace &rhs)
Compare color spaces for equality.
Definition: color_space.cpp:506
bool isValue() const
Return whether the YamlObject is a value.
Definition: yaml_parser.h:149
const YamlObject & operator[](std::size_t index) const
Retrieve the element from list YamlObject by index.
Definition: yaml_parser.cpp:450
Top-level libcamera namespace.
Definition: backtrace.h:17
ListAdapter asList() const
Wrap a list YamlObject in an adapter that exposes iterators.
Definition: yaml_parser.h:196
bool isDictionary() const
Return whether the YamlObject is a dictionary.
Definition: yaml_parser.h:157
bool isList() const
Return whether the YamlObject is a list.
Definition: yaml_parser.h:153
std::optional< std::vector< T > > getList() const
Parse the YamlObject as a list of T.
Interface for I/O operations on files.
Definition: file.h:24
bool contains(const std::string &key) const
Check if an element of a dictionary exists.
Definition: yaml_parser.cpp:469
Transform operator*(Transform t0, Transform t1)
Compose two transforms by applying t0 first then t1.
Definition: transform.cpp:209
#define LIBCAMERA_DISABLE_COPY_AND_MOVE(klass)
Disable copy and move construction and assignment of the klass.
std::size_t size() const
Retrieve the number of elements in a dictionary or list YamlObject.
Definition: yaml_parser.cpp:84
DictAdapter asDict() const
Wrap a dictionary YamlObject in an adapter that exposes iterators.
Definition: yaml_parser.h:195
A class representing the tree structure of the YAML content.
Definition: yaml_parser.h:25
A helper class for parsing a YAML file.
Definition: yaml_parser.h:228
Data structures related to geometric objects.