wrapper_object.h 792 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // wrapper_object.hpp
  3. // logging
  4. //
  5. // Created by Sam Jaffe on 4/4/19.
  6. //
  7. #pragma once
  8. #include <iosfwd>
  9. #include <string>
  10. #include "detail/to_string.h"
  11. namespace logging {
  12. class object {
  13. public:
  14. template <typename T>
  15. explicit object(T & object);
  16. std::string to_string() const;
  17. private:
  18. template <typename> static std::string to_string(void * ptr);
  19. private:
  20. void * ptr_;
  21. std::string (*to_string_)(void*);
  22. };
  23. std::ostream & operator<<(std::ostream &, object const &);
  24. template <typename T>
  25. std::string object::to_string(void * ptr) {
  26. return logging::detail::to_string(*static_cast<T*>(ptr));
  27. }
  28. template <typename T>
  29. object::object(T & object)
  30. : ptr_(&object), to_string_(&object::to_string<T>) {
  31. }
  32. }