| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- //
- // wrapper_object.hpp
- // logging
- //
- // Created by Sam Jaffe on 4/4/19.
- //
- #pragma once
- #include <iostream>
- #include <string>
- #include "detail/to_string.h"
- #include "detail/to_json.h"
- namespace logging { namespace detail {
- class object {
- public:
- template <typename T> 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 <typename> static std::string to_string_impl(void * ptr);
- template <typename> static Json::Value to_json_impl(void * ptr);
- private:
- void * ptr_;
- std::string (*to_string_)(void*);
- Json::Value (*to_json_)(void*);
- };
-
-
- template <typename T>
- std::string object::to_string_impl(void * ptr) {
- return to_string(*static_cast<T*>(ptr));
- }
- template <typename T>
- Json::Value object::to_json_impl(void * ptr) {
- return to_json(*static_cast<T*>(ptr));
- }
- template <typename T>
- object::object(T & object)
- : ptr_(&object),
- to_string_(&object::to_string_impl<T>),
- to_json_(&object::to_json_impl<T>) {
-
- }
- } }
|