message_stringifier.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #pragma once
  2. //
  3. // Copyright (c) 2019-2024 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
  4. //
  5. // Distributed under the MIT Software License
  6. //
  7. #include "rotor/export.h"
  8. #include <string>
  9. #include <sstream>
  10. #include <memory>
  11. #if defined(_MSC_VER)
  12. #pragma warning(push)
  13. #pragma warning(disable : 4251)
  14. #endif
  15. namespace rotor {
  16. struct message_base_t;
  17. /** \struct message_stringifier_t
  18. * \brief Abstract interface for making textual/string representation of a message
  19. *
  20. * As the concrete/final message type might not be known at compile time
  21. * the message stringifier tries to do it's best by guessing final message type.
  22. * (In other words, because the double dispatch visitor pattern is not available).
  23. *
  24. * That means that the message stringifier potentially has **LOW PERFORMANCE**
  25. * and should NOT be used, for example, for logging every message at least in
  26. * production code.
  27. *
  28. */
  29. struct ROTOR_API message_stringifier_t {
  30. virtual ~message_stringifier_t() = default;
  31. /** \brief returns string representation of a message */
  32. virtual std::string stringify(const message_base_t &) const;
  33. /** \brief dumps string representation of a message to output stream */
  34. virtual void stringify_to(std::ostream &, const message_base_t &) const = 0;
  35. };
  36. /** \brief smart pointer for message stringifier */
  37. using message_stringifier_ptr_t = std::unique_ptr<message_stringifier_t>;
  38. }; // namespace rotor
  39. #if defined(_MSC_VER)
  40. #pragma warning(pop)
  41. #endif