From 1d055261b4144dbf86b2658437015b15d4dd9bff Mon Sep 17 00:00:00 2001 From: Richard Date: Sun, 4 Sep 2022 00:32:56 +0100 Subject: initial --- include/jsoncons/pretty_print.hpp | 89 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 include/jsoncons/pretty_print.hpp (limited to 'include/jsoncons/pretty_print.hpp') diff --git a/include/jsoncons/pretty_print.hpp b/include/jsoncons/pretty_print.hpp new file mode 100644 index 0000000..599c1ce --- /dev/null +++ b/include/jsoncons/pretty_print.hpp @@ -0,0 +1,89 @@ +// Copyright 2013 Daniel Parker +// Distributed under the Boost license, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See https://github.com/danielaparker/jsoncons for latest version + +#ifndef JSONCONS_PRETTY_PRINT_HPP +#define JSONCONS_PRETTY_PRINT_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace jsoncons { + +template +class json_printable +{ +public: + using char_type = typename Json::char_type; + + json_printable(const Json& j, indenting line_indent) + : j_(&j), indenting_(line_indent) + { + } + + json_printable(const Json& j, + const basic_json_encode_options& options, + indenting line_indent) + : j_(&j), options_(options), indenting_(line_indent) + { + } + + void dump(std::basic_ostream& os) const + { + j_->dump(os, options_, indenting_); + } + + friend std::basic_ostream& operator<<(std::basic_ostream& os, const json_printable& pr) + { + pr.dump(os); + return os; + } + + const Json *j_; + basic_json_encode_options options_; + indenting indenting_; +private: + json_printable(); +}; + +template +json_printable print(const Json& j) +{ + return json_printable(j, indenting::no_indent); +} + +template +json_printable print(const Json& j, + const basic_json_encode_options& options) +{ + return json_printable(j, options, indenting::no_indent); +} + +template +json_printable pretty_print(const Json& j) +{ + return json_printable(j, indenting::indent); +} + +template +json_printable pretty_print(const Json& j, + const basic_json_encode_options& options) +{ + return json_printable(j, options, indenting::indent); +} + +} + +#endif -- cgit v1.2.3