Ring Daemon 16.0.0
Loading...
Searching...
No Matches
yamlparser.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 Savoir-faire Linux Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include "logger.h"
20
21#include <yaml-cpp/yaml.h>
22#include <filesystem>
23
24namespace jami {
25namespace yaml_utils {
26
27// set T to the value stored at key, or leaves T unchanged
28// if no value is stored.
29template<typename T>
30void
31parseValue(const YAML::Node& node, const char* key, T& value)
32{
33 value = node[key].as<T>();
34}
35
36template<typename T>
37bool
38parseValueOptional(const YAML::Node& node, const char* key, T& value)
39{
40 try {
41 parseValue(node, key, value);
42 return true;
43 } catch (const std::exception& e) {
44 // JAMI_DBG("Unable to read yaml field: %s", key);
45 }
46 return false;
47}
48
49void parsePath(const YAML::Node& node, const char* key, std::string& path, const std::filesystem::path& base);
50void parsePathOptional(const YAML::Node& node, const char* key, std::string& path, const std::filesystem::path& base);
51
52std::vector<std::map<std::string, std::string>> parseVectorMap(
53 const YAML::Node& node, const std::initializer_list<std::string>& keys);
54std::set<std::string> parseVector(const YAML::Node& node);
55
56} // namespace yaml_utils
57} // namespace jami
void parseValue(const YAML::Node &node, const char *key, T &value)
Definition yamlparser.h:31
std::set< std::string > parseVector(const YAML::Node &node)
void parsePath(const YAML::Node &node, const char *key, std::string &path, const std::filesystem::path &base)
void parsePathOptional(const YAML::Node &node, const char *key, std::string &path, const std::filesystem::path &base)
bool parseValueOptional(const YAML::Node &node, const char *key, T &value)
Definition yamlparser.h:38
void emitSignal(Args... args)
Definition ring_signal.h:64