Line data Source code
1 : /* 2 : * Copyright (C) 2004-2024 Savoir-faire Linux Inc. 3 : * 4 : * Authors: Alexandre Savard <alexandre.savard@savoirfairelinux.com> 5 : * Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> 6 : * 7 : * This program is free software; you can redistribute it and/or modify 8 : * it under the terms of the GNU General Public License as published by 9 : * the Free Software Foundation; either version 3 of the License, or 10 : * (at your option) any later version. 11 : * 12 : * This program is distributed in the hope that it will be useful, 13 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 : * GNU General Public License for more details. 16 : * 17 : * You should have received a copy of the GNU General Public License 18 : * along with this program; if not, write to the Free Software 19 : * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 : */ 21 : 22 : #pragma once 23 : 24 : #include "logger.h" 25 : 26 : #include <yaml-cpp/yaml.h> 27 : #include <filesystem> 28 : 29 : namespace jami { 30 : namespace yaml_utils { 31 : 32 : // set T to the value stored at key, or leaves T unchanged 33 : // if no value is stored. 34 : template<typename T> 35 : void 36 1206 : parseValue(const YAML::Node& node, const char* key, T& value) 37 : { 38 1206 : value = node[key].as<T>(); 39 1200 : } 40 : 41 : template<typename T> 42 : bool 43 0 : parseValueOptional(const YAML::Node& node, const char* key, T& value) 44 : { 45 : try { 46 0 : parseValue(node, key, value); 47 0 : return true; 48 0 : } catch (const std::exception& e) { 49 : // JAMI_DBG("Can't read yaml field: %s", key); 50 : } 51 0 : return false; 52 : } 53 : 54 : void parsePath(const YAML::Node& node, const char* key, std::string& path, const std::filesystem::path& base); 55 : void parsePathOptional(const YAML::Node& node, const char* key, std::string& path, const std::filesystem::path& base); 56 : 57 : std::vector<std::map<std::string, std::string>> parseVectorMap( 58 : const YAML::Node& node, const std::initializer_list<std::string>& keys); 59 : std::set<std::string> parseVector(const YAML::Node& node); 60 : 61 : } // namespace yaml_utils 62 : } // namespace jami