24class YamlParserContext;
30 Value(std::string &&k, std::unique_ptr<YamlObject> &&v)
31 : key(std::move(k)), value(std::move(v))
35 std::unique_ptr<YamlObject> value;
38 using Container = std::vector<Value>;
39 using ListContainer = std::vector<std::unique_ptr<YamlObject>>;
43 template<
typename Derived>
47 using difference_type = std::ptrdiff_t;
48 using iterator_category = std::forward_iterator_tag;
50 Iterator(
typename Container::const_iterator it)
58 return *
static_cast<Derived *
>(
this);
61 Derived operator++(
int)
63 Derived it = *
static_cast<Derived *
>(
this);
68 friend bool operator==(
const Iterator &a,
const Iterator &b)
70 return a.it_ == b.it_;
73 friend bool operator!=(
const Iterator &a,
const Iterator &b)
75 return a.it_ != b.it_;
79 Container::const_iterator it_;
82 template<
typename Iterator>
86 Adapter(
const Container &container)
87 : container_(container)
91 Iterator begin()
const
93 return Iterator{ container_.begin() };
98 return Iterator{ container_.end() };
102 const Container &container_;
105 class ListIterator :
public Iterator<ListIterator>
110 using reference = value_type;
114 return *it_->value.get();
117 pointer operator->()
const
119 return it_->value.get();
123 class DictIterator :
public Iterator<DictIterator>
126 using value_type = std::pair<const std::string &, const YamlObject &>;
127 using pointer = value_type *;
128 using reference = value_type &;
132 return { it_->key, *it_->value.get() };
136 class DictAdapter :
public Adapter<DictIterator>
139 using key_type = std::string;
142 class ListAdapter :
public Adapter<ListIterator>
152 return type_ == Type::Value;
156 return type_ == Type::List;
160 return type_ == Type::Dictionary;
164 return type_ == Type::Empty;
166 explicit operator bool()
const
168 return type_ != Type::Empty;
171 std::size_t
size()
const;
174 std::optional<T>
get()
const
176 return Getter<T>{}.get(*
this);
179 template<
typename T,
typename U>
180 T
get(U &&defaultValue)
const
182 return get<T>().value_or(std::forward<U>(defaultValue));
188 std::is_same_v<bool, T> ||
189 std::is_same_v<float, T> ||
190 std::is_same_v<double, T> ||
191 std::is_same_v<int8_t, T> ||
192 std::is_same_v<uint8_t, T> ||
193 std::is_same_v<int16_t, T> ||
194 std::is_same_v<uint16_t, T> ||
195 std::is_same_v<int32_t, T> ||
196 std::is_same_v<uint32_t, T> ||
197 std::is_same_v<std::string, T> ||
198 std::is_same_v<Size, T>> * =
nullptr>
202 std::optional<std::vector<T>>
getList()
const;
204 DictAdapter
asDict()
const {
return DictAdapter{ list_ }; }
205 ListAdapter
asList()
const {
return ListAdapter{ list_ }; }
209 bool contains(
const std::string &key)
const;
216 friend struct Getter;
217 friend class YamlParserContext;
228 std::optional<T>
get(
const YamlObject &obj)
const;
235 std::map<std::string, YamlObject *> dictionary_;
241 static std::unique_ptr<YamlObject>
parse(
File &file);
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
Interface for I/O operations on files.
Definition file.h:25
A class representing the tree structure of the YAML content.
Definition yaml_parser.h:27
std::size_t size() const
Retrieve the number of elements in a dictionary or list YamlObject.
Definition yaml_parser.cpp:98
std::optional< T > get() const
Parse the YamlObject as a T value.
Definition yaml_parser.h:174
bool contains(const std::string &key) const
Check if an element of a dictionary exists.
Definition yaml_parser.cpp:484
T get(U &&defaultValue) const
Parse the YamlObject as a T value.
Definition yaml_parser.h:180
bool isValue() const
Return whether the YamlObject is a value.
Definition yaml_parser.h:150
bool isDictionary() const
Return whether the YamlObject is a dictionary.
Definition yaml_parser.h:158
const YamlObject & operator[](std::size_t index) const
Retrieve the element from list YamlObject by index.
Definition yaml_parser.cpp:465
DictAdapter asDict() const
Wrap a dictionary YamlObject in an adapter that exposes iterators.
Definition yaml_parser.h:204
bool isEmpty() const
Return whether the YamlObject is an empty.
Definition yaml_parser.h:162
std::optional< std::vector< T > > getList() const
Parse the YamlObject as a list of T.
ListAdapter asList() const
Wrap a list YamlObject in an adapter that exposes iterators.
Definition yaml_parser.h:205
bool isList() const
Return whether the YamlObject is a list.
Definition yaml_parser.h:154
A helper class for parsing a YAML file.
Definition yaml_parser.h:239
static std::unique_ptr< YamlObject > parse(File &file)
Parse a YAML file as a YamlObject.
Definition yaml_parser.cpp:871
Data structures related to geometric objects.
Top-level libcamera namespace.
Definition backtrace.h:17
Transform operator*(Transform t0, Transform t1)
Compose two transforms by applying t0 first then t1.
Definition transform.cpp:209
bool operator==(const ColorSpace &lhs, const ColorSpace &rhs)
Compare color spaces for equality.
Definition color_space.cpp:506