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