Compare commits

...

6 Commits

Author SHA1 Message Date
943af9408c fix some error 2026-02-22 13:13:10 +03:00
28906c37b2 fix logger clang error 2026-02-22 12:57:30 +03:00
ba5d76c49c fix logic 2025-12-26 19:50:59 +03:00
7cb97ff8d9 add new comparator logic 2025-12-26 19:48:25 +03:00
bf2d4efcba fix abs from comparation 2025-11-21 18:56:41 +03:00
53adbf4d6e fix comparators func name 2025-11-21 12:28:53 +03:00
8 changed files with 119 additions and 86 deletions

View File

@@ -2,9 +2,9 @@
auto main(int argc, char *argv[]) -> int
{
std::vector<float> frequencies = { 30.81, 138.59, 146.83, 155.56, 164.81, 174.61, 185.00, 196.00, 207.65, 220.00, 233.08, 246.94 };
float c_array[] = { 130.81, 138.59, 146.83, 155.56, 164.81, 174.61, 185.00, 196.00, 207.65, 220.00, 233.08, 246.94 };
std::vector<float> frequencies = { 0, -0.000920129, 0.00195607, -0.00334136, 0.00524956, -0.0085677, 0.0140421, -0.0279224, 0.0594694, -0.468169, -1.3376, -2.26262, -3.03318, 3.08953, -3.11554, 3.12384, -3.12944, 3.13217, -3.1343, 3.13554, -3.13658, 3.13726, -3.13786, 3.13827, -3.13865, 3.13892, -3.13918, 3.13937, -3.13955, 3.13969, -3.13983, 3.13994, -3.14004, 3.14012, -3.14021, 3.14028, -3.14034, 3.1404, -3.14045, 3.1405, -3.14054, 3.14058, -3.14062, 3.14066, -3.14069, 3.14072, -3.14075, 3.14077, -3.1408, 3.14082, -3.14084, 3.14086, -3.14088, 3.1409, -3.14092, 3.14094, -3.14095, 3.14097, -3.14098, 3.141, -3.14101, 3.14102, -3.14103, 3.14104, -3.14105, 3.14107, -3.14108, 3.14109, -3.14109, 3.1411, -3.14111, 3.14111, -3.14113, 3.14114, -3.14113, 3.14116, -3.14116, 3.14116, -3.14117, 3.14118, -3.14118, 3.14119, -3.1412, 3.1412, -3.14121, 3.14121, -3.14122, 3.14122, -3.14123, 3.14123, -3.14124, 3.14125, -3.14125, 3.14125, -3.14125, 3.14126, -3.14126, 3.14127, -3.14127, 3.14127, -3.14128, 3.14129, -3.14128, 3.14128, -3.14129, 3.14131, -3.14129, 3.14131, -3.14131, 3.14131, -3.14132, 3.14131, -3.14131, 3.14132, -3.14132, 3.14132, -3.14134, 3.14136, -3.14131, 3.14133, -3.14135, 3.14133, -3.14135, 3.14134, -3.14136, 3.14133, -3.14137, 3.14135, -3.14135, 3.14135, -3.14136, 3.14137, -3.14136, 3.14136, -3.14138, 3.14136, -3.14139, 3.14137, -3.14137, 3.14137, -3.1414, 3.1414, -3.14137, 3.14139, -3.14138, 3.14138, -3.14138, 3.14139, -3.14139, 3.14141, -3.1414, 3.14142, -3.1414, 3.1414, -3.14142, 3.14141, -3.1414, 3.14142, -3.14141, 3.1414, -3.14141, 3.14142, -3.14143, 3.14141, -3.14141, 3.14143, -3.14142, 3.14141, -3.14143, 3.14142, -3.14141, 3.14142, -3.14143, 3.14141, -3.14143, 3.14146, -3.14142, 3.14144, -3.14142, 3.14144, -3.14143, 3.14145, -3.14143, 3.14146, -3.14144, 3.14144, -3.14146, 3.14142, -3.14145, 3.14148, -3.14144, 3.14146, -3.14146, 3.14144, -3.14145, 3.14144, -3.14148, 3.14143, -3.14148, 3.14145, -3.14145, 3.14146, -3.14145, 3.14143, -3.14147, 3.14145, -3.14145, 3.14145, -3.14147, 3.14147, -3.14145, 3.14147, -3.14147, 3.14146, -3.14148, 3.14146, -3.14148, 3.14147, -3.14145, 3.14147, -3.14145, 3.14146, -3.14146, 3.14147, -3.14148, 3.14147, -3.14149, 3.14147, -3.14147, 3.14152, -3.14148, 3.14149, -3.14148, 3.14151, -3.1415, 3.14151, -3.14152, 3.14149, -3.14154, 3.14149, -3.14148, 3.14148, -3.14149, 3.1415, -3.14144, 3.14144, -3.14152, 3.1415, -3.14149, 3.1415, -3.1415, 3.14153, -3.14149, 3.14151, -3.14147, 3.14148, -3.1415, 3.14151, -3.14147, 3.14152, -3.1415, 3.14153, -3.14152, 3.14151, -3.14148, 3.14149, -3.14158, 3.14157, -3.14148, 3.14143, -3.14151, 3.14149, -3.14149, 3.14151, -3.1415, 3.14156, -3.14151, 3.14155, -3.14152, 3.14146, -3.14148, 3.14153, -3.14153, 3.14147, -3.14154, 3.14153, -3.14153, 3.14156, -3.14151, 3.14153, -3.14148, 3.14153, -3.14147, 3.14152, -3.14146, 3.14151, -3.14151, 3.14153, -3.14154, 3.14156, -3.14152, 3.14151, -3.14154, 3.14157, -3.14152, 3.1415, -3.14149, -3.14157, -3.14147, -3.14159, -3.14152, 3.14146, -3.14159, 3.14149, -3.14157, 3.14146, -3.14153, 3.14154, -3.14151, 3.14148, -3.14153, 3.14154, -3.14151, 3.14155, -3.14153, -3.14156, -3.14149, 3.14146, -3.14153, 3.14142, 3.14153, 3.14152, -3.14158, 3.14143, 3.14159, 3.14159, -3.14156, 3.14152, -3.14152, 3.14156, -3.1415, 3.14154, -3.14148, 3.14146, -3.14151, 3.14151, -3.14153, 3.14159, -3.14151, 3.14149, -3.14153, 3.14155, -3.14155, 3.14154, -3.1415, 3.14155, -3.14155, 3.14158, -3.14152, 3.14154, -3.14155, 3.14154, -3.14153, 3.14151, 3.14157, 3.14146, -3.14155, 3.14155, -3.14155, -3.14159, -3.14154, 3.14158, -3.14142, 3.14157, 3.14158, 3.14142, -3.14152, 3.14159, -3.14151, 3.14155, -3.1415, -3.14159, -3.14149, -3.14158, -3.14154, 3.1415, -3.14156, 3.14155, -3.14159, 3.1415, -3.14156, 3.1415, 3.14158, -3.14159, -3.1415, 3.14153, 3.14157, 3.1415, -3.14151, -3.14159, -3.14159, 3.14151, -3.14157, 3.14152, -3.14158, 3.14156, -3.14154, -3.14152, -3.14158, -3.14159, -3.14156, 3.14155, -3.14155, -3.14146, -3.14153, 3.14148, -3.14157, -3.14158, -3.14153, 3.14152, 3.14158, 3.14159, -3.14156, -3.14154, 3.14158, 3.14156, -3.14144, 3.14155, -3.14158, 3.14151, 3.14158, 3.14149, -3.14158, 3.14151, 3.14157, 3.14154, 3.14145, 3.14134, 3.14146, -3.14127, -3.14151, -3.14154, -3.1415, 3.14156, -3.14155, -3.14154, 3.14158, 3.14153, -3.14159, 3.14153, 3.14155, -3.14159, 3.14157, 3.14155, 3.14152, 3.14153, 3.14153, 3.14157, 3.14156, 3.14152, 3.14158, 3.14159, -3.14158, -3.14159, 3.14156, 3.14154, 3.14157, -3.14155, -3.14154, 3.14156, 3.14151, 3.14148, -3.14156, 3.14158, 3.1415, 3.14157, 3.14156, 3.14153, 3.14155, 3.14155, 3.14159, 3.14154, -3.14157, 3.14159, -3.14155, -3.14154, 3.14157, -3.14159, -3.14156, 3.14159, 3.14158, 3.14153, 3.14153, 3.14158, -3.14158, -3.14153, -3.14159, -3.14153, -3.14153, -3.14153, -3.14159, -3.14111, -3.14159, 3.14135, -3.14159, 3.14153, -3.14159, -3.14159, -3.14159, -3.14153, 3.14153, 3.14153, 3.14159 };
float c_array[] = { 0, -0.000920188, 0.00195607, -0.00334141, 0.00524961, -0.0085677, 0.0140421, -0.0279224, 0.0594694, -0.468169, -1.3376, -2.26262, -3.03318, 3.08953, -3.11554, 3.12384, -3.12944, 3.13217, -3.1343, 3.13554, -3.13658, 3.13726, -3.13786, 3.13827, -3.13865, 3.13892, -3.13918, 3.13937, -3.13955, 3.13969, -3.13983, 3.13994, -3.14004, 3.14012, -3.14021, 3.14028, -3.14034, 3.1404, -3.14045, 3.1405, -3.14054, 3.14058, -3.14062, 3.14066, -3.14069, 3.14072, -3.14075, 3.14078, -3.1408, 3.14082, -3.14084, 3.14087, -3.14088, 3.14091, -3.14092, 3.14094, -3.14095, 3.14097, -3.14098, 3.141, -3.14101, 3.14102, -3.14103, 3.14105, -3.14105, 3.14106, -3.14107, 3.14109, -3.14109, 3.1411, -3.14111, 3.14112, -3.14113, 3.14114, -3.14114, 3.14116, -3.14116, 3.14116, -3.14117, 3.14118, -3.14118, 3.14119, -3.1412, 3.1412, -3.14121, 3.14122, -3.14122, 3.14121, -3.14122, 3.14123, -3.14124, 3.14124, -3.14125, 3.14125, -3.14125, 3.14126, -3.14126, 3.14126, -3.14127, 3.14127, -3.14128, 3.14129, -3.14129, 3.14128, -3.14129, 3.14131, -3.14129, 3.1413, -3.14131, 3.14131, -3.14132, 3.14131, -3.14131, 3.14133, -3.14132, 3.14132, -3.14133, 3.14133, -3.14131, 3.14135, -3.14135, 3.14133, -3.14137, 3.14134, -3.14135, 3.14133, -3.14137, 3.14135, -3.14136, 3.14135, -3.14136, 3.14138, -3.14137, 3.14136, -3.14138, 3.14137, -3.1414, 3.14134, -3.14139, 3.14138, -3.14139, 3.14139, -3.14136, 3.1414, -3.14139, 3.14139, -3.14138, 3.14139, -3.1414, 3.14141, -3.14139, 3.14141, -3.1414, 3.14141, -3.14141, 3.14141, -3.14141, 3.14142, -3.1414, 3.14139, -3.14143, 3.14143, -3.14141, 3.14142, -3.14139, 3.14144, -3.1414, 3.14142, -3.14142, 3.14143, -3.14143, 3.14139, -3.14142, 3.1414, -3.14144, 3.14145, -3.14143, 3.14145, -3.14141, 3.14143, -3.14143, 3.14147, -3.14144, 3.14146, -3.14145, 3.14143, -3.14147, 3.14146, -3.14146, 3.14148, -3.14145, 3.14147, -3.14145, 3.14143, -3.14145, 3.14146, -3.14142, 3.14142, -3.1415, 3.14144, -3.14144, 3.14145, -3.14144, 3.14142, -3.14146, 3.14145, -3.14145, 3.14145, -3.14148, 3.14146, -3.14143, 3.1415, -3.14147, 3.14148, -3.14149, 3.14147, -3.14148, 3.14148, -3.14148, 3.14148, -3.14147, 3.14147, -3.14144, 3.14146, -3.14148, 3.14146, -3.14149, 3.14147, -3.14148, 3.14155, -3.14146, 3.14151, -3.1415, 3.14152, -3.14145, 3.14152, -3.14149, 3.1415, -3.14151, 3.14147, -3.14149, 3.14147, -3.14148, 3.14147, -3.14149, 3.14144, -3.14152, 3.14153, -3.14149, 3.14153, -3.14147, 3.14149, -3.14151, 3.14151, -3.1415, 3.14149, -3.1415, 3.14154, -3.14149, 3.14154, -3.14149, 3.14156, -3.14151, 3.14153, -3.14151, 3.14149, -3.14158, 3.14155, -3.14148, 3.14142, -3.14152, 3.14152, -3.14146, 3.1415, -3.14154, 3.14155, -3.14149, 3.14152, -3.14153, 3.14149, -3.14151, 3.14152, -3.1415, 3.14153, -3.14154, 3.14154, -3.14153, 3.14153, -3.14151, 3.1415, -3.14152, 3.14151, -3.14152, 3.14151, -3.14146, 3.14156, -3.14154, 3.14153, -3.14153, 3.14159, -3.14151, 3.14151, -3.14151, 3.14155, -3.14152, 3.14151, -3.14151, 3.14156, -3.14151, -3.14155, -3.14151, 3.14149, -3.14157, 3.1415, -3.14159, 3.14145, -3.14156, 3.14152, -3.14153, 3.14149, -3.14154, 3.14151, -3.1415, 3.14153, -3.14156, 3.14159, -3.14147, 3.14147, -3.14154, 3.14152, -3.14159, 3.14156, -3.14156, 3.14146, -3.14157, 3.14159, -3.14154, 3.14153, -3.14154, 3.14156, -3.14148, 3.14151, -3.14148, 3.1415, -3.14151, 3.14158, -3.14155, 3.14158, -3.1415, 3.14147, -3.14157, 3.14156, -3.14157, 3.1415, -3.14153, 3.14156, -3.14157, 3.14157, -3.14148, 3.14155, -3.14155, 3.14158, 3.14153, 3.14153, 3.14158, 3.14143, -3.14156, 3.14157, -3.14153, 3.14158, -3.14155, 3.14152, -3.14142, 3.14143, 3.14146, 3.1415, -3.14151, 3.14158, -3.1415, 3.14156, -3.14149, -3.14159, -3.14149, -3.14156, -3.14157, -3.14158, -3.14155, 3.14157, -3.14159, 3.14157, -3.14155, 3.14142, -3.14156, 3.14143, -3.14153, 3.14158, -3.14158, 3.14149, -3.14159, -3.14157, 3.14159, 3.14149, 3.14157, 3.14149, -3.14155, 3.14152, -3.14152, 3.14155, -3.14156, 3.14157, -3.14157, -3.14157, -3.14151, -3.14149, 3.14159, 3.1415, -3.14156, -3.14156, -3.1415, 3.14155, 3.14159, -3.14159, 3.14156, -3.14153, -3.14154, 3.14155, -3.14154, 3.14148, -3.14156, 3.14148, 3.14158, 3.14152, -3.14157, 3.14149, 3.14158, 3.14158, 3.14148, 3.14143, 3.14153, -3.1414, -3.14155, 3.14151, -3.14159, -3.14159, -3.14157, -3.14152, 3.14157, 3.1415, 3.14159, 3.14154, 3.14157, 3.14156, 3.14157, 3.14156, -3.14159, 3.14151, 3.14153, 3.1415, -3.14158, -3.14156, -3.14156, 3.14153, -3.14152, 3.14157, 3.14159, 3.14156, -3.14156, -3.14158, -3.14153, -3.14155, 3.14152, 3.14144, 3.14156, 3.14152, 3.14157, -3.14154, 3.14148, -3.14157, 3.14157, 3.14154, 3.14158, 3.14155, -3.14154, 3.14155, -3.14156, 3.14156, 3.14155, 3.14159, -3.14159, -3.14159, 3.14158, -3.14159, -3.14156, -3.14156, 3.14155, -3.14153, -3.14156, -3.14144, -3.14147, -3.14147, -3.14135, -3.14111, -3.14159, -3.14147, -3.14159, 3.14147, 3.14153, -3.14153, -3.14153, -3.14153, 3.14147, -3.14159, 3.14159 };
hack::comparators::source(c_array, frequencies.size(), "/mnt/raid/projects/hack/hack/bin/examples/comparators/test.txt");
hack::comparators::compare(frequencies, "/mnt/raid/projects/hack/hack/bin/examples/comparators/test.txt");
hack::comparators::compare(frequencies, "/mnt/raid/projects/hack/hack/bin/examples/comparators/test.txt", 0.000'1);
}

View File

@@ -4,11 +4,12 @@
#include <map>
#include "hack/logger/logger.hpp"
#include "hack/patterns/ring_buffer.hpp"
#include "hack/utils/timestamp.hpp"
auto main(int argc, char *argv[]) -> int
{
std::string str = "hi";
hack::log()(str);
int i = 1;
double d = 2.0;
float f = 3.f;
@@ -69,7 +70,6 @@ auto main(int argc, char *argv[]) -> int
hack::log()(rb);
hack::log()(str.c_str());
hack::log()(str);
std::filesystem::path p { "/test/file/path.txt" };
hack::log()(p);

View File

@@ -5,9 +5,9 @@ executable(
# 'examples/math/main.cpp',
# 'examples/range/main.cpp',
# 'examples/patterns/main.cpp',
# 'examples/logger/main.cpp',
'examples/logger/main.cpp',
# 'examples/exception/main.cpp',
'examples/comparators/main.cpp',
# 'examples/comparators/main.cpp',
dependencies : deps,
cpp_args: args,
include_directories : inc

View File

@@ -1,3 +1,3 @@
Вся работа с аудио на данный момент крутиться во круг wav.
Т.е. что-то типа - воспроизвести/записать в mp3 или что-то подобное требует своей реализации, которой
буду заниматься по мерее её необходимости !!!
буду заниматься по мере её необходимости !!!

View File

@@ -37,16 +37,15 @@ namespace hack::comparators
namespace {
struct comp_result
{
bool m_is_equal; // Результат сравнения
size_t m_file_size; // Размер массива из файла
size_t m_input_size; // Размер входного массива
size_t m_mismatch_count; // Количество несовпадающих элементов
std::vector<size_t> m_mismatch_indices; // Индексы несовпадений
bool m_is_equal; // Результат сравнения
size_t m_file_size; // Размер массива из файла
size_t m_input_size; // Размер входного массива
size_t m_mismatch_count; // Количество несовпадающих элементов
std::vector<std::size_t> m_mismatch_indices; // Индексы несовпадений
};
// epsilon - допустимая погрешность для float
template<typename T>
comp_result compare_float_array_with_file(const std::vector<T>& in, const std::filesystem::path& path, float epsilon = 0.000'01)
comp_result compare_array_with_file(const std::vector<T>& in, const std::filesystem::path& path, float relative_epsilon = 1e-6f, /* 0.0001% */ float absolute_epsilon = 1e-12f) /* для чисел близких к нулю */
{
comp_result res{};
@@ -65,35 +64,76 @@ namespace hack::comparators
// Сравниваем размеры
if (target_size != in.size())
{
hack::log()("Size mismatch: file has", target_size, "elements, input has", in.size(), "elements");
res.m_is_equal = false;
return res;
}
// Создаём вектор для данных из файла
std::vector<float> target(target_size);
std::vector<T> target(target_size);
// Читаем данные из файла
if (target_size > 0)
{
file.read(reinterpret_cast<char*>(target.data()), target_size * sizeof(float));
file.read(reinterpret_cast<char*>(target.data()), target_size * sizeof(T));
if (!file) throw std::runtime_error("Failed to read data from file: " + path.string());
}
// Сравниваем элементы с учётом погрешности
// Сравниваем элементы с учётом погрешностей
res.m_mismatch_count = 0;
for (size_t i = 0; i < target_size; ++i)
for (std::size_t i = 0; i < target_size; ++i)
{
if (std::fabs(target[i] - in[i]) > epsilon)
// Вычисляем абсолютную разность
float diff = std::fabs(static_cast<float>(target[i]) - static_cast<float>(in[i]));
// Максимальное абсолютное значение из двух чисел
float max_abs = std::max(std::fabs(static_cast<float>(target[i])),
std::fabs(static_cast<float>(in[i])));
bool is_equal = false;
// Выбираем стратегию сравнения
if (max_abs < absolute_epsilon)
{
// Оба числа очень маленькие (близки к нулю)
// Используем абсолютную погрешность
is_equal = (diff <= absolute_epsilon);
}
else
{
// Используем относительную погрешность
float relative_diff = diff / max_abs;
is_equal = (relative_diff <= relative_epsilon);
}
if (!is_equal)
{
++res.m_mismatch_count;
res.m_mismatch_indices.push_back(i);
// Ограничиваем вывод для слишком большого количества несовпадений
if (res.m_mismatch_count >= 100 && res.m_mismatch_count % 1000 == 0)
hack::log()("Mismatch count reached", res.m_mismatch_count, "at index", i);
}
}
res.m_is_equal = (res.m_mismatch_count == 0);
log()(in);
log()(target);
// Финальный отчет
if (!res.m_is_equal)
{
hack::log()("FALSE:", res.m_mismatch_count, "mismatches out of", target_size, "elements (", (100.0f * res.m_mismatch_count / target_size), "%)");
// Показываем первые 10 индексов несовпадений
size_t examples_to_show = std::min(size_t(10), res.m_mismatch_indices.size());
hack::log()("First", examples_to_show, "mismatch indices:");
for (size_t j = 0; j < examples_to_show; ++j)
{
size_t idx = res.m_mismatch_indices[j];
hack::log()(" [", idx, "] file:", target[idx], "vs input:", in[idx], "diff:", std::fabs(target[idx] - in[idx]));
}
}
return res;
}
@@ -102,7 +142,7 @@ namespace hack::comparators
template<typename T>
inline void compare(const std::vector<T>& in, const std::filesystem::path& path, float epsilon = 1e-6f)
{
auto r = compare_float_array_with_file(in, path, epsilon);
auto r = compare_array_with_file(in, path, epsilon);
log().set_devider("");
log()("result: ", r.m_is_equal == true ? "TRUE " : "FALSE ");
if (!r.m_is_equal)

View File

@@ -2,7 +2,6 @@
#include <vector>
#include <list>
#include <iostream>
#include <map>
#include <unordered_map>
#include <forward_list>
@@ -265,10 +264,11 @@ namespace hack::concepts
template<typename Container, typename Key>
concept can_find = requires(Container c, Key&& key) { c.find(std::forward<Key>(key)); };
// для логирования собственных структур
// для логирования собственных структур
// мало где используется, только в логере для проверки и выдачи сообщения
template<typename T>
concept has_get_logger_data = requires(T t) {
concept has_get_logger_data = requires(T t)
{
{ t.get_logger_data() };
};
}

View File

@@ -12,13 +12,42 @@
#include "hack/exception/exception.hpp"
// HERE
// и нужно сделать реализацию где выводлится все в одной линии но при помощи цикла
// и нужно сделать реализацию где выводится все в одной линии но при помощи цикла
// типа такого:
// for (auto i : range) hack::log(hack::log::line)(i);
namespace hack
{
class logger : public hack::patterns::singleton<logger>
{
private:
// настройки по умолчанию
struct config
{
bool m_on_file = true; // показывать/не показывать название файла/пути в выоде логов
bool m_on_full_path = false; // показывать/не показывать название файла/пути в выоде логов
bool m_on_func = false; // показывать/не показывать название функции в выоде логов
bool m_on_row = true; // показывать/не показывать номер строки в выоде логов
bool m_bool_as_number = false; // показывет bool как число или как текст (0, false);
std::string m_devider = " "; // разделитель по умолчанию
} m_base_config;
enum class type
{
LOG,
WARN,
ERROR
} m_type;
private:
std::source_location m_location;
std::size_t m_count = 0;
std::string m_devider = m_base_config.m_devider;
bool m_on_func = m_base_config.m_on_func;
bool m_on_full_path = m_base_config.m_on_full_path;
bool m_on_file = m_base_config.m_on_file;
bool m_on_row = m_base_config.m_on_row;
bool m_bool_as_number = m_base_config.m_bool_as_number;
public:
void set_location(std::source_location location) { m_location = location; }
void set_devider(std::string devider) { m_devider = devider; }
@@ -43,34 +72,6 @@ namespace hack
void on_warn() { m_type = type::WARN; }
void on_error() { m_type = type::ERROR; }
public:
template<typename... Args>
void operator() (const Args&... args)
{
m_count = sizeof...(Args);
prepare();
print_impl(args...);
}
private:
// настройки по умолчанию
struct config
{
bool m_on_file = true; // показывать/не показывать название файла/пути в выоде логов
bool m_on_full_path = false; // показывать/не показывать название файла/пути в выоде логов
bool m_on_func = false; // показывать/не показывать название функции в выоде логов
bool m_on_row = true; // показывать/не показывать номер строки в выоде логов
bool m_bool_as_number = false; // показывет bool как число или как текст (0, false);
std::string m_devider = " "; // разделитель по умолчанию
} m_base_config;
enum class type
{
LOG,
WARN,
ERROR
} m_type;
private:
void prepare()
{
@@ -115,15 +116,15 @@ namespace hack
void print_impl() { std::cout << std::endl; }
// для строк
template<concepts::is_string T>
// для всех чисел
template<concepts::is_number T>
void print_t(const T& data)
{
std::cout << data << (m_count != 0 ? m_devider : "");
}
// для всех чисел
template<concepts::is_number T>
// для строк
template<concepts::is_string T>
void print_t(const T& data)
{
std::cout << data << (m_count != 0 ? m_devider : "");
@@ -228,7 +229,7 @@ namespace hack
// для пользовательских типов
// у них должен быть отпределен метод get_logger_data()
// возвращающий один из обработанных типов
template<concepts::not_supported T>
template<concepts::has_get_logger_data T>
void print_t(const T& rb)
{
static_assert(concepts::has_get_logger_data<T>, "Type must have get_logger_data() method that returns value_type");
@@ -258,18 +259,9 @@ namespace hack
std::cout << key << ": ";
if (value.type() == typeid(std::string))
{
// HERE
// хотельсь бы написать так:
// print_t(std::any_cast<std::string>(value));
// но по какой-то причине на эту запись ругается clangd
//  Client clangd quit with exit code 0 and signal 11. Check log for errors: /home/chatlanin/.local/state/nvim/lsp.log
// когда они это порявят напишем а пока... пише так:
print_t(std::any_cast<std::string>(value).c_str());
}
print_t(std::any_cast<std::string>(value));
else if (value.type() == typeid(std::filesystem::path))
print_t(std::any_cast<std::filesystem::path>(value).c_str());
// конец HERE выше
else if (value.type() == typeid(int))
print_t(std::any_cast<int>(value));
@@ -279,6 +271,7 @@ namespace hack
print_t(std::any_cast<float>(value));
else if (value.type() == typeid(bool))
print_t(std::any_cast<bool>(value));
// vector
else if (value.type() == typeid(std::vector<std::string>))
print_t(std::any_cast<std::vector<std::string>>(value));
@@ -288,6 +281,7 @@ namespace hack
print_t(std::any_cast<std::vector<double>>(value));
else if (value.type() == typeid(std::vector<float>))
print_t(std::any_cast<std::vector<float>>(value));
// map
else if (value.type() == typeid(std::map<std::string, std::string>))
print_t(std::any_cast<std::map<std::string, std::string>>(value));
@@ -306,15 +300,14 @@ namespace hack
}
}
private:
std::source_location m_location;
std::size_t m_count = 0;
std::string m_devider = m_base_config.m_devider;
bool m_on_func = m_base_config.m_on_func;
bool m_on_full_path = m_base_config.m_on_full_path;
bool m_on_file = m_base_config.m_on_file;
bool m_on_row = m_base_config.m_on_row;
bool m_bool_as_number = m_base_config.m_bool_as_number;
public:
template<typename... Args>
void operator() (const Args&... args)
{
m_count = sizeof...(Args);
prepare();
print_impl(args...);
}
};
// основная функция вызова логера

View File

@@ -6,15 +6,15 @@ namespace hack::patterns
struct no_copy
{
no_copy() = default;
no_copy(const no_copy&&) = delete;
no_copy operator=(const no_copy&&) = delete;
no_copy(const no_copy&) = delete; // Было: const no_copy&&
no_copy& operator=(const no_copy&) = delete; // Было: const no_copy&&
};
struct no_move
{
no_move() = default;
no_move(no_move&&) = delete;
no_move operator=(no_move&&) = delete;
no_move(no_move&&) = delete; // Было: no_move&&
no_move& operator=(no_move&&) = delete; // Было: no_move&&
};
template<typename T>