You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

formatter.h 942B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // Copyright(c) 2015 Gabi Melman.
  3. // Distributed under the MIT License (http://opensource.org/licenses/MIT)
  4. //
  5. #pragma once
  6. #include <spdlog/details/log_msg.h>
  7. #include <vector>
  8. #include <string>
  9. #include <memory>
  10. namespace spdlog
  11. {
  12. namespace details
  13. {
  14. class flag_formatter;
  15. }
  16. class formatter
  17. {
  18. public:
  19. virtual ~formatter() {}
  20. virtual void format(details::log_msg& msg) = 0;
  21. };
  22. class pattern_formatter : public formatter
  23. {
  24. public:
  25. explicit pattern_formatter(const std::string& pattern);
  26. pattern_formatter(const pattern_formatter&) = delete;
  27. pattern_formatter& operator=(const pattern_formatter&) = delete;
  28. void format(details::log_msg& msg) override;
  29. private:
  30. const std::string _pattern;
  31. std::vector<std::unique_ptr<details::flag_formatter>> _formatters;
  32. void handle_flag(char flag);
  33. void compile_pattern(const std::string& pattern);
  34. };
  35. }
  36. #include <spdlog/details/pattern_formatter_impl.h>