| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- //
- // to_json.h
- // logger
- //
- // Created by Sam Jaffe on 4/4/19.
- //
- #pragma once
- #include <iostream>
- #if defined(LOGGING_JSON_SJAFFE)
- # 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>
- std::string to_json(T const & obj, bool compact = false) {
- return "\"" + to_string(obj) + "\"";
- }
- } }
|