From 3392ab980e38b2d737decd3410dfe886e0ec3b47 Mon Sep 17 00:00:00 2001 From: Jesse Beder Date: Thu, 12 May 2016 23:20:03 -0500 Subject: [PATCH] Update doc, formatting for parse.h. --- include/yaml-cpp/node/parse.h | 50 ++++++++++++++++++++++++++++++++++- src/parse.cpp | 14 ++++++---- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/include/yaml-cpp/node/parse.h b/include/yaml-cpp/node/parse.h index 0ea4948..7745fd7 100644 --- a/include/yaml-cpp/node/parse.h +++ b/include/yaml-cpp/node/parse.h @@ -16,15 +16,63 @@ namespace YAML { class Node; +/** + * Loads the input string as a single YAML document. + * + * @throws {@link ParserException} if it is malformed. + */ YAML_CPP_API Node Load(const std::string& input); + +/** + * Loads the input string as a single YAML document. + * + * @throws {@link ParserException} if it is malformed. + */ YAML_CPP_API Node Load(const char* input); + +/** + * Loads the input stream as a single YAML document. + * + * @throws {@link ParserException} if it is malformed. + */ YAML_CPP_API Node Load(std::istream& input); + +/** + * Loads the input file as a single YAML document. + * + * @throws {@link ParserException} if it is malformed. + * @throws {@link BadFile} if the file cannot be loaded. + */ YAML_CPP_API Node LoadFile(const std::string& filename); +/** + * Loads the input string as a list of YAML documents. + * + * @throws {@link ParserException} if it is malformed. + */ YAML_CPP_API std::vector LoadAll(const std::string& input); + +/** + * Loads the input string as a list of YAML documents. + * + * @throws {@link ParserException} if it is malformed. + */ YAML_CPP_API std::vector LoadAll(const char* input); + +/** + * Loads the input stream as a list of YAML documents. + * + * @throws {@link ParserException} if it is malformed. + */ YAML_CPP_API std::vector LoadAll(std::istream& input); + +/** + * Loads the input file as a list of YAML documents. + * + * @throws {@link ParserException} if it is malformed. + * @throws {@link BadFile} if the file cannot be loaded. + */ YAML_CPP_API std::vector LoadAllFromFile(const std::string& filename); -} +} // namespace YAML #endif // VALUE_PARSE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/src/parse.cpp b/src/parse.cpp index 1ef474d..0b2ae4a 100644 --- a/src/parse.cpp +++ b/src/parse.cpp @@ -22,16 +22,18 @@ Node Load(const char* input) { Node Load(std::istream& input) { Parser parser(input); NodeBuilder builder; - if (!parser.HandleNextDocument(builder)) + if (!parser.HandleNextDocument(builder)) { return Node(); + } return builder.Root(); } Node LoadFile(const std::string& filename) { std::ifstream fin(filename.c_str()); - if (!fin) + if (!fin) { throw BadFile(); + } return Load(fin); } @@ -51,8 +53,9 @@ std::vector LoadAll(std::istream& input) { Parser parser(input); while (1) { NodeBuilder builder; - if (!parser.HandleNextDocument(builder)) + if (!parser.HandleNextDocument(builder)) { break; + } docs.push_back(builder.Root()); } @@ -61,8 +64,9 @@ std::vector LoadAll(std::istream& input) { std::vector LoadAllFromFile(const std::string& filename) { std::ifstream fin(filename.c_str()); - if (!fin) + if (!fin) { throw BadFile(); + } return LoadAll(fin); } -} +} // namespace YAML