22 class YamlParserContext;
27 using DictContainer = std::map<std::string, std::unique_ptr<YamlObject>>;
28 using ListContainer = std::vector<std::unique_ptr<YamlObject>>;
32 template<
typename Container,
typename Derived>
36 using difference_type = std::ptrdiff_t;
37 using iterator_category = std::forward_iterator_tag;
39 Iterator(
typename Container::const_iterator it)
47 return *
static_cast<Derived *
>(
this);
50 Derived operator++(
int)
52 Derived it = *
static_cast<Derived *
>(
this);
57 friend bool operator==(
const Iterator &a,
const Iterator &b)
59 return a.it_ == b.it_;
62 friend bool operator!=(
const Iterator &a,
const Iterator &b)
64 return a.it_ != b.it_;
68 typename Container::const_iterator it_;
71 template<
typename Container,
typename Iterator>
75 Adapter(
const Container &container)
76 : container_(container)
80 Iterator begin()
const 82 return Iterator{ container_.begin() };
87 return Iterator{ container_.end() };
91 const Container &container_;
94 class ListIterator :
public Iterator<ListContainer, ListIterator>
99 using reference = value_type;
106 pointer operator->()
const 112 class DictIterator :
public Iterator<DictContainer, DictIterator>
115 using value_type = std::pair<const std::string &, const YamlObject &>;
116 using pointer = value_type *;
117 using reference = value_type &;
121 return { it_->first, *it_->second.get() };
125 class DictAdapter :
public Adapter<DictContainer, DictIterator>
128 using key_type = std::string;
131 class ListAdapter :
public Adapter<ListContainer, ListIterator>
141 return type_ == Type::Value;
145 return type_ == Type::List;
149 return type_ == Type::Dictionary;
152 std::size_t
size()
const;
156 typename std::enable_if_t<
157 std::is_same_v<bool, T> ||
158 std::is_same_v<double, T> ||
159 std::is_same_v<int16_t, T> ||
160 std::is_same_v<uint16_t, T> ||
161 std::is_same_v<int32_t, T> ||
162 std::is_same_v<uint32_t, T> ||
163 std::is_same_v<std::string, T> ||
164 std::is_same_v<Size, T>> * =
nullptr>
168 T
get(
const T &defaultValue,
bool *ok =
nullptr)
const;
170 DictAdapter
asDict()
const {
return DictAdapter{ dictionary_ }; }
171 ListAdapter
asList()
const {
return ListAdapter{ list_ }; }
175 bool contains(
const std::string &key)
const;
181 friend class YamlParserContext;
193 DictContainer dictionary_;
199 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:303
bool isValue() const
Return whether the YamlObject is a value.
Definition: yaml_parser.h:139
const YamlObject & operator[](std::size_t index) const
Retrieve the element from list YamlObject by index.
Definition: yaml_parser.cpp:377
Transform operator*(Transform t0, Transform t1)
Compose two transforms together.
Definition: transform.cpp:207
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:171
bool isDictionary() const
Return whether the YamlObject is a dictionary.
Definition: yaml_parser.h:147
bool isList() const
Return whether the YamlObject is a list.
Definition: yaml_parser.h:143
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:396
#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:90
DictAdapter asDict() const
Wrap a dictionary YamlObject in an adapter that exposes iterators.
Definition: yaml_parser.h:170
A class representing the tree structure of the YAML content.
Definition: yaml_parser.h:24
A helper class for parsing a YAML file.
Definition: yaml_parser.h:196
Data structures related to geometric objects.