mirror of
https://github.com/tristanpenman/valijson.git
synced 2024-12-12 18:20:27 +01:00
Added simple loading utility.
This commit is contained in:
parent
66424a1116
commit
76c9f40c42
29
include/valijson/utils/yaml_cpp_utils.hpp
Normal file
29
include/valijson/utils/yaml_cpp_utils.hpp
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
#include <valijson/utils/file_utils.hpp>
|
||||
|
||||
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
|
Loading…
Reference in New Issue
Block a user