// // to_json.h // logger // // Created by Sam Jaffe on 4/4/19. // #pragma once #include #if defined(LOGGING_JSON_SJAFFE) # include "json/json.hpp" #endif #if defined(LOGGING_JSON_VALUE) # include # include "json/json.h" #endif namespace logging { namespace detail { template std::string to_string(T const & obj); // TODO: Establish bindings #if defined(LOGGING_JSON_SJAFFE) template void to_stream(json::binder::visitor 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 ptr(build.newStreamWriter()); return ptr->write(obj, &os); } #endif template std::string to_json(T const & obj, bool compact = false) { return to_string(obj); } } }