libcamera: Rename YamlObject to ValueNode

The YamlObject class is now a generic data container to model trees of
values. Rename it to ValueNode and expand the class documentation.

While at it, drop the unneeded libcamera:: namespace prefix when using
the ValueNode class.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
This commit is contained in:
Laurent Pinchart
2025-10-19 15:28:34 +03:00
parent 9be3ed8104
commit 554c5c7fa1
134 changed files with 813 additions and 800 deletions

View File

@@ -31,7 +31,7 @@ public:
static std::unique_ptr<ConverterDW100Module> createModule(DeviceEnumerator *enumerator);
int init(const YamlObject &params);
int init(const ValueNode &params);
int configure(const StreamConfiguration &inputCfg,
const std::vector<std::reference_wrapper<const StreamConfiguration>>

View File

@@ -14,14 +14,14 @@
#include <libcamera/base/utils.h>
#include "libcamera/internal/yaml_object.h"
#include "libcamera/internal/value_node.h"
namespace libcamera {
class GlobalConfiguration
{
public:
using Configuration = const YamlObject &;
using Configuration = const ValueNode &;
GlobalConfiguration();
@@ -32,7 +32,7 @@ public:
std::optional<T> option(
const std::initializer_list<std::string_view> confPath) const
{
const YamlObject *c = &configuration();
const ValueNode *c = &configuration();
for (auto part : confPath) {
c = &(*c)[part];
if (!*c)
@@ -55,8 +55,8 @@ private:
bool loadFile(const std::filesystem::path &fileName);
void load();
std::unique_ptr<YamlObject> yamlConfiguration_ =
std::make_unique<YamlObject>();
std::unique_ptr<ValueNode> yamlConfiguration_ =
std::make_unique<ValueNode>();
};
} /* namespace libcamera */

View File

@@ -14,7 +14,7 @@
#include <libcamera/base/log.h>
#include <libcamera/base/span.h>
#include "libcamera/internal/yaml_object.h"
#include "libcamera/internal/value_node.h"
namespace libcamera {
@@ -188,7 +188,7 @@ constexpr Matrix<T, Rows, Cols> operator+(const Matrix<T, Rows, Cols> &m1, const
}
#ifndef __DOXYGEN__
bool matrixValidateYaml(const YamlObject &obj, unsigned int size);
bool matrixValidateYaml(const ValueNode &obj, unsigned int size);
#endif /* __DOXYGEN__ */
#ifndef __DOXYGEN__
@@ -200,8 +200,8 @@ std::ostream &operator<<(std::ostream &out, const Matrix<T, Rows, Cols> &m)
}
template<typename T, unsigned int Rows, unsigned int Cols>
struct YamlObject::Accessor<Matrix<T, Rows, Cols>> {
std::optional<Matrix<T, Rows, Cols>> get(const YamlObject &obj) const
struct ValueNode::Accessor<Matrix<T, Rows, Cols>> {
std::optional<Matrix<T, Rows, Cols>> get(const ValueNode &obj) const
{
if (!matrixValidateYaml(obj, Rows * Cols))
return std::nullopt;
@@ -210,7 +210,7 @@ struct YamlObject::Accessor<Matrix<T, Rows, Cols>> {
T *data = &matrix[0][0];
unsigned int i = 0;
for (const YamlObject &entry : obj.asList()) {
for (const ValueNode &entry : obj.asList()) {
const auto value = entry.get<T>();
if (!value)
return std::nullopt;

View File

@@ -48,8 +48,8 @@ libcamera_internal_headers = files([
'v4l2_request.h',
'v4l2_subdevice.h',
'v4l2_videodevice.h',
'value_node.h',
'vector.h',
'yaml_object.h',
'yaml_parser.h',
])

View File

@@ -3,7 +3,7 @@
* Copyright (C) 2022, Google Inc.
* Copyright (C) 2026, Ideas on Board
*
* libcamera YAML object
* Data structure to manage tree of values
*/
#pragma once
@@ -22,16 +22,16 @@
namespace libcamera {
class YamlObject
class ValueNode
{
private:
struct Value {
Value(std::string k, std::unique_ptr<YamlObject> &&v)
Value(std::string k, std::unique_ptr<ValueNode> &&v)
: key(std::move(k)), value(std::move(v))
{
}
std::string key;
std::unique_ptr<YamlObject> value;
std::unique_ptr<ValueNode> value;
};
using ValueContainer = std::vector<Value>;
@@ -103,8 +103,8 @@ public:
class ListIterator : public Iterator<ListIterator>
{
public:
using value_type = const YamlObject &;
using pointer = const YamlObject *;
using value_type = const ValueNode &;
using pointer = const ValueNode *;
using reference = value_type;
value_type operator*() const
@@ -121,7 +121,7 @@ public:
class DictIterator : public Iterator<DictIterator>
{
public:
using value_type = std::pair<const std::string &, const YamlObject &>;
using value_type = std::pair<const std::string &, const ValueNode &>;
using pointer = value_type *;
using reference = value_type &;
@@ -142,8 +142,8 @@ public:
};
#endif /* __DOXYGEN__ */
YamlObject();
~YamlObject();
ValueNode();
~ValueNode();
bool isValue() const
{
@@ -190,16 +190,16 @@ public:
DictAdapter asDict() const { return DictAdapter{ list_ }; }
ListAdapter asList() const { return ListAdapter{ list_ }; }
const YamlObject &operator[](std::size_t index) const;
const ValueNode &operator[](std::size_t index) const;
bool contains(std::string_view key) const;
const YamlObject &operator[](std::string_view key) const;
const ValueNode &operator[](std::string_view key) const;
YamlObject *add(std::unique_ptr<YamlObject> &&child);
YamlObject *add(std::string key, std::unique_ptr<YamlObject> &&child);
ValueNode *add(std::unique_ptr<ValueNode> &&child);
ValueNode *add(std::string key, std::unique_ptr<ValueNode> &&child);
private:
LIBCAMERA_DISABLE_COPY_AND_MOVE(YamlObject)
LIBCAMERA_DISABLE_COPY_AND_MOVE(ValueNode)
template<typename T>
friend struct Accessor;
@@ -213,15 +213,15 @@ private:
template<typename T, typename Enable = void>
struct Accessor {
std::optional<T> get(const YamlObject &obj) const;
void set(YamlObject &obj, T value);
std::optional<T> get(const ValueNode &obj) const;
void set(ValueNode &obj, T value);
};
Type type_;
std::string value_;
ValueContainer list_;
std::map<std::string, YamlObject *, std::less<>> dictionary_;
std::map<std::string, ValueNode *, std::less<>> dictionary_;
};
} /* namespace libcamera */

View File

@@ -19,7 +19,7 @@
#include <libcamera/base/span.h>
#include "libcamera/internal/matrix.h"
#include "libcamera/internal/yaml_object.h"
#include "libcamera/internal/value_node.h"
namespace libcamera {
@@ -329,7 +329,7 @@ bool operator!=(const Vector<T, Rows> &lhs, const Vector<T, Rows> &rhs)
}
#ifndef __DOXYGEN__
bool vectorValidateYaml(const YamlObject &obj, unsigned int size);
bool vectorValidateYaml(const ValueNode &obj, unsigned int size);
#endif /* __DOXYGEN__ */
#ifndef __DOXYGEN__
@@ -347,8 +347,8 @@ std::ostream &operator<<(std::ostream &out, const Vector<T, Rows> &v)
}
template<typename T, unsigned int Rows>
struct YamlObject::Accessor<Vector<T, Rows>> {
std::optional<Vector<T, Rows>> get(const YamlObject &obj) const
struct ValueNode::Accessor<Vector<T, Rows>> {
std::optional<Vector<T, Rows>> get(const ValueNode &obj) const
{
if (!vectorValidateYaml(obj, Rows))
return std::nullopt;
@@ -356,7 +356,7 @@ struct YamlObject::Accessor<Vector<T, Rows>> {
Vector<T, Rows> vector;
unsigned int i = 0;
for (const YamlObject &entry : obj.asList()) {
for (const ValueNode &entry : obj.asList()) {
const auto value = entry.get<T>();
if (!value)
return std::nullopt;

View File

@@ -9,7 +9,7 @@
#include <memory>
#include "libcamera/internal/yaml_object.h"
#include "libcamera/internal/value_node.h"
namespace libcamera {
@@ -18,7 +18,7 @@ class File;
class YamlParser final
{
public:
static std::unique_ptr<YamlObject> parse(File &file);
static std::unique_ptr<ValueNode> parse(File &file);
};
} /* namespace libcamera */