hack/sandbox/bin/utils/main.cpp
2024-05-15 18:52:32 +03:00

104 lines
2.2 KiB
C++

#include "hack/logger/logger.hpp"
#include "hack/utils/utils.hpp"
#include "hack/utils/singleton.hpp"
#include "hack/utils/func_query.hpp"
int f(int a)
{
hack::log()("f implementatioln");
return ++a;
}
int plus(int a)
{
return ++a;
}
int minus(int a)
{
return --a;
}
struct counter_test
{
counter_test() : id { ++hack::utils::counter<int>::id } { }
int id;
};
struct counter_test_2
{
counter_test_2() : id { ++hack::utils::counter<int>::id } { }
int id;
};
struct test_singleton : public hack::utils::singleton<test_singleton>
{
void print()
{
hack::log()("Print singleton");
}
};
auto main(int argc, char *argv[]) -> int
{
{// ex: utils::func_memory
int a = 12;
auto cach_f = hack::utils::func_memory(f);
hack::log()("result 1", cach_f(a));
hack::log()("result 2", cach_f(a));
}
{// ex: utils::func_concat
int a = 1;
auto combine ( hack::utils::func_concat(plus, minus, plus, f) );
hack::log("")("func_concat result: ", combine(a), a);
}
{// ex: utils::exec
hack::log()(hack::utils::unix_cmd("ls"));
hack::log()(hack::utils::unix_cmd("pwd"));
auto t = hack::utils::unix_cmd("pwd");
hack::log::type_trace(t);
}
{// ex: counter
counter_test a, b, c;
counter_test_2 a1, b1, c1;
hack::log()(c.id);
hack::log()(c1.id);
}
{// ex: case as string
switch(hack::utils::case_int("test"))
{
case hack::utils::case_int("test"): hack::log()("wow"); break;
case hack::utils::case_int("no_test"): hack::log()("ups"); break;
}
}
{// ex: query function
auto query = hack::utils::make_query("super_function", "1", "two");
hack::log()("query", query);
query = hack::utils::make_query("super_function", 1, 'c');
hack::log()("query", query);
std::string jstr { "{\"test\",\"data\"}" };
query = hack::utils::make_query("super_function", 1, 123.3f, jstr);
hack::log()("JSON sting", query);
nlohmann::json js { "test", "data" };
query = hack::utils::make_query("super_function", 1'000'000, 123.3f, js);
hack::log()("JSON", query);
query = hack::utils::make_query("super_function");
hack::log()("query", query);
}
{// ex: singleton
test_singleton::instance().print();
}
}