diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..e6e42b7
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/zlib.iml b/.idea/zlib.iml
new file mode 100644
index 0000000..5e764c4
--- /dev/null
+++ b/.idea/zlib.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/zasm/.gitignore b/src/ReflTest/.gitignore
similarity index 100%
rename from src/zasm/.gitignore
rename to src/ReflTest/.gitignore
diff --git a/src/ReflTest/src/TestUDRefl.cpp b/src/ReflTest/src/TestUDRefl.cpp
new file mode 100644
index 0000000..2b9976c
--- /dev/null
+++ b/src/ReflTest/src/TestUDRefl.cpp
@@ -0,0 +1 @@
+#include "TestUDRefl.h"
diff --git a/src/ReflTest/src/TestUDRefl.h b/src/ReflTest/src/TestUDRefl.h
new file mode 100644
index 0000000..52c55c3
--- /dev/null
+++ b/src/ReflTest/src/TestUDRefl.h
@@ -0,0 +1,40 @@
+#pragma once
+#include
+#include
+#include
+
+using namespace Ubpa;
+using namespace Ubpa::UDRefl;
+
+struct Vec {
+ float x;
+ float y;
+ float norm() const {
+ return std::sqrt(x * x + y * y);
+ }
+};
+
+int TestUDRefl() {
+ Mngr.RegisterType();
+ Mngr.AddField<&Vec::x>("x");
+ Mngr.AddField<&Vec::y>("y");
+ Mngr.AddMethod<&Vec::norm>("norm");
+
+ SharedObject v = Mngr.MakeShared(Type_of);
+ std::cout << v.GetType().GetName() << std::endl; // prints "Vec"
+
+ v.Var("x") = 3;
+ v.Var("y") = 4;
+
+ std::cout << "x: " << v.Var("x") << std::endl;
+ std::cout << "norm: " << v.Invoke("norm") << std::endl;
+
+ for (auto&& [name, info] : FieldRange_of)
+ std::cout << name.GetView() << std::endl;
+
+ for (auto&& [name, info] : MethodRange_of)
+ std::cout << name.GetView() << std::endl;
+
+ for (auto&& [name, var] : v.GetVars())
+ std::cout << name.GetView() << ": " << var << std::endl;
+}
diff --git a/src/ReflTest/src/TestUSRefl.cpp b/src/ReflTest/src/TestUSRefl.cpp
new file mode 100644
index 0000000..1e6de20
--- /dev/null
+++ b/src/ReflTest/src/TestUSRefl.cpp
@@ -0,0 +1 @@
+#include "TestUSRefl.h"
diff --git a/src/ReflTest/src/TestUSRefl.h b/src/ReflTest/src/TestUSRefl.h
new file mode 100644
index 0000000..c0c1432
--- /dev/null
+++ b/src/ReflTest/src/TestUSRefl.h
@@ -0,0 +1,45 @@
+#pragma once
+#include "USRefl_99.h"
+#include
+#include
+#include
+
+using namespace Ubpa::USRefl;
+
+struct Vec {
+ float x;
+ float y;
+ float norm() const {
+ return std::sqrt(x * x + y * y);
+ }
+};
+
+template<>
+struct Ubpa::USRefl::TypeInfo :
+ TypeInfoBase
+{
+ static constexpr AttrList attrs = {};
+ static constexpr FieldList fields = {
+ Field {TSTR("x"), &Type::x},
+ Field {TSTR("y"), &Type::y},
+ Field {TSTR("norm"), &Type::norm},
+ };
+};
+
+int TestUSRefl() {
+ TypeInfo::fields.ForEach([](const auto& field) {
+ std::cout << field.name << std::endl;
+ });
+
+ Vec v;
+
+ std::invoke(TypeInfo::fields.Find(TSTR("x")).value, v) = 3.f;
+ std::invoke(TypeInfo::fields.Find(TSTR("y")).value, v) = 4.f;
+ std::cout << "x: " << std::invoke(TypeInfo::fields.Find(TSTR("x")).value, v) << std::endl;
+
+ std::cout << "norm: " << std::invoke(TypeInfo::fields.Find(TSTR("norm")).value, v) << std::endl;
+
+ TypeInfo::ForEachVarOf(v, [](const auto& field, const auto& var) {
+ std::cout << field.name << ": " << var << std::endl;
+ });
+}
diff --git a/src/ReflTest/src/main.cpp b/src/ReflTest/src/main.cpp
new file mode 100644
index 0000000..453d662
--- /dev/null
+++ b/src/ReflTest/src/main.cpp
@@ -0,0 +1,102 @@
+#include
+
+#include
+
+#include
+
+using namespace Ubpa::USRefl;
+using namespace std;
+
+template
+constexpr std::size_t Func() { return N; }
+
+enum class [[enum_attr("enum_attr_value")]] Color {
+ RED [[enumerator_attr("enumerator_attr_value"), func(&Func<1>)]] = 1,
+ GREEN [[func(&Func<2>)]] = 2,
+ BLUE [[func(&Func<3>)]] = 4
+};
+
+template<>
+struct Ubpa::USRefl::TypeInfo :
+ TypeInfoBase
+{
+ static constexpr AttrList attrs = {
+ Attr {TSTR("enum_attr"), "enum_attr_value"},
+ };
+ static constexpr FieldList fields = {
+ Field {TSTR("RED"), Type::RED, AttrList {
+ Attr {TSTR("enumerator_attr"), "enumerator_attr_value"},
+ Attr {TSTR("func"), &Func<1>},
+ }},
+ Field {TSTR("GREEN"), Type::GREEN, AttrList {
+ Attr {TSTR("func"), &Func<2>},
+ }},
+ Field {TSTR("BLUE"), Type::BLUE, AttrList {
+ Attr {TSTR("func"), &Func<3>},
+ }},
+ };
+};
+
+int main() {
+ cout << TypeInfo::name << endl;
+
+ TypeInfo::fields.ForEach([](auto field) {
+ cout << field.name << endl;
+ });
+
+ Color red = Color::RED;
+ std::string_view nameof_red = "RED";
+
+ // name -> value
+ {
+ // compile-time
+ static_assert(TypeInfo::fields.ValueOfName("GREEN") == Color::GREEN);
+
+ // runtime
+ assert(TypeInfo::fields.ValueOfName(nameof_red) == red);
+ }
+
+ // value -> name
+ {
+ // compile-time
+ static_assert(TypeInfo::fields.NameOfValue(Color::GREEN) == "GREEN");
+
+ // runtime
+ assert(TypeInfo::fields.NameOfValue(red) == nameof_red);
+ }
+
+ // name -> attr
+ {
+ // compile-time
+ static_assert(TypeInfo::fields.Find(TSTR("GREEN")).attrs.Find(TSTR("func")).value() == 2);
+ // runtime
+ std::size_t rst = static_cast(-1);
+ TypeInfo::fields.FindIf([nameof_red, &rst](auto field) {
+ if (field.name == nameof_red) {
+ rst = field.attrs.Find(TSTR("func")).value();
+ return true;
+ }
+ else
+ return false;
+ });
+ assert(rst == 1);
+ }
+
+ // value -> attr
+ {
+ static_assert(USRefl_ElemList_GetByValue(TypeInfo::fields, Color::GREEN).attrs.Find(TSTR("func")).value() == 2);
+
+ // runtime
+ std::size_t rst = static_cast(-1);
+ TypeInfo::fields.FindIf([red, &rst](auto field) {
+ if (field.value == red) {
+ rst = field.attrs.Find(TSTR("func")).value();
+ return true;
+ }
+ else
+ return false;
+ });
+ assert(rst == 1);
+ }
+
+}
diff --git a/src/zasm/xmake.lua b/src/ReflTest/xmake.lua
similarity index 89%
rename from src/zasm/xmake.lua
rename to src/ReflTest/xmake.lua
index a1963fb..3009cec 100644
--- a/src/zasm/xmake.lua
+++ b/src/ReflTest/xmake.lua
@@ -1,9 +1,12 @@
add_rules("mode.debug", "mode.release")
-
-target("zasm")
+--add_requires("UTemplate","USmallFlat","USRefl","UDRefl")
+target("ReflTest")
set_kind("binary")
+ set_languages("c++20")
+ add_packages("USRefl","UDRefl")
add_files("src/*.cpp")
-
+ add_headerfiles("src/*.h")
+
--
-- If you want to known more usage about xmake, please see https://xmake.io
--
@@ -44,7 +47,7 @@ target("zasm")
-- -- add debug and release modes
-- add_rules("mode.debug", "mode.release")
--
--- -- add macro definition
+-- -- add macro defination
-- add_defines("NDEBUG", "_GNU_SOURCE=1")
--
-- -- set warning all as error
diff --git a/src/zasm/src/main.cpp b/src/zasm/src/main.cpp
deleted file mode 100644
index fbafc96..0000000
--- a/src/zasm/src/main.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-//#include
-
-//using namespace std;
-
-int main(int argc, char** argv)
-{
- //cout << "hello world!" << endl;
- return 0;
-}
diff --git a/src/zcore/src/log/log_system.h b/src/zcore/src/log/log_system.h
index 5ef3d64..018463e 100644
--- a/src/zcore/src/log/log_system.h
+++ b/src/zcore/src/log/log_system.h
@@ -20,7 +20,16 @@ public:
public:
LogSystem();
~LogSystem();
-
+ static std::shared_ptr getInstance()
+ {
+ static std::weak_ptr instance;
+ auto ret = instance.lock();
+ if (!ret) {
+ ret.reset(new LogSystem());
+ instance = ret;
+ }
+ return ret;
+ }
template
void log(LogLevel level, TARGS&&... args)
{
@@ -56,4 +65,16 @@ public:
private:
std::shared_ptr m_logger;
-};
\ No newline at end of file
+};
+#define LOG_HELPER(LOG_LEVEL, ...) \
+ LogSystem::getInstance()->log(LOG_LEVEL, "[" + std::string(__FUNCTION__) + "] " + __VA_ARGS__);
+
+#define LOG_DEBUG(...) LOG_HELPER(LogSystem::LogLevel::debug, __VA_ARGS__);
+
+#define LOG_INFO(...) LOG_HELPER(LogSystem::LogLevel::info, __VA_ARGS__);
+
+#define LOG_WARN(...) LOG_HELPER(LogSystem::LogLevel::warn, __VA_ARGS__);
+
+#define LOG_ERROR(...) LOG_HELPER(LogSystem::LogLevel::error, __VA_ARGS__);
+
+#define LOG_FATAL(...) LOG_HELPER(LogSystem::LogLevel::fatal, __VA_ARGS__);
\ No newline at end of file
diff --git a/src/zcoro/include/zcoro/task.h b/src/zcoro/include/zcoro/task.h
new file mode 100644
index 0000000..e69de29
diff --git a/src/zcoro/include/zthread/channel.h b/src/zcoro/include/zthread/channel.h
new file mode 100644
index 0000000..c2746cb
--- /dev/null
+++ b/src/zcoro/include/zthread/channel.h
@@ -0,0 +1,64 @@
+#include
+#include
+#include
+namespace zstd {
+ template
+ class channel {
+ protected:
+ int m_tail;
+ int m_head;
+ int m_size;
+ T* m_buf;
+ std::mutex m_mtx;
+ std::condition_variable m_cv;
+ public:
+ ~channel() {
+ reset();
+ free(m_buf);
+ }
+ channel(int size = 1) {
+ m_tail = 0;
+ m_head = 0;
+ m_size = size;
+ m_buf = (T*)malloc(sizeof(T) * size);
+ }
+ int head() {
+ return m_head;
+ }
+ int tail() {
+ return m_tail;
+ }
+ int count() {
+ return m_head - m_tail;
+ }
+ void reset() {
+ for (int i = m_tail; i < m_head; i++) {
+ std::destroy_at(m_buf + (m_tail % m_size));
+ }
+ m_tail = 0;
+ m_head = 0;
+ }
+ template
+ void release(Args... args) {
+ std::unique_lock lck(m_mtx);
+ if (m_head >= m_tail + m_size) {
+ std::cout << "release wait \n";
+ m_cv.wait(lck);
+ }
+ std::construct_at(m_buf + m_head % m_size, std::forward(args)...);
+ if(m_head++ == m_tail)
+ m_cv.notify_one();
+ };
+ T acquire() {
+ std::unique_lock lck(m_mtx);
+ if (m_tail == m_head) {
+ std::cout << "acquire wait \n";
+ m_cv.wait(lck);
+ }
+ int tail = m_tail % m_size;
+ if(m_tail++ == m_head - m_size)
+ m_cv.notify_one();
+ return std::move(*(m_buf + tail));
+ };
+ };
+}
\ No newline at end of file
diff --git a/src/zcoro/main.cpp b/src/zcoro/main.cpp
new file mode 100644
index 0000000..010a862
--- /dev/null
+++ b/src/zcoro/main.cpp
@@ -0,0 +1,71 @@
+#include "zthread/channel.h"
+#include
+#include
+#define LOOP_TIMES 10
+int del_count = 0;
+int add_count = 0;
+int cpy_count = 0;
+int mov_count = 0;
+class object {
+public:
+ const char* name;
+ int res;
+public:
+ ~object() {
+ char buf[1024];
+ sprintf(buf, "~~~~ %d %x \n", ++del_count, (int)this);
+ std::cout << buf;
+ };
+ object(const char* name, int res) {
+ this->name = name;
+ this->res = res;
+ char buf[1024];
+ sprintf(buf, "++++ %d %x \n", ++add_count, (int)this);
+ std::cout << buf;
+ }
+ object(object& obj) {
+ char buf[1024];
+ sprintf(buf, "cccc %d %x<--%x\n", ++cpy_count, (int)this, (int) & obj);
+ std::cout << buf;
+ this->name = obj.name;
+ this->res = obj.res;
+ }
+ object(object&& obj) noexcept{
+ char buf[1024];
+ sprintf(buf, "mmmm %d %x<--%x\n", ++mov_count, (int)this, (int)&obj);
+ std::cout << buf;
+ this->name = obj.name;
+ this->res = obj.res;
+ }
+};
+void test1() {
+ zstd::channel