| 123456789101112131415161718192021222324252627282930313233343536 |
- //
- // 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 <typename P>
- class pointer_binder : public binder_impl<P> {
- // Maybe a reference type
- using Tr = decltype(*std::declval<P>());
- using T = typename std::remove_reference<Tr>::type;
- public:
- pointer_binder(binder<T> impl) : m_impl(impl) {}
-
- virtual binder_impl<P>* 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<T> m_impl;
- };
- } }
|