| | 590 | template <bool FALSE> struct last_error_t { |
| | 591 | static std::string s; |
| | 592 | }; |
| | 593 | template <bool FALSE> std::string last_error_t<FALSE>::s; |
| | 594 | |
| | 595 | inline void set_last_error(const std::string& s) { |
| | 596 | last_error_t<false>::s = s; |
| | 597 | } |
| | 598 | |
| | 599 | inline const std::string& get_last_error() { |
| | 600 | return last_error_t<false>::s; |
| | 601 | } |
| | 602 | } |
| | 603 | |
| | 604 | inline std::istream& operator>>(std::istream& is, picojson::value& x) |
| | 605 | { |
| | 606 | picojson::set_last_error(std::string()); |
| | 607 | std::string err = picojson::parse(x, is); |
| | 608 | if (! err.empty()) { |
| | 609 | picojson::set_last_error(err); |
| | 610 | is.setstate(std::ios::failbit); |
| | 611 | } |
| | 612 | return is; |
| | 613 | } |
| | 614 | |
| | 615 | inline std::ostream& operator<<(std::ostream& os, const picojson::value& x) |
| | 616 | { |
| | 617 | x.serialize(std::ostream_iterator<char>(os)); |
| | 618 | return os; |