json: remove path based parsers

parsers don't store copies of the data, so we can't allow functions that
allocate data themselves.
This commit is contained in:
Danny Robson 2016-06-28 15:59:53 +10:00
parent bf5cab6156
commit d7204d7cac
3 changed files with 27 additions and 43 deletions

View File

@ -177,7 +177,10 @@ MAP(
std::string::iterator,
std::string::const_iterator,
const char*restrict
const char* restrict,
const char*,
char *restrict,
char *
)
#undef INSTANTIATE

View File

@ -20,10 +20,11 @@
#include "./except.hpp"
#include "./flat.hpp"
#include "../cast.hpp"
#include "../debug.hpp"
#include "../io.hpp"
#include "../maths.hpp"
#include "../cast.hpp"
#include "../preprocessor.hpp"
#include <algorithm>
#include <cstdlib>
@ -213,29 +214,6 @@ parse (typename std::vector<json::flat::item<T>>::const_iterator first,
///////////////////////////////////////////////////////////////////////////////
std::unique_ptr<json::tree::node>
json::tree::parse (const boost::filesystem::path &path)
{
const util::mapped_file f (path.string ().c_str ());
return parse<const char*restrict> (f.operator util::view<const char*restrict> ());
}
//-----------------------------------------------------------------------------
std::unique_ptr<json::tree::node>
json::tree::parse (const std::string &data)
{
return parse<std::string::const_iterator> (::util::make_view (data));
}
//-----------------------------------------------------------------------------
void
json::tree::write (const json::tree::node &node, std::ostream &os)
{ node.write (os); }
//-----------------------------------------------------------------------------
template <typename T>
std::unique_ptr<json::tree::node>
json::tree::parse (const util::view<T> src)
@ -250,22 +228,33 @@ json::tree::parse (const util::view<T> src)
return output;
}
#define INSTANTIATE(KLASS) \
template \
std::unique_ptr<json::tree::node> \
json::tree::parse (util::view<KLASS>);
MAP(
INSTANTIATE,
std::string::iterator,
std::string::const_iterator,
const char* restrict,
const char*,
char* restrict,
char *
);
#undef INSTANTIATE
///////////////////////////////////////////////////////////////////////////////
std::unique_ptr<json::tree::node>
json::tree::from_path (const char *path)
void
json::tree::write (const json::tree::node &node, std::ostream &os)
{
return json::tree::parse (boost::filesystem::path (path));
node.write (os);
}
//-----------------------------------------------------------------------------
std::unique_ptr<json::tree::node>
json::tree::from_path (const std::string &path)
{
return json::tree::from_path (path.c_str ());
}
///////////////////////////////////////////////////////////////////////////////
// Type conversion

View File

@ -23,8 +23,6 @@
#include <string>
#include <vector>
#include <boost/filesystem.hpp>
#include "../iterator.hpp"
#include "../view.hpp"
#include "./flat.hpp"
@ -41,16 +39,10 @@ namespace json { namespace tree {
};
/// Parse an encoded form of JSON into a tree structure
extern std::unique_ptr<node> parse (const boost::filesystem::path &path);
extern std::unique_ptr<node> parse (const std::string &data);
template <typename T>
std::unique_ptr<node>
parse (util::view<T> data);
extern std::unique_ptr<node> from_path (const char *path);
extern std::unique_ptr<node> from_path (const std::string&);
extern void write (const json::tree::node&, std::ostream&);
/// Abstract base for all JSON values