// // json_pointer_binder.hpp // json // // Created by Sam Jaffe on 11/15/18. // Copyright © 2018 Sam Jaffe. All rights reserved. // #pragma once #include "json_binder.hpp" namespace json { namespace binder { template class pointer_binder : public binder_impl

{ // Maybe a reference type using Tr = decltype(*std::declval

()); using T = typename std::remove_reference::type; public: pointer_binder(binder impl) : m_impl(impl) {} virtual binder_impl

* clone() const { return new pointer_binder(*this); } virtual void parse(P & v, char const *& data, parser::options opts) const { if (!strncmp(data, "null", 4)) v = nullptr; else m_impl.parse(*(v = P(new T)), data, opts); } void write(P const & v, std::ostream & os) const { if (v) m_impl.write(*v, os); else os << "null"; } private: binder m_impl; }; }}