From f3446cbcea00f953462b82d4b75d8b098eb64883 Mon Sep 17 00:00:00 2001 From: beder Date: Wed, 11 Jan 2012 21:31:01 -0600 Subject: [PATCH] Added LoadFile and LoadAllFromFile (new API) --- include/yaml-cpp/node/parse.h | 2 ++ src/node/parse.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/yaml-cpp/node/parse.h b/include/yaml-cpp/node/parse.h index 1a8304b..82dbdc1 100644 --- a/include/yaml-cpp/node/parse.h +++ b/include/yaml-cpp/node/parse.h @@ -16,10 +16,12 @@ namespace YAML Node Load(const std::string& input); Node Load(const char *input); Node Load(std::istream& input); + Node LoadFile(const std::string& filename); std::vector LoadAll(const std::string& input); std::vector LoadAll(const char *input); std::vector LoadAll(std::istream& input); + std::vector LoadAllFromFile(const std::string& filename); } #endif // VALUE_PARSE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/src/node/parse.cpp b/src/node/parse.cpp index 3cbf196..3a33931 100644 --- a/src/node/parse.cpp +++ b/src/node/parse.cpp @@ -4,6 +4,7 @@ #include "yaml-cpp/parser.h" #include "nodebuilder.h" +#include #include namespace YAML @@ -27,6 +28,11 @@ namespace YAML return builder.Root(); } + Node LoadFile(const std::string& filename) { + std::ifstream fin(filename.c_str()); + return Load(fin); + } + std::vector LoadAll(const std::string& input) { std::stringstream stream(input); return LoadAll(stream); @@ -50,4 +56,9 @@ namespace YAML return docs; } + + std::vector LoadAllFromFile(const std::string& filename) { + std::ifstream fin(filename.c_str()); + return LoadAll(fin); + } }