|
|
@@ -7,27 +7,42 @@
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
-#if defined(LOGGING_USE_JSON)
|
|
|
+#include <iostream>
|
|
|
+
|
|
|
#if defined(LOGGING_JSON_SJAFFE)
|
|
|
-#include "json/json.hpp"
|
|
|
-namespace logging {
|
|
|
- typedef json::value json;
|
|
|
-}
|
|
|
-#elif defined(LOGGING_JSON_VALUE)
|
|
|
-#include "json/json_fwd.h"
|
|
|
-namespace logging {
|
|
|
- typedef Json::Value json;
|
|
|
-}
|
|
|
+# include "json/json.hpp"
|
|
|
+#endif
|
|
|
+#if defined(LOGGING_JSON_VALUE)
|
|
|
+# include <memory>
|
|
|
+# include "json/json.h"
|
|
|
#endif
|
|
|
+
|
|
|
namespace logging { namespace detail {
|
|
|
+ template <typename T> std::string to_string(T const & obj);
|
|
|
+
|
|
|
+// TODO: Establish bindings
|
|
|
+#if defined(LOGGING_JSON_SJAFFE)
|
|
|
+ template <typename T, typename S>
|
|
|
+ void to_stream(json::binder::visitor<T, S> const & visitor,
|
|
|
+ std::ostream & out) {
|
|
|
+ json::parser::write(visitor, out);
|
|
|
+ }
|
|
|
+
|
|
|
+ void to_stream(json::value const & obj, std::ostream & os) {
|
|
|
+ json::parser::write(obj, os);
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
+#if defined(LOGGING_JSON_VALUE)
|
|
|
+ void to_stream(Json::Value const & obj, std::ostream & os) {
|
|
|
+ Json::StreamWriterBuilder build;
|
|
|
+ std::unique_ptr<Json::StreamWriter> ptr(build.newStreamWriter());
|
|
|
+ return ptr->write(obj, &os);
|
|
|
+ }
|
|
|
+#endif
|
|
|
+
|
|
|
template <typename T>
|
|
|
- json to_json(T const & obj);
|
|
|
+ std::string to_json(T const & obj, bool compact = false) {
|
|
|
+ return to_string(obj);
|
|
|
+ }
|
|
|
} }
|
|
|
-#else
|
|
|
-namespace logging {
|
|
|
- typedef void json;
|
|
|
-}
|
|
|
-namespace logging { namespace detail {
|
|
|
- template <typename T> void to_json(T const &) {}
|
|
|
-} }
|
|
|
-#endif
|