23class 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;
167 std::is_same_v<bool, T> ||
168 std::is_same_v<double, T> ||
169 std::is_same_v<int8_t, T> ||
170 std::is_same_v<uint8_t, T> ||
171 std::is_same_v<int16_t, T> ||
172 std::is_same_v<uint16_t, T> ||
173 std::is_same_v<int32_t, T> ||
174 std::is_same_v<uint32_t, T> ||
175 std::is_same_v<std::string, T> ||
176 std::is_same_v<Size, T>> * =
nullptr>
180 std::optional<T>
get()
const;
183 T
get(
const T &defaultValue)
const
185 return get<T>().value_or(defaultValue);
191 std::is_same_v<bool, T> ||
192 std::is_same_v<double, T> ||
193 std::is_same_v<int8_t, T> ||
194 std::is_same_v<uint8_t, T> ||
195 std::is_same_v<int16_t, T> ||
196 std::is_same_v<uint16_t, T> ||
197 std::is_same_v<int32_t, T> ||
198 std::is_same_v<uint32_t, T> ||
199 std::is_same_v<std::string, T> ||
200 std::is_same_v<Size, T>> * =
nullptr>
204 std::optional<std::vector<T>>
getList()
const;
206 DictAdapter
asDict()
const {
return DictAdapter{ list_ }; }
207 ListAdapter
asList()
const {
return ListAdapter{ list_ }; }
211 bool contains(
const std::string &key)
const;
217 friend class YamlParserContext;
229 std::map<std::string, YamlObject *> dictionary_;
235 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.
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:26
std::size_t size() const
Retrieve the number of elements in a dictionary or list YamlObject.
Definition: yaml_parser.cpp:84
T get(const T &defaultValue) const
Parse the YamlObject as a T value.
Definition: yaml_parser.h:183
bool contains(const std::string &key) const
Check if an element of a dictionary exists.
Definition: yaml_parser.cpp:450
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.
std::optional< T > get() const
Parse the YamlObject as a T value.
const YamlObject & operator[](std::size_t index) const
Retrieve the element from list YamlObject by index.
Definition: yaml_parser.cpp:431
DictAdapter asDict() const
Wrap a dictionary YamlObject in an adapter that exposes iterators.
Definition: yaml_parser.h:206
bool isValue() const
Return whether the YamlObject is a value.
Definition: yaml_parser.h:149
bool isDictionary() const
Return whether the YamlObject is a dictionary.
Definition: yaml_parser.h:157
ListAdapter asList() const
Wrap a list YamlObject in an adapter that exposes iterators.
Definition: yaml_parser.h:207
A helper class for parsing a YAML file.
Definition: yaml_parser.h:233
static std::unique_ptr< YamlObject > parse(File &file)
Parse a YAML file as a YamlObject.
Definition: yaml_parser.cpp:834
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