Ring Daemon 16.0.0
Loading...
Searching...
No Matches
yamlparser.cpp
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
18#include "yamlparser.h"
19#include "fileutils.h"
20
21namespace jami {
22namespace yaml_utils {
23
24void
25parsePath(const YAML::Node& node, const char* key, std::string& path, const std::filesystem::path& base)
26{
27 std::string val;
28 parseValue(node, key, val);
29 path = fileutils::getFullPath(base, val).string();
30}
31
32void
33parsePathOptional(const YAML::Node& node, const char* key, std::string& path, const std::filesystem::path& base)
34{
35 std::string val;
36 if (parseValueOptional(node, key, val))
37 path = fileutils::getFullPath(base, val).string();
38}
39
40std::vector<std::map<std::string, std::string>>
41parseVectorMap(const YAML::Node& node, const std::initializer_list<std::string>& keys)
42{
43 std::vector<std::map<std::string, std::string>> result;
44 result.reserve(node.size());
45 for (const auto& n : node) {
46 std::map<std::string, std::string> t;
47 for (const auto& k : keys) {
48 t[k] = n[k].as<std::string>("");
49 }
50 result.emplace_back(std::move(t));
51 }
52 return result;
53}
54
55std::set<std::string>
56parseVector(const YAML::Node& node)
57{
58 std::set<std::string> result;
59 for (const auto& n : node) {
60 result.emplace(n.as<std::string>(""));
61 }
62 return result;
63}
64} // namespace yaml_utils
65} // namespace jami
std::filesystem::path getFullPath(const std::filesystem::path &base, const std::filesystem::path &path)
If path is relative, it is appended to base.
void parseValue(const YAML::Node &node, const char *key, T &value)
Definition yamlparser.h:31
std::set< std::string > parseVector(const YAML::Node &node)
std::vector< std::map< std::string, std::string > > parseVectorMap(const YAML::Node &node, const std::initializer_list< std::string > &keys)
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