Wrapped everything in namespaces
This commit is contained in:
parent
e028e43b6a
commit
83332cc295
16
inc/Logger.h
16
inc/Logger.h
@ -6,8 +6,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
|
||||||
#include <utility.h>
|
|
||||||
#include <parsing.h>
|
#include <parsing.h>
|
||||||
|
#include <utility.h>
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -17,18 +17,24 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
concept output_policy_c = requires(T t) {
|
concept output_policy_c = requires(T t) {
|
||||||
t.write('c');
|
t.write('c');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
template <output_policy_c output_policy_t>
|
|
||||||
|
template <detail::output_policy_c output_policy_t>
|
||||||
class Logger {
|
class Logger {
|
||||||
public:
|
|
||||||
Logger(output_policy_t output_policy) : m_output_policy(output_policy) {}
|
|
||||||
|
|
||||||
template<ConstString msg, typename... args_t>
|
public:
|
||||||
|
Logger(output_policy_t output_policy) : m_output_policy(output_policy) {
|
||||||
|
}
|
||||||
|
|
||||||
|
template <detail::ConstString msg, typename... args_t>
|
||||||
void log(args_t...) {
|
void log(args_t...) {
|
||||||
constexpr int len = get_output_len(msg);
|
constexpr int len = get_output_len(msg);
|
||||||
static_assert(len > 0, "Syntax error in log string");
|
static_assert(len > 0, "Syntax error in log string");
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
//
|
|
||||||
// Created by andreas on 11/18/21.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef LOGGER_PARSING_H
|
#ifndef LOGGER_PARSING_H
|
||||||
#define LOGGER_PARSING_H
|
#define LOGGER_PARSING_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <utility.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -114,7 +116,8 @@ constexpr std::pair<unsigned, int> parse_type(ConstString<N> s, unsigned i) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <std::size_t N>
|
template <std::size_t N>
|
||||||
constexpr std::pair<unsigned, int> parse_fmt_string(ConstString<N> s, unsigned i) {
|
constexpr std::pair<unsigned, int> parse_fmt_string(ConstString<N> s,
|
||||||
|
unsigned i) {
|
||||||
int result_extra_len = 0;
|
int result_extra_len = 0;
|
||||||
|
|
||||||
if (s[i] == '0')
|
if (s[i] == '0')
|
||||||
@ -143,7 +146,6 @@ constexpr std::pair<unsigned, int> parse_fmt_string(ConstString<N> s, unsigned i
|
|||||||
return {i, -1};
|
return {i, -1};
|
||||||
i = new_i;
|
i = new_i;
|
||||||
result_extra_len += extra_len;
|
result_extra_len += extra_len;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {i, result_extra_len};
|
return {i, result_extra_len};
|
||||||
@ -197,4 +199,7 @@ constexpr int get_output_len(ConstString<N> s) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
|
||||||
#endif // LOGGER_PARSING_H
|
#endif // LOGGER_PARSING_H
|
||||||
|
|||||||
@ -2,6 +2,9 @@
|
|||||||
#define LOGGER_UTILITY_H
|
#define LOGGER_UTILITY_H
|
||||||
|
|
||||||
|
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
|
||||||
template <std::size_t N>
|
template <std::size_t N>
|
||||||
class ConstString {
|
class ConstString {
|
||||||
public:
|
public:
|
||||||
@ -21,8 +24,12 @@ public:
|
|||||||
std::array<char, N> m_content;
|
std::array<char, N> m_content;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <std::size_t N>
|
template <std::size_t N>
|
||||||
ConstString(const char (&)[N]) -> ConstString<N>;
|
ConstString(const char (&)[N]) -> ConstString<N>;
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
|
||||||
#endif // LOGGER_UTILITY_H
|
#endif // LOGGER_UTILITY_H
|
||||||
|
|||||||
@ -16,7 +16,7 @@ int main() {
|
|||||||
Uart uart;
|
Uart uart;
|
||||||
|
|
||||||
Logger logger(uart);
|
Logger logger(uart);
|
||||||
logger.log<"Test format string: {} {}">(1, 2, 3);
|
logger.log<"Test format string: {:08.4f} {}">(1, 2, 3);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user