| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- //
- // json_direct_binder.hpp
- // json
- //
- // Created by Sam Jaffe on 4/23/16.
- //
- #pragma once
- #include "json_binder.hpp"
- namespace json { namespace binder {
- template <typename T, typename E, typename = void> class direct_binder;
- template <typename T, typename E, typename = void>
- class forward_binder : public binder_impl<T> {
- public:
- forward_binder(E T::*p, binder<E> const & i) : ptr(p), impl(i) {}
- virtual binder_impl<T> * clone() const override {
- return new forward_binder(*this);
- }
- virtual void parse(T & val, char const *& data,
- parser::options opts) const override {
- impl.parse(val.*ptr, data, opts);
- }
- virtual void write(T const & val, std::ostream & data) const override {
- impl.write(val.*ptr, data);
- }
- private:
- E T::*ptr;
- binder<E> impl;
- };
- template <typename T> class value_binder : public binder_impl<T> {
- private:
- struct detail {
- T value;
- };
- public:
- template <typename... Args>
- value_binder(Args &&... args) : impl(&detail::value, args...) {}
- virtual binder_impl<T> * clone() const override {
- return new value_binder(*this);
- }
- virtual void parse(T & val, char const *& data,
- parser::options opts) const override {
- detail tmp;
- impl.parse(tmp, data, opts);
- val = std::move(tmp.value);
- }
- virtual void write(T const & val, std::ostream & data) const override {
- impl.write({val}, data);
- }
- private:
- direct_binder<detail, T> impl;
- };
- }}
|