#pragma once #include "json_binder.hpp" #include "json/json_common.hpp" #include #include namespace json { namespace binder { template class visitor { public: visitor(S& o, binder_impl& b) : obj(o), b(b) {} void parse(char const* data, parser::options opts) { b.parse(obj, data, opts); if ( json::helper::get_next_element(data) && opts & parser::disable_concatenated_json_bodies ) { throw malformed_json_exception{ "Config set to require json input be terminated" }; } } void write(std::ostream & data) const { b.write(obj, data); } private: S& obj; binder_impl& b; }; template visitor bind(S& object, binder_impl& b) { return {object, b}; } } } namespace json { namespace parser { template void parse(binder::visitor& visitor, char const* data, options opts = allow_all) { visitor.parse(data, opts); } template void write(binder::visitor const & visitor, std::ostream & out) { visitor.write(out); } template void write(binder::visitor const & visitor, std::string & data) { std::stringstream ss; visitor.write(ss); data = ss.str(); } } }