Put everything into a new 'const_fmt' namespace; Renamed namespace detail to const_fmt_detail
This commit is contained in:
parent
70fd273a70
commit
2ecc001a64
@ -4,12 +4,12 @@
|
|||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
#include "format_impl.h"
|
||||||
#include "parse.h"
|
#include "parse.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
#include "format_impl.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace detail {
|
namespace const_fmt { namespace const_fmt_detail {
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -42,12 +42,12 @@ constexpr inline void check_fmt_params() {
|
|||||||
|
|
||||||
template <fmt_data_t fmt_data, std::integral arg_t>
|
template <fmt_data_t fmt_data, std::integral arg_t>
|
||||||
constexpr inline void format_arg(char* dest, arg_t arg) {
|
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 <fmt_data_t fmt_data, std::floating_point arg_t>
|
template <fmt_data_t fmt_data, std::floating_point arg_t>
|
||||||
constexpr inline void format_arg(char* dest, arg_t arg){
|
constexpr inline void format_arg(char* dest, arg_t arg){
|
||||||
//detail::format_float(dest, arg, fmt_data);
|
// const_fmt_detail::format_float(dest, arg, fmt_data);
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Error handling
|
// TODO: Error handling
|
||||||
@ -74,14 +74,16 @@ constexpr inline void format_args(char*) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <auto fmt_data_array, typename first_arg_t, typename... args_t>
|
template <auto fmt_data_array, typename first_arg_t, typename... args_t>
|
||||||
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<fmt_data_array[0]>(dest + fmt_data_array[0].position, first_arg);
|
format_arg<fmt_data_array[0]>(dest + fmt_data_array[0].position, first_arg);
|
||||||
format_args<drop_first(fmt_data_array)>(dest, args...);
|
format_args<drop_first(fmt_data_array)>(dest, args...);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <auto ast>
|
template <auto ast>
|
||||||
consteval inline std::array<char, get_ast_output_len<ast>()> get_preproc_string() {
|
consteval inline std::array<char, get_ast_output_len<ast>()>
|
||||||
|
get_preproc_string() {
|
||||||
auto result = get_init_array<get_ast_output_len<ast>()>('f');
|
auto result = get_init_array<get_ast_output_len<ast>()>('f');
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -97,7 +99,7 @@ consteval inline std::array<char, get_ast_output_len<ast>()> get_preproc_string(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace detail
|
}} // namespace const_fmt::const_fmt_detail
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -107,20 +109,23 @@ consteval inline std::array<char, get_ast_output_len<ast>()> get_preproc_string(
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
template <detail::ConstString s, typename... args_t>
|
namespace const_fmt {
|
||||||
|
|
||||||
|
|
||||||
|
template <const_fmt_detail::ConstString s, typename... args_t>
|
||||||
constexpr inline auto format(args_t... args) {
|
constexpr inline auto format(args_t... args) {
|
||||||
constexpr auto ast = detail::parse_string<s>().value;
|
constexpr auto ast = const_fmt_detail::parse_string<s>().value;
|
||||||
constexpr auto fmt_data = detail::get_fmt_data<ast>();
|
constexpr auto fmt_data = const_fmt_detail::get_fmt_data<ast>();
|
||||||
|
|
||||||
auto result = detail::get_preproc_string<ast>();
|
auto result = const_fmt_detail::get_preproc_string<ast>();
|
||||||
|
|
||||||
detail::format_args<fmt_data>(result.begin(), args...);
|
const_fmt_detail::format_args<fmt_data>(result.begin(), args...);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template<detail::ConstString t_s>
|
template <const_fmt_detail::ConstString t_s>
|
||||||
class fmt_literal_obj_t {
|
class fmt_literal_obj_t {
|
||||||
public:
|
public:
|
||||||
template <typename... args_t>
|
template <typename... args_t>
|
||||||
@ -129,10 +134,13 @@ class fmt_literal_obj_t {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <detail::ConstString t_s>
|
template <const_fmt_detail::ConstString t_s>
|
||||||
constexpr auto operator""_fmt() {
|
constexpr auto operator""_fmt() {
|
||||||
return fmt_literal_obj_t<t_s>{};
|
return fmt_literal_obj_t<t_s>{};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace const_fmt
|
||||||
|
|
||||||
|
|
||||||
#endif // LOGGER_FORMAT_H
|
#endif // LOGGER_FORMAT_H
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
#include "utility.h"
|
#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
|
#endif // LOGGER_FORMAT_IMPL_H
|
||||||
|
|||||||
@ -37,7 +37,7 @@
|
|||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
|
|
||||||
namespace detail {
|
namespace const_fmt { namespace const_fmt_detail {
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -214,7 +214,8 @@ constexpr inline parse_result_t<fmt_node_t> parse_braces(unsigned i) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <ConstString s>
|
template <ConstString s>
|
||||||
constexpr inline parse_result_t<string_result_t<get_ast_len<s>()>> parse_string() {
|
constexpr inline parse_result_t<string_result_t<get_ast_len<s>()>>
|
||||||
|
parse_string() {
|
||||||
parse_result_t<string_result_t<get_ast_len<s>()>> result;
|
parse_result_t<string_result_t<get_ast_len<s>()>> result;
|
||||||
result.is_valid = true;
|
result.is_valid = true;
|
||||||
|
|
||||||
@ -242,7 +243,7 @@ constexpr inline parse_result_t<string_result_t<get_ast_len<s>()>> parse_string(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace detail
|
}} // namespace const_fmt::const_fmt_detail
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
|
|
||||||
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
|
#endif // LOGGER_TYPES_H
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
#include "types.h"
|
#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) {
|
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 <auto ast>
|
template <auto ast>
|
||||||
consteval inline std::array<fmt_data_t, count_ast_format_nodes<ast>()> get_fmt_data() {
|
consteval inline std::array<fmt_data_t, count_ast_format_nodes<ast>()>
|
||||||
|
get_fmt_data() {
|
||||||
std::array<fmt_data_t, count_ast_format_nodes<ast>()> result = {};
|
std::array<fmt_data_t, count_ast_format_nodes<ast>()> result = {};
|
||||||
|
|
||||||
std::size_t position = 0;
|
std::size_t position = 0;
|
||||||
@ -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
|
#endif // LOGGER_UTILITY_H
|
||||||
|
|||||||
@ -2,7 +2,8 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace detail;
|
using namespace const_fmt;
|
||||||
|
using namespace const_fmt::const_fmt_detail;
|
||||||
|
|
||||||
|
|
||||||
TEST(Format, positive_int) {
|
TEST(Format, positive_int) {
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
#include <const_fmt/parse.h>
|
#include <const_fmt/parse.h>
|
||||||
|
|
||||||
|
|
||||||
using namespace detail;
|
using namespace const_fmt::const_fmt_detail;
|
||||||
|
|
||||||
|
|
||||||
TEST(Parse, parse_number) {
|
TEST(Parse, parse_number) {
|
||||||
|
|||||||
@ -1,9 +1,11 @@
|
|||||||
#include <const_fmt/utility.h>
|
#include <const_fmt/utility.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
using namespace const_fmt;
|
||||||
|
|
||||||
TEST(Utility, const_pow) {
|
TEST(Utility, const_pow) {
|
||||||
EXPECT_EQ(detail::const_pow(10, 0), 1);
|
EXPECT_EQ(const_fmt_detail::const_pow(10, 0), 1);
|
||||||
EXPECT_EQ(detail::const_pow(0, 1), 0);
|
EXPECT_EQ(const_fmt_detail::const_pow(0, 1), 0);
|
||||||
EXPECT_EQ(detail::const_pow(2, 8), 0b1'0000'0000);
|
EXPECT_EQ(const_fmt_detail::const_pow(2, 8), 0b1'0000'0000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user