diff --git a/inc/Logger.h b/inc/Logger.h index c4e2d4f..39d357e 100644 --- a/inc/Logger.h +++ b/inc/Logger.h @@ -6,8 +6,8 @@ #include #include -#include #include +#include /* @@ -17,18 +17,24 @@ */ +namespace detail { + template concept output_policy_c = requires(T t) { t.write('c'); }; +} // namespace detail -template + +template class Logger { -public: - Logger(output_policy_t output_policy) : m_output_policy(output_policy) {} - template +public: + Logger(output_policy_t output_policy) : m_output_policy(output_policy) { + } + + template void log(args_t...) { constexpr int len = get_output_len(msg); static_assert(len > 0, "Syntax error in log string"); diff --git a/inc/parsing.h b/inc/parsing.h index 94e26b2..3111ba2 100644 --- a/inc/parsing.h +++ b/inc/parsing.h @@ -1,11 +1,13 @@ -// -// Created by andreas on 11/18/21. -// - #ifndef LOGGER_PARSING_H #define LOGGER_PARSING_H +#include + + +namespace detail { + + // clang-format off /* @@ -38,12 +40,12 @@ // clang-format on -template +template constexpr bool is_digit(ConstString s, unsigned i) { return (s[i] > 47) && (s[i] < 58); } -template +template constexpr std::pair parse_number(ConstString s, unsigned i) { while ((i < s.size()) && is_digit(s, i)) { ++i; @@ -52,7 +54,7 @@ constexpr std::pair parse_number(ConstString s, unsigned i) { return {i, 0}; } -template +template constexpr std::pair parse_type(ConstString s, unsigned i) { if (s[i] == 's') { // string ++i; @@ -113,8 +115,9 @@ constexpr std::pair parse_type(ConstString s, unsigned i) { return {i, -1}; } -template -constexpr std::pair parse_fmt_string(ConstString s, unsigned i) { +template +constexpr std::pair parse_fmt_string(ConstString s, + unsigned i) { int result_extra_len = 0; if (s[i] == '0') @@ -143,13 +146,12 @@ constexpr std::pair parse_fmt_string(ConstString s, unsigned i return {i, -1}; i = new_i; result_extra_len += extra_len; - } return {i, result_extra_len}; } -template +template constexpr std::pair parse_braces(ConstString s, unsigned i) { int result_extra_len = 0; @@ -174,7 +176,7 @@ constexpr std::pair parse_braces(ConstString s, unsigned i) { return {i, -1}; } -template +template constexpr int get_output_len(ConstString s) { int result_extra_len = 0; @@ -197,4 +199,7 @@ constexpr int get_output_len(ConstString s) { } -#endif //LOGGER_PARSING_H +} // namespace detail + + +#endif // LOGGER_PARSING_H diff --git a/inc/utility.h b/inc/utility.h index f22ee41..fe6dad0 100644 --- a/inc/utility.h +++ b/inc/utility.h @@ -2,6 +2,9 @@ #define LOGGER_UTILITY_H +namespace detail { + + template class ConstString { public: @@ -15,14 +18,18 @@ public: } constexpr std::size_t size() const noexcept { - return N-1; + return N - 1; } std::array m_content; }; + template ConstString(const char (&)[N]) -> ConstString; -#endif //LOGGER_UTILITY_H +} // namespace detail + + +#endif // LOGGER_UTILITY_H diff --git a/src/main.cpp b/src/main.cpp index 2753e93..fec0435 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,7 +16,7 @@ int main() { Uart uart; Logger logger(uart); - logger.log<"Test format string: {} {}">(1, 2, 3); + logger.log<"Test format string: {:08.4f} {}">(1, 2, 3); return 0; } \ No newline at end of file