libcamera: yaml_parser: Move Size handling to geometry.cpp

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>
Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
Reviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>
This commit is contained in:
Laurent Pinchart
2025-10-19 02:42:35 +03:00
parent 2894f2c14b
commit bc0318e8c8
5 changed files with 33 additions and 24 deletions

View File

@@ -17,8 +17,6 @@
#include <libcamera/base/class.h>
#include <libcamera/geometry.h>
namespace libcamera {
class File;

View File

@@ -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 {

View File

@@ -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 */

View File

@@ -286,27 +286,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::optional<std::vector<T>> get(const YamlObject &obj) const
@@ -338,7 +317,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__ */
/**

View File

@@ -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"