json_direct_binder.hpp 739 B

123456789101112131415161718192021222324252627282930313233
  1. //
  2. // json_direct_binder.hpp
  3. // json
  4. //
  5. // Created by Sam Jaffe on 4/23/16.
  6. //
  7. #pragma once
  8. namespace json { namespace binder {
  9. template <typename T, typename E, typename = void>
  10. class direct_binder : public binder_impl<T> {
  11. public:
  12. direct_binder(E T::*p, binder<E> const& i) :
  13. ptr(p), impl(i) {
  14. }
  15. virtual binder_impl<T>* clone() const override {
  16. return new direct_binder(*this);
  17. }
  18. virtual void parse(T& val, char const*& data, parser::options opts) const override {
  19. impl.parse(val.*ptr, data, opts);
  20. }
  21. virtual void write(T const& val, std::ostream & data) const override {
  22. impl.write(val.*ptr, data);
  23. }
  24. private:
  25. E T::*ptr;
  26. binder<E> impl;
  27. };
  28. } }