From 73c30561af9f26fbdb273aae57f38cc8ee5357ad Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 28 Jun 2016 16:57:25 +1000 Subject: [PATCH] json/tree: reinstate path based parsers json::tree::node is a fat object, so it's safe to load the source data from within the parsing function --- json/tree.cpp | 9 +++++++++ json/tree.hpp | 15 +++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/json/tree.cpp b/json/tree.cpp index ef57ccc8..8b66bddf 100644 --- a/json/tree.cpp +++ b/json/tree.cpp @@ -247,6 +247,15 @@ MAP( #undef INSTANTIATE +//----------------------------------------------------------------------------- +std::unique_ptr +json::tree::parse (const boost::filesystem::path &src) +{ + const util::mapped_file data (src.string ().c_str ()); + return parse (data.as_view ()); +} + + /////////////////////////////////////////////////////////////////////////////// void json::tree::write (const json::tree::node &node, std::ostream &os) diff --git a/json/tree.hpp b/json/tree.hpp index 5a0e0199..acb2a78b 100644 --- a/json/tree.hpp +++ b/json/tree.hpp @@ -17,16 +17,20 @@ #ifndef __UTIL_JSON_TREE_HPP #define __UTIL_JSON_TREE_HPP +#include "./flat.hpp" +#include "./fwd.hpp" + +#include "../iterator.hpp" +#include "../view.hpp" + #include #include #include #include #include -#include "../iterator.hpp" -#include "../view.hpp" -#include "./flat.hpp" -#include "./fwd.hpp" +#include + namespace json { namespace tree { enum type_t { @@ -43,6 +47,9 @@ namespace json { namespace tree { std::unique_ptr parse (util::view data); + std::unique_ptr + parse (const boost::filesystem::path &); + extern void write (const json::tree::node&, std::ostream&); /// Abstract base for all JSON values