25class YamlParserContext;
31 Value(std::string &&k, std::unique_ptr<YamlObject> &&v)
32 : key(std::move(k)), value(std::move(v))
36 std::unique_ptr<YamlObject> value;
39 using Container = std::vector<Value>;
40 using ListContainer = std::vector<std::unique_ptr<YamlObject>>;
44 template<
typename Derived>
48 using difference_type = std::ptrdiff_t;
49 using iterator_category = std::forward_iterator_tag;
51 Iterator(
typename Container::const_iterator it)
59 return *
static_cast<Derived *
>(
this);
62 Derived operator++(
int)
64 Derived it = *
static_cast<Derived *
>(
this);
69 friend bool operator==(
const Iterator &a,
const Iterator &b)
71 return a.it_ == b.it_;
74 friend bool operator!=(
const Iterator &a,
const Iterator &b)
76 return a.it_ != b.it_;
80 Container::const_iterator it_;
83 template<
typename Iterator>
87 Adapter(
const Container &container)
88 : container_(container)
92 Iterator begin()
const
94 return Iterator{ container_.begin() };
99 return Iterator{ container_.end() };
103 const Container &container_;
106 class ListIterator :
public Iterator<ListIterator>
109 using value_type =
const YamlObject &;
110 using pointer =
const YamlObject *;
111 using reference = value_type;
115 return *it_->value.get();
118 pointer operator->()
const
120 return it_->value.get();
124 class DictIterator :
public Iterator<DictIterator>
127 using value_type = std::pair<const std::string &, const YamlObject &>;
128 using pointer = value_type *;
129 using reference = value_type &;
133 return { it_->key, *it_->value.get() };
137 class DictAdapter :
public Adapter<DictIterator>
140 using key_type = std::string;
143 class ListAdapter :
public Adapter<ListIterator>
153 return type_ == Type::Value;
157 return type_ == Type::List;
161 return type_ == Type::Dictionary;
165 return type_ == Type::Empty;
167 explicit operator bool()
const
169 return type_ != Type::Empty;
172 std::size_t
size()
const;
175 std::optional<T>
get()
const
177 return Getter<T>{}.get(*
this);
180 template<
typename T,
typename U>
181 T
get(U &&defaultValue)
const
183 return get<T>().value_or(std::forward<U>(defaultValue));
189 std::is_same_v<bool, T> ||
190 std::is_same_v<float, T> ||
191 std::is_same_v<double, T> ||
192 std::is_same_v<int8_t, T> ||
193 std::is_same_v<uint8_t, T> ||
194 std::is_same_v<int16_t, T> ||
195 std::is_same_v<uint16_t, T> ||
196 std::is_same_v<int32_t, T> ||
197 std::is_same_v<uint32_t, T> ||
198 std::is_same_v<std::string, T> ||
199 std::is_same_v<Size, T>> * =
nullptr>
203 std::optional<std::vector<T>>
getList()
const;
205 DictAdapter
asDict()
const {
return DictAdapter{ list_ }; }
206 ListAdapter
asList()
const {
return ListAdapter{ list_ }; }
210 bool contains(std::string_view key)
const;
217 friend struct Getter;
218 friend class YamlParserContext;
227 template<
typename T,
typename Enable =
void>
229 std::optional<T>
get(
const YamlObject &obj)
const;
236 std::map<std::string, YamlObject *, std::less<>> dictionary_;
242 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:28
std::size_t size() const
Retrieve the number of elements in a dictionary or list YamlObject.
Definition yaml_parser.cpp:99
std::optional< T > get() const
Parse the YamlObject as a T value.
Definition yaml_parser.h:175
T get(U &&defaultValue) const
Parse the YamlObject as a T value.
Definition yaml_parser.h:181
bool isValue() const
Return whether the YamlObject is a value.
Definition yaml_parser.h:151
bool contains(std::string_view key) const
Check if an element of a dictionary exists.
Definition yaml_parser.cpp:372
bool isDictionary() const
Return whether the YamlObject is a dictionary.
Definition yaml_parser.h:159
const YamlObject & operator[](std::size_t index) const
Retrieve the element from list YamlObject by index.
Definition yaml_parser.cpp:353
DictAdapter asDict() const
Wrap a dictionary YamlObject in an adapter that exposes iterators.
Definition yaml_parser.h:205
bool isEmpty() const
Return whether the YamlObject is an empty.
Definition yaml_parser.h:163
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:206
bool isList() const
Return whether the YamlObject is a list.
Definition yaml_parser.h:155
A helper class for parsing a YAML file.
Definition yaml_parser.h:240
static std::unique_ptr< YamlObject > parse(File &file)
Parse a YAML file as a YamlObject.
Definition yaml_parser.cpp:765
Data structures related to geometric objects.
Top-level libcamera namespace.
Definition backtrace.h:17
Matrix< U, Rows, Cols > operator*(T d, const Matrix< U, Rows, Cols > &m)
Multiply the matrix by a scalar.
Definition matrix.h:101