aboutsummaryrefslogtreecommitdiff
path: root/include/jsoncons/pretty_print.hpp
diff options
context:
space:
mode:
authorRichard <q@1bpm.net>2022-09-04 00:32:56 +0100
committerRichard <q@1bpm.net>2022-09-04 00:32:56 +0100
commit1d055261b4144dbf86b2658437015b15d4dd9bff (patch)
tree6049b19d1bf953a650383de1a5e438b8b82679f6 /include/jsoncons/pretty_print.hpp
downloadcsound-json-1d055261b4144dbf86b2658437015b15d4dd9bff.tar.gz
csound-json-1d055261b4144dbf86b2658437015b15d4dd9bff.tar.bz2
csound-json-1d055261b4144dbf86b2658437015b15d4dd9bff.zip
initial
Diffstat (limited to 'include/jsoncons/pretty_print.hpp')
-rw-r--r--include/jsoncons/pretty_print.hpp89
1 files changed, 89 insertions, 0 deletions
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 <string>
+#include <exception>
+#include <cstring>
+#include <ostream>
+#include <memory>
+#include <typeinfo>
+#include <cstring>
+#include <jsoncons/json_exception.hpp>
+#include <jsoncons/json_options.hpp>
+#include <jsoncons/json_encoder.hpp>
+#include <jsoncons/json_type_traits.hpp>
+#include <jsoncons/json_error.hpp>
+
+namespace jsoncons {
+
+template<class Json>
+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<char_type>& options,
+ indenting line_indent)
+ : j_(&j), options_(options), indenting_(line_indent)
+ {
+ }
+
+ void dump(std::basic_ostream<char_type>& os) const
+ {
+ j_->dump(os, options_, indenting_);
+ }
+
+ friend std::basic_ostream<char_type>& operator<<(std::basic_ostream<char_type>& os, const json_printable<Json>& pr)
+ {
+ pr.dump(os);
+ return os;
+ }
+
+ const Json *j_;
+ basic_json_encode_options<char_type> options_;
+ indenting indenting_;
+private:
+ json_printable();
+};
+
+template<class Json>
+json_printable<Json> print(const Json& j)
+{
+ return json_printable<Json>(j, indenting::no_indent);
+}
+
+template<class Json>
+json_printable<Json> print(const Json& j,
+ const basic_json_encode_options<typename Json::char_type>& options)
+{
+ return json_printable<Json>(j, options, indenting::no_indent);
+}
+
+template<class Json>
+json_printable<Json> pretty_print(const Json& j)
+{
+ return json_printable<Json>(j, indenting::indent);
+}
+
+template<class Json>
+json_printable<Json> pretty_print(const Json& j,
+ const basic_json_encode_options<typename Json::char_type>& options)
+{
+ return json_printable<Json>(j, options, indenting::indent);
+}
+
+}
+
+#endif