[15/36] libcamera: yaml_parser: Move Size handling to geometry.cpp
diff mbox series

Message ID 20260113000808.15395-16-laurent.pinchart@ideasonboard.com
State New
Headers show
Series
  • libcamera: Global configuration file improvements
Related show

Commit Message

Laurent Pinchart Jan. 13, 2026, 12:07 a.m. UTC
The YamlObject::Accessor structure is designed to extend the YamlObject
class with new getter and setter types without modifying
yaml_parser.cpp. This feature is used for various libcamera classes,
while standard C++ types are handled in yaml_parser.cpp.

The Size class is an outlier: it is a libcamera class, but is handled in
yaml_parser.cpp. Move it to geometry.cpp. Drop the std::vector<Size>
specialization as it is currently unused.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 include/libcamera/internal/yaml_parser.h |  2 --
 src/ipa/libipa/lsc_polynomial.h          |  2 ++
 src/libcamera/geometry.cpp               | 29 ++++++++++++++++++++++++
 src/libcamera/yaml_parser.cpp            | 25 +-------------------
 test/yaml-parser.cpp                     |  2 ++
 5 files changed, 34 insertions(+), 26 deletions(-)

Patch
diff mbox series

diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h
index 02e39e4cd7a1..7b6d16de1a04 100644
--- a/include/libcamera/internal/yaml_parser.h
+++ b/include/libcamera/internal/yaml_parser.h
@@ -17,8 +17,6 @@ 
 
 #include <libcamera/base/class.h>
 
-#include <libcamera/geometry.h>
-
 namespace libcamera {
 
 class File;
diff --git a/src/ipa/libipa/lsc_polynomial.h b/src/ipa/libipa/lsc_polynomial.h
index df3a0d4b39c4..c71f215de3fc 100644
--- a/src/ipa/libipa/lsc_polynomial.h
+++ b/src/ipa/libipa/lsc_polynomial.h
@@ -14,6 +14,8 @@ 
 #include <libcamera/base/log.h>
 #include <libcamera/base/span.h>
 
+#include <libcamera/geometry.h>
+
 #include "libcamera/internal/yaml_parser.h"
 
 namespace libcamera {
diff --git a/src/libcamera/geometry.cpp b/src/libcamera/geometry.cpp
index 2763967a6e57..2e8e9e33ea78 100644
--- a/src/libcamera/geometry.cpp
+++ b/src/libcamera/geometry.cpp
@@ -12,6 +12,8 @@ 
 
 #include <libcamera/base/log.h>
 
+#include "libcamera/internal/yaml_parser.h"
+
 /**
  * \file geometry.h
  * \brief Data structures related to geometric objects
@@ -924,4 +926,31 @@  std::ostream &operator<<(std::ostream &out, const Rectangle &r)
 	return out;
 }
 
+#ifndef __DOXYGEN__
+/*
+ * The YAML data shall be a list of two numerical values containing the x and y
+ * coordinates, in that order.
+ */
+template<>
+std::optional<Size>
+YamlObject::Accessor<Size>::get(const YamlObject &obj) const
+{
+	if (obj.type_ != Type::List)
+		return std::nullopt;
+
+	if (obj.list_.size() != 2)
+		return std::nullopt;
+
+	auto width = obj.list_[0].value->get<uint32_t>();
+	if (!width)
+		return std::nullopt;
+
+	auto height = obj.list_[1].value->get<uint32_t>();
+	if (!height)
+		return std::nullopt;
+
+	return Size(*width, *height);
+}
+#endif /* __DOXYGEN__ */
+
 } /* namespace libcamera */
diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp
index fa1a487a13dc..46c1fb9bce7e 100644
--- a/src/libcamera/yaml_parser.cpp
+++ b/src/libcamera/yaml_parser.cpp
@@ -284,27 +284,6 @@  void YamlObject::Accessor<std::string>::set(YamlObject &obj, std::string value)
 	obj.value_ = std::move(value);
 }
 
-template<>
-std::optional<Size>
-YamlObject::Accessor<Size>::get(const YamlObject &obj) const
-{
-	if (obj.type_ != Type::List)
-		return std::nullopt;
-
-	if (obj.list_.size() != 2)
-		return std::nullopt;
-
-	auto width = obj.list_[0].value->get<uint32_t>();
-	if (!width)
-		return std::nullopt;
-
-	auto height = obj.list_[1].value->get<uint32_t>();
-	if (!height)
-		return std::nullopt;
-
-	return Size(*width, *height);
-}
-
 template<typename T>
 struct YamlObject::Accessor<std::vector<T>, std::enable_if_t<
 	std::is_same_v<bool, T> ||
@@ -316,8 +295,7 @@  struct YamlObject::Accessor<std::vector<T>, std::enable_if_t<
 	std::is_same_v<uint16_t, T> ||
 	std::is_same_v<int32_t, T> ||
 	std::is_same_v<uint32_t, T> ||
-	std::is_same_v<std::string, T> ||
-	std::is_same_v<Size, T>>>
+	std::is_same_v<std::string, T>>>
 {
 	std::optional<std::vector<T>> get(const YamlObject &obj) const
 	{
@@ -348,7 +326,6 @@  template struct YamlObject::Accessor<std::vector<uint16_t>>;
 template struct YamlObject::Accessor<std::vector<int32_t>>;
 template struct YamlObject::Accessor<std::vector<uint32_t>>;
 template struct YamlObject::Accessor<std::vector<std::string>>;
-template struct YamlObject::Accessor<std::vector<Size>>;
 #endif /* __DOXYGEN__ */
 
 /**
diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp
index 566401afcab6..01e734d23059 100644
--- a/test/yaml-parser.cpp
+++ b/test/yaml-parser.cpp
@@ -14,6 +14,8 @@ 
 #include <libcamera/base/file.h>
 #include <libcamera/base/utils.h>
 
+#include <libcamera/geometry.h>
+
 #include "libcamera/internal/yaml_parser.h"
 
 #include "test.h"