refresh struct

This commit is contained in:
chatlanin
2024-07-05 10:26:32 +03:00
parent e22967accb
commit 40da1bbaa9
68 changed files with 17 additions and 56 deletions

View File

@@ -0,0 +1,22 @@
#include <vector>
#include <forward_list>
#include "hack/logger/logger.hpp"
#include "hack/algorithms/sort.hpp"
auto main(int argc, char *argv[]) -> int
{
{// ex: sort
std::vector<int> v { 4, 4, 6, 1, 4, 3, 2 };
std::forward_list<int> l { 8, 7, 5, 9, 0, 1, 3, 2, 6, 4 };
hack::algorithms::sort(v);
hack::algorithms::sort(l);
hack::log log;
log(v);
log(l);
}
}

View File

@@ -0,0 +1,42 @@
#include <set>
#include <unordered_set>
#include "hack/logger/logger.hpp"
#include "hack/concepts/concepts.hpp"
template<hack::concepts::is_map T>
void test_map(const T& m)
{
hack::log()("is map", m);
}
template<hack::concepts::is_associative_container T>
void test_associative(const T& m)
{
hack::log()("is associative", m);
}
template<hack::concepts::is_unordered_set T>
void test_unordered_set(const T& m)
{
hack::log()("is unordered set", m);
}
auto main(int argc, char *argv[]) -> int
{
std::map<std::string, int> m { { "a", 1 }, { "b", 2 } };
test_map(m);
test_associative(m);
auto t = std::make_tuple("a", 1, "b", 2);
test_associative(t);
std::vector<int> v { 1, 2, 3 };
// test_associative(v); error !!!
std::unordered_set<int> us { 1, 2, 3 };
test_unordered_set(us);
test_associative(us);
}

View File

@@ -0,0 +1,40 @@
#include <set>
#include "hack/logger/logger.hpp"
#include "hack/containers/containers.hpp"
auto main(int argc, char *argv[]) -> int
{
hack::log()("============================================================");
hack::log()("container::vector_multiset");
{// ex: containers::vector
std::vector<std::string> v;
hack::containers::vector::multiset(v, "asdf", "qwer", "zcv");
hack::log()(v);
hack::containers::vector::remove_at(v, 1);
hack::log()(v);
hack::containers::vector::multiset(v, "aa", "bb", "cc");
hack::log()(v);
auto it = std::find(v.begin(), v.end(), "aa");
hack::log()(*it);
hack::containers::vector::remove_at(v, it);
hack::log()(v);
}
{// ex: containers::utils::count
std::vector<std::string> v { "aa", "bb", "cc" };
auto r = hack::containers::utils::count(v, "aa", "bb");
hack::log()(r);
}
{// ex: containers::set
std::set<int> s;
hack::containers::set::multiset(s, 1, 2, 3);
hack::warn()("TODO: реализовать в log вывод set контейнера!");
}
}

View File

@@ -0,0 +1,25 @@
#include <set>
#include "hack/logger/logger.hpp"
#include "hack/iterators/associative_ostream_iterator.hpp"
#include "hack/concepts/concepts.hpp"
template<hack::concepts::is_map T>
static void print_t(const T& data)
{
std::cout << "{";
std::copy(data.cbegin(), data.cend(), hack::iterators::associative_ostream_iterator<typename T::value_type>(data.size(), std::cout));
std::cout << "}";
}
auto main(int argc, char *argv[]) -> int
{
std::map<std::string, int> m { { "a", 1 }, { "b", 2 } };
for (auto& [key, value] : m)
hack::log()(key, value);
print_t(m);
}

17
examples/logger/main.cpp Normal file
View File

@@ -0,0 +1,17 @@
#include <set>
#include <unordered_set>
#include "hack/logger/logger.hpp"
auto main(int argc, char *argv[]) -> int
{
std::set<int> s { 1, 2, 3 };
hack::log()(s);
std::vector<int> v { 1, 2, 3 };
hack::log()(v, s);
std::unordered_set<int> us { 1, 2, 3 };
hack::log()(v, s, us);
}

12
examples/macros/main.cpp Normal file
View File

@@ -0,0 +1,12 @@
#include <set>
#include "hack/logger/logger.hpp"
#include "hack/macros/macros.hpp"
auto main(int argc, char *argv[]) -> int
{
std::string s { MAKE_STR(test) };
hack::log()(s);
}

16
examples/memory/main.cpp Normal file
View File

@@ -0,0 +1,16 @@
#include <array>
#include "hack/logger/logger.hpp"
#include "hack/memory/make_ptr.hpp"
auto main(int argc, char *argv[]) -> int
{
auto a = hack::memory::make_unique<int>(5);
hack::log()(*a);
auto arr = hack::memory::make_unique<int[]>(5);
arr[0] = 1;
hack::log()(arr[0]);
}

View File

@@ -0,0 +1,25 @@
#include <array>
#include "hack/logger/logger.hpp"
#include "hack/security/uuid.hpp"
#include "hack/security/is_link.hpp"
#include "hack/security/is_string.hpp"
#include "hack/security/validate_email.hpp"
auto main(int argc, char *argv[]) -> int
{
auto uuid = hack::security::generate_uuid();
hack::log()(uuid);
hack::log()(hack::security::validate_uuid(uuid));
std::string url = "https://google.com";
hack::log()(hack::security::is_link(url));
hack::log()(hack::security::is_string<decltype (url)>::value);
std::string email = "asdf@asdf.com";
hack::log()(hack::security::validate_email(email));;
}

42
examples/string/main.cpp Normal file
View File

@@ -0,0 +1,42 @@
#include <array>
#include "hack/logger/logger.hpp"
#include "hack/string/string.hpp"
#include "hack/string/string_concat_helper.hpp"
#include "hack/string/utf8_len.hpp"
auto main(int argc, char *argv[]) -> int
{
{// ex: split string
std::string str { "asdf,qwer,zxcv" };
std::string str_int { "1 2 3" };
hack::string::v_str v = hack::string::split_str(str, ',');
auto v_int = hack::string::split_stoi(str_int, ' ');
hack::log log;
for (const auto& c : v) log(c);
for (const auto& c : v_int) log(c);
std::string str_2 { "qqq,aaa:eee,ggg" };
hack::string::v_str v_2 = hack::string::split_str(str_2, ",:");
for (const auto& c : v_2) log(c);
}
{// ex: string::str_concat
std::string name = "tro";
std::string surname = "lolo";
const auto full_name = hack::string::str_concat + name + ", " + surname;
hack::log()(full_name);
hack::log()(hack::string::str_concat + "super", + "string");
}
{// ex: utf8_size
std::string str = "hi hi";
auto s = hack::string::utf8_len(str);
hack::log()(s);
s = hack::string::utf8_len("asdf");
hack::log()(s);
}
}

103
examples/utils/main.cpp Normal file
View File

@@ -0,0 +1,103 @@
#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();
}
}