Line data Source code
1 : /* 2 : * Copyright (C) 2004-2024 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 : 24 : namespace jami { 25 : namespace yaml_utils { 26 : 27 : // set T to the value stored at key, or leaves T unchanged 28 : // if no value is stored. 29 : template<typename T> 30 : void 31 1206 : parseValue(const YAML::Node& node, const char* key, T& value) 32 : { 33 1206 : value = node[key].as<T>(); 34 1200 : } 35 : 36 : template<typename T> 37 : bool 38 0 : parseValueOptional(const YAML::Node& node, const char* key, T& value) 39 : { 40 : try { 41 0 : parseValue(node, key, value); 42 0 : return true; 43 0 : } catch (const std::exception& e) { 44 : // JAMI_DBG("Unable to read yaml field: %s", key); 45 : } 46 0 : return false; 47 : } 48 : 49 : void parsePath(const YAML::Node& node, const char* key, std::string& path, const std::filesystem::path& base); 50 : void parsePathOptional(const YAML::Node& node, const char* key, std::string& path, const std::filesystem::path& base); 51 : 52 : std::vector<std::map<std::string, std::string>> parseVectorMap( 53 : const YAML::Node& node, const std::initializer_list<std::string>& keys); 54 : std::set<std::string> parseVector(const YAML::Node& node); 55 : 56 : } // namespace yaml_utils 57 : } // namespace jami