From 76c9f40c4242236895a910a9fde6edf741af64a6 Mon Sep 17 00:00:00 2001 From: Pras Velagapudi Date: Sun, 13 Feb 2022 05:38:54 -0500 Subject: [PATCH] Added simple loading utility. --- include/valijson/utils/yaml_cpp_utils.hpp | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 include/valijson/utils/yaml_cpp_utils.hpp diff --git a/include/valijson/utils/yaml_cpp_utils.hpp b/include/valijson/utils/yaml_cpp_utils.hpp new file mode 100644 index 0000000..6c93800 --- /dev/null +++ b/include/valijson/utils/yaml_cpp_utils.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include +#include +#include + +#include + +#include + +namespace valijson { +namespace utils { + +inline bool loadDocument(const std::string &path, YAML::Node &document) +{ + try { + document = YAML::LoadFile(path); + return true; + } catch (const YAML::BadFile &ex) { + std::cerr << "Failed to load YAML from file '" << path << "'." << std::endl; + return false; + } catch (const YAML::ParserException &ex) { + std::cout << "yaml-cpp failed to parse the document '" << ex.what() << std::endl; + return false; + } +} + +} // namespace utils +} // namespace valijson