|
@@ -24,43 +24,27 @@ namespace json {
|
|
|
public:
|
|
public:
|
|
|
virtual binder_impl<T>* clone() const = 0;
|
|
virtual binder_impl<T>* clone() const = 0;
|
|
|
virtual ~binder_impl() {}
|
|
virtual ~binder_impl() {}
|
|
|
- virtual void parse(T&, char const*&) const = 0;
|
|
|
|
|
|
|
+ virtual void parse(T&, char const*&, parser::options) const = 0;
|
|
|
virtual void write(T const&, std::ostream &) const = 0;
|
|
virtual void write(T const&, std::ostream &) const = 0;
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
template <typename T>
|
|
|
class binder {
|
|
class binder {
|
|
|
public:
|
|
public:
|
|
|
- binder() :
|
|
|
|
|
- impl(nullptr) {
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- binder(binder const& other) :
|
|
|
|
|
- impl(other.impl->clone()) {
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- explicit binder(binder_impl<T> const* p) :
|
|
|
|
|
- impl(p) {
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ binder() : impl(nullptr) {}
|
|
|
|
|
+ binder(binder const& other) : impl(other.impl->clone()) {}
|
|
|
|
|
+ explicit binder(binder_impl<T> const* p) : impl(p) {}
|
|
|
|
|
+ explicit binder(binder_impl<T> const& r) : impl(r.clone()) {}
|
|
|
|
|
|
|
|
- explicit binder(binder_impl<T> const& r) :
|
|
|
|
|
- impl(r.clone()) {
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ ~binder() { delete impl; }
|
|
|
|
|
|
|
|
- ~binder() {
|
|
|
|
|
- if (impl) {
|
|
|
|
|
- delete impl;
|
|
|
|
|
- impl = nullptr;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- void parse(T& object, char const*& data) const {
|
|
|
|
|
- if (!impl) return;
|
|
|
|
|
- impl->parse(object, data);
|
|
|
|
|
|
|
+ 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 {
|
|
void write(T const& object, std::ostream & data) const {
|
|
|
- if (!impl) return;
|
|
|
|
|
|
|
+ if (!impl) return; // error?
|
|
|
impl->write(object, data);
|
|
impl->write(object, data);
|
|
|
}
|
|
}
|
|
|
private:
|
|
private:
|
|
@@ -72,8 +56,11 @@ namespace json {
|
|
|
public:
|
|
public:
|
|
|
visitor(S& o, binder_impl<T>& b) : obj(o), b(b) {}
|
|
visitor(S& o, binder_impl<T>& b) : obj(o), b(b) {}
|
|
|
|
|
|
|
|
- void parse(char const* data) {
|
|
|
|
|
- b.parse(obj, data);
|
|
|
|
|
|
|
+ void parse(char const* data, parser::options opts) {
|
|
|
|
|
+ b.parse(obj, data, opts);
|
|
|
|
|
+ if ( json::helper::get_next_element(data) && opts & parser::disable_concatenated_json_bodies ) {
|
|
|
|
|
+ throw malformed_json_exception{"Config set to require json input be terminated"};
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void write(std::ostream & data) const {
|
|
void write(std::ostream & data) const {
|
|
@@ -91,10 +78,10 @@ namespace json {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- namespace parser {
|
|
|
|
|
|
|
+ namespace parser {
|
|
|
template <typename T>
|
|
template <typename T>
|
|
|
- void parse(binder::visitor<T>& visitor, char const* data) {
|
|
|
|
|
- visitor.parse(data);
|
|
|
|
|
|
|
+ void parse(binder::visitor<T>& visitor, char const* data, options opts = allow_all) {
|
|
|
|
|
+ visitor.parse(data, opts);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
template <typename T, typename S>
|
|
template <typename T, typename S>
|