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
This commit is contained in:
Danny Robson 2016-06-28 16:57:25 +10:00
parent d7204d7cac
commit 73c30561af
2 changed files with 20 additions and 4 deletions

View File

@ -247,6 +247,15 @@ MAP(
#undef INSTANTIATE
//-----------------------------------------------------------------------------
std::unique_ptr<json::tree::node>
json::tree::parse (const boost::filesystem::path &src)
{
const util::mapped_file data (src.string ().c_str ());
return parse (data.as_view<char> ());
}
///////////////////////////////////////////////////////////////////////////////
void
json::tree::write (const json::tree::node &node, std::ostream &os)

View File

@ -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 <iostream>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "../iterator.hpp"
#include "../view.hpp"
#include "./flat.hpp"
#include "./fwd.hpp"
#include <boost/filesystem/path.hpp>
namespace json { namespace tree {
enum type_t {
@ -43,6 +47,9 @@ namespace json { namespace tree {
std::unique_ptr<node>
parse (util::view<T> data);
std::unique_ptr<node>
parse (const boost::filesystem::path &);
extern void write (const json::tree::node&, std::ostream&);
/// Abstract base for all JSON values