summaryrefslogtreecommitdiff
path: root/src/ipa/libipa/vector.h
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-06-13 02:52:15 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2024-06-16 03:28:25 +0300
commit64ed07d4d057411c3fb669dc1faa27e61efd2811 (patch)
treeb36313020388589728048d7e14b4a16947a2bce6 /src/ipa/libipa/vector.h
parent922686067a2d610a93072cc9bbd3d9758087f4d1 (diff)
ipa: libipa: vector: Specialize YamlObject getter
Implement a specialization of the YamlObject::Getter structure to support deserializing ipa::Vector objects from YAML data. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Diffstat (limited to 'src/ipa/libipa/vector.h')
-rw-r--r--src/ipa/libipa/vector.h25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/ipa/libipa/vector.h b/src/ipa/libipa/vector.h
index 7c444363..4b2fe581 100644
--- a/src/ipa/libipa/vector.h
+++ b/src/ipa/libipa/vector.h
@@ -180,6 +180,10 @@ bool operator!=(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs)
return !(lhs == rhs);
}
+#ifndef __DOXYGEN__
+bool vectorValidateYaml(const YamlObject &obj, unsigned int size);
+#endif /* __DOXYGEN__ */
+
} /* namespace ipa */
#ifndef __DOXYGEN__
@@ -195,6 +199,27 @@ std::ostream &operator<<(std::ostream &out, const ipa::Vector<T, Rows> &v)
return out;
}
+
+template<typename T, unsigned int Rows>
+struct YamlObject::Getter<ipa::Vector<T, Rows>> {
+ std::optional<ipa::Vector<T, Rows>> get(const YamlObject &obj) const
+ {
+ if (!ipa::vectorValidateYaml(obj, Rows))
+ return std::nullopt;
+
+ ipa::Vector<T, Rows> vector;
+
+ unsigned int i = 0;
+ for (const YamlObject &entry : obj.asList()) {
+ const auto value = entry.get<T>();
+ if (!value)
+ return std::nullopt;
+ vector[i++] = *value;
+ }
+
+ return vector;
+ }
+};
#endif /* __DOXYGEN__ */
} /* namespace libcamera */