json_direct_get_binder.hpp 987 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. //
  2. // json_direct_tuple_binder.hpp
  3. // json
  4. //
  5. // Created by Sam Jaffe on 2/26/17.
  6. //
  7. #pragma once
  8. namespace json { namespace binder {
  9. template <typename T, std::size_t I>
  10. class get_binder : public binder_impl<T> {
  11. public:
  12. using value_type = typename std::remove_reference<decltype(std::get<I>(std::declval<T>()))>::type;
  13. get_binder(binder<value_type> val_binder)
  14. : impl(std::move(val_binder)) {
  15. }
  16. get_binder(binder_impl<value_type> const & val_binder = value_binder<value_type>())
  17. : impl(val_binder) {
  18. }
  19. virtual binder_impl<T>* clone() const override { return new get_binder(*this); }
  20. virtual void parse(T& object, char const*& data, parser::options opts) const override {
  21. impl.parse(std::get<I>(object), data, opts);
  22. }
  23. virtual void write(T const& val, std::ostream & data) const override {
  24. impl.write(std::get<I>(val), data);
  25. }
  26. private:
  27. binder<value_type> impl;
  28. };
  29. } }