| 1234567891011121314151617181920212223242526272829303132333435363738 |
- #pragma once
- #include "json/json_common.hpp"
- #include <iostream>
- namespace json { namespace binder {
- template <typename T> class binder_impl {
- public:
- virtual binder_impl<T> * clone() const = 0;
- virtual ~binder_impl() {}
- virtual void parse(T &, char const *&, parser::options) const = 0;
- virtual void write(T const &, std::ostream &) const = 0;
- };
- template <typename T> class binder {
- public:
- binder() : impl(nullptr) {}
- binder(binder const & other) : impl(other.impl->clone()) {}
- binder(binder_impl<T> const * p) : impl(p) {}
- binder(binder_impl<T> const & r) : impl(r.clone()) {}
- ~binder() { delete impl; }
- void parse(T & object, char const *& data, parser::options opts) const {
- if (!impl) return; // error?
- impl->parse(object, data, opts);
- }
- void write(T const & object, std::ostream & data) const {
- if (!impl) return; // error?
- impl->write(object, data);
- }
- private:
- binder_impl<T> const * impl;
- };
- }}
|