diff --git a/const_fmt/format.h b/const_fmt/format.h index 6691a87..45806e1 100644 --- a/const_fmt/format.h +++ b/const_fmt/format.h @@ -4,12 +4,12 @@ #include +#include "format_impl.h" #include "parse.h" #include "utility.h" -#include "format_impl.h" -namespace detail { +namespace const_fmt { namespace const_fmt_detail { /* @@ -42,16 +42,16 @@ constexpr inline void check_fmt_params() { template constexpr inline void format_arg(char* dest, arg_t arg) { - detail::format_int(dest, arg, fmt_data); + const_fmt_detail::format_int(dest, arg, fmt_data); }; template -constexpr inline void format_arg(char* dest, arg_t arg) { - //detail::format_float(dest, arg, fmt_data); +constexpr inline void format_arg(char* dest, arg_t arg){ + // const_fmt_detail::format_float(dest, arg, fmt_data); }; // TODO: Error handling -template +template constexpr inline void format_arg(char* dest, const char* arg) { const std::size_t len = const_strlen(arg); if (len > fmt_data.length) return; @@ -74,14 +74,16 @@ constexpr inline void format_args(char*) { } template -constexpr inline void format_args(char* dest, first_arg_t first_arg, args_t... args) { +constexpr inline void format_args(char* dest, first_arg_t first_arg, + args_t... args) { format_arg(dest + fmt_data_array[0].position, first_arg); format_args(dest, args...); } template -consteval inline std::array()> get_preproc_string() { +consteval inline std::array()> +get_preproc_string() { auto result = get_init_array()>('f'); int i = 0; @@ -97,7 +99,7 @@ consteval inline std::array()> get_preproc_string( } -} // namespace detail +}} // namespace const_fmt::const_fmt_detail /* @@ -107,32 +109,38 @@ consteval inline std::array()> get_preproc_string( */ -template +namespace const_fmt { + + +template constexpr inline auto format(args_t... args) { - constexpr auto ast = detail::parse_string().value; - constexpr auto fmt_data = detail::get_fmt_data(); + constexpr auto ast = const_fmt_detail::parse_string().value; + constexpr auto fmt_data = const_fmt_detail::get_fmt_data(); - auto result = detail::get_preproc_string(); + auto result = const_fmt_detail::get_preproc_string(); - detail::format_args(result.begin(), args...); + const_fmt_detail::format_args(result.begin(), args...); return result; } -template +template class fmt_literal_obj_t { - public: - template - constexpr auto operator()(args_t... args) { - return format(args...); - } +public: + template + constexpr auto operator()(args_t... args) { + return format(args...); + } }; -template +template constexpr auto operator""_fmt() { return fmt_literal_obj_t{}; } +} // namespace const_fmt + + #endif // LOGGER_FORMAT_H diff --git a/const_fmt/format_impl.h b/const_fmt/format_impl.h index 2624ae0..2cd6cc5 100644 --- a/const_fmt/format_impl.h +++ b/const_fmt/format_impl.h @@ -16,7 +16,7 @@ #include "utility.h" -namespace detail { +namespace const_fmt { namespace const_fmt_detail { /* @@ -148,7 +148,7 @@ constexpr inline void format_float(char* out, float_t value, } -} // namespace detail +}} // namespace const_fmt::const_fmt_detail #endif // LOGGER_FORMAT_IMPL_H diff --git a/const_fmt/parse.h b/const_fmt/parse.h index f1da473..e5350b6 100644 --- a/const_fmt/parse.h +++ b/const_fmt/parse.h @@ -37,7 +37,7 @@ // clang-format on -namespace detail { +namespace const_fmt { namespace const_fmt_detail { /* @@ -119,42 +119,42 @@ constexpr inline parse_result_t parse_number(unsigned i) { template constexpr inline parse_result_t parse_type(unsigned i) { switch (s[i]) { - case 's': - return {true, ++i, FormatType::s}; - case 'c': - return {true, ++i, FormatType::c}; - case 'b': - return {true, ++i, FormatType::b}; - case 'B': - return {true, ++i, FormatType::B}; - case 'd': - return {true, ++i, FormatType::d}; - case 'o': - return {true, ++i, FormatType::o}; - case 'x': - return {true, ++i, FormatType::x}; - case 'X': - return {true, ++i, FormatType::X}; - case 'a': - return {true, ++i, FormatType::a}; - case 'A': - return {true, ++i, FormatType::A}; - case 'e': - return {true, ++i, FormatType::e}; - case 'E': - return {true, ++i, FormatType::E}; - case 'f': - return {true, ++i, FormatType::f}; - case 'F': - return {true, ++i, FormatType::F}; - case 'g': - return {true, ++i, FormatType::g}; - case 'G': - return {true, ++i, FormatType::G}; - case 'p': - return {true, ++i, FormatType::p}; - default: - return {false, i, FormatType::s}; + case 's': + return {true, ++i, FormatType::s}; + case 'c': + return {true, ++i, FormatType::c}; + case 'b': + return {true, ++i, FormatType::b}; + case 'B': + return {true, ++i, FormatType::B}; + case 'd': + return {true, ++i, FormatType::d}; + case 'o': + return {true, ++i, FormatType::o}; + case 'x': + return {true, ++i, FormatType::x}; + case 'X': + return {true, ++i, FormatType::X}; + case 'a': + return {true, ++i, FormatType::a}; + case 'A': + return {true, ++i, FormatType::A}; + case 'e': + return {true, ++i, FormatType::e}; + case 'E': + return {true, ++i, FormatType::E}; + case 'f': + return {true, ++i, FormatType::f}; + case 'F': + return {true, ++i, FormatType::F}; + case 'g': + return {true, ++i, FormatType::g}; + case 'G': + return {true, ++i, FormatType::G}; + case 'p': + return {true, ++i, FormatType::p}; + default: + return {false, i, FormatType::s}; } } @@ -214,7 +214,8 @@ constexpr inline parse_result_t parse_braces(unsigned i) { } template -constexpr inline parse_result_t()>> parse_string() { +constexpr inline parse_result_t()>> +parse_string() { parse_result_t()>> result; result.is_valid = true; @@ -242,7 +243,7 @@ constexpr inline parse_result_t()>> parse_string( } -} // namespace detail +}} // namespace const_fmt::const_fmt_detail diff --git a/const_fmt/types.h b/const_fmt/types.h index 1bd9049..071937a 100644 --- a/const_fmt/types.h +++ b/const_fmt/types.h @@ -5,7 +5,7 @@ #include -namespace detail { +namespace const_fmt { namespace const_fmt_detail { /* @@ -136,7 +136,7 @@ struct fmt_data_t { }; -} // namespace detail +}} // namespace const_fmt::const_fmt_detail #endif // LOGGER_TYPES_H diff --git a/const_fmt/utility.h b/const_fmt/utility.h index 0aba545..dd11140 100644 --- a/const_fmt/utility.h +++ b/const_fmt/utility.h @@ -7,7 +7,7 @@ #include "types.h" -namespace detail { +namespace const_fmt { namespace const_fmt_detail { constexpr inline std::size_t const_pow(std::size_t base, std::size_t pow) { @@ -41,7 +41,8 @@ consteval inline std::size_t count_ast_format_nodes() { template -consteval inline std::array()> get_fmt_data() { +consteval inline std::array()> +get_fmt_data() { std::array()> result = {}; std::size_t position = 0; @@ -96,7 +97,7 @@ consteval inline int get_ast_output_len() { return result; } -constexpr inline std::size_t const_strlen(const char* arg) { +constexpr inline std::size_t const_strlen(const char* arg) { if (std::is_constant_evaluated()) { return *arg ? 1 + const_strlen(arg + 1) : 0; } else { @@ -105,7 +106,7 @@ constexpr inline std::size_t const_strlen(const char* arg) { } -} // namespace detail +}} // namespace const_fmt::const_fmt_detail #endif // LOGGER_UTILITY_H diff --git a/test/src/format.cpp b/test/src/format.cpp index bf875db..0c1344c 100644 --- a/test/src/format.cpp +++ b/test/src/format.cpp @@ -2,7 +2,8 @@ #include -using namespace detail; +using namespace const_fmt; +using namespace const_fmt::const_fmt_detail; TEST(Format, positive_int) { diff --git a/test/src/parse.cpp b/test/src/parse.cpp index eb42a95..d7f0b34 100644 --- a/test/src/parse.cpp +++ b/test/src/parse.cpp @@ -2,7 +2,7 @@ #include -using namespace detail; +using namespace const_fmt::const_fmt_detail; TEST(Parse, parse_number) { diff --git a/test/src/utility.cpp b/test/src/utility.cpp index 0480b21..cdb7c30 100644 --- a/test/src/utility.cpp +++ b/test/src/utility.cpp @@ -1,9 +1,11 @@ #include #include +using namespace const_fmt; + TEST(Utility, const_pow) { - EXPECT_EQ(detail::const_pow(10, 0), 1); - EXPECT_EQ(detail::const_pow(0, 1), 0); - EXPECT_EQ(detail::const_pow(2, 8), 0b1'0000'0000); + EXPECT_EQ(const_fmt_detail::const_pow(10, 0), 1); + EXPECT_EQ(const_fmt_detail::const_pow(0, 1), 0); + EXPECT_EQ(const_fmt_detail::const_pow(2, 8), 0b1'0000'0000); }