// // wrapper_object.hpp // logging // // Created by Sam Jaffe on 4/4/19. // #pragma once #include #include #include #include namespace logging { namespace detail { class object { public: template explicit object(T & object); Json::Value json() const { return to_json_(ptr_); } private: friend std::ostream & operator<<(std::ostream & os, object const & obj) { return os << obj.to_string_(obj.ptr_); } template static std::string to_string_impl(void * ptr); template static Json::Value to_json_impl(void * ptr); private: void * ptr_; std::string (*to_string_)(void*); Json::Value (*to_json_)(void*); }; template void to_stream(T const & obj, std::ostream & os) { os << obj; } template std::string to_string(T const & obj) { std::stringstream ss; to_stream(obj, ss); return ss.str(); } template Json::Value to_json(T const & obj) { return to_string(obj); } template std::string object::to_string_impl(void * ptr) { return to_string(*static_cast(ptr)); } template Json::Value object::to_json_impl(void * ptr) { return to_json(*static_cast(ptr)); } template object::object(T & object) : ptr_(&object), to_string_(&object::to_string_impl), to_json_(&object::to_json_impl) { } } }