Member functions should be implemented in the .cpp file in the same order as in the class definition, within each access group. Move them to the right location. While at it, move load() before loadFile() in the class definition to match execution order, making the code easier to read. 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>
63 lines
1.4 KiB
C++
63 lines
1.4 KiB
C++
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
|
/*
|
|
* Copyright (C) 2024-2025 Red Hat, inc.
|
|
*
|
|
* Global configuration handling
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <filesystem>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
#include <libcamera/base/utils.h>
|
|
|
|
#include "libcamera/internal/value_node.h"
|
|
|
|
namespace libcamera {
|
|
|
|
class GlobalConfiguration
|
|
{
|
|
public:
|
|
using Configuration = const ValueNode &;
|
|
|
|
GlobalConfiguration();
|
|
|
|
unsigned int version() const;
|
|
Configuration configuration() const;
|
|
|
|
template<typename T>
|
|
std::optional<T> option(
|
|
const std::initializer_list<std::string_view> confPath) const
|
|
{
|
|
const ValueNode *c = &configuration();
|
|
for (auto part : confPath) {
|
|
c = &(*c)[part];
|
|
if (!*c)
|
|
return {};
|
|
}
|
|
return c->get<T>();
|
|
}
|
|
|
|
std::optional<std::vector<std::string>> listOption(
|
|
const std::initializer_list<std::string_view> confPath) const;
|
|
std::optional<std::string> envOption(
|
|
const char *const envVariable,
|
|
const std::initializer_list<std::string_view> confPath) const;
|
|
std::optional<std::vector<std::string>> envListOption(
|
|
const char *const envVariable,
|
|
const std::initializer_list<std::string_view> confPath,
|
|
const std::string delimiter = ":") const;
|
|
|
|
private:
|
|
void load();
|
|
bool loadFile(const std::filesystem::path &fileName);
|
|
|
|
std::unique_ptr<ValueNode> yamlConfiguration_ =
|
|
std::make_unique<ValueNode>();
|
|
};
|
|
|
|
} /* namespace libcamera */
|