diff --git a/Import/GacUI.h b/Import/GacUI.h index f2f6ff07..b3bdbab4 100644 --- a/Import/GacUI.h +++ b/Import/GacUI.h @@ -5,8 +5,8 @@ DEVELOPER: Zihan Chen(vczh) #include "VlppParser.h" #include "VlppWorkflowLibrary.h" #include "VlppReflection.h" -#include "Vlpp.h" #include "VlppOS.h" +#include "Vlpp.h" #include "VlppRegex.h" /*********************************************************************** diff --git a/Import/GacUICompiler.h b/Import/GacUICompiler.h index eaac763b..61d335b0 100644 --- a/Import/GacUICompiler.h +++ b/Import/GacUICompiler.h @@ -8,8 +8,8 @@ DEVELOPER: Zihan Chen(vczh) #include "VlppParser.h" #include "VlppWorkflowLibrary.h" #include "VlppReflection.h" -#include "Vlpp.h" #include "VlppOS.h" +#include "Vlpp.h" #include "VlppRegex.h" #include "VlppWorkflowRuntime.h" diff --git a/Import/GacUIReflection.h b/Import/GacUIReflection.h index 0fad5989..0265b9e1 100644 --- a/Import/GacUIReflection.h +++ b/Import/GacUIReflection.h @@ -7,8 +7,8 @@ DEVELOPER: Zihan Chen(vczh) #include "VlppParser.h" #include "VlppWorkflowLibrary.h" #include "VlppReflection.h" -#include "Vlpp.h" #include "VlppOS.h" +#include "Vlpp.h" #include "VlppRegex.h" #include "VlppWorkflowRuntime.h" @@ -550,7 +550,7 @@ GuiEventInfoImpl return false; } - void InvokeInternal(DescriptableObject* thisObject, Ptr arguments)override + void InvokeInternal(DescriptableObject* thisObject, Ptr arguments)override { GuiGraphicsEvent* eventObject=eventRetriver(thisObject, false); if(eventObject) diff --git a/Import/GacUIWindows.h b/Import/GacUIWindows.h index 8289071c..c07800bf 100644 --- a/Import/GacUIWindows.h +++ b/Import/GacUIWindows.h @@ -6,8 +6,8 @@ DEVELOPER: Zihan Chen(vczh) #include "VlppParser.h" #include "VlppWorkflowLibrary.h" #include "VlppReflection.h" -#include "Vlpp.h" #include "VlppOS.h" +#include "Vlpp.h" #include "VlppRegex.h" /*********************************************************************** diff --git a/Import/Skins/DarkSkin/DarkSkin.cpp b/Import/Skins/DarkSkin/DarkSkin.cpp index 413b0868..832aaffb 100644 --- a/Import/Skins/DarkSkin/DarkSkin.cpp +++ b/Import/Skins/DarkSkin/DarkSkin.cpp @@ -23932,7 +23932,7 @@ namespace darkskin } (this->__vwsn_precompile_2 = ::vl::Ptr<::vl::presentation::elements::GuiPolygonElement>(::vl::reflection::description::Element_Constructor<::vl::presentation::elements::GuiPolygonElement>())); { - [&]()->decltype(auto){ auto __vwsn_temp_x0 = ::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(4); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(8); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }())).list)); ::vl::collections::Array<::vl::presentation::Point> __vwsn_temp_0; ::vl::reflection::description::UnboxParameter(__vwsn_temp_x0, __vwsn_temp_0); return ::vl::__vwsn::This(this->__vwsn_precompile_2.Obj())->SetPointsArray(__vwsn_temp_0); }(); + ::vl::__vwsn::This(this->__vwsn_precompile_2.Obj())->SetPointsArray(::vl::reflection::description::UnboxParameter<::vl::collections::Array<::vl::presentation::Point>>(::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(4); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(8); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }())).list))).Ref()); } { ::vl::__vwsn::This(this->__vwsn_precompile_2.Obj())->SetSize([&](){ ::vl::presentation::Size __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(9); __vwsn_temp__.y = static_cast<::vl::vint>(5); return __vwsn_temp__; }()); @@ -24445,7 +24445,7 @@ Class (::darkskin::ComboBoxTemplateConstructor) } (this->__vwsn_precompile_8 = ::vl::Ptr<::vl::presentation::elements::GuiPolygonElement>(::vl::reflection::description::Element_Constructor<::vl::presentation::elements::GuiPolygonElement>())); { - [&]()->decltype(auto){ auto __vwsn_temp_x0 = ::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(2); __vwsn_temp__.y = static_cast<::vl::vint>(2); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }())).list)); ::vl::collections::Array<::vl::presentation::Point> __vwsn_temp_0; ::vl::reflection::description::UnboxParameter(__vwsn_temp_x0, __vwsn_temp_0); return ::vl::__vwsn::This(this->__vwsn_precompile_8.Obj())->SetPointsArray(__vwsn_temp_0); }(); + ::vl::__vwsn::This(this->__vwsn_precompile_8.Obj())->SetPointsArray(::vl::reflection::description::UnboxParameter<::vl::collections::Array<::vl::presentation::Point>>(::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(2); __vwsn_temp__.y = static_cast<::vl::vint>(2); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }())).list))).Ref()); } { ::vl::__vwsn::This(this->__vwsn_precompile_8.Obj())->SetSize([&](){ ::vl::presentation::Size __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(5); __vwsn_temp__.y = static_cast<::vl::vint>(3); return __vwsn_temp__; }()); @@ -24979,7 +24979,7 @@ Class (::darkskin::ExpandingDecoratorTemplateConstructor) } (this->__vwsn_precompile_3 = ::vl::Ptr<::vl::presentation::elements::GuiPolygonElement>(::vl::reflection::description::Element_Constructor<::vl::presentation::elements::GuiPolygonElement>())); { - [&]()->decltype(auto){ auto __vwsn_temp_x0 = ::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(1); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(5); __vwsn_temp__.y = static_cast<::vl::vint>(4); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(1); __vwsn_temp__.y = static_cast<::vl::vint>(8); return __vwsn_temp__; }())).list)); ::vl::collections::Array<::vl::presentation::Point> __vwsn_temp_0; ::vl::reflection::description::UnboxParameter(__vwsn_temp_x0, __vwsn_temp_0); return ::vl::__vwsn::This(this->__vwsn_precompile_3.Obj())->SetPointsArray(__vwsn_temp_0); }(); + ::vl::__vwsn::This(this->__vwsn_precompile_3.Obj())->SetPointsArray(::vl::reflection::description::UnboxParameter<::vl::collections::Array<::vl::presentation::Point>>(::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(1); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(5); __vwsn_temp__.y = static_cast<::vl::vint>(4); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(1); __vwsn_temp__.y = static_cast<::vl::vint>(8); return __vwsn_temp__; }())).list))).Ref()); } { ::vl::__vwsn::This(this->__vwsn_precompile_3.Obj())->SetSize([&](){ ::vl::presentation::Size __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(7); __vwsn_temp__.y = static_cast<::vl::vint>(9); return __vwsn_temp__; }()); @@ -24996,7 +24996,7 @@ Class (::darkskin::ExpandingDecoratorTemplateConstructor) } (this->__vwsn_precompile_5 = ::vl::Ptr<::vl::presentation::elements::GuiPolygonElement>(::vl::reflection::description::Element_Constructor<::vl::presentation::elements::GuiPolygonElement>())); { - [&]()->decltype(auto){ auto __vwsn_temp_x0 = ::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(5); __vwsn_temp__.y = static_cast<::vl::vint>(2); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(5); __vwsn_temp__.y = static_cast<::vl::vint>(7); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(7); return __vwsn_temp__; }())).list)); ::vl::collections::Array<::vl::presentation::Point> __vwsn_temp_0; ::vl::reflection::description::UnboxParameter(__vwsn_temp_x0, __vwsn_temp_0); return ::vl::__vwsn::This(this->__vwsn_precompile_5.Obj())->SetPointsArray(__vwsn_temp_0); }(); + ::vl::__vwsn::This(this->__vwsn_precompile_5.Obj())->SetPointsArray(::vl::reflection::description::UnboxParameter<::vl::collections::Array<::vl::presentation::Point>>(::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(5); __vwsn_temp__.y = static_cast<::vl::vint>(2); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(5); __vwsn_temp__.y = static_cast<::vl::vint>(7); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(7); return __vwsn_temp__; }())).list))).Ref()); } { ::vl::__vwsn::This(this->__vwsn_precompile_5.Obj())->SetSize([&](){ ::vl::presentation::Size __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(7); __vwsn_temp__.y = static_cast<::vl::vint>(9); return __vwsn_temp__; }()); @@ -25736,7 +25736,7 @@ Class (::darkskin::LeftScrollButtonTemplateConstructor) } (this->__vwsn_precompile_2 = ::vl::Ptr<::vl::presentation::elements::GuiPolygonElement>(::vl::reflection::description::Element_Constructor<::vl::presentation::elements::GuiPolygonElement>())); { - [&]()->decltype(auto){ auto __vwsn_temp_x0 = ::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(4); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(8); return __vwsn_temp__; }())).list)); ::vl::collections::Array<::vl::presentation::Point> __vwsn_temp_0; ::vl::reflection::description::UnboxParameter(__vwsn_temp_x0, __vwsn_temp_0); return ::vl::__vwsn::This(this->__vwsn_precompile_2.Obj())->SetPointsArray(__vwsn_temp_0); }(); + ::vl::__vwsn::This(this->__vwsn_precompile_2.Obj())->SetPointsArray(::vl::reflection::description::UnboxParameter<::vl::collections::Array<::vl::presentation::Point>>(::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(4); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(8); return __vwsn_temp__; }())).list))).Ref()); } { ::vl::__vwsn::This(this->__vwsn_precompile_2.Obj())->SetSize([&](){ ::vl::presentation::Size __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(5); __vwsn_temp__.y = static_cast<::vl::vint>(9); return __vwsn_temp__; }()); @@ -25876,7 +25876,7 @@ Class (::darkskin::ListViewColumnHeaderTemplateConstructor) } (this->__vwsn_precompile_8 = ::vl::Ptr<::vl::presentation::elements::GuiPolygonElement>(::vl::reflection::description::Element_Constructor<::vl::presentation::elements::GuiPolygonElement>())); { - [&]()->decltype(auto){ auto __vwsn_temp_x0 = ::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(3); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(3); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(6); __vwsn_temp__.y = static_cast<::vl::vint>(3); return __vwsn_temp__; }())).list)); ::vl::collections::Array<::vl::presentation::Point> __vwsn_temp_0; ::vl::reflection::description::UnboxParameter(__vwsn_temp_x0, __vwsn_temp_0); return ::vl::__vwsn::This(this->__vwsn_precompile_8.Obj())->SetPointsArray(__vwsn_temp_0); }(); + ::vl::__vwsn::This(this->__vwsn_precompile_8.Obj())->SetPointsArray(::vl::reflection::description::UnboxParameter<::vl::collections::Array<::vl::presentation::Point>>(::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(3); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(3); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(6); __vwsn_temp__.y = static_cast<::vl::vint>(3); return __vwsn_temp__; }())).list))).Ref()); } { ::vl::__vwsn::This(this->__vwsn_precompile_8.Obj())->SetSize([&](){ ::vl::presentation::Size __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(7); __vwsn_temp__.y = static_cast<::vl::vint>(4); return __vwsn_temp__; }()); @@ -25893,7 +25893,7 @@ Class (::darkskin::ListViewColumnHeaderTemplateConstructor) } (this->__vwsn_precompile_10 = ::vl::Ptr<::vl::presentation::elements::GuiPolygonElement>(::vl::reflection::description::Element_Constructor<::vl::presentation::elements::GuiPolygonElement>())); { - [&]()->decltype(auto){ auto __vwsn_temp_x0 = ::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(3); __vwsn_temp__.y = static_cast<::vl::vint>(3); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(6); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }())).list)); ::vl::collections::Array<::vl::presentation::Point> __vwsn_temp_0; ::vl::reflection::description::UnboxParameter(__vwsn_temp_x0, __vwsn_temp_0); return ::vl::__vwsn::This(this->__vwsn_precompile_10.Obj())->SetPointsArray(__vwsn_temp_0); }(); + ::vl::__vwsn::This(this->__vwsn_precompile_10.Obj())->SetPointsArray(::vl::reflection::description::UnboxParameter<::vl::collections::Array<::vl::presentation::Point>>(::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(3); __vwsn_temp__.y = static_cast<::vl::vint>(3); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(6); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }())).list))).Ref()); } { ::vl::__vwsn::This(this->__vwsn_precompile_10.Obj())->SetSize([&](){ ::vl::presentation::Size __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(7); __vwsn_temp__.y = static_cast<::vl::vint>(4); return __vwsn_temp__; }()); @@ -26376,7 +26376,7 @@ Class (::darkskin::MenuItemButtonTemplateConstructor) } (this->__vwsn_precompile_11 = ::vl::Ptr<::vl::presentation::elements::GuiPolygonElement>(::vl::reflection::description::Element_Constructor<::vl::presentation::elements::GuiPolygonElement>())); { - [&]()->decltype(auto){ auto __vwsn_temp_x0 = ::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(3); __vwsn_temp__.y = static_cast<::vl::vint>(3); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(6); return __vwsn_temp__; }())).list)); ::vl::collections::Array<::vl::presentation::Point> __vwsn_temp_0; ::vl::reflection::description::UnboxParameter(__vwsn_temp_x0, __vwsn_temp_0); return ::vl::__vwsn::This(this->__vwsn_precompile_11.Obj())->SetPointsArray(__vwsn_temp_0); }(); + ::vl::__vwsn::This(this->__vwsn_precompile_11.Obj())->SetPointsArray(::vl::reflection::description::UnboxParameter<::vl::collections::Array<::vl::presentation::Point>>(::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(3); __vwsn_temp__.y = static_cast<::vl::vint>(3); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(6); return __vwsn_temp__; }())).list))).Ref()); } { ::vl::__vwsn::This(this->__vwsn_precompile_11.Obj())->SetSize([&](){ ::vl::presentation::Size __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(7); return __vwsn_temp__; }()); @@ -27051,7 +27051,7 @@ Class (::darkskin::RibbonGalleryDropdownButtonTemplateConstructor) } (this->__vwsn_precompile_4 = ::vl::Ptr<::vl::presentation::elements::GuiPolygonElement>(::vl::reflection::description::Element_Constructor<::vl::presentation::elements::GuiPolygonElement>())); { - [&]()->decltype(auto){ auto __vwsn_temp_x0 = ::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(4); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(8); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }())).list)); ::vl::collections::Array<::vl::presentation::Point> __vwsn_temp_0; ::vl::reflection::description::UnboxParameter(__vwsn_temp_x0, __vwsn_temp_0); return ::vl::__vwsn::This(this->__vwsn_precompile_4.Obj())->SetPointsArray(__vwsn_temp_0); }(); + ::vl::__vwsn::This(this->__vwsn_precompile_4.Obj())->SetPointsArray(::vl::reflection::description::UnboxParameter<::vl::collections::Array<::vl::presentation::Point>>(::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(4); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(8); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }())).list))).Ref()); } { ::vl::__vwsn::This(this->__vwsn_precompile_4.Obj())->SetSize([&](){ ::vl::presentation::Size __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(9); __vwsn_temp__.y = static_cast<::vl::vint>(5); return __vwsn_temp__; }()); @@ -27373,7 +27373,7 @@ Class (::darkskin::RibbonGroupExpandButtonTemplateConstructor) } (this->__vwsn_precompile_1 = ::vl::Ptr<::vl::presentation::elements::GuiPolygonElement>(::vl::reflection::description::Element_Constructor<::vl::presentation::elements::GuiPolygonElement>())); { - [&]()->decltype(auto){ auto __vwsn_temp_x0 = ::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(6); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(6); __vwsn_temp__.y = static_cast<::vl::vint>(6); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(6); return __vwsn_temp__; }())).list)); ::vl::collections::Array<::vl::presentation::Point> __vwsn_temp_0; ::vl::reflection::description::UnboxParameter(__vwsn_temp_x0, __vwsn_temp_0); return ::vl::__vwsn::This(this->__vwsn_precompile_1.Obj())->SetPointsArray(__vwsn_temp_0); }(); + ::vl::__vwsn::This(this->__vwsn_precompile_1.Obj())->SetPointsArray(::vl::reflection::description::UnboxParameter<::vl::collections::Array<::vl::presentation::Point>>(::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(6); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(6); __vwsn_temp__.y = static_cast<::vl::vint>(6); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(6); return __vwsn_temp__; }())).list))).Ref()); } { ::vl::__vwsn::This(this->__vwsn_precompile_1.Obj())->SetSize([&](){ ::vl::presentation::Size __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(7); __vwsn_temp__.y = static_cast<::vl::vint>(7); return __vwsn_temp__; }()); @@ -28060,7 +28060,7 @@ Class (::darkskin::RibbonLargeDropdownButtonTemplateConstructor) } (this->__vwsn_precompile_12 = ::vl::Ptr<::vl::presentation::elements::GuiPolygonElement>(::vl::reflection::description::Element_Constructor<::vl::presentation::elements::GuiPolygonElement>())); { - [&]()->decltype(auto){ auto __vwsn_temp_x0 = ::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(2); __vwsn_temp__.y = static_cast<::vl::vint>(2); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }())).list)); ::vl::collections::Array<::vl::presentation::Point> __vwsn_temp_0; ::vl::reflection::description::UnboxParameter(__vwsn_temp_x0, __vwsn_temp_0); return ::vl::__vwsn::This(this->__vwsn_precompile_12.Obj())->SetPointsArray(__vwsn_temp_0); }(); + ::vl::__vwsn::This(this->__vwsn_precompile_12.Obj())->SetPointsArray(::vl::reflection::description::UnboxParameter<::vl::collections::Array<::vl::presentation::Point>>(::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(2); __vwsn_temp__.y = static_cast<::vl::vint>(2); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }())).list))).Ref()); } { ::vl::__vwsn::This(this->__vwsn_precompile_12.Obj())->SetSize([&](){ ::vl::presentation::Size __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(5); __vwsn_temp__.y = static_cast<::vl::vint>(3); return __vwsn_temp__; }()); @@ -28643,7 +28643,7 @@ Class (::darkskin::RibbonSmallDropdownButtonTemplateConstructor) } (this->__vwsn_precompile_11 = ::vl::Ptr<::vl::presentation::elements::GuiPolygonElement>(::vl::reflection::description::Element_Constructor<::vl::presentation::elements::GuiPolygonElement>())); { - [&]()->decltype(auto){ auto __vwsn_temp_x0 = ::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(2); __vwsn_temp__.y = static_cast<::vl::vint>(2); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }())).list)); ::vl::collections::Array<::vl::presentation::Point> __vwsn_temp_0; ::vl::reflection::description::UnboxParameter(__vwsn_temp_x0, __vwsn_temp_0); return ::vl::__vwsn::This(this->__vwsn_precompile_11.Obj())->SetPointsArray(__vwsn_temp_0); }(); + ::vl::__vwsn::This(this->__vwsn_precompile_11.Obj())->SetPointsArray(::vl::reflection::description::UnboxParameter<::vl::collections::Array<::vl::presentation::Point>>(::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(2); __vwsn_temp__.y = static_cast<::vl::vint>(2); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }())).list))).Ref()); } { ::vl::__vwsn::This(this->__vwsn_precompile_11.Obj())->SetSize([&](){ ::vl::presentation::Size __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(5); __vwsn_temp__.y = static_cast<::vl::vint>(3); return __vwsn_temp__; }()); @@ -29186,7 +29186,7 @@ Class (::darkskin::RibbonSplitArrowTemplateConstructor) } (this->__vwsn_precompile_6 = ::vl::Ptr<::vl::presentation::elements::GuiPolygonElement>(::vl::reflection::description::Element_Constructor<::vl::presentation::elements::GuiPolygonElement>())); { - [&]()->decltype(auto){ auto __vwsn_temp_x0 = ::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(2); __vwsn_temp__.y = static_cast<::vl::vint>(2); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }())).list)); ::vl::collections::Array<::vl::presentation::Point> __vwsn_temp_0; ::vl::reflection::description::UnboxParameter(__vwsn_temp_x0, __vwsn_temp_0); return ::vl::__vwsn::This(this->__vwsn_precompile_6.Obj())->SetPointsArray(__vwsn_temp_0); }(); + ::vl::__vwsn::This(this->__vwsn_precompile_6.Obj())->SetPointsArray(::vl::reflection::description::UnboxParameter<::vl::collections::Array<::vl::presentation::Point>>(::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(2); __vwsn_temp__.y = static_cast<::vl::vint>(2); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }())).list))).Ref()); } { ::vl::__vwsn::This(this->__vwsn_precompile_6.Obj())->SetSize([&](){ ::vl::presentation::Size __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(5); __vwsn_temp__.y = static_cast<::vl::vint>(3); return __vwsn_temp__; }()); @@ -29570,7 +29570,7 @@ Class (::darkskin::RightScrollButtonTemplateConstructor) } (this->__vwsn_precompile_2 = ::vl::Ptr<::vl::presentation::elements::GuiPolygonElement>(::vl::reflection::description::Element_Constructor<::vl::presentation::elements::GuiPolygonElement>())); { - [&]()->decltype(auto){ auto __vwsn_temp_x0 = ::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(4); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(8); return __vwsn_temp__; }())).list)); ::vl::collections::Array<::vl::presentation::Point> __vwsn_temp_0; ::vl::reflection::description::UnboxParameter(__vwsn_temp_x0, __vwsn_temp_0); return ::vl::__vwsn::This(this->__vwsn_precompile_2.Obj())->SetPointsArray(__vwsn_temp_0); }(); + ::vl::__vwsn::This(this->__vwsn_precompile_2.Obj())->SetPointsArray(::vl::reflection::description::UnboxParameter<::vl::collections::Array<::vl::presentation::Point>>(::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(4); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(8); return __vwsn_temp__; }())).list))).Ref()); } { ::vl::__vwsn::This(this->__vwsn_precompile_2.Obj())->SetSize([&](){ ::vl::presentation::Size __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(5); __vwsn_temp__.y = static_cast<::vl::vint>(9); return __vwsn_temp__; }()); @@ -30835,7 +30835,7 @@ Class (::darkskin::ToolstripDropdownButtonTemplateConstructor) } (this->__vwsn_precompile_8 = ::vl::Ptr<::vl::presentation::elements::GuiPolygonElement>(::vl::reflection::description::Element_Constructor<::vl::presentation::elements::GuiPolygonElement>())); { - [&]()->decltype(auto){ auto __vwsn_temp_x0 = ::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(2); __vwsn_temp__.y = static_cast<::vl::vint>(2); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }())).list)); ::vl::collections::Array<::vl::presentation::Point> __vwsn_temp_0; ::vl::reflection::description::UnboxParameter(__vwsn_temp_x0, __vwsn_temp_0); return ::vl::__vwsn::This(this->__vwsn_precompile_8.Obj())->SetPointsArray(__vwsn_temp_0); }(); + ::vl::__vwsn::This(this->__vwsn_precompile_8.Obj())->SetPointsArray(::vl::reflection::description::UnboxParameter<::vl::collections::Array<::vl::presentation::Point>>(::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(2); __vwsn_temp__.y = static_cast<::vl::vint>(2); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }())).list))).Ref()); } { ::vl::__vwsn::This(this->__vwsn_precompile_8.Obj())->SetSize([&](){ ::vl::presentation::Size __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(5); __vwsn_temp__.y = static_cast<::vl::vint>(3); return __vwsn_temp__; }()); @@ -31032,7 +31032,7 @@ Class (::darkskin::ToolstripSplitArrowTemplateConstructor) } (this->__vwsn_precompile_3 = ::vl::Ptr<::vl::presentation::elements::GuiPolygonElement>(::vl::reflection::description::Element_Constructor<::vl::presentation::elements::GuiPolygonElement>())); { - [&]()->decltype(auto){ auto __vwsn_temp_x0 = ::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(2); __vwsn_temp__.y = static_cast<::vl::vint>(2); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }())).list)); ::vl::collections::Array<::vl::presentation::Point> __vwsn_temp_0; ::vl::reflection::description::UnboxParameter(__vwsn_temp_x0, __vwsn_temp_0); return ::vl::__vwsn::This(this->__vwsn_precompile_3.Obj())->SetPointsArray(__vwsn_temp_0); }(); + ::vl::__vwsn::This(this->__vwsn_precompile_3.Obj())->SetPointsArray(::vl::reflection::description::UnboxParameter<::vl::collections::Array<::vl::presentation::Point>>(::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(2); __vwsn_temp__.y = static_cast<::vl::vint>(2); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }())).list))).Ref()); } { ::vl::__vwsn::This(this->__vwsn_precompile_3.Obj())->SetSize([&](){ ::vl::presentation::Size __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(5); __vwsn_temp__.y = static_cast<::vl::vint>(3); return __vwsn_temp__; }()); @@ -31479,7 +31479,7 @@ Class (::darkskin::TopScrollButtonTemplateConstructor) } (this->__vwsn_precompile_2 = ::vl::Ptr<::vl::presentation::elements::GuiPolygonElement>(::vl::reflection::description::Element_Constructor<::vl::presentation::elements::GuiPolygonElement>())); { - [&]()->decltype(auto){ auto __vwsn_temp_x0 = ::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(4); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(8); __vwsn_temp__.y = static_cast<::vl::vint>(4); return __vwsn_temp__; }())).list)); ::vl::collections::Array<::vl::presentation::Point> __vwsn_temp_0; ::vl::reflection::description::UnboxParameter(__vwsn_temp_x0, __vwsn_temp_0); return ::vl::__vwsn::This(this->__vwsn_precompile_2.Obj())->SetPointsArray(__vwsn_temp_0); }(); + ::vl::__vwsn::This(this->__vwsn_precompile_2.Obj())->SetPointsArray(::vl::reflection::description::UnboxParameter<::vl::collections::Array<::vl::presentation::Point>>(::vl::__vwsn::Box(::vl::Ptr<::vl::reflection::description::IValueReadonlyList>((::vl::__vwsn::CreateArray().Resize(3).Set(0, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(0); __vwsn_temp__.y = static_cast<::vl::vint>(4); return __vwsn_temp__; }()).Set(1, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(4); __vwsn_temp__.y = static_cast<::vl::vint>(0); return __vwsn_temp__; }()).Set(2, [&](){ ::vl::presentation::Point __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(8); __vwsn_temp__.y = static_cast<::vl::vint>(4); return __vwsn_temp__; }())).list))).Ref()); } { ::vl::__vwsn::This(this->__vwsn_precompile_2.Obj())->SetSize([&](){ ::vl::presentation::Size __vwsn_temp__; __vwsn_temp__.x = static_cast<::vl::vint>(9); __vwsn_temp__.y = static_cast<::vl::vint>(5); return __vwsn_temp__; }()); diff --git a/Import/Skins/DarkSkin/DarkSkin.h b/Import/Skins/DarkSkin/DarkSkin.h index 35a4a318..3358e3e9 100644 --- a/Import/Skins/DarkSkin/DarkSkin.h +++ b/Import/Skins/DarkSkin/DarkSkin.h @@ -6,8 +6,8 @@ DEVELOPER: Zihan Chen(vczh) #include "VlppParser.h" #include "VlppWorkflowLibrary.h" #include "VlppReflection.h" -#include "Vlpp.h" #include "VlppOS.h" +#include "Vlpp.h" #include "VlppRegex.h" /*********************************************************************** diff --git a/Import/Skins/DarkSkin/DarkSkinReflection.h b/Import/Skins/DarkSkin/DarkSkinReflection.h index 0e2a9529..178922a4 100644 --- a/Import/Skins/DarkSkin/DarkSkinReflection.h +++ b/Import/Skins/DarkSkin/DarkSkinReflection.h @@ -8,8 +8,8 @@ DEVELOPER: Zihan Chen(vczh) #include "VlppParser.h" #include "VlppWorkflowLibrary.h" #include "VlppReflection.h" -#include "Vlpp.h" #include "VlppOS.h" +#include "Vlpp.h" #include "VlppRegex.h" /*********************************************************************** diff --git a/Import/VlppParser.h b/Import/VlppParser.h index 3437d1c4..f239e823 100644 --- a/Import/VlppParser.h +++ b/Import/VlppParser.h @@ -3,8 +3,8 @@ THIS FILE IS AUTOMATICALLY GENERATED. DO NOT MODIFY DEVELOPER: Zihan Chen(vczh) ***********************************************************************/ #include "VlppReflection.h" -#include "Vlpp.h" #include "VlppOS.h" +#include "Vlpp.h" #include "VlppRegex.h" /*********************************************************************** diff --git a/Import/VlppReflection.cpp b/Import/VlppReflection.cpp index ff2e2343..de6124de 100644 --- a/Import/VlppReflection.cpp +++ b/Import/VlppReflection.cpp @@ -5,7 +5,7 @@ DEVELOPER: Zihan Chen(vczh) #include "VlppReflection.h" /*********************************************************************** -.\GUITYPEDESCRIPTOR.CPP +.\DESCRIPTABLEINTERFACES.CPP ***********************************************************************/ /*********************************************************************** Author: Zihan Chen (vczh) @@ -19,7 +19,1999 @@ namespace vl namespace reflection { + namespace description + { +/*********************************************************************** +description::TypeManager +***********************************************************************/ +#ifndef VCZH_DEBUG_NO_REFLECTION + + class TypeManager : public Object, public ITypeManager + { + public: + static vint typeVersion; + + protected: + Dictionary> typeDescriptors; + List> typeLoaders; + ITypeDescriptor* rootType = nullptr; + bool loaded = false; + + public: + TypeManager() + { + } + + ~TypeManager() + { + Unload(); + } + + vint GetTypeDescriptorCount()override + { + return typeDescriptors.Values().Count(); + } + + ITypeDescriptor* GetTypeDescriptor(vint index)override + { + return typeDescriptors.Values().Get(index).Obj(); + } + + ITypeDescriptor* GetTypeDescriptor(const WString& name)override + { + vint index = typeDescriptors.Keys().IndexOf(name); + return index == -1 ? 0 : typeDescriptors.Values().Get(index).Obj(); + } + + bool SetTypeDescriptor(const WString& name, Ptr typeDescriptor)override + { + if (typeDescriptor && name != typeDescriptor->GetTypeName()) + { + return false; + } + if (!typeDescriptors.Keys().Contains(name)) + { + if (typeDescriptor) + { + typeDescriptors.Add(name, typeDescriptor); + typeVersion++; + return true; + } + } + else + { + if (!typeDescriptor) + { + typeDescriptors.Remove(name); + typeVersion++; + return true; + } + } + return false; + } + + bool AddTypeLoader(Ptr typeLoader)override + { + vint index = typeLoaders.IndexOf(typeLoader.Obj()); + if (index == -1) + { + typeLoaders.Add(typeLoader); + if (loaded) + { + auto oldTypeVersion = typeVersion; + typeLoader->Load(this); + typeVersion = oldTypeVersion + 1; + } + return true; + } + else + { + return false; + } + } + + bool RemoveTypeLoader(Ptr typeLoader)override + { + vint index = typeLoaders.IndexOf(typeLoader.Obj()); + if (index != -1) + { + if (loaded) + { + auto oldTypeVersion = typeVersion; + typeLoader->Unload(this); + typeVersion = oldTypeVersion + 1; + } + typeLoaders.RemoveAt(index); + return true; + } + else + { + return false; + } + } + + bool Load()override + { + if (!loaded) + { + loaded = true; + auto oldTypeVersion = typeVersion; + for (vint i = 0; i < typeLoaders.Count(); i++) + { + typeLoaders[i]->Load(this); + } + typeVersion = oldTypeVersion + 1; + return true; + } + else + { + return false; + } + } + + bool Unload()override + { + if (loaded) + { + loaded = false; + rootType = 0; + auto oldTypeVersion = typeVersion; + for (vint i = 0; i < typeLoaders.Count(); i++) + { + typeLoaders[i]->Unload(this); + } + typeVersion = oldTypeVersion + 1; + typeDescriptors.Clear(); + return true; + } + else + { + return false; + } + } + + bool Reload()override + { + Unload(); + Load(); + return true; + } + + bool IsLoaded()override + { + return loaded; + } + + ITypeDescriptor* GetRootType()override + { + if (!rootType) + { + rootType = description::GetTypeDescriptor(); + } + return rootType; + } + + vint GetTypeVersion() override + { + return typeVersion; + } + }; + vint TypeManager::typeVersion = -1; + +/*********************************************************************** +description::TypeManager helper functions +***********************************************************************/ + + ITypeManager* globalTypeManager=0; + bool initializedGlobalTypeManager=false; + + ITypeManager* GetGlobalTypeManager() + { + if (!initializedGlobalTypeManager) + { + initializedGlobalTypeManager = true; + globalTypeManager = new TypeManager; + } + return globalTypeManager; + } + + bool DestroyGlobalTypeManager() + { + if (initializedGlobalTypeManager && globalTypeManager) + { + delete globalTypeManager; + globalTypeManager = nullptr; + TypeManager::typeVersion++; + return true; + } + else + { + return false; + } + } + + bool ResetGlobalTypeManager() + { + if (!DestroyGlobalTypeManager()) return false; + initializedGlobalTypeManager = false; + return true; + } + + ITypeDescriptor* GetTypeDescriptor(const WString& name) + { + if (globalTypeManager) + { + if (!globalTypeManager->IsLoaded()) + { + globalTypeManager->Load(); + } + return globalTypeManager->GetTypeDescriptor(name); + } + return nullptr; + } + +/*********************************************************************** +Cpp Helper Functions +***********************************************************************/ + + WString CppGetFullName(ITypeDescriptor* type) + { + if (auto cpp = type->GetCpp()) + { + if (cpp->GetFullName() == L"void" || cpp->GetFullName() == L"vl::reflection::description::VoidValue") + { + return L"void"; + } + else if (cpp->GetFullName() == L"float") + { + return L"float"; + } + else if (cpp->GetFullName() == L"double") + { + return L"double"; + } + else if (cpp->GetFullName() == L"bool") + { + return L"bool"; + } + else if (cpp->GetFullName() == L"wchar_t") + { + return L"wchar_t"; + } + else + { + return L"::" + cpp->GetFullName(); + } + } + else + { + return L"::vl::" + type->GetTypeName(); + } + } + + WString CppGetReferenceTemplate(IPropertyInfo* prop) + { + if (auto cpp = prop->GetCpp()) + { + return cpp->GetReferenceTemplate(); + } + else if ((prop->GetOwnerTypeDescriptor()->GetTypeDescriptorFlags() & TypeDescriptorFlags::ReferenceType) != TypeDescriptorFlags::Undefined) + { + return WString::Unmanaged(L"$This->$Name"); + } + else + { + return WString::Unmanaged(L"$This.$Name"); + } + } + + WString CppGetClosureTemplate(IMethodInfo* method) + { + if (auto cpp = method->GetCpp()) + { + return cpp->GetClosureTemplate(); + } + + if (method->IsStatic()) + { + return WString::Unmanaged(L"::vl::Func<$Func>(&$Type::$Name)"); + } + else + { + return WString::Unmanaged(L"::vl::Func<$Func>($This, &$Type::$Name)"); + } + } + + WString CppGetInvokeTemplate(IMethodInfo* method) + { + if (auto cpp = method->GetCpp()) + { + return cpp->GetInvokeTemplate(); + } + + if (method->GetOwnerMethodGroup() == method->GetOwnerTypeDescriptor()->GetConstructorGroup()) + { + return WString::Unmanaged(L"new $Type($Arguments)"); + } + else if (method->IsStatic()) + { + return WString::Unmanaged(L"$Type::$Name($Arguments)"); + } + else + { + return WString::Unmanaged(L"$This->$Name($Arguments)"); + } + } + + WString CppGetAttachTemplate(IEventInfo* ev) + { + auto cpp = ev->GetCpp(); + return cpp == nullptr ? WString::Unmanaged(L"::vl::__vwsn::EventAttach($This->$Name, $Handler)") : cpp->GetAttachTemplate(); + } + + WString CppGetDetachTemplate(IEventInfo* ev) + { + auto cpp = ev->GetCpp(); + return cpp == nullptr ? WString::Unmanaged(L"::vl::__vwsn::EventDetach($This->$Name, $Handler)") : cpp->GetDetachTemplate(); + } + + WString CppGetInvokeTemplate(IEventInfo* ev) + { + auto cpp = ev->GetCpp(); + return cpp == nullptr ? WString::Unmanaged(L"::vl::__vwsn::EventInvoke($This->$Name)($Arguments)") : cpp->GetInvokeTemplate(); + } + + bool CppExists(ITypeDescriptor* type) + { + auto cpp = type->GetCpp(); + return cpp == nullptr || cpp->GetFullName() != L"*"; + } + + bool CppExists(IPropertyInfo* prop) + { + if (auto cpp = prop->GetCpp()) + { + return cpp->GetReferenceTemplate() != L"*"; + } + else if (auto method = prop->GetGetter()) + { + return CppExists(method); + } + else + { + return true; + } + } + + bool CppExists(IMethodInfo* method) + { + auto cpp = method->GetCpp(); + return cpp == nullptr || cpp->GetInvokeTemplate() != L"*"; + } + + bool CppExists(IEventInfo* ev) + { + auto cpp = ev->GetCpp(); + return cpp == nullptr || cpp->GetInvokeTemplate() != L"*"; + } + +#endif + } + } +} + + +/*********************************************************************** +.\DESCRIPTABLEINTERFACES_LOG.CPP +***********************************************************************/ +/*********************************************************************** +Author: Zihan Chen (vczh) +Licensed under https://github.com/vczh-libraries/License +***********************************************************************/ + + +namespace vl +{ + namespace reflection + { + namespace description + { + using namespace collections; + +#ifndef VCZH_DEBUG_NO_REFLECTION + +/*********************************************************************** +LogTypeManager (enum) +***********************************************************************/ + + void LogTypeManager_Enum(stream::TextWriter& writer, ITypeDescriptor* type) + { + if (type->GetTypeDescriptorFlags() == TypeDescriptorFlags::FlagEnum) + { + writer.WriteLine(L"@Flags"); + } + writer.WriteLine(L"enum " + type->GetTypeName() + L" {"); + + auto enumType = type->GetEnumType(); + for (vint j = 0; j < enumType->GetItemCount(); j++) + { + writer.WriteLine(L" " + enumType->GetItemName(j) + L" = " + u64tow(enumType->GetItemValue(j)) + L","); + } + + writer.WriteLine(L"}"); + } + +/*********************************************************************** +LogTypeManager (struct) +***********************************************************************/ + + void LogTypeManager_Property(stream::TextWriter& writer, IPropertyInfo* info) + { + if (auto cpp = info->GetCpp()) + { + writer.WriteLine(L" @ReferenceTemplate:" + cpp->GetReferenceTemplate()); + } + writer.WriteString(L" property " + info->GetName() + L" : " + info->GetReturn()->GetTypeFriendlyName()); + if (info->IsReadable() && info->IsWritable() && !info->GetGetter() && !info->GetSetter() && !info->GetValueChangedEvent()) + { + writer.WriteLine(L";"); + } + else + { + writer.WriteString(L" { "); + if (info->IsReadable()) + { + writer.WriteString(L"get"); + if (auto mi = info->GetGetter()) + { + writer.WriteString(L":" + mi->GetName()); + } + writer.WriteString(L" "); + } + if (info->IsWritable()) + { + writer.WriteString(L"set"); + if (auto mi = info->GetSetter()) + { + writer.WriteString(L":" + mi->GetName()); + } + writer.WriteString(L" "); + } + if (auto ei = info->GetValueChangedEvent()) + { + writer.WriteString(L"event:" + ei->GetName() + L" "); + } + writer.WriteLine(L"}"); + } + } + + void LogTypeManager_Struct(stream::TextWriter& writer, ITypeDescriptor* type) + { + writer.WriteLine(L"struct " + type->GetTypeName() + L" {"); + for (vint j = 0; jGetPropertyCount(); j++) + { + IPropertyInfo* info = type->GetProperty(j); + LogTypeManager_Property(writer, info); + } + writer.WriteLine(L"}"); + } + +/*********************************************************************** +LogTypeManager (data) +***********************************************************************/ + + void LogTypeManager_Data(stream::TextWriter& writer, ITypeDescriptor* type) + { + writer.WriteLine(L"primitive " + type->GetTypeName() + L";"); + } + +/*********************************************************************** +LogTypeManager (class) +***********************************************************************/ + + void LogTypeManager_PrintEvents(stream::TextWriter& writer, ITypeDescriptor* type) + { + bool printed = false; + for (vint j = 0; j < type->GetEventCount(); j++) + { + printed = true; + IEventInfo* info = type->GetEvent(j); + if (auto cpp = info->GetCpp()) + { + writer.WriteLine(L" @AttachTemplate:" + cpp->GetAttachTemplate()); + writer.WriteLine(L" @DetachTemplate:" + cpp->GetDetachTemplate()); + writer.WriteLine(L" @InvokeTemplate:" + cpp->GetInvokeTemplate()); + } + + writer.WriteString(L" event " + info->GetName() + L" : " + info->GetHandlerType()->GetTypeFriendlyName()); + + if (info->GetObservingPropertyCount() > 0) + { + writer.WriteString(L" observing {"); + vint count = info->GetObservingPropertyCount(); + for (vint i = 0; i < count; i++) + { + writer.WriteLine(L" " + info->GetObservingProperty(i)->GetName() + L","); + } + writer.WriteString(L"}"); + } + else + { + writer.WriteLine(L";"); + } + } + if (printed) + { + writer.WriteLine(L""); + } + } + + void LogTypeManager_PrintProperties(stream::TextWriter& writer, ITypeDescriptor* type) + { + bool printed = false; + for (vint j = 0; j < type->GetPropertyCount(); j++) + { + printed = true; + IPropertyInfo* info = type->GetProperty(j); + LogTypeManager_Property(writer, info); + } + if (printed) + { + writer.WriteLine(L""); + } + } + + void LogTypeManager_Method(stream::TextWriter& writer, IMethodInfo* info, const wchar_t* title) + { + if (auto cpp = info->GetCpp()) + { + writer.WriteLine(L" @InvokeTemplate:" + cpp->GetInvokeTemplate()); + writer.WriteLine(L" @ClosureTemplate:" + cpp->GetClosureTemplate()); + } + + writer.WriteString(L" "); + writer.WriteString(title); + writer.WriteString(L" " + info->GetName() + L"("); + for (vint l = 0; l < info->GetParameterCount(); l++) + { + if (l > 0) writer.WriteString(L", "); + IParameterInfo* parameter = info->GetParameter(l); + writer.WriteString(parameter->GetName() + L" : " + parameter->GetType()->GetTypeFriendlyName()); + } + writer.WriteLine(L") : " + info->GetReturn()->GetTypeFriendlyName() + L";"); + } + + void LogTypeManager_PrintMethods(stream::TextWriter& writer, ITypeDescriptor* type) + { + bool printed = false; + for (vint j = 0; j < type->GetMethodGroupCount(); j++) + { + IMethodGroupInfo* group = type->GetMethodGroup(j); + for (vint k = 0; k < group->GetMethodCount(); k++) + { + printed = true; + IMethodInfo* info = group->GetMethod(k); + if (info->IsStatic()) + { + LogTypeManager_Method(writer, info, L"static function"); + } + else + { + LogTypeManager_Method(writer, info, L"function"); + } + } + } + if (printed) + { + writer.WriteLine(L""); + } + } + + void LogTypeManager_PrintConstructors(stream::TextWriter& writer, ITypeDescriptor* type) + { + if (IMethodGroupInfo* group = type->GetConstructorGroup()) + { + for (vint k = 0; k < group->GetMethodCount(); k++) + { + IMethodInfo* info = group->GetMethod(k); + LogTypeManager_Method(writer, info, L"constructor"); + } + } + } + + void LogTypeManager_Class(stream::TextWriter& writer, ITypeDescriptor* type) + { + bool acceptProxy = false; + bool isInterface = (type->GetTypeDescriptorFlags() & TypeDescriptorFlags::InterfaceType) != TypeDescriptorFlags::Undefined; + writer.WriteString((isInterface ? L"interface " : L"class ") + type->GetTypeName()); + for (vint j = 0; jGetBaseTypeDescriptorCount(); j++) + { + writer.WriteString(j == 0 ? L" : " : L", "); + writer.WriteString(type->GetBaseTypeDescriptor(j)->GetTypeName()); + } + writer.WriteLine(L" {"); + + LogTypeManager_PrintEvents(writer, type); + LogTypeManager_PrintProperties(writer, type); + LogTypeManager_PrintMethods(writer, type); + LogTypeManager_PrintConstructors(writer, type); + + writer.WriteLine(L"}"); + } + +/*********************************************************************** +LogTypeManager +***********************************************************************/ + + bool IsInterfaceType(ITypeDescriptor* typeDescriptor, bool& acceptProxy) + { + bool containsConstructor = false; + if (IMethodGroupInfo* group = typeDescriptor->GetConstructorGroup()) + { + containsConstructor = group->GetMethodCount() > 0; + if (group->GetMethodCount() == 1) + { + if (IMethodInfo* info = group->GetMethod(0)) + { + if (info->GetParameterCount() == 1 && info->GetParameter(0)->GetType()->GetTypeDescriptor()->GetTypeName() == TypeInfo::content.typeName) + { + acceptProxy = true; + return true; + } + } + } + } + + if (!containsConstructor) + { + if (typeDescriptor->GetTypeName() == TypeInfo::content.typeName) + { + return true; + } + else + { + for (vint i = 0; i < typeDescriptor->GetBaseTypeDescriptorCount(); i++) + { + bool _acceptProxy = false; + if (!IsInterfaceType(typeDescriptor->GetBaseTypeDescriptor(i), _acceptProxy)) + { + return false; + } + } + const wchar_t* name = typeDescriptor->GetTypeName().Buffer(); + while (const wchar_t* next = ::wcschr(name, L':')) + { + name = next + 1; + } + return name[0] == L'I' && (L'A' <= name[1] && name[1] <= L'Z'); + } + } + return false; + } + + void LogTypeManager(stream::TextWriter& writer) + { + for (vint i = 0; i < GetGlobalTypeManager()->GetTypeDescriptorCount(); i++) + { + ITypeDescriptor* type = GetGlobalTypeManager()->GetTypeDescriptor(i); + if (auto cpp = type->GetCpp()) + { + writer.WriteLine(L"@FullName:" + cpp->GetFullName()); + } + if (type->GetValueType()) + { + writer.WriteLine(L"@ValueType"); + } + if (type->GetSerializableType()) + { + writer.WriteLine(L"@Serializable"); + } + + switch (type->GetTypeDescriptorFlags()) + { + case TypeDescriptorFlags::Object: + case TypeDescriptorFlags::IDescriptable: + case TypeDescriptorFlags::Class: + case TypeDescriptorFlags::Interface: + LogTypeManager_Class(writer, type); + break; + case TypeDescriptorFlags::FlagEnum: + case TypeDescriptorFlags::NormalEnum: + LogTypeManager_Enum(writer, type); + break; + case TypeDescriptorFlags::Primitive: + LogTypeManager_Data(writer, type); + break; + case TypeDescriptorFlags::Struct: + LogTypeManager_Struct(writer, type); + break; + default:; + } + writer.WriteLine(L""); + } + } +#endif + } + } +} + + +/*********************************************************************** +.\DESCRIPTABLEINTERFACES_METAONLY.CPP +***********************************************************************/ +/*********************************************************************** +Author: Zihan Chen (vczh) +Licensed under https://github.com/vczh-libraries/License +***********************************************************************/ + + +#ifndef VCZH_DEBUG_NO_REFLECTION + +namespace vl +{ + namespace reflection + { + namespace description + { + using namespace collections; + +/*********************************************************************** +Context +***********************************************************************/ + + struct MetaonlyWriterContext + { + Dictionary tdIndex; + Dictionary miIndex; + Dictionary piIndex; + Dictionary eiIndex; + }; + + struct MetaonlyReaderContext + { + Dictionary> serializableTypes; + List> tds; + List> mis; + List> pis; + List> eis; + }; + +/*********************************************************************** +MetaonlyTypeInfo +***********************************************************************/ + + class MetaonlyTypeInfo : public Object, public ITypeInfo + { + friend struct stream::internal::Serialization; + protected: + MetaonlyReaderContext* context = nullptr; + Decorator decorator = TypeDescriptor; + TypeInfoHint hint = TypeInfoHint::Normal; + Ptr elementType; + vint typeDecriptor = -1; + List> genericArguments; + + public: + MetaonlyTypeInfo() = default; + + MetaonlyTypeInfo(MetaonlyWriterContext& _context, ITypeInfo* typeInfo) + : decorator(typeInfo->GetDecorator()) + , hint(typeInfo->GetHint()) + , typeDecriptor(_context.tdIndex[typeInfo->GetTypeDescriptor()]) + { + if (auto et = typeInfo->GetElementType()) + { + elementType = new MetaonlyTypeInfo(_context, et); + } + for (vint i = 0; i < typeInfo->GetGenericArgumentCount(); i++) + { + auto ga = typeInfo->GetGenericArgument(i); + genericArguments.Add(new MetaonlyTypeInfo(_context, ga)); + } + } + + void SetContext(MetaonlyReaderContext* _context) + { + context = _context; + if (elementType) + { + elementType->SetContext(_context); + } + for (vint i = 0; i < genericArguments.Count(); i++) + { + genericArguments[i]->SetContext(_context); + } + } + + Decorator GetDecorator() override + { + return decorator; + } + + TypeInfoHint GetHint() override + { + return hint; + } + + ITypeInfo* GetElementType() override + { + return elementType.Obj(); + } + + ITypeDescriptor* GetTypeDescriptor() override + { + return context->tds[typeDecriptor].Obj(); + } + + vint GetGenericArgumentCount() override + { + return genericArguments.Count(); + } + + ITypeInfo* GetGenericArgument(vint index) override + { + return genericArguments[index].Obj(); + } + + WString GetTypeFriendlyName() override + { + switch (decorator) + { + case RawPtr: return elementType->GetTypeFriendlyName() + L"*"; + case SharedPtr: return elementType->GetTypeFriendlyName() + L"^"; + case Nullable: return elementType->GetTypeFriendlyName() + L"?"; + case TypeDescriptor: return GetTypeDescriptor()->GetTypeName(); + default:; + } + WString result = elementType->GetTypeFriendlyName() + L"<"; + for (auto [type, i] : indexed(genericArguments)) + { + if (i > 0) result += L", "; + result += type->GetTypeFriendlyName(); + } + result += L">"; + return result; + } + }; + + ITypeInfo* EnsureSetContext(ITypeInfo* info, MetaonlyReaderContext* context) + { + if (auto minfo = dynamic_cast(info)) + { + minfo->SetContext(context); + } + return info; + } + +/*********************************************************************** +Metadata +***********************************************************************/ + + struct IdRange + { + vint start = -1; + vint count = 0; + }; + + struct ParameterInfoMetadata + { + WString name; + Ptr type; + }; + + struct MethodInfoMetadata + { + WString invokeTemplate; + WString closureTemplate; + WString name; + vint ownerTypeDescriptor = -1; + vint ownerProperty = -1; + List> parameters; + Ptr returnType; + bool isStatic = false; + }; + + struct PropertyInfoMetadata + { + WString referenceTemplate; + WString name; + vint ownerTypeDescriptor = -1; + bool isReadable = false; + bool isWritable = false; + Ptr returnType; + vint getter = -1; + vint setter = -1; + vint valueChangedEvent = -1; + }; + + struct EventInfoMetadata + { + WString attachTemplate; + WString detachTemplate; + WString invokeTemplate; + WString name; + vint ownerTypeDescriptor = -1; + Ptr handlerType; + List observingProperties; + }; + + struct TypeDescriptorMetadata + { + WString fullName; + WString typeName; + TypeDescriptorFlags flags = TypeDescriptorFlags::Undefined; + bool isAggregatable = false; + bool isValueType = false; + bool isSerializable = false; + bool isEnumType = false; + bool isFlagEnum = false; + List enumItems; + List enumValues; + List baseTypeDescriptors; + List properties; + List events; + List methods; + List methodGroups; + IdRange constructorGroup; + }; + } + } + + namespace stream + { + namespace internal + { + +/*********************************************************************** +Serialization +***********************************************************************/ + + SERIALIZE_ENUM(reflection::description::ITypeInfo::Decorator) + SERIALIZE_ENUM(reflection::description::TypeInfoHint) + SERIALIZE_ENUM(reflection::description::TypeDescriptorFlags) + + BEGIN_SERIALIZATION(reflection::description::IdRange) + SERIALIZE(start) + SERIALIZE(count) + END_SERIALIZATION + + BEGIN_SERIALIZATION(reflection::description::MetaonlyTypeInfo) + SERIALIZE(decorator) + SERIALIZE(hint) + SERIALIZE(elementType) + SERIALIZE(typeDecriptor) + SERIALIZE(genericArguments) + END_SERIALIZATION + + BEGIN_SERIALIZATION(reflection::description::ParameterInfoMetadata) + SERIALIZE(name) + SERIALIZE(type) + END_SERIALIZATION + + BEGIN_SERIALIZATION(reflection::description::MethodInfoMetadata) + SERIALIZE(invokeTemplate) + SERIALIZE(closureTemplate) + SERIALIZE(name) + SERIALIZE(ownerTypeDescriptor) + SERIALIZE(ownerProperty) + SERIALIZE(parameters) + SERIALIZE(returnType) + SERIALIZE(isStatic) + END_SERIALIZATION + + BEGIN_SERIALIZATION(reflection::description::PropertyInfoMetadata) + SERIALIZE(referenceTemplate) + SERIALIZE(name) + SERIALIZE(ownerTypeDescriptor) + SERIALIZE(isReadable) + SERIALIZE(isWritable) + SERIALIZE(returnType) + SERIALIZE(getter) + SERIALIZE(setter) + SERIALIZE(valueChangedEvent) + END_SERIALIZATION + + BEGIN_SERIALIZATION(reflection::description::EventInfoMetadata) + SERIALIZE(attachTemplate) + SERIALIZE(detachTemplate) + SERIALIZE(invokeTemplate) + SERIALIZE(name) + SERIALIZE(ownerTypeDescriptor) + SERIALIZE(handlerType) + SERIALIZE(observingProperties) + END_SERIALIZATION + + BEGIN_SERIALIZATION(reflection::description::TypeDescriptorMetadata) + SERIALIZE(fullName) + SERIALIZE(typeName) + SERIALIZE(flags) + SERIALIZE(isAggregatable) + SERIALIZE(isValueType) + SERIALIZE(isSerializable) + SERIALIZE(isEnumType) + SERIALIZE(isFlagEnum) + SERIALIZE(enumItems) + SERIALIZE(enumValues) + SERIALIZE(baseTypeDescriptors) + SERIALIZE(properties) + SERIALIZE(events) + SERIALIZE(methods) + SERIALIZE(methodGroups) + SERIALIZE(constructorGroup) + END_SERIALIZATION + } + } + + namespace reflection + { + namespace description + { + + using Reader = stream::internal::Reader>; + using Writer = stream::internal::Writer>; + +/*********************************************************************** +IMethodInfo +***********************************************************************/ + + class MetaonlyParameterInfo : public Object, public IParameterInfo + { + protected: + MetaonlyReaderContext* context = nullptr; + Ptr metadata; + vint ownerTypeDescriptor = -1; + IMethodInfo* ownerMethod = nullptr; + + public: + MetaonlyParameterInfo(MetaonlyReaderContext* _context, Ptr _metadata, vint _ownerTypeDescriptor, IMethodInfo* _ownerMethod) + : context(_context) + , metadata(_metadata) + , ownerTypeDescriptor(_ownerTypeDescriptor) + , ownerMethod(_ownerMethod) + { + } + + ITypeDescriptor* GetOwnerTypeDescriptor() override + { + return context->tds[ownerTypeDescriptor].Obj(); + } + + const WString& GetName() override + { + return metadata->name; + } + + ITypeInfo* GetType() override + { + return EnsureSetContext(metadata->type.Obj(), context); + } + + IMethodInfo* GetOwnerMethod() override + { + return ownerMethod; + } + }; + + class MetaonlyMethodInfo : public Object, public IMethodInfo, protected IMethodInfo::ICpp + { + friend class MetaonlyMethodGroupInfo; + protected: + MetaonlyReaderContext* context = nullptr; + Ptr metadata; + IMethodGroupInfo* methodGroup = nullptr; + List> parameters; + + public: + MetaonlyMethodInfo(MetaonlyReaderContext* _context, Ptr _metadata) + : context(_context) + , metadata(_metadata) + { + for (vint i = 0; i < metadata->parameters.Count(); i++) + { + parameters.Add(new MetaonlyParameterInfo(context, metadata->parameters[i], metadata->ownerTypeDescriptor, this)); + } + } + + // ICpp + + const WString& GetInvokeTemplate() override + { + return metadata->invokeTemplate; + } + + const WString& GetClosureTemplate() override + { + return metadata->closureTemplate; + } + + // IMemberInfo + + ITypeDescriptor* GetOwnerTypeDescriptor() override + { + return context->tds[metadata->ownerTypeDescriptor].Obj(); + } + + const WString& GetName() override + { + return metadata->name; + } + + // IMethodInfo + + IMethodInfo::ICpp* GetCpp() override + { + if (metadata->invokeTemplate.Length() + metadata->closureTemplate.Length() > 0) + { + return this; + } + return nullptr; + } + + IMethodGroupInfo* GetOwnerMethodGroup() override + { + return methodGroup; + } + + IPropertyInfo* GetOwnerProperty() override + { + return metadata->ownerProperty == -1 ? nullptr : context->pis[metadata->ownerProperty].Obj(); + } + + vint GetParameterCount() override + { + return parameters.Count(); + } + + IParameterInfo* GetParameter(vint index) override + { + return parameters[index].Obj(); + } + + ITypeInfo* GetReturn() override + { + return EnsureSetContext(metadata->returnType.Obj(), context); + } + + bool IsStatic() override + { + return metadata->isStatic; + } + + void CheckArguments(collections::Array& arguments) override + { + CHECK_FAIL(L"Not Supported!"); + } + + Value Invoke(const Value& thisObject, collections::Array& arguments) override + { + CHECK_FAIL(L"Not Supported!"); + } + + Value CreateFunctionProxy(const Value& thisObject) override + { + CHECK_FAIL(L"Not Supported!"); + } + }; + + class MetaonlyMethodGroupInfo : public Object, public IMethodGroupInfo + { + protected: + MetaonlyReaderContext* context = nullptr; + Ptr metadata; + IdRange idRange; + public: + MetaonlyMethodGroupInfo(MetaonlyReaderContext* _context, Ptr _metadata, IdRange _idRange) + : context(_context) + , metadata(_metadata) + , idRange(_idRange) + { + } + + // IMemberInfo + + ITypeDescriptor* GetOwnerTypeDescriptor() override + { + return GetMethod(0)->GetOwnerTypeDescriptor(); + } + + const WString& GetName() override + { + return GetMethod(0)->GetName(); + } + + // IMethodGroupInfo + + vint GetMethodCount() override + { + return idRange.count; + } + + IMethodInfo* GetMethod(vint index) override + { + CHECK_ERROR(0 <= index && index < idRange.count, L"IMethodGroupInfo::GetMethod(vint)#Index out of range."); + auto info = dynamic_cast(context->mis[metadata->methods[idRange.start + index]].Obj()); + if (info->methodGroup == nullptr) + { + info->methodGroup = this; + } + return info; + } + }; + +/*********************************************************************** +IPropertyInfo +***********************************************************************/ + + class MetaonlyPropertyInfo : public Object, public IPropertyInfo, protected IPropertyInfo::ICpp + { + protected: + MetaonlyReaderContext* context = nullptr; + Ptr metadata; + + public: + MetaonlyPropertyInfo(MetaonlyReaderContext* _context, Ptr _metadata) + : context(_context) + , metadata(_metadata) + { + } + + // ICpp + + const WString& GetReferenceTemplate() override + { + return metadata->referenceTemplate; + } + + // IMemberInfo + + ITypeDescriptor* GetOwnerTypeDescriptor() override + { + return context->tds[metadata->ownerTypeDescriptor].Obj(); + } + + const WString& GetName() override + { + return metadata->name; + } + + // IPropertyInfo + + IPropertyInfo::ICpp* GetCpp() override + { + if (metadata->referenceTemplate.Length() > 0) + { + return this; + } + return nullptr; + } + + bool IsReadable() override + { + return metadata->isReadable; + } + + bool IsWritable() override + { + return metadata->isWritable; + } + + ITypeInfo* GetReturn() override + { + return EnsureSetContext(metadata->returnType.Obj(), context); + } + + IMethodInfo* GetGetter() override + { + return metadata->getter == -1 ? nullptr : context->mis[metadata->getter].Obj(); + } + + IMethodInfo* GetSetter() override + { + return metadata->setter == -1 ? nullptr : context->mis[metadata->setter].Obj(); + } + + IEventInfo* GetValueChangedEvent() override + { + return metadata->valueChangedEvent == -1 ? nullptr : context->eis[metadata->valueChangedEvent].Obj(); + } + + Value GetValue(const Value& thisObject) override + { + CHECK_FAIL(L"Not Supported!"); + } + + void SetValue(Value& thisObject, const Value& newValue) override + { + CHECK_FAIL(L"Not Supported!"); + } + }; + +/*********************************************************************** +IEventInfo +***********************************************************************/ + + class MetaonlyEventInfo : public Object, public IEventInfo, protected IEventInfo::ICpp + { + protected: + MetaonlyReaderContext* context = nullptr; + Ptr metadata; + + public: + MetaonlyEventInfo(MetaonlyReaderContext* _context, Ptr _metadata) + : context(_context) + , metadata(_metadata) + { + } + + // ICpp + + const WString& GetAttachTemplate() override + { + return metadata->attachTemplate; + } + + const WString& GetDetachTemplate() override + { + return metadata->detachTemplate; + } + + const WString& GetInvokeTemplate() override + { + return metadata->invokeTemplate; + } + + // IMemberInfo + + ITypeDescriptor* GetOwnerTypeDescriptor() override + { + return context->tds[metadata->ownerTypeDescriptor].Obj(); + } + + const WString& GetName() override + { + return metadata->name; + } + + // IEventInfo + + IEventInfo::ICpp* GetCpp() override + { + if (metadata->attachTemplate.Length() + metadata->detachTemplate.Length() + metadata->invokeTemplate.Length() > 0) + { + return this; + } + return nullptr; + } + + ITypeInfo* GetHandlerType() override + { + return EnsureSetContext(metadata->handlerType.Obj(), context); + } + + vint GetObservingPropertyCount() override + { + return metadata->observingProperties.Count(); + } + + IPropertyInfo* GetObservingProperty(vint index) override + { + return context->pis[metadata->observingProperties[index]].Obj(); + } + + Ptr Attach(const Value& thisObject, Ptr handler) override + { + CHECK_FAIL(L"Not Supported!"); + } + + bool Detach(const Value& thisObject, Ptr handler) override + { + CHECK_FAIL(L"Not Supported!"); + } + + void Invoke(const Value& thisObject, Ptr arguments) override + { + CHECK_FAIL(L"Not Supported!"); + } + }; + +/*********************************************************************** +ITypeDescriptor +***********************************************************************/ + + class MetaonlyTypeDescriptor + : public Object + , public ITypeDescriptor + , protected ITypeDescriptor::ICpp + , protected IValueType + , protected IEnumType + { + protected: + MetaonlyReaderContext* context = nullptr; + Ptr metadata; + ISerializableType* serializableType = nullptr; + List> methodGroups; + Ptr constructorGroup; + + public: + MetaonlyTypeDescriptor(MetaonlyReaderContext* _context, Ptr _metadata) + : context(_context) + , metadata(_metadata) + { + if (metadata->isSerializable) + { + serializableType = context->serializableTypes[metadata->typeName].Obj(); + } + + for (vint i = 0; i < metadata->methodGroups.Count(); i++) + { + methodGroups.Add(new MetaonlyMethodGroupInfo(context, metadata, metadata->methodGroups[i])); + } + if (metadata->constructorGroup.start != -1) + { + constructorGroup = new MetaonlyMethodGroupInfo(context, metadata, metadata->constructorGroup); + } + } + + // ICpp + + const WString& GetFullName() override + { + return metadata->fullName; + } + + // IValueType + + Value CreateDefault() override + { + CHECK_FAIL(L"Not Supported!"); + } + + IBoxedValue::CompareResult Compare(const Value& a, const Value& b) override + { + CHECK_FAIL(L"Not Supported!"); + } + + // IEnumType + + bool IsFlagEnum() override + { + return metadata->isFlagEnum; + } + + vint GetItemCount() override + { + return metadata->enumItems.Count(); + } + + WString GetItemName(vint index) override + { + return metadata->enumItems[index]; + } + + vuint64_t GetItemValue(vint index) override + { + return metadata->enumValues[index]; + } + + vint IndexOfItem(WString name) override + { + return metadata->enumItems.IndexOf(name); + } + + Value ToEnum(vuint64_t value) override + { + CHECK_FAIL(L"Not Supported!"); + } + + vuint64_t FromEnum(const Value& value) override + { + CHECK_FAIL(L"Not Supported!"); + } + + // ITypeDescriptor + + ITypeDescriptor::ICpp* GetCpp() override + { + if (metadata->fullName.Length() > 0) + { + return this; + } + return nullptr; + } + + TypeDescriptorFlags GetTypeDescriptorFlags() override + { + return metadata->flags; + } + + bool IsAggregatable() override + { + return metadata->isAggregatable; + } + + const WString& GetTypeName() override + { + return metadata->typeName; + } + + IValueType* GetValueType() override + { + return metadata->isValueType ? this : nullptr; + } + + IEnumType* GetEnumType() override + { + return metadata->isEnumType ? this : nullptr; + } + + ISerializableType* GetSerializableType() override + { + return serializableType; + } + + vint GetBaseTypeDescriptorCount() override + { + return metadata->baseTypeDescriptors.Count(); + } + + ITypeDescriptor* GetBaseTypeDescriptor(vint index) override + { + return context->tds[metadata->baseTypeDescriptors[index]].Obj(); + } + + bool CanConvertTo(ITypeDescriptor* targetType) override + { + if (this == targetType) return true; + vint count = GetBaseTypeDescriptorCount(); + for (vint i = 0; i < count; i++) + { + if (GetBaseTypeDescriptor(i)->CanConvertTo(targetType)) return true; + } + return false; + } + + vint GetPropertyCount() override + { + return metadata->properties.Count(); + } + + IPropertyInfo* GetProperty(vint index) override + { + return context->pis[metadata->properties[index]].Obj(); + } + + bool IsPropertyExists(const WString& name, bool inheritable) override + { + return GetPropertyByName(name, inheritable); + } + + IPropertyInfo* GetPropertyByName(const WString& name, bool inheritable) override + { + for (vint i = 0; i < metadata->properties.Count(); i++) + { + auto info = GetProperty(i); + if (info->GetName() == name) + { + return info; + } + } + if (inheritable) + { + for (vint i = 0; i < metadata->baseTypeDescriptors.Count(); i++) + { + if (auto info = GetBaseTypeDescriptor(i)->GetPropertyByName(name, true)) + { + return info; + } + } + } + return nullptr; + } + + vint GetEventCount() override + { + return metadata->events.Count(); + } + + IEventInfo* GetEvent(vint index) override + { + return context->eis[metadata->events[index]].Obj(); + } + + bool IsEventExists(const WString& name, bool inheritable) override + { + return GetEventByName(name, inheritable); + } + + IEventInfo* GetEventByName(const WString& name, bool inheritable) override + { + for (vint i = 0; i < metadata->events.Count(); i++) + { + auto info = GetEvent(i); + if (info->GetName() == name) + { + return info; + } + } + if (inheritable) + { + for (vint i = 0; i < metadata->baseTypeDescriptors.Count(); i++) + { + if (auto info = GetBaseTypeDescriptor(i)->GetEventByName(name, true)) + { + return info; + } + } + } + return nullptr; + } + + vint GetMethodGroupCount() override + { + return methodGroups.Count(); + } + + IMethodGroupInfo* GetMethodGroup(vint index) override + { + return methodGroups[index].Obj(); + } + + bool IsMethodGroupExists(const WString& name, bool inheritable) override + { + return GetMethodGroupByName(name, inheritable); + } + + IMethodGroupInfo* GetMethodGroupByName(const WString& name, bool inheritable) override + { + for (vint i = 0; i < methodGroups.Count(); i++) + { + auto info = methodGroups[i].Obj(); + if (info->GetName() == name) + { + return info; + } + } + if (inheritable) + { + for (vint i = 0; i < metadata->baseTypeDescriptors.Count(); i++) + { + if (auto info = GetBaseTypeDescriptor(i)->GetMethodGroupByName(name, true)) + { + return info; + } + } + } + return nullptr; + } + + IMethodGroupInfo* GetConstructorGroup() override + { + return constructorGroup.Obj(); + } + }; + +/*********************************************************************** +GenerateMetaonlyTypes +***********************************************************************/ + + void GenerateMetaonlyTypeDescriptor(Writer& writer, ITypeDescriptor* td) + { + auto metadata = MakePtr(); + if (auto cpp = td->GetCpp()) + { + metadata->fullName = cpp->GetFullName(); + } + metadata->typeName = td->GetTypeName(); + metadata->flags = td->GetTypeDescriptorFlags(); + metadata->isAggregatable = td->IsAggregatable(); + metadata->isValueType = td->GetValueType(); + metadata->isSerializable = td->GetSerializableType(); + if (auto enumType = td->GetEnumType()) + { + metadata->isEnumType = true; + metadata->isFlagEnum = enumType->IsFlagEnum(); + for (vint i = 0; i < enumType->GetItemCount(); i++) + { + metadata->enumItems.Add(enumType->GetItemName(i)); + metadata->enumValues.Add(enumType->GetItemValue(i)); + } + } + + for (vint i = 0; i < td->GetBaseTypeDescriptorCount(); i++) + { + metadata->baseTypeDescriptors.Add(writer.context->tdIndex[td->GetBaseTypeDescriptor(i)]); + } + + for (vint i = 0; i < td->GetPropertyCount(); i++) + { + metadata->properties.Add(writer.context->piIndex[td->GetProperty(i)]); + } + + for (vint i = 0; i < td->GetEventCount(); i++) + { + metadata->events.Add(writer.context->eiIndex[td->GetEvent(i)]); + } + + for (vint i = 0; i < td->GetMethodGroupCount(); i++) + { + auto mg = td->GetMethodGroup(i); + IdRange ir; + ir.start = metadata->methods.Count(); + for (vint j = 0; j < mg->GetMethodCount(); j++) + { + metadata->methods.Add(writer.context->miIndex[mg->GetMethod(j)]); + } + ir.count = metadata->methods.Count() - ir.start; + metadata->methodGroups.Add(ir); + } + + if (auto cg = td->GetConstructorGroup()) + { + metadata->constructorGroup.start = metadata->methods.Count(); + for (vint j = 0; j < cg->GetMethodCount(); j++) + { + metadata->methods.Add(writer.context->miIndex[cg->GetMethod(j)]); + } + metadata->constructorGroup.count = metadata->methods.Count() - metadata->constructorGroup.start; + } + + writer << metadata; + } + + void GenerateMetaonlyMethodInfo(Writer& writer, IMethodInfo* mi) + { + auto metadata = MakePtr(); + if (auto cpp = mi->GetCpp()) + { + metadata->invokeTemplate = cpp->GetInvokeTemplate(); + metadata->closureTemplate = cpp->GetClosureTemplate(); + } + metadata->name = mi->GetName(); + metadata->ownerTypeDescriptor = writer.context->tdIndex[mi->GetOwnerTypeDescriptor()]; + if (auto pi = mi->GetOwnerProperty()) + { + metadata->ownerProperty = writer.context->piIndex[pi]; + } + for (vint i = 0; i < mi->GetParameterCount(); i++) + { + auto pi = mi->GetParameter(i); + auto piMetadata = MakePtr(); + piMetadata->name = pi->GetName(); + piMetadata->type = new MetaonlyTypeInfo(*writer.context.Obj(), pi->GetType()); + metadata->parameters.Add(piMetadata); + } + metadata->returnType = new MetaonlyTypeInfo(*writer.context.Obj(), mi->GetReturn()); + metadata->isStatic = mi->IsStatic(); + writer << metadata; + } + + void GenerateMetaonlyPropertyInfo(Writer& writer, IPropertyInfo* pi) + { + auto metadata = MakePtr();; + if (auto cpp = pi->GetCpp()) + { + metadata->referenceTemplate = cpp->GetReferenceTemplate(); + } + metadata->name = pi->GetName(); + metadata->ownerTypeDescriptor = writer.context->tdIndex[pi->GetOwnerTypeDescriptor()]; + metadata->isReadable = pi->IsReadable(); + metadata->isWritable = pi->IsWritable(); + metadata->returnType = new MetaonlyTypeInfo(*writer.context.Obj(), pi->GetReturn()); + if (auto mi = pi->GetGetter()) + { + metadata->getter = writer.context->miIndex[mi]; + } + if (auto mi = pi->GetSetter()) + { + metadata->setter = writer.context->miIndex[mi]; + } + if (auto ei = pi->GetValueChangedEvent()) + { + metadata->valueChangedEvent = writer.context->eiIndex[ei]; + } + writer << metadata; + } + + void GenerateMetaonlyEventInfo(Writer& writer, IEventInfo* ei) + { + auto metadata = MakePtr();; + if (auto cpp = ei->GetCpp()) + { + metadata->attachTemplate = cpp->GetAttachTemplate(); + metadata->detachTemplate = cpp->GetDetachTemplate(); + metadata->invokeTemplate = cpp->GetInvokeTemplate(); + } + metadata->name = ei->GetName(); + metadata->ownerTypeDescriptor = writer.context->tdIndex[ei->GetOwnerTypeDescriptor()]; + metadata->handlerType = new MetaonlyTypeInfo(*writer.context.Obj(), ei->GetHandlerType()); + for (vint i = 0; i < ei->GetObservingPropertyCount(); i++) + { + metadata->observingProperties.Add(writer.context->piIndex[ei->GetObservingProperty(i)]); + } + writer << metadata; + } + + void GenerateMetaonlyTypes(stream::IStream& outputStream) + { + Writer writer(outputStream); + writer.context = MakePtr(); + + Dictionary tds; + List mis; + List pis; + List eis; + + { + auto tm = GetGlobalTypeManager(); + vint count = tm->GetTypeDescriptorCount(); + + for (vint i = 0; i < count; i++) + { + auto td = tm->GetTypeDescriptor(i); + tds.Add(td->GetTypeName(), td); + } + } + { + vint count = tds.Count(); + for (vint i = 0; i < count; i++) + { + auto td = tds.Values()[i]; + writer.context->tdIndex.Add(td, writer.context->tdIndex.Count()); + + vint mgCount = td->GetMethodGroupCount(); + for (vint j = 0; j < mgCount; j++) + { + auto mg = td->GetMethodGroup(j); + vint miCount = mg->GetMethodCount(); + for (vint k = 0; k < miCount; k++) + { + auto mi = mg->GetMethod(k); + writer.context->miIndex.Add(mi, mis.Count()); + mis.Add(mi); + } + } + + if (auto cg = td->GetConstructorGroup()) + { + vint miCount = cg->GetMethodCount(); + for (vint k = 0; k < miCount; k++) + { + auto mi = cg->GetMethod(k); + writer.context->miIndex.Add(mi, mis.Count()); + mis.Add(mi); + } + } + + vint piCount = td->GetPropertyCount(); + for (vint j = 0; j < piCount; j++) + { + auto pi = td->GetProperty(j); + writer.context->piIndex.Add(pi, pis.Count()); + pis.Add(pi); + } + + vint eiCount = td->GetEventCount(); + for (vint j = 0; j < eiCount; j++) + { + auto ei = td->GetEvent(j); + writer.context->eiIndex.Add(ei, eis.Count()); + eis.Add(ei); + } + } + } + { + vint tdCount = tds.Count(); + vint miCount = mis.Count(); + vint piCount = pis.Count(); + vint eiCount = eis.Count(); + writer << tdCount << miCount << piCount << eiCount; + + for (vint i = 0; i < tdCount; i++) + { + GenerateMetaonlyTypeDescriptor(writer, tds.Values()[i]); + } + for (vint i = 0; i < miCount; i++) + { + GenerateMetaonlyMethodInfo(writer, mis[i]); + } + for (vint i = 0; i < piCount; i++) + { + GenerateMetaonlyPropertyInfo(writer, pis[i]); + } + for (vint i = 0; i < eiCount; i++) + { + GenerateMetaonlyEventInfo(writer, eis[i]); + } + } + } + +/*********************************************************************** +LoadMetaonlyTypes +***********************************************************************/ + + class MetaonlyTypeLoader : public Object, public ITypeLoader + { + public: + Ptr context; + + void Load(ITypeManager* manager) override + { + for (vint i = 0; i < context->tds.Count(); i++) + { + auto td = context->tds[i]; + manager->SetTypeDescriptor(td->GetTypeName(), td); + } + } + + void Unload(ITypeManager* manager) override + { + } + }; + + Ptr LoadMetaonlyTypes(stream::IStream& inputStream, const collections::Dictionary>& serializableTypes) + { + auto context = MakePtr(); + CopyFrom(context->serializableTypes, serializableTypes); + auto loader = MakePtr(); + loader->context = context; + Reader reader(inputStream); + reader.context = context; + + { + vint tdCount = 0; + vint miCount = 0; + vint piCount = 0; + vint eiCount = 0; + reader << tdCount << miCount << piCount << eiCount; + + for (vint i = 0; i < tdCount; i++) + { + Ptr metadata; + reader << metadata; + context->tds.Add(new MetaonlyTypeDescriptor(context.Obj(), metadata)); + } + for (vint i = 0; i < miCount; i++) + { + Ptr metadata; + reader << metadata; + context->mis.Add(new MetaonlyMethodInfo(context.Obj(), metadata)); + } + for (vint i = 0; i < piCount; i++) + { + Ptr metadata; + reader << metadata; + context->pis.Add(new MetaonlyPropertyInfo(context.Obj(), metadata)); + } + for (vint i = 0; i < eiCount; i++) + { + Ptr metadata; + reader << metadata; + context->eis.Add(new MetaonlyEventInfo(context.Obj(), metadata)); + } + } + + return loader; + } + } + } +} + +#endif + +/*********************************************************************** +.\DESCRIPTABLEOBJECT.CPP +***********************************************************************/ +/*********************************************************************** +Author: Zihan Chen (vczh) +Licensed under https://github.com/vczh-libraries/License +***********************************************************************/ + + +namespace vl +{ + namespace reflection + { /*********************************************************************** DescriptableObject ***********************************************************************/ @@ -100,7 +2092,7 @@ DescriptableObject CHECK_ERROR(!IsAggregated(), L"vl::reflection::DescriptableObject::InitializeAggregation(vint)#This function should not be called on aggregated objects."); CHECK_ERROR(size >= 0, L"vl::reflection::DescriptableObject::InitializeAggregation(vint)#Size shout not be negative."); aggregationSize = size; - aggregationInfo = new DescriptableObject*[size + 2]; + aggregationInfo = new DescriptableObject * [size + 2]; memset(aggregationInfo, 0, sizeof(*aggregationInfo) * (size + 2)); } #endif @@ -192,52 +2184,52 @@ DescriptableObject description::ITypeDescriptor* DescriptableObject::GetTypeDescriptor() { - return typeDescriptor?*typeDescriptor:0; + return typeDescriptor ? *typeDescriptor : 0; } #endif Ptr DescriptableObject::GetInternalProperty(const WString& name) { - if(!internalProperties) return 0; - vint index=internalProperties->Keys().IndexOf(name); - if(index==-1) return 0; + if (!internalProperties) return 0; + vint index = internalProperties->Keys().IndexOf(name); + if (index == -1) return 0; return internalProperties->Values().Get(index); } void DescriptableObject::SetInternalProperty(const WString& name, Ptr value) { - if(internalProperties) + if (internalProperties) { - vint index=internalProperties->Keys().IndexOf(name); - if(index==-1) + vint index = internalProperties->Keys().IndexOf(name); + if (index == -1) { - if(value) + if (value) { internalProperties->Add(name, value); } } else { - if(value) + if (value) { internalProperties->Set(name, value); } else { internalProperties->Remove(name); - if(internalProperties->Count()==0) + if (internalProperties->Count() == 0) { - internalProperties=0; + internalProperties = 0; } } } } else { - if(value) + if (value) { - internalProperties=new InternalPropertyMap; + internalProperties = new InternalPropertyMap; internalProperties->Add(name, value); } } @@ -286,6 +2278,25 @@ DescriptableObject } #endif + } +} + + +/*********************************************************************** +.\DESCRIPTABLEVALUE.CPP +***********************************************************************/ +/*********************************************************************** +Author: Zihan Chen (vczh) +Licensed under https://github.com/vczh-libraries/License +***********************************************************************/ + + +namespace vl +{ + using namespace collections; + + namespace reflection + { /*********************************************************************** description::Value @@ -796,390 +2807,13 @@ description::Value *this=Value(); return true; } - -#ifndef VCZH_DEBUG_NO_REFLECTION - -/*********************************************************************** -description::TypeManager -***********************************************************************/ - - class TypeManager : public Object, public ITypeManager - { - public: - static vint typeVersion; - - protected: - Dictionary> typeDescriptors; - List> typeLoaders; - ITypeDescriptor* rootType = nullptr; - bool loaded = false; - - public: - TypeManager() - { - } - - ~TypeManager() - { - Unload(); - } - - vint GetTypeDescriptorCount()override - { - return typeDescriptors.Values().Count(); - } - - ITypeDescriptor* GetTypeDescriptor(vint index)override - { - return typeDescriptors.Values().Get(index).Obj(); - } - - ITypeDescriptor* GetTypeDescriptor(const WString& name)override - { - vint index = typeDescriptors.Keys().IndexOf(name); - return index == -1 ? 0 : typeDescriptors.Values().Get(index).Obj(); - } - - bool SetTypeDescriptor(const WString& name, Ptr typeDescriptor)override - { - if (typeDescriptor && name != typeDescriptor->GetTypeName()) - { - return false; - } - if (!typeDescriptors.Keys().Contains(name)) - { - if (typeDescriptor) - { - typeDescriptors.Add(name, typeDescriptor); - typeVersion++; - return true; - } - } - else - { - if (!typeDescriptor) - { - typeDescriptors.Remove(name); - typeVersion++; - return true; - } - } - return false; - } - - bool AddTypeLoader(Ptr typeLoader)override - { - vint index = typeLoaders.IndexOf(typeLoader.Obj()); - if (index == -1) - { - typeLoaders.Add(typeLoader); - if (loaded) - { - auto oldTypeVersion = typeVersion; - typeLoader->Load(this); - typeVersion = oldTypeVersion + 1; - } - return true; - } - else - { - return false; - } - } - - bool RemoveTypeLoader(Ptr typeLoader)override - { - vint index = typeLoaders.IndexOf(typeLoader.Obj()); - if (index != -1) - { - if (loaded) - { - auto oldTypeVersion = typeVersion; - typeLoader->Unload(this); - typeVersion = oldTypeVersion + 1; - } - typeLoaders.RemoveAt(index); - return true; - } - else - { - return false; - } - } - - bool Load()override - { - if (!loaded) - { - loaded = true; - auto oldTypeVersion = typeVersion; - for (vint i = 0; i < typeLoaders.Count(); i++) - { - typeLoaders[i]->Load(this); - } - typeVersion = oldTypeVersion + 1; - return true; - } - else - { - return false; - } - } - - bool Unload()override - { - if (loaded) - { - loaded = false; - rootType = 0; - auto oldTypeVersion = typeVersion; - for (vint i = 0; i < typeLoaders.Count(); i++) - { - typeLoaders[i]->Unload(this); - } - typeVersion = oldTypeVersion + 1; - typeDescriptors.Clear(); - return true; - } - else - { - return false; - } - } - - bool Reload()override - { - Unload(); - Load(); - return true; - } - - bool IsLoaded()override - { - return loaded; - } - - ITypeDescriptor* GetRootType()override - { - if (!rootType) - { - rootType = description::GetTypeDescriptor(); - } - return rootType; - } - - vint GetTypeVersion() override - { - return typeVersion; - } - }; - vint TypeManager::typeVersion = -1; - -/*********************************************************************** -description::TypeManager helper functions -***********************************************************************/ - - ITypeManager* globalTypeManager=0; - bool initializedGlobalTypeManager=false; - - ITypeManager* GetGlobalTypeManager() - { - if (!initializedGlobalTypeManager) - { - initializedGlobalTypeManager = true; - globalTypeManager = new TypeManager; - } - return globalTypeManager; - } - - bool DestroyGlobalTypeManager() - { - if (initializedGlobalTypeManager && globalTypeManager) - { - delete globalTypeManager; - globalTypeManager = nullptr; - TypeManager::typeVersion++; - return true; - } - else - { - return false; - } - } - - bool ResetGlobalTypeManager() - { - if (!DestroyGlobalTypeManager()) return false; - initializedGlobalTypeManager = false; - return true; - } - - ITypeDescriptor* GetTypeDescriptor(const WString& name) - { - if (globalTypeManager) - { - if (!globalTypeManager->IsLoaded()) - { - globalTypeManager->Load(); - } - return globalTypeManager->GetTypeDescriptor(name); - } - return nullptr; - } - -/*********************************************************************** -Cpp Helper Functions -***********************************************************************/ - - WString CppGetFullName(ITypeDescriptor* type) - { - if (auto cpp = type->GetCpp()) - { - if (cpp->GetFullName() == L"void" || cpp->GetFullName() == L"vl::reflection::description::VoidValue") - { - return L"void"; - } - else if (cpp->GetFullName() == L"float") - { - return L"float"; - } - else if (cpp->GetFullName() == L"double") - { - return L"double"; - } - else if (cpp->GetFullName() == L"bool") - { - return L"bool"; - } - else if (cpp->GetFullName() == L"wchar_t") - { - return L"wchar_t"; - } - else - { - return L"::" + cpp->GetFullName(); - } - } - else - { - return L"::vl::" + type->GetTypeName(); - } - } - - WString CppGetReferenceTemplate(IPropertyInfo* prop) - { - if (auto cpp = prop->GetCpp()) - { - return cpp->GetReferenceTemplate(); - } - else if ((prop->GetOwnerTypeDescriptor()->GetTypeDescriptorFlags() & TypeDescriptorFlags::ReferenceType) != TypeDescriptorFlags::Undefined) - { - return WString::Unmanaged(L"$This->$Name"); - } - else - { - return WString::Unmanaged(L"$This.$Name"); - } - } - - WString CppGetClosureTemplate(IMethodInfo* method) - { - if (auto cpp = method->GetCpp()) - { - return cpp->GetClosureTemplate(); - } - - if (method->IsStatic()) - { - return WString::Unmanaged(L"::vl::Func<$Func>(&$Type::$Name)"); - } - else - { - return WString::Unmanaged(L"::vl::Func<$Func>($This, &$Type::$Name)"); - } - } - - WString CppGetInvokeTemplate(IMethodInfo* method) - { - if (auto cpp = method->GetCpp()) - { - return cpp->GetInvokeTemplate(); - } - - if (method->GetOwnerMethodGroup() == method->GetOwnerTypeDescriptor()->GetConstructorGroup()) - { - return WString::Unmanaged(L"new $Type($Arguments)"); - } - else if (method->IsStatic()) - { - return WString::Unmanaged(L"$Type::$Name($Arguments)"); - } - else - { - return WString::Unmanaged(L"$This->$Name($Arguments)"); - } - } - - WString CppGetAttachTemplate(IEventInfo* ev) - { - auto cpp = ev->GetCpp(); - return cpp == nullptr ? WString::Unmanaged(L"::vl::__vwsn::EventAttach($This->$Name, $Handler)") : cpp->GetAttachTemplate(); - } - - WString CppGetDetachTemplate(IEventInfo* ev) - { - auto cpp = ev->GetCpp(); - return cpp == nullptr ? WString::Unmanaged(L"::vl::__vwsn::EventDetach($This->$Name, $Handler)") : cpp->GetDetachTemplate(); - } - - WString CppGetInvokeTemplate(IEventInfo* ev) - { - auto cpp = ev->GetCpp(); - return cpp == nullptr ? WString::Unmanaged(L"::vl::__vwsn::EventInvoke($This->$Name)($Arguments)") : cpp->GetInvokeTemplate(); - } - - bool CppExists(ITypeDescriptor* type) - { - auto cpp = type->GetCpp(); - return cpp == nullptr || cpp->GetFullName() != L"*"; - } - - bool CppExists(IPropertyInfo* prop) - { - if (auto cpp = prop->GetCpp()) - { - return cpp->GetReferenceTemplate() != L"*"; - } - else if (auto method = prop->GetGetter()) - { - return CppExists(method); - } - else - { - return true; - } - } - - bool CppExists(IMethodInfo* method) - { - auto cpp = method->GetCpp(); - return cpp == nullptr || cpp->GetInvokeTemplate() != L"*"; - } - - bool CppExists(IEventInfo* ev) - { - auto cpp = ev->GetCpp(); - return cpp == nullptr || cpp->GetInvokeTemplate() != L"*"; - } - -#endif } } } /*********************************************************************** -.\GUITYPEDESCRIPTORBUILDER.CPP +.\METADATA\METADATA.CPP ***********************************************************************/ /*********************************************************************** Author: Zihan Chen (vczh) @@ -1904,7 +3538,7 @@ EventInfoImpl #endif } - void EventInfoImpl::Invoke(const Value& thisObject, Ptr arguments) + void EventInfoImpl::Invoke(const Value& thisObject, Ptr arguments) { #ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA if(thisObject.IsNull()) @@ -2479,33 +4113,12 @@ TypeDescriptorImpl return constructorGroup.Obj(); } #endif - -/*********************************************************************** -Function Related -***********************************************************************/ - - namespace internal_helper - { - void UnboxSpecifiedParameter(Ptr arguments, vint index) - { - } - -#ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA - void UnboxSpecifiedParameter(MethodInfoImpl* methodInfo, collections::Array& arguments, vint index) - { - } -#endif - - void AddValueToList(Ptr arguments) - { - } - } } } } /*********************************************************************** -.\GUITYPEDESCRIPTORPREDEFINED.CPP +.\PREDEFINED\PREDEFINEDTYPES.CPP ***********************************************************************/ /*********************************************************************** Author: Zihan Chen (vczh) @@ -2682,7 +4295,7 @@ IValueException /*********************************************************************** -.\GUITYPEDESCRIPTORREFLECTION.CPP +.\REFLECTION\REFLECTION.CPP ***********************************************************************/ /*********************************************************************** Author: Zihan Chen (vczh) @@ -3554,1601 +5167,3 @@ LoadPredefinedTypes } } - -/*********************************************************************** -.\GUITYPEDESCRIPTOR_LOG.CPP -***********************************************************************/ -/*********************************************************************** -Author: Zihan Chen (vczh) -Licensed under https://github.com/vczh-libraries/License -***********************************************************************/ - - -namespace vl -{ - namespace reflection - { - namespace description - { - using namespace collections; - -#ifndef VCZH_DEBUG_NO_REFLECTION - -/*********************************************************************** -LogTypeManager (enum) -***********************************************************************/ - - void LogTypeManager_Enum(stream::TextWriter& writer, ITypeDescriptor* type) - { - if (type->GetTypeDescriptorFlags() == TypeDescriptorFlags::FlagEnum) - { - writer.WriteLine(L"@Flags"); - } - writer.WriteLine(L"enum " + type->GetTypeName() + L" {"); - - auto enumType = type->GetEnumType(); - for (vint j = 0; j < enumType->GetItemCount(); j++) - { - writer.WriteLine(L" " + enumType->GetItemName(j) + L" = " + u64tow(enumType->GetItemValue(j)) + L","); - } - - writer.WriteLine(L"}"); - } - -/*********************************************************************** -LogTypeManager (struct) -***********************************************************************/ - - void LogTypeManager_Property(stream::TextWriter& writer, IPropertyInfo* info) - { - if (auto cpp = info->GetCpp()) - { - writer.WriteLine(L" @ReferenceTemplate:" + cpp->GetReferenceTemplate()); - } - writer.WriteString(L" property " + info->GetName() + L" : " + info->GetReturn()->GetTypeFriendlyName()); - if (info->IsReadable() && info->IsWritable() && !info->GetGetter() && !info->GetSetter() && !info->GetValueChangedEvent()) - { - writer.WriteLine(L";"); - } - else - { - writer.WriteString(L" { "); - if (info->IsReadable()) - { - writer.WriteString(L"get"); - if (auto mi = info->GetGetter()) - { - writer.WriteString(L":" + mi->GetName()); - } - writer.WriteString(L" "); - } - if (info->IsWritable()) - { - writer.WriteString(L"set"); - if (auto mi = info->GetSetter()) - { - writer.WriteString(L":" + mi->GetName()); - } - writer.WriteString(L" "); - } - if (auto ei = info->GetValueChangedEvent()) - { - writer.WriteString(L"event:" + ei->GetName() + L" "); - } - writer.WriteLine(L"}"); - } - } - - void LogTypeManager_Struct(stream::TextWriter& writer, ITypeDescriptor* type) - { - writer.WriteLine(L"struct " + type->GetTypeName() + L" {"); - for (vint j = 0; jGetPropertyCount(); j++) - { - IPropertyInfo* info = type->GetProperty(j); - LogTypeManager_Property(writer, info); - } - writer.WriteLine(L"}"); - } - -/*********************************************************************** -LogTypeManager (data) -***********************************************************************/ - - void LogTypeManager_Data(stream::TextWriter& writer, ITypeDescriptor* type) - { - writer.WriteLine(L"primitive " + type->GetTypeName() + L";"); - } - -/*********************************************************************** -LogTypeManager (class) -***********************************************************************/ - - void LogTypeManager_PrintEvents(stream::TextWriter& writer, ITypeDescriptor* type) - { - bool printed = false; - for (vint j = 0; j < type->GetEventCount(); j++) - { - printed = true; - IEventInfo* info = type->GetEvent(j); - if (auto cpp = info->GetCpp()) - { - writer.WriteLine(L" @AttachTemplate:" + cpp->GetAttachTemplate()); - writer.WriteLine(L" @DetachTemplate:" + cpp->GetDetachTemplate()); - writer.WriteLine(L" @InvokeTemplate:" + cpp->GetInvokeTemplate()); - } - - writer.WriteString(L" event " + info->GetName() + L" : " + info->GetHandlerType()->GetTypeFriendlyName()); - - if (info->GetObservingPropertyCount() > 0) - { - writer.WriteString(L" observing {"); - vint count = info->GetObservingPropertyCount(); - for (vint i = 0; i < count; i++) - { - writer.WriteLine(L" " + info->GetObservingProperty(i)->GetName() + L","); - } - writer.WriteString(L"}"); - } - else - { - writer.WriteLine(L";"); - } - } - if (printed) - { - writer.WriteLine(L""); - } - } - - void LogTypeManager_PrintProperties(stream::TextWriter& writer, ITypeDescriptor* type) - { - bool printed = false; - for (vint j = 0; j < type->GetPropertyCount(); j++) - { - printed = true; - IPropertyInfo* info = type->GetProperty(j); - LogTypeManager_Property(writer, info); - } - if (printed) - { - writer.WriteLine(L""); - } - } - - void LogTypeManager_Method(stream::TextWriter& writer, IMethodInfo* info, const wchar_t* title) - { - if (auto cpp = info->GetCpp()) - { - writer.WriteLine(L" @InvokeTemplate:" + cpp->GetInvokeTemplate()); - writer.WriteLine(L" @ClosureTemplate:" + cpp->GetClosureTemplate()); - } - - writer.WriteString(L" "); - writer.WriteString(title); - writer.WriteString(L" " + info->GetName() + L"("); - for (vint l = 0; l < info->GetParameterCount(); l++) - { - if (l > 0) writer.WriteString(L", "); - IParameterInfo* parameter = info->GetParameter(l); - writer.WriteString(parameter->GetName() + L" : " + parameter->GetType()->GetTypeFriendlyName()); - } - writer.WriteLine(L") : " + info->GetReturn()->GetTypeFriendlyName() + L";"); - } - - void LogTypeManager_PrintMethods(stream::TextWriter& writer, ITypeDescriptor* type) - { - bool printed = false; - for (vint j = 0; j < type->GetMethodGroupCount(); j++) - { - IMethodGroupInfo* group = type->GetMethodGroup(j); - for (vint k = 0; k < group->GetMethodCount(); k++) - { - printed = true; - IMethodInfo* info = group->GetMethod(k); - if (info->IsStatic()) - { - LogTypeManager_Method(writer, info, L"static function"); - } - else - { - LogTypeManager_Method(writer, info, L"function"); - } - } - } - if (printed) - { - writer.WriteLine(L""); - } - } - - void LogTypeManager_PrintConstructors(stream::TextWriter& writer, ITypeDescriptor* type) - { - if (IMethodGroupInfo* group = type->GetConstructorGroup()) - { - for (vint k = 0; k < group->GetMethodCount(); k++) - { - IMethodInfo* info = group->GetMethod(k); - LogTypeManager_Method(writer, info, L"constructor"); - } - } - } - - void LogTypeManager_Class(stream::TextWriter& writer, ITypeDescriptor* type) - { - bool acceptProxy = false; - bool isInterface = (type->GetTypeDescriptorFlags() & TypeDescriptorFlags::InterfaceType) != TypeDescriptorFlags::Undefined; - writer.WriteString((isInterface ? L"interface " : L"class ") + type->GetTypeName()); - for (vint j = 0; jGetBaseTypeDescriptorCount(); j++) - { - writer.WriteString(j == 0 ? L" : " : L", "); - writer.WriteString(type->GetBaseTypeDescriptor(j)->GetTypeName()); - } - writer.WriteLine(L" {"); - - LogTypeManager_PrintEvents(writer, type); - LogTypeManager_PrintProperties(writer, type); - LogTypeManager_PrintMethods(writer, type); - LogTypeManager_PrintConstructors(writer, type); - - writer.WriteLine(L"}"); - } - -/*********************************************************************** -LogTypeManager -***********************************************************************/ - - bool IsInterfaceType(ITypeDescriptor* typeDescriptor, bool& acceptProxy) - { - bool containsConstructor = false; - if (IMethodGroupInfo* group = typeDescriptor->GetConstructorGroup()) - { - containsConstructor = group->GetMethodCount() > 0; - if (group->GetMethodCount() == 1) - { - if (IMethodInfo* info = group->GetMethod(0)) - { - if (info->GetParameterCount() == 1 && info->GetParameter(0)->GetType()->GetTypeDescriptor()->GetTypeName() == TypeInfo::content.typeName) - { - acceptProxy = true; - return true; - } - } - } - } - - if (!containsConstructor) - { - if (typeDescriptor->GetTypeName() == TypeInfo::content.typeName) - { - return true; - } - else - { - for (vint i = 0; i < typeDescriptor->GetBaseTypeDescriptorCount(); i++) - { - bool _acceptProxy = false; - if (!IsInterfaceType(typeDescriptor->GetBaseTypeDescriptor(i), _acceptProxy)) - { - return false; - } - } - const wchar_t* name = typeDescriptor->GetTypeName().Buffer(); - while (const wchar_t* next = ::wcschr(name, L':')) - { - name = next + 1; - } - return name[0] == L'I' && (L'A' <= name[1] && name[1] <= L'Z'); - } - } - return false; - } - - void LogTypeManager(stream::TextWriter& writer) - { - for (vint i = 0; i < GetGlobalTypeManager()->GetTypeDescriptorCount(); i++) - { - ITypeDescriptor* type = GetGlobalTypeManager()->GetTypeDescriptor(i); - if (auto cpp = type->GetCpp()) - { - writer.WriteLine(L"@FullName:" + cpp->GetFullName()); - } - if (type->GetValueType()) - { - writer.WriteLine(L"@ValueType"); - } - if (type->GetSerializableType()) - { - writer.WriteLine(L"@Serializable"); - } - - switch (type->GetTypeDescriptorFlags()) - { - case TypeDescriptorFlags::Object: - case TypeDescriptorFlags::IDescriptable: - case TypeDescriptorFlags::Class: - case TypeDescriptorFlags::Interface: - LogTypeManager_Class(writer, type); - break; - case TypeDescriptorFlags::FlagEnum: - case TypeDescriptorFlags::NormalEnum: - LogTypeManager_Enum(writer, type); - break; - case TypeDescriptorFlags::Primitive: - LogTypeManager_Data(writer, type); - break; - case TypeDescriptorFlags::Struct: - LogTypeManager_Struct(writer, type); - break; - default:; - } - writer.WriteLine(L""); - } - } - -#endif - } - } -} - - -/*********************************************************************** -.\GUITYPEDESCRIPTOR_METAONLY.CPP -***********************************************************************/ -/*********************************************************************** -Author: Zihan Chen (vczh) -Licensed under https://github.com/vczh-libraries/License -***********************************************************************/ - - -#ifndef VCZH_DEBUG_NO_REFLECTION - -namespace vl -{ - namespace reflection - { - namespace description - { - using namespace collections; - -/*********************************************************************** -Context -***********************************************************************/ - - struct MetaonlyWriterContext - { - Dictionary tdIndex; - Dictionary miIndex; - Dictionary piIndex; - Dictionary eiIndex; - }; - - struct MetaonlyReaderContext - { - Dictionary> serializableTypes; - List> tds; - List> mis; - List> pis; - List> eis; - }; - -/*********************************************************************** -MetaonlyTypeInfo -***********************************************************************/ - - class MetaonlyTypeInfo : public Object, public ITypeInfo - { - friend struct stream::internal::Serialization; - protected: - MetaonlyReaderContext* context = nullptr; - Decorator decorator = TypeDescriptor; - TypeInfoHint hint = TypeInfoHint::Normal; - Ptr elementType; - vint typeDecriptor = -1; - List> genericArguments; - - public: - MetaonlyTypeInfo() = default; - - MetaonlyTypeInfo(MetaonlyWriterContext& _context, ITypeInfo* typeInfo) - : decorator(typeInfo->GetDecorator()) - , hint(typeInfo->GetHint()) - , typeDecriptor(_context.tdIndex[typeInfo->GetTypeDescriptor()]) - { - if (auto et = typeInfo->GetElementType()) - { - elementType = new MetaonlyTypeInfo(_context, et); - } - for (vint i = 0; i < typeInfo->GetGenericArgumentCount(); i++) - { - auto ga = typeInfo->GetGenericArgument(i); - genericArguments.Add(new MetaonlyTypeInfo(_context, ga)); - } - } - - void SetContext(MetaonlyReaderContext* _context) - { - context = _context; - if (elementType) - { - elementType->SetContext(_context); - } - for (vint i = 0; i < genericArguments.Count(); i++) - { - genericArguments[i]->SetContext(_context); - } - } - - Decorator GetDecorator() override - { - return decorator; - } - - TypeInfoHint GetHint() override - { - return hint; - } - - ITypeInfo* GetElementType() override - { - return elementType.Obj(); - } - - ITypeDescriptor* GetTypeDescriptor() override - { - return context->tds[typeDecriptor].Obj(); - } - - vint GetGenericArgumentCount() override - { - return genericArguments.Count(); - } - - ITypeInfo* GetGenericArgument(vint index) override - { - return genericArguments[index].Obj(); - } - - WString GetTypeFriendlyName() override - { - switch (decorator) - { - case RawPtr: return elementType->GetTypeFriendlyName() + L"*"; - case SharedPtr: return elementType->GetTypeFriendlyName() + L"^"; - case Nullable: return elementType->GetTypeFriendlyName() + L"?"; - case TypeDescriptor: return GetTypeDescriptor()->GetTypeName(); - default:; - } - WString result = elementType->GetTypeFriendlyName() + L"<"; - for (auto [type, i] : indexed(genericArguments)) - { - if (i > 0) result += L", "; - result += type->GetTypeFriendlyName(); - } - result += L">"; - return result; - } - }; - - ITypeInfo* EnsureSetContext(ITypeInfo* info, MetaonlyReaderContext* context) - { - if (auto minfo = dynamic_cast(info)) - { - minfo->SetContext(context); - } - return info; - } - -/*********************************************************************** -Metadata -***********************************************************************/ - - struct IdRange - { - vint start = -1; - vint count = 0; - }; - - struct ParameterInfoMetadata - { - WString name; - Ptr type; - }; - - struct MethodInfoMetadata - { - WString invokeTemplate; - WString closureTemplate; - WString name; - vint ownerTypeDescriptor = -1; - vint ownerProperty = -1; - List> parameters; - Ptr returnType; - bool isStatic = false; - }; - - struct PropertyInfoMetadata - { - WString referenceTemplate; - WString name; - vint ownerTypeDescriptor = -1; - bool isReadable = false; - bool isWritable = false; - Ptr returnType; - vint getter = -1; - vint setter = -1; - vint valueChangedEvent = -1; - }; - - struct EventInfoMetadata - { - WString attachTemplate; - WString detachTemplate; - WString invokeTemplate; - WString name; - vint ownerTypeDescriptor = -1; - Ptr handlerType; - List observingProperties; - }; - - struct TypeDescriptorMetadata - { - WString fullName; - WString typeName; - TypeDescriptorFlags flags = TypeDescriptorFlags::Undefined; - bool isAggregatable = false; - bool isValueType = false; - bool isSerializable = false; - bool isEnumType = false; - bool isFlagEnum = false; - List enumItems; - List enumValues; - List baseTypeDescriptors; - List properties; - List events; - List methods; - List methodGroups; - IdRange constructorGroup; - }; - } - } - - namespace stream - { - namespace internal - { - -/*********************************************************************** -Serialization -***********************************************************************/ - - SERIALIZE_ENUM(reflection::description::ITypeInfo::Decorator) - SERIALIZE_ENUM(reflection::description::TypeInfoHint) - SERIALIZE_ENUM(reflection::description::TypeDescriptorFlags) - - BEGIN_SERIALIZATION(reflection::description::IdRange) - SERIALIZE(start) - SERIALIZE(count) - END_SERIALIZATION - - BEGIN_SERIALIZATION(reflection::description::MetaonlyTypeInfo) - SERIALIZE(decorator) - SERIALIZE(hint) - SERIALIZE(elementType) - SERIALIZE(typeDecriptor) - SERIALIZE(genericArguments) - END_SERIALIZATION - - BEGIN_SERIALIZATION(reflection::description::ParameterInfoMetadata) - SERIALIZE(name) - SERIALIZE(type) - END_SERIALIZATION - - BEGIN_SERIALIZATION(reflection::description::MethodInfoMetadata) - SERIALIZE(invokeTemplate) - SERIALIZE(closureTemplate) - SERIALIZE(name) - SERIALIZE(ownerTypeDescriptor) - SERIALIZE(ownerProperty) - SERIALIZE(parameters) - SERIALIZE(returnType) - SERIALIZE(isStatic) - END_SERIALIZATION - - BEGIN_SERIALIZATION(reflection::description::PropertyInfoMetadata) - SERIALIZE(referenceTemplate) - SERIALIZE(name) - SERIALIZE(ownerTypeDescriptor) - SERIALIZE(isReadable) - SERIALIZE(isWritable) - SERIALIZE(returnType) - SERIALIZE(getter) - SERIALIZE(setter) - SERIALIZE(valueChangedEvent) - END_SERIALIZATION - - BEGIN_SERIALIZATION(reflection::description::EventInfoMetadata) - SERIALIZE(attachTemplate) - SERIALIZE(detachTemplate) - SERIALIZE(invokeTemplate) - SERIALIZE(name) - SERIALIZE(ownerTypeDescriptor) - SERIALIZE(handlerType) - SERIALIZE(observingProperties) - END_SERIALIZATION - - BEGIN_SERIALIZATION(reflection::description::TypeDescriptorMetadata) - SERIALIZE(fullName) - SERIALIZE(typeName) - SERIALIZE(flags) - SERIALIZE(isAggregatable) - SERIALIZE(isValueType) - SERIALIZE(isSerializable) - SERIALIZE(isEnumType) - SERIALIZE(isFlagEnum) - SERIALIZE(enumItems) - SERIALIZE(enumValues) - SERIALIZE(baseTypeDescriptors) - SERIALIZE(properties) - SERIALIZE(events) - SERIALIZE(methods) - SERIALIZE(methodGroups) - SERIALIZE(constructorGroup) - END_SERIALIZATION - } - } - - namespace reflection - { - namespace description - { - - using Reader = stream::internal::Reader>; - using Writer = stream::internal::Writer>; - -/*********************************************************************** -IMethodInfo -***********************************************************************/ - - class MetaonlyParameterInfo : public Object, public IParameterInfo - { - protected: - MetaonlyReaderContext* context = nullptr; - Ptr metadata; - vint ownerTypeDescriptor = -1; - IMethodInfo* ownerMethod = nullptr; - - public: - MetaonlyParameterInfo(MetaonlyReaderContext* _context, Ptr _metadata, vint _ownerTypeDescriptor, IMethodInfo* _ownerMethod) - : context(_context) - , metadata(_metadata) - , ownerTypeDescriptor(_ownerTypeDescriptor) - , ownerMethod(_ownerMethod) - { - } - - ITypeDescriptor* GetOwnerTypeDescriptor() override - { - return context->tds[ownerTypeDescriptor].Obj(); - } - - const WString& GetName() override - { - return metadata->name; - } - - ITypeInfo* GetType() override - { - return EnsureSetContext(metadata->type.Obj(), context); - } - - IMethodInfo* GetOwnerMethod() override - { - return ownerMethod; - } - }; - - class MetaonlyMethodInfo : public Object, public IMethodInfo, protected IMethodInfo::ICpp - { - friend class MetaonlyMethodGroupInfo; - protected: - MetaonlyReaderContext* context = nullptr; - Ptr metadata; - IMethodGroupInfo* methodGroup = nullptr; - List> parameters; - - public: - MetaonlyMethodInfo(MetaonlyReaderContext* _context, Ptr _metadata) - : context(_context) - , metadata(_metadata) - { - for (vint i = 0; i < metadata->parameters.Count(); i++) - { - parameters.Add(new MetaonlyParameterInfo(context, metadata->parameters[i], metadata->ownerTypeDescriptor, this)); - } - } - - // ICpp - - const WString& GetInvokeTemplate() override - { - return metadata->invokeTemplate; - } - - const WString& GetClosureTemplate() override - { - return metadata->closureTemplate; - } - - // IMemberInfo - - ITypeDescriptor* GetOwnerTypeDescriptor() override - { - return context->tds[metadata->ownerTypeDescriptor].Obj(); - } - - const WString& GetName() override - { - return metadata->name; - } - - // IMethodInfo - - IMethodInfo::ICpp* GetCpp() override - { - if (metadata->invokeTemplate.Length() + metadata->closureTemplate.Length() > 0) - { - return this; - } - return nullptr; - } - - IMethodGroupInfo* GetOwnerMethodGroup() override - { - return methodGroup; - } - - IPropertyInfo* GetOwnerProperty() override - { - return metadata->ownerProperty == -1 ? nullptr : context->pis[metadata->ownerProperty].Obj(); - } - - vint GetParameterCount() override - { - return parameters.Count(); - } - - IParameterInfo* GetParameter(vint index) override - { - return parameters[index].Obj(); - } - - ITypeInfo* GetReturn() override - { - return EnsureSetContext(metadata->returnType.Obj(), context); - } - - bool IsStatic() override - { - return metadata->isStatic; - } - - void CheckArguments(collections::Array& arguments) override - { - CHECK_FAIL(L"Not Supported!"); - } - - Value Invoke(const Value& thisObject, collections::Array& arguments) override - { - CHECK_FAIL(L"Not Supported!"); - } - - Value CreateFunctionProxy(const Value& thisObject) override - { - CHECK_FAIL(L"Not Supported!"); - } - }; - - class MetaonlyMethodGroupInfo : public Object, public IMethodGroupInfo - { - protected: - MetaonlyReaderContext* context = nullptr; - Ptr metadata; - IdRange idRange; - public: - MetaonlyMethodGroupInfo(MetaonlyReaderContext* _context, Ptr _metadata, IdRange _idRange) - : context(_context) - , metadata(_metadata) - , idRange(_idRange) - { - } - - // IMemberInfo - - ITypeDescriptor* GetOwnerTypeDescriptor() override - { - return GetMethod(0)->GetOwnerTypeDescriptor(); - } - - const WString& GetName() override - { - return GetMethod(0)->GetName(); - } - - // IMethodGroupInfo - - vint GetMethodCount() override - { - return idRange.count; - } - - IMethodInfo* GetMethod(vint index) override - { - CHECK_ERROR(0 <= index && index < idRange.count, L"IMethodGroupInfo::GetMethod(vint)#Index out of range."); - auto info = dynamic_cast(context->mis[metadata->methods[idRange.start + index]].Obj()); - if (info->methodGroup == nullptr) - { - info->methodGroup = this; - } - return info; - } - }; - -/*********************************************************************** -IPropertyInfo -***********************************************************************/ - - class MetaonlyPropertyInfo : public Object, public IPropertyInfo, protected IPropertyInfo::ICpp - { - protected: - MetaonlyReaderContext* context = nullptr; - Ptr metadata; - - public: - MetaonlyPropertyInfo(MetaonlyReaderContext* _context, Ptr _metadata) - : context(_context) - , metadata(_metadata) - { - } - - // ICpp - - const WString& GetReferenceTemplate() override - { - return metadata->referenceTemplate; - } - - // IMemberInfo - - ITypeDescriptor* GetOwnerTypeDescriptor() override - { - return context->tds[metadata->ownerTypeDescriptor].Obj(); - } - - const WString& GetName() override - { - return metadata->name; - } - - // IPropertyInfo - - IPropertyInfo::ICpp* GetCpp() override - { - if (metadata->referenceTemplate.Length() > 0) - { - return this; - } - return nullptr; - } - - bool IsReadable() override - { - return metadata->isReadable; - } - - bool IsWritable() override - { - return metadata->isWritable; - } - - ITypeInfo* GetReturn() override - { - return EnsureSetContext(metadata->returnType.Obj(), context); - } - - IMethodInfo* GetGetter() override - { - return metadata->getter == -1 ? nullptr : context->mis[metadata->getter].Obj(); - } - - IMethodInfo* GetSetter() override - { - return metadata->setter == -1 ? nullptr : context->mis[metadata->setter].Obj(); - } - - IEventInfo* GetValueChangedEvent() override - { - return metadata->valueChangedEvent == -1 ? nullptr : context->eis[metadata->valueChangedEvent].Obj(); - } - - Value GetValue(const Value& thisObject) override - { - CHECK_FAIL(L"Not Supported!"); - } - - void SetValue(Value& thisObject, const Value& newValue) override - { - CHECK_FAIL(L"Not Supported!"); - } - }; - -/*********************************************************************** -IEventInfo -***********************************************************************/ - - class MetaonlyEventInfo : public Object, public IEventInfo, protected IEventInfo::ICpp - { - protected: - MetaonlyReaderContext* context = nullptr; - Ptr metadata; - - public: - MetaonlyEventInfo(MetaonlyReaderContext* _context, Ptr _metadata) - : context(_context) - , metadata(_metadata) - { - } - - // ICpp - - const WString& GetAttachTemplate() override - { - return metadata->attachTemplate; - } - - const WString& GetDetachTemplate() override - { - return metadata->detachTemplate; - } - - const WString& GetInvokeTemplate() override - { - return metadata->invokeTemplate; - } - - // IMemberInfo - - ITypeDescriptor* GetOwnerTypeDescriptor() override - { - return context->tds[metadata->ownerTypeDescriptor].Obj(); - } - - const WString& GetName() override - { - return metadata->name; - } - - // IEventInfo - - IEventInfo::ICpp* GetCpp() override - { - if (metadata->attachTemplate.Length() + metadata->detachTemplate.Length() + metadata->invokeTemplate.Length() > 0) - { - return this; - } - return nullptr; - } - - ITypeInfo* GetHandlerType() override - { - return EnsureSetContext(metadata->handlerType.Obj(), context); - } - - vint GetObservingPropertyCount() override - { - return metadata->observingProperties.Count(); - } - - IPropertyInfo* GetObservingProperty(vint index) override - { - return context->pis[metadata->observingProperties[index]].Obj(); - } - - Ptr Attach(const Value& thisObject, Ptr handler) override - { - CHECK_FAIL(L"Not Supported!"); - } - - bool Detach(const Value& thisObject, Ptr handler) override - { - CHECK_FAIL(L"Not Supported!"); - } - - void Invoke(const Value& thisObject, Ptr arguments) override - { - CHECK_FAIL(L"Not Supported!"); - } - }; - -/*********************************************************************** -ITypeDescriptor -***********************************************************************/ - - class MetaonlyTypeDescriptor - : public Object - , public ITypeDescriptor - , protected ITypeDescriptor::ICpp - , protected IValueType - , protected IEnumType - { - protected: - MetaonlyReaderContext* context = nullptr; - Ptr metadata; - ISerializableType* serializableType = nullptr; - List> methodGroups; - Ptr constructorGroup; - - public: - MetaonlyTypeDescriptor(MetaonlyReaderContext* _context, Ptr _metadata) - : context(_context) - , metadata(_metadata) - { - if (metadata->isSerializable) - { - serializableType = context->serializableTypes[metadata->typeName].Obj(); - } - - for (vint i = 0; i < metadata->methodGroups.Count(); i++) - { - methodGroups.Add(new MetaonlyMethodGroupInfo(context, metadata, metadata->methodGroups[i])); - } - if (metadata->constructorGroup.start != -1) - { - constructorGroup = new MetaonlyMethodGroupInfo(context, metadata, metadata->constructorGroup); - } - } - - // ICpp - - const WString& GetFullName() override - { - return metadata->fullName; - } - - // IValueType - - Value CreateDefault() override - { - CHECK_FAIL(L"Not Supported!"); - } - - IBoxedValue::CompareResult Compare(const Value& a, const Value& b) override - { - CHECK_FAIL(L"Not Supported!"); - } - - // IEnumType - - bool IsFlagEnum() override - { - return metadata->isFlagEnum; - } - - vint GetItemCount() override - { - return metadata->enumItems.Count(); - } - - WString GetItemName(vint index) override - { - return metadata->enumItems[index]; - } - - vuint64_t GetItemValue(vint index) override - { - return metadata->enumValues[index]; - } - - vint IndexOfItem(WString name) override - { - return metadata->enumItems.IndexOf(name); - } - - Value ToEnum(vuint64_t value) override - { - CHECK_FAIL(L"Not Supported!"); - } - - vuint64_t FromEnum(const Value& value) override - { - CHECK_FAIL(L"Not Supported!"); - } - - // ITypeDescriptor - - ITypeDescriptor::ICpp* GetCpp() override - { - if (metadata->fullName.Length() > 0) - { - return this; - } - return nullptr; - } - - TypeDescriptorFlags GetTypeDescriptorFlags() override - { - return metadata->flags; - } - - bool IsAggregatable() override - { - return metadata->isAggregatable; - } - - const WString& GetTypeName() override - { - return metadata->typeName; - } - - IValueType* GetValueType() override - { - return metadata->isValueType ? this : nullptr; - } - - IEnumType* GetEnumType() override - { - return metadata->isEnumType ? this : nullptr; - } - - ISerializableType* GetSerializableType() override - { - return serializableType; - } - - vint GetBaseTypeDescriptorCount() override - { - return metadata->baseTypeDescriptors.Count(); - } - - ITypeDescriptor* GetBaseTypeDescriptor(vint index) override - { - return context->tds[metadata->baseTypeDescriptors[index]].Obj(); - } - - bool CanConvertTo(ITypeDescriptor* targetType) override - { - if (this == targetType) return true; - vint count = GetBaseTypeDescriptorCount(); - for (vint i = 0; i < count; i++) - { - if (GetBaseTypeDescriptor(i)->CanConvertTo(targetType)) return true; - } - return false; - } - - vint GetPropertyCount() override - { - return metadata->properties.Count(); - } - - IPropertyInfo* GetProperty(vint index) override - { - return context->pis[metadata->properties[index]].Obj(); - } - - bool IsPropertyExists(const WString& name, bool inheritable) override - { - return GetPropertyByName(name, inheritable); - } - - IPropertyInfo* GetPropertyByName(const WString& name, bool inheritable) override - { - for (vint i = 0; i < metadata->properties.Count(); i++) - { - auto info = GetProperty(i); - if (info->GetName() == name) - { - return info; - } - } - if (inheritable) - { - for (vint i = 0; i < metadata->baseTypeDescriptors.Count(); i++) - { - if (auto info = GetBaseTypeDescriptor(i)->GetPropertyByName(name, true)) - { - return info; - } - } - } - return nullptr; - } - - vint GetEventCount() override - { - return metadata->events.Count(); - } - - IEventInfo* GetEvent(vint index) override - { - return context->eis[metadata->events[index]].Obj(); - } - - bool IsEventExists(const WString& name, bool inheritable) override - { - return GetEventByName(name, inheritable); - } - - IEventInfo* GetEventByName(const WString& name, bool inheritable) override - { - for (vint i = 0; i < metadata->events.Count(); i++) - { - auto info = GetEvent(i); - if (info->GetName() == name) - { - return info; - } - } - if (inheritable) - { - for (vint i = 0; i < metadata->baseTypeDescriptors.Count(); i++) - { - if (auto info = GetBaseTypeDescriptor(i)->GetEventByName(name, true)) - { - return info; - } - } - } - return nullptr; - } - - vint GetMethodGroupCount() override - { - return methodGroups.Count(); - } - - IMethodGroupInfo* GetMethodGroup(vint index) override - { - return methodGroups[index].Obj(); - } - - bool IsMethodGroupExists(const WString& name, bool inheritable) override - { - return GetMethodGroupByName(name, inheritable); - } - - IMethodGroupInfo* GetMethodGroupByName(const WString& name, bool inheritable) override - { - for (vint i = 0; i < methodGroups.Count(); i++) - { - auto info = methodGroups[i].Obj(); - if (info->GetName() == name) - { - return info; - } - } - if (inheritable) - { - for (vint i = 0; i < metadata->baseTypeDescriptors.Count(); i++) - { - if (auto info = GetBaseTypeDescriptor(i)->GetMethodGroupByName(name, true)) - { - return info; - } - } - } - return nullptr; - } - - IMethodGroupInfo* GetConstructorGroup() override - { - return constructorGroup.Obj(); - } - }; - -/*********************************************************************** -GenerateMetaonlyTypes -***********************************************************************/ - - void GenerateMetaonlyTypeDescriptor(Writer& writer, ITypeDescriptor* td) - { - auto metadata = MakePtr(); - if (auto cpp = td->GetCpp()) - { - metadata->fullName = cpp->GetFullName(); - } - metadata->typeName = td->GetTypeName(); - metadata->flags = td->GetTypeDescriptorFlags(); - metadata->isAggregatable = td->IsAggregatable(); - metadata->isValueType = td->GetValueType(); - metadata->isSerializable = td->GetSerializableType(); - if (auto enumType = td->GetEnumType()) - { - metadata->isEnumType = true; - metadata->isFlagEnum = enumType->IsFlagEnum(); - for (vint i = 0; i < enumType->GetItemCount(); i++) - { - metadata->enumItems.Add(enumType->GetItemName(i)); - metadata->enumValues.Add(enumType->GetItemValue(i)); - } - } - - for (vint i = 0; i < td->GetBaseTypeDescriptorCount(); i++) - { - metadata->baseTypeDescriptors.Add(writer.context->tdIndex[td->GetBaseTypeDescriptor(i)]); - } - - for (vint i = 0; i < td->GetPropertyCount(); i++) - { - metadata->properties.Add(writer.context->piIndex[td->GetProperty(i)]); - } - - for (vint i = 0; i < td->GetEventCount(); i++) - { - metadata->events.Add(writer.context->eiIndex[td->GetEvent(i)]); - } - - for (vint i = 0; i < td->GetMethodGroupCount(); i++) - { - auto mg = td->GetMethodGroup(i); - IdRange ir; - ir.start = metadata->methods.Count(); - for (vint j = 0; j < mg->GetMethodCount(); j++) - { - metadata->methods.Add(writer.context->miIndex[mg->GetMethod(j)]); - } - ir.count = metadata->methods.Count() - ir.start; - metadata->methodGroups.Add(ir); - } - - if (auto cg = td->GetConstructorGroup()) - { - metadata->constructorGroup.start = metadata->methods.Count(); - for (vint j = 0; j < cg->GetMethodCount(); j++) - { - metadata->methods.Add(writer.context->miIndex[cg->GetMethod(j)]); - } - metadata->constructorGroup.count = metadata->methods.Count() - metadata->constructorGroup.start; - } - - writer << metadata; - } - - void GenerateMetaonlyMethodInfo(Writer& writer, IMethodInfo* mi) - { - auto metadata = MakePtr(); - if (auto cpp = mi->GetCpp()) - { - metadata->invokeTemplate = cpp->GetInvokeTemplate(); - metadata->closureTemplate = cpp->GetClosureTemplate(); - } - metadata->name = mi->GetName(); - metadata->ownerTypeDescriptor = writer.context->tdIndex[mi->GetOwnerTypeDescriptor()]; - if (auto pi = mi->GetOwnerProperty()) - { - metadata->ownerProperty = writer.context->piIndex[pi]; - } - for (vint i = 0; i < mi->GetParameterCount(); i++) - { - auto pi = mi->GetParameter(i); - auto piMetadata = MakePtr(); - piMetadata->name = pi->GetName(); - piMetadata->type = new MetaonlyTypeInfo(*writer.context.Obj(), pi->GetType()); - metadata->parameters.Add(piMetadata); - } - metadata->returnType = new MetaonlyTypeInfo(*writer.context.Obj(), mi->GetReturn()); - metadata->isStatic = mi->IsStatic(); - writer << metadata; - } - - void GenerateMetaonlyPropertyInfo(Writer& writer, IPropertyInfo* pi) - { - auto metadata = MakePtr();; - if (auto cpp = pi->GetCpp()) - { - metadata->referenceTemplate = cpp->GetReferenceTemplate(); - } - metadata->name = pi->GetName(); - metadata->ownerTypeDescriptor = writer.context->tdIndex[pi->GetOwnerTypeDescriptor()]; - metadata->isReadable = pi->IsReadable(); - metadata->isWritable = pi->IsWritable(); - metadata->returnType = new MetaonlyTypeInfo(*writer.context.Obj(), pi->GetReturn()); - if (auto mi = pi->GetGetter()) - { - metadata->getter = writer.context->miIndex[mi]; - } - if (auto mi = pi->GetSetter()) - { - metadata->setter = writer.context->miIndex[mi]; - } - if (auto ei = pi->GetValueChangedEvent()) - { - metadata->valueChangedEvent = writer.context->eiIndex[ei]; - } - writer << metadata; - } - - void GenerateMetaonlyEventInfo(Writer& writer, IEventInfo* ei) - { - auto metadata = MakePtr();; - if (auto cpp = ei->GetCpp()) - { - metadata->attachTemplate = cpp->GetAttachTemplate(); - metadata->detachTemplate = cpp->GetDetachTemplate(); - metadata->invokeTemplate = cpp->GetInvokeTemplate(); - } - metadata->name = ei->GetName(); - metadata->ownerTypeDescriptor = writer.context->tdIndex[ei->GetOwnerTypeDescriptor()]; - metadata->handlerType = new MetaonlyTypeInfo(*writer.context.Obj(), ei->GetHandlerType()); - for (vint i = 0; i < ei->GetObservingPropertyCount(); i++) - { - metadata->observingProperties.Add(writer.context->piIndex[ei->GetObservingProperty(i)]); - } - writer << metadata; - } - - void GenerateMetaonlyTypes(stream::IStream& outputStream) - { - Writer writer(outputStream); - writer.context = MakePtr(); - - Dictionary tds; - List mis; - List pis; - List eis; - - { - auto tm = GetGlobalTypeManager(); - vint count = tm->GetTypeDescriptorCount(); - - for (vint i = 0; i < count; i++) - { - auto td = tm->GetTypeDescriptor(i); - tds.Add(td->GetTypeName(), td); - } - } - { - vint count = tds.Count(); - for (vint i = 0; i < count; i++) - { - auto td = tds.Values()[i]; - writer.context->tdIndex.Add(td, writer.context->tdIndex.Count()); - - vint mgCount = td->GetMethodGroupCount(); - for (vint j = 0; j < mgCount; j++) - { - auto mg = td->GetMethodGroup(j); - vint miCount = mg->GetMethodCount(); - for (vint k = 0; k < miCount; k++) - { - auto mi = mg->GetMethod(k); - writer.context->miIndex.Add(mi, mis.Count()); - mis.Add(mi); - } - } - - if (auto cg = td->GetConstructorGroup()) - { - vint miCount = cg->GetMethodCount(); - for (vint k = 0; k < miCount; k++) - { - auto mi = cg->GetMethod(k); - writer.context->miIndex.Add(mi, mis.Count()); - mis.Add(mi); - } - } - - vint piCount = td->GetPropertyCount(); - for (vint j = 0; j < piCount; j++) - { - auto pi = td->GetProperty(j); - writer.context->piIndex.Add(pi, pis.Count()); - pis.Add(pi); - } - - vint eiCount = td->GetEventCount(); - for (vint j = 0; j < eiCount; j++) - { - auto ei = td->GetEvent(j); - writer.context->eiIndex.Add(ei, eis.Count()); - eis.Add(ei); - } - } - } - { - vint tdCount = tds.Count(); - vint miCount = mis.Count(); - vint piCount = pis.Count(); - vint eiCount = eis.Count(); - writer << tdCount << miCount << piCount << eiCount; - - for (vint i = 0; i < tdCount; i++) - { - GenerateMetaonlyTypeDescriptor(writer, tds.Values()[i]); - } - for (vint i = 0; i < miCount; i++) - { - GenerateMetaonlyMethodInfo(writer, mis[i]); - } - for (vint i = 0; i < piCount; i++) - { - GenerateMetaonlyPropertyInfo(writer, pis[i]); - } - for (vint i = 0; i < eiCount; i++) - { - GenerateMetaonlyEventInfo(writer, eis[i]); - } - } - } - -/*********************************************************************** -LoadMetaonlyTypes -***********************************************************************/ - - class MetaonlyTypeLoader : public Object, public ITypeLoader - { - public: - Ptr context; - - void Load(ITypeManager* manager) override - { - for (vint i = 0; i < context->tds.Count(); i++) - { - auto td = context->tds[i]; - manager->SetTypeDescriptor(td->GetTypeName(), td); - } - } - - void Unload(ITypeManager* manager) override - { - } - }; - - Ptr LoadMetaonlyTypes(stream::IStream& inputStream, const collections::Dictionary>& serializableTypes) - { - auto context = MakePtr(); - CopyFrom(context->serializableTypes, serializableTypes); - auto loader = MakePtr(); - loader->context = context; - Reader reader(inputStream); - reader.context = context; - - { - vint tdCount = 0; - vint miCount = 0; - vint piCount = 0; - vint eiCount = 0; - reader << tdCount << miCount << piCount << eiCount; - - for (vint i = 0; i < tdCount; i++) - { - Ptr metadata; - reader << metadata; - context->tds.Add(new MetaonlyTypeDescriptor(context.Obj(), metadata)); - } - for (vint i = 0; i < miCount; i++) - { - Ptr metadata; - reader << metadata; - context->mis.Add(new MetaonlyMethodInfo(context.Obj(), metadata)); - } - for (vint i = 0; i < piCount; i++) - { - Ptr metadata; - reader << metadata; - context->pis.Add(new MetaonlyPropertyInfo(context.Obj(), metadata)); - } - for (vint i = 0; i < eiCount; i++) - { - Ptr metadata; - reader << metadata; - context->eis.Add(new MetaonlyEventInfo(context.Obj(), metadata)); - } - } - - return loader; - } - } - } -} - -#endif diff --git a/Import/VlppReflection.h b/Import/VlppReflection.h index 0c0161aa..4489c6ed 100644 --- a/Import/VlppReflection.h +++ b/Import/VlppReflection.h @@ -2,20 +2,20 @@ THIS FILE IS AUTOMATICALLY GENERATED. DO NOT MODIFY DEVELOPER: Zihan Chen(vczh) ***********************************************************************/ -#include "Vlpp.h" #include "VlppOS.h" +#include "Vlpp.h" #include "VlppRegex.h" /*********************************************************************** -.\GUITYPEDESCRIPTOR.H +.\DESCRIPTABLEOBJECT.H ***********************************************************************/ /*********************************************************************** Author: Zihan Chen (vczh) Licensed under https://github.com/vczh-libraries/License ***********************************************************************/ -#ifndef VCZH_REFLECTION_GUITYPEDESCRIPTOR -#define VCZH_REFLECTION_GUITYPEDESCRIPTOR +#ifndef VCZH_REFLECTION_DESCRIPTABLEOBJECT +#define VCZH_REFLECTION_DESCRIPTABLEOBJECT #if (defined VCZH_DEBUG_NO_REFLECTION) && (defined VCZH_DEBUG_METAONLY_REFLECTION) @@ -30,43 +30,15 @@ namespace vl { namespace reflection { - -/*********************************************************************** -Attribute -***********************************************************************/ - namespace description { class ITypeDescriptor; - class ITypeInfo; - class IEventHandler; - class IEventInfo; - class IPropertyInfo; - class IParameterInfo; - class IMethodInfo; - class IMethodGroupInfo; - - class IValueFunctionProxy; - class IValueInterfaceProxy; - class IValueSubscription; - - class IValueEnumerable; - class IValueEnumerator; - class IValueReadonlyList; - class IValueList; - class IValueObservableList; - class IValueReadonlyDictionary; - class IValueDictionary; - - class IValueCallStack; - class IValueException; - - template - struct TypedValueSerializerProvider - { - }; } +/*********************************************************************** +DescriptableObject +***********************************************************************/ + /// ///

/// Base class of all reflectable value types (class). @@ -671,6 +643,15 @@ Attribute #endif }; +#ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA + template + description::ITypeDescriptor* Description::associatedTypeDescriptor = 0; +#endif + +/*********************************************************************** +AggregatableDescription +***********************************************************************/ + ///

/// Inherit from this class when you want to create a reflectable class that can be inherited by Workflow script classes. /// @@ -680,10 +661,9 @@ Attribute { }; -#ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA - template - description::ITypeDescriptor* Description::associatedTypeDescriptor=0; -#endif +/*********************************************************************** +IDescriptable +***********************************************************************/ /// Base type of all reflectable interfaces. All reflectable interface types should be virtual inherited. class IDescriptable : public virtual Interface, public Description @@ -724,10 +704,73 @@ ReferenceCounterOperator namespace reflection { + namespace description + { +/*********************************************************************** +Exceptions +***********************************************************************/ + + class TypeDescriptorException abstract : public Exception + { + public: + TypeDescriptorException(const WString& message) + :Exception(message) + { + } + }; + + class ObjectDisposedException : public TypeDescriptorException + { + public: + ObjectDisposedException() + :TypeDescriptorException(L"The referenced native object has been disposed.") + { + } + }; + + class ValueNotDisposableException : public TypeDescriptorException + { + public: + ValueNotDisposableException() + :TypeDescriptorException(L"Cannot dispose an object whose reference counter is not 0.") + { + } + }; + } + } +} + +#endif + +/*********************************************************************** +.\DESCRIPTABLEVALUE.H +***********************************************************************/ +/*********************************************************************** +Author: Zihan Chen (vczh) +Licensed under https://github.com/vczh-libraries/License +***********************************************************************/ + +#ifndef VCZH_REFLECTION_DESCRIPTABLEVALUE +#define VCZH_REFLECTION_DESCRIPTABLEVALUE + + +namespace vl +{ + namespace reflection + { + namespace description + { + class ITypeInfo; + class IMethodGroupInfo; + class IMethodInfo; + class IPropertyInfo; + class IEventInfo; + class IEventHandler; + class IValueFunctionProxy; + } namespace description { - /*********************************************************************** Value ***********************************************************************/ @@ -1820,7 +1863,35 @@ Value /// ]]> bool DeleteRawPtr(); }; + } + } +} +#endif + +/*********************************************************************** +.\DESCRIPTABLEINTERFACES.H +***********************************************************************/ +/*********************************************************************** +Author: Zihan Chen (vczh) +Licensed under https://github.com/vczh-libraries/License +***********************************************************************/ + +#ifndef VCZH_REFLECTION_DESCRIPTABLEINTERFACES +#define VCZH_REFLECTION_DESCRIPTABLEINTERFACES + + +namespace vl +{ + namespace reflection + { + namespace description + { + class IValueReadonlyList; + } + + namespace description + { /*********************************************************************** ValueType ***********************************************************************/ @@ -2007,7 +2078,7 @@ ITypeDescriptor (event) virtual IPropertyInfo* GetObservingProperty(vint index)=0; virtual Ptr Attach(const Value& thisObject, Ptr handler)=0; virtual bool Detach(const Value& thisObject, Ptr handler)=0; - virtual void Invoke(const Value& thisObject, Ptr arguments)=0; + virtual void Invoke(const Value& thisObject, Ptr arguments)=0; }; /*********************************************************************** @@ -2337,33 +2408,6 @@ Cpp Helper Functions Exceptions ***********************************************************************/ - class TypeDescriptorException abstract : public Exception - { - public: - TypeDescriptorException(const WString& message) - :Exception(message) - { - } - }; - - class ObjectDisposedException : public TypeDescriptorException - { - public: - ObjectDisposedException() - :TypeDescriptorException(L"The referenced native object has been disposed.") - { - } - }; - - class ValueNotDisposableException : public TypeDescriptorException - { - public: - ValueNotDisposableException() - :TypeDescriptorException(L"Cannot dispose an object whose reference counter is not 0.") - { - } - }; - #ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA class TypeNotExistsException : public TypeDescriptorException @@ -2478,15 +2522,15 @@ Exceptions #endif /*********************************************************************** -.\GUITYPEDESCRIPTOROBSERVABLELIST.H +.\PREDEFINED\OBSERVABLELIST.H ***********************************************************************/ /*********************************************************************** Author: Zihan Chen (vczh) Licensed under https://github.com/vczh-libraries/License ***********************************************************************/ -#ifndef VCZH_REFLECTION_GUITYPEDESCRIPTORBUILDER_OBSERVABLELIST -#define VCZH_REFLECTION_GUITYPEDESCRIPTORBUILDER_OBSERVABLELIST +#ifndef VCZH_REFLECTION_TYPES_OBSERVABLELIST +#define VCZH_REFLECTION_TYPES_OBSERVABLELIST namespace vl @@ -2753,15 +2797,15 @@ namespace vl #endif /*********************************************************************** -.\GUITYPEDESCRIPTORPREDEFINED.H +.\PREDEFINED\PREDEFINEDTYPES.H ***********************************************************************/ /*********************************************************************** Author: Zihan Chen (vczh) Licensed under https://github.com/vczh-libraries/License ***********************************************************************/ -#ifndef VCZH_REFLECTION_GUITYPEDESCRIPTORPREDEFINED -#define VCZH_REFLECTION_GUITYPEDESCRIPTORPREDEFINED +#ifndef VCZH_REFLECTION_TYPES_PREDEFINEDTYPES +#define VCZH_REFLECTION_TYPES_PREDEFINEDTYPES #include @@ -3493,7 +3537,7 @@ Interface Implementation Proxy class IValueInterfaceProxy : public virtual IDescriptable, public Description { public: - virtual Value Invoke(IMethodInfo* methodInfo, Ptr arguments) = 0; + virtual Value Invoke(IMethodInfo* methodInfo, Ptr arguments) = 0; }; /// A reflectable version of . @@ -3504,7 +3548,7 @@ Interface Implementation Proxy /// Call the function. /// Return value from the function. /// Arguments to call the function. - virtual Value Invoke(Ptr arguments) = 0; + virtual Value Invoke(Ptr arguments) = 0; }; /// A reflectable subscription, usually created by the bind expression in Workflow script. @@ -3607,30 +3651,23 @@ Runtime Exception /*********************************************************************** -.\GUITYPEDESCRIPTORBUILDER.H +.\METADATA\METADATA.H ***********************************************************************/ /*********************************************************************** Author: Zihan Chen (vczh) Licensed under https://github.com/vczh-libraries/License ***********************************************************************/ -#ifndef VCZH_REFLECTION_GUITYPEDESCRIPTORBUILDER -#define VCZH_REFLECTION_GUITYPEDESCRIPTORBUILDER +#ifndef VCZH_REFLECTION_METADATA_METADATA +#define VCZH_REFLECTION_METADATA_METADATA namespace vl { - namespace collections - { - template - class ObservableList; - } - namespace reflection { namespace description { - #ifndef VCZH_DEBUG_NO_REFLECTION /*********************************************************************** @@ -3657,9 +3694,7 @@ TypeInfo }; template - struct TypeInfo - { - }; + struct TypeInfo; /// Get a registered type given a C++ type. /// Returns the metadata class for this registered type. @@ -3949,7 +3984,7 @@ EventInfoImpl virtual Ptr AttachInternal(DescriptableObject* thisObject, Ptr handler)=0; virtual bool DetachInternal(DescriptableObject* thisObject, Ptr handler)=0; - virtual void InvokeInternal(DescriptableObject* thisObject, Ptr arguments)=0; + virtual void InvokeInternal(DescriptableObject* thisObject, Ptr arguments)=0; virtual Ptr GetHandlerTypeInternal()=0; public: EventInfoImpl(ITypeDescriptor* _ownerTypeDescriptor, const WString& _name); @@ -3962,7 +3997,7 @@ EventInfoImpl IPropertyInfo* GetObservingProperty(vint index)override; Ptr Attach(const Value& thisObject, Ptr handler)override; bool Detach(const Value& thisObject, Ptr handler)override; - void Invoke(const Value& thisObject, Ptr arguments)override; + void Invoke(const Value& thisObject, Ptr arguments)override; }; /*********************************************************************** @@ -4097,6 +4132,343 @@ TypeDescriptorImpl #endif +#ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA + +/*********************************************************************** +CustomFieldInfoImpl +***********************************************************************/ + + template + class CustomFieldInfoImpl : public FieldInfoImpl + { + protected: + TField TClass::* fieldRef; + + Value GetValueInternal(const Value& thisObject)override + { + TClass* object = UnboxValue(thisObject); + if (object) + { + return BoxParameter(object->*fieldRef, GetReturn()->GetTypeDescriptor()); + } + return Value(); + } + + void SetValueInternal(Value& thisObject, const Value& newValue)override + { + if constexpr (std::is_copy_assignable_v) + { + TClass* object = UnboxValue(thisObject); + if (object) + { + auto result = UnboxParameter(newValue, GetReturn()->GetTypeDescriptor(), L"newValue"); + object->*fieldRef = result.Ref(); + } + } + else + { + throw PropertyIsNotWritableException(this); + } + } + public: + CustomFieldInfoImpl(ITypeDescriptor* _ownerTypeDescriptor, const WString& _name, TField TClass::* _fieldRef) + :FieldInfoImpl(_ownerTypeDescriptor, _name, TypeInfoRetriver::CreateTypeInfo()) + , fieldRef(_fieldRef) + { + } + + IPropertyInfo::ICpp* GetCpp()override + { + return nullptr; + } + + bool IsWritable()override + { + return std::is_copy_assignable_v; + } + }; + +#endif + +/*********************************************************************** +PrimitiveTypeDescriptor +***********************************************************************/ + +#ifndef VCZH_DEBUG_NO_REFLECTION + + template + class SerializableValueType : public Object, public virtual IValueType + { + public: + Value CreateDefault()override + { + return BoxValue(TypedValueSerializerProvider::GetDefaultValue()); + } + + IBoxedValue::CompareResult Compare(const Value& a, const Value& b)override + { + auto va = UnboxValue(a); + auto vb = UnboxValue(b); + return TypedValueSerializerProvider::Compare(va, vb); + } + }; + + template + class SerializableType : public Object, public virtual ISerializableType + { + public: + bool Serialize(const Value& input, WString& output)override + { + return TypedValueSerializerProvider::Serialize(UnboxValue(input), output); + } + + bool Deserialize(const WString& input, Value& output)override + { + T value; + if (!TypedValueSerializerProvider::Deserialize(input, value)) + { + return false; + } + output = BoxValue(value); + return true; + } + }; + +#endif + +#ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA + + template + class PrimitiveTypeDescriptor : public TypedValueTypeDescriptorBase + { + protected: + void LoadInternal()override + { + this->valueType = new SerializableValueType(); + this->serializableType = new SerializableType(); + } + }; + +/*********************************************************************** +EnumTypeDescriptor +***********************************************************************/ + + template + class EnumValueType : public Object, public virtual IValueType + { + public: + Value CreateDefault()override + { + return BoxValue(static_cast(0)); + } + + IBoxedValue::CompareResult Compare(const Value& a, const Value& b)override + { + auto ea = static_cast(UnboxValue(a)); + auto eb = static_cast(UnboxValue(b)); + if (ea < eb) return IBoxedValue::Smaller; + if (ea > eb)return IBoxedValue::Greater; + return IBoxedValue::Equal; + } + }; + + template + class EnumType : public Object, public virtual IEnumType + { + protected: + collections::Dictionary candidates; + + public: + void AddItem(WString name, T value) + { + candidates.Add(name, value); + } + + bool IsFlagEnum()override + { + return Flag; + } + + vint GetItemCount()override + { + return candidates.Count(); + } + + WString GetItemName(vint index)override + { + if (index < 0 || index >= candidates.Count()) + { + return L""; + } + return candidates.Keys()[index]; + } + + vuint64_t GetItemValue(vint index)override + { + if (index < 0 || index >= candidates.Count()) + { + return 0; + } + return static_cast(candidates.Values()[index]); + } + + vint IndexOfItem(WString name)override + { + return candidates.Keys().IndexOf(name); + } + + Value ToEnum(vuint64_t value)override + { + return BoxValue(static_cast(value)); + } + + vuint64_t FromEnum(const Value& value)override + { + return static_cast(UnboxValue(value)); + } + }; + + template + class EnumTypeDescriptor : public TypedValueTypeDescriptorBase + { + using TEnumType = EnumType; + protected: + Ptr enumType; + + void LoadInternal()override + { + this->enumType = new TEnumType; + this->valueType = new EnumValueType(); + TypedValueTypeDescriptorBase::enumType = enumType; + } + }; + +/*********************************************************************** +StructTypeDescriptor +***********************************************************************/ + + template + class StructValueType : public Object, public virtual IValueType + { + public: + Value CreateDefault()override + { + return BoxValue(T{}); + } + + IBoxedValue::CompareResult Compare(const Value& a, const Value& b)override + { + return IBoxedValue::NotComparable; + } + }; + + template + class StructTypeDescriptor : public TypedValueTypeDescriptorBase + { + protected: + template + class StructFieldInfo : public FieldInfoImpl + { + protected: + TField T::* field; + + Value GetValueInternal(const Value& thisObject)override + { + auto structValue = thisObject.GetBoxedValue().Cast>(); + if (!structValue) + { + throw ArgumentTypeMismtatchException(L"thisObject", GetOwnerTypeDescriptor(), Value::BoxedValue, thisObject); + } + return BoxValue(structValue->value.*field); + } + + void SetValueInternal(Value& thisObject, const Value& newValue)override + { + auto structValue = thisObject.GetBoxedValue().Cast>(); + if (!structValue) + { + throw ArgumentTypeMismtatchException(L"thisObject", GetOwnerTypeDescriptor(), Value::BoxedValue, thisObject); + } + (structValue->value.*field) = UnboxValue(newValue); + } + public: + StructFieldInfo(ITypeDescriptor* _ownerTypeDescriptor, TField T::* _field, const WString& _name) + :field(_field) + , FieldInfoImpl(_ownerTypeDescriptor, _name, TypeInfoRetriver::CreateTypeInfo()) + { + } + + IPropertyInfo::ICpp* GetCpp()override + { + return nullptr; + } + }; + + protected: + collections::Dictionary> fields; + + public: + StructTypeDescriptor() + { + this->valueType = new StructValueType(); + } + + vint GetPropertyCount()override + { + this->Load(); + return fields.Count(); + } + + IPropertyInfo* GetProperty(vint index)override + { + this->Load(); + if (index < 0 || index >= fields.Count()) + { + return nullptr; + } + return fields.Values()[index].Obj(); + } + + bool IsPropertyExists(const WString& name, bool inheritable)override + { + this->Load(); + return fields.Keys().Contains(name); + } + + IPropertyInfo* GetPropertyByName(const WString& name, bool inheritable)override + { + this->Load(); + vint index = fields.Keys().IndexOf(name); + if (index == -1) return nullptr; + return fields.Values()[index].Obj(); + } + }; +#endif + } + } +} + +#endif + + +/*********************************************************************** +.\BOXING\TYPEINFORETRIVER.H +***********************************************************************/ +/*********************************************************************** +Author: Zihan Chen (vczh) +Licensed under https://github.com/vczh-libraries/License +***********************************************************************/ + +#ifndef VCZH_REFLECTION_BOXING_TYPEINFORETRIVER +#define VCZH_REFLECTION_BOXING_TYPEINFORETRIVER + + +namespace vl +{ + namespace reflection + { + namespace description + { /*********************************************************************** TypeFlagTester ***********************************************************************/ @@ -4393,30 +4765,220 @@ TypeHintTester }; /*********************************************************************** -TypeInfoRetriver +DetailTypeInfoRetriver ***********************************************************************/ template - struct DetailTypeInfoRetriver + struct DetailTypeInfoRetriver; + +/*********************************************************************** +Basic Types +***********************************************************************/ + + template + struct DetailTypeInfoRetriver { static const ITypeInfo::Decorator Decorator=ITypeInfo::TypeDescriptor; - typedef void Type; - typedef void TempValueType; - typedef void ResultReferenceType; - typedef void ResultNonReferenceType; + +#ifndef VCZH_DEBUG_NO_REFLECTION + static Ptr CreateTypeInfo(TypeInfoHint hint) + { + return MakePtr(GetTypeDescriptor(), hint); + } +#endif }; +/*********************************************************************** +Decorated Types +***********************************************************************/ + + template + struct DetailTypeInfoRetriver + { + typedef DetailTypeInfoRetriver UpLevelRetriver; + + static const ITypeInfo::Decorator Decorator=ITypeInfo::RawPtr; + +#ifndef VCZH_DEBUG_NO_REFLECTION + static Ptr CreateTypeInfo(TypeInfoHint hint) + { + return MakePtr(TypeInfoRetriver::CreateTypeInfo()); + } +#endif + }; + + template + struct DetailTypeInfoRetriver, TypeFlags::NonGenericType> + { + typedef DetailTypeInfoRetriver UpLevelRetriver; + + static const ITypeInfo::Decorator Decorator=ITypeInfo::SharedPtr; + +#ifndef VCZH_DEBUG_NO_REFLECTION + static Ptr CreateTypeInfo(TypeInfoHint hint) + { + return MakePtr(TypeInfoRetriver::CreateTypeInfo()); + } +#endif + }; + + template + struct DetailTypeInfoRetriver, TypeFlags::NonGenericType> + { + typedef DetailTypeInfoRetriver UpLevelRetriver; + + static const ITypeInfo::Decorator Decorator=ITypeInfo::Nullable; + +#ifndef VCZH_DEBUG_NO_REFLECTION + static Ptr CreateTypeInfo(TypeInfoHint hint) + { + return MakePtr(TypeInfoRetriver::CreateTypeInfo()); + } +#endif + }; + +/*********************************************************************** +Containers +***********************************************************************/ + + template + struct DetailTypeInfoRetriver_Template1 + { + typedef DetailTypeInfoRetriver UpLevelRetriver; + + static const ITypeInfo::Decorator Decorator = UpLevelRetriver::Decorator; + +#ifndef VCZH_DEBUG_NO_REFLECTION + static Ptr CreateTypeInfo(TypeInfoHint hint) + { + auto arrayType = MakePtr(GetTypeDescriptor(), hint); + + auto genericType = MakePtr(arrayType); + genericType->AddGenericArgument(TypeInfoRetriver::CreateTypeInfo()); + + auto type = MakePtr(genericType); + return type; + } +#endif + }; + + template + struct DetailTypeInfoRetriver_Template2 + { + typedef DetailTypeInfoRetriver UpLevelRetriver; + + static const ITypeInfo::Decorator Decorator = UpLevelRetriver::Decorator; + +#ifndef VCZH_DEBUG_NO_REFLECTION + static Ptr CreateTypeInfo(TypeInfoHint hint) + { + auto arrayType = MakePtr(GetTypeDescriptor(), hint); + + auto genericType = MakePtr(arrayType); + genericType->AddGenericArgument(TypeInfoRetriver::CreateTypeInfo()); + genericType->AddGenericArgument(TypeInfoRetriver::CreateTypeInfo()); + + auto type = MakePtr(genericType); + return type; + } +#endif + }; + + template + struct DetailTypeInfoRetriver : DetailTypeInfoRetriver_Template1 + { + }; + + template + struct DetailTypeInfoRetriver : DetailTypeInfoRetriver_Template1 + { + }; + + template + struct DetailTypeInfoRetriver : DetailTypeInfoRetriver_Template1 + { + }; + + template + struct DetailTypeInfoRetriver : DetailTypeInfoRetriver_Template1 + { + }; + + template + struct DetailTypeInfoRetriver : DetailTypeInfoRetriver_Template1 + { + }; + + template + struct DetailTypeInfoRetriver : DetailTypeInfoRetriver_Template2 + { + }; + + template + struct DetailTypeInfoRetriver : DetailTypeInfoRetriver_Template2 + { + }; + +/*********************************************************************** +Functions +***********************************************************************/ + +#ifndef VCZH_DEBUG_NO_REFLECTION + namespace internal_helper + { + template + struct GenericArgumentAdder + { + static void Add(Ptr genericType) + { + } + }; + + template + struct GenericArgumentAdder> + { + static void Add(Ptr genericType) + { + genericType->AddGenericArgument(TypeInfoRetriver::CreateTypeInfo()); + GenericArgumentAdder>::Add(genericType); + } + }; + } +#endif + + template + struct DetailTypeInfoRetriver, TypeFlags::FunctionType> + { + typedef DetailTypeInfoRetriver, TypeFlags::NonGenericType> UpLevelRetriver; + + static const ITypeInfo::Decorator Decorator=UpLevelRetriver::Decorator; + +#ifndef VCZH_DEBUG_NO_REFLECTION + static Ptr CreateTypeInfo(TypeInfoHint hint) + { + auto functionType = MakePtr(GetTypeDescriptor(), hint); + + auto genericType = MakePtr(functionType); + genericType->AddGenericArgument(TypeInfoRetriver::CreateTypeInfo()); + internal_helper::GenericArgumentAdder>::Add(genericType); + + auto type = MakePtr(genericType); + return type; + } +#endif + }; + +/*********************************************************************** +TypeInfoRetriver +***********************************************************************/ + template struct TypeInfoRetriver { - static const TypeFlags TypeFlag = TypeFlagSelector::Result; - static const TypeInfoHint Hint = TypeHintTester::Result; - static const ITypeInfo::Decorator Decorator = DetailTypeInfoRetriver::Decorator; - - typedef typename DetailTypeInfoRetriver::Type Type; - typedef typename DetailTypeInfoRetriver::TempValueType TempValueType; - typedef typename DetailTypeInfoRetriver::ResultReferenceType ResultReferenceType; - typedef typename DetailTypeInfoRetriver::ResultNonReferenceType ResultNonReferenceType; + static const TypeFlags TypeFlag = TypeFlagSelector::Result; + static const TypeInfoHint Hint = TypeHintTester::Result; + typedef DetailTypeInfoRetriver, TypeFlag> Detail; + static const ITypeInfo::Decorator Decorator = Detail::Decorator; #ifndef VCZH_DEBUG_NO_REFLECTION static Ptr CreateTypeInfo() @@ -4426,8 +4988,37 @@ TypeInfoRetriver #endif }; + template<> + struct TypeInfoRetriver : public TypeInfoRetriver + { + }; + } + } +} + +#endif + + /*********************************************************************** -TypeInfoRetriver Helper Functions (BoxValue, UnboxValue) +.\BOXING\BOXINGVALUE.H +***********************************************************************/ +/*********************************************************************** +Author: Zihan Chen (vczh) +Licensed under https://github.com/vczh-libraries/License +***********************************************************************/ + +#ifndef VCZH_REFLECTION_BOXING_BOXINGVALUE +#define VCZH_REFLECTION_BOXING_BOXINGVALUE + + +namespace vl +{ + namespace reflection + { + namespace description + { +/*********************************************************************** +BoxValue, UnboxValue ***********************************************************************/ template @@ -4461,1193 +5052,9 @@ TypeInfoRetriver Helper Functions (BoxValue, UnboxValue) } /*********************************************************************** -TypeInfoRetriver Helper Functions (BoxParameter, UnboxParameter) +Basic Types ***********************************************************************/ - template - struct ParameterAccessor - { - }; - - /// Box an reflectable object. It supports generic types such as containers, functions (should be Func<T>), etc. - /// The boxed value. - /// Type of the object. - /// The object to box. - /// The type descriptor of the object (optional). - template - Value BoxParameter(T&& object, ITypeDescriptor* typeDescriptor = nullptr) - { - using TIR = TypeInfoRetriver>; - return ParameterAccessor::BoxParameter(object, typeDescriptor); - } - - /// Box an reflectable object. It supports generic types such as containers, functions (should be Func<T>), etc. - /// Type of the object. - /// The value to unbox. - /// The unboxed object. - /// The type descriptor of the object (optional). - /// The name of the object to provide a friendly exception message if the conversion is failed (optional). - template - void UnboxParameter(const Value& value, T& result, ITypeDescriptor* typeDescriptor = nullptr, const WString& valueName = WString::Unmanaged(L"value")) - { - using TIR = TypeInfoRetriver>; - ParameterAccessor::UnboxParameter(value, result, typeDescriptor, valueName); - } - -#ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA - -/*********************************************************************** -Value_xs -***********************************************************************/ - - class Value_xs - { - protected: - collections::Array arguments; - public: - Value_xs() - { - } - - template - Value_xs& operator,(T& value) - { - arguments.Resize(arguments.Count() + 1); - arguments[arguments.Count() - 1] = BoxParameter(value); - return *this; - } - - Value_xs& operator,(const Value& value) - { - arguments.Resize(arguments.Count()+1); - arguments[arguments.Count()-1]=value; - return *this; - } - - operator collections::Array&() - { - return arguments; - } - }; - -/*********************************************************************** -CustomFieldInfoImpl -***********************************************************************/ - - template - class CustomFieldInfoImpl : public FieldInfoImpl - { - protected: - TField TClass::* fieldRef; - - Value GetValueInternal(const Value& thisObject)override - { - TClass* object=UnboxValue(thisObject); - if(object) - { - return BoxParameter(object->*fieldRef, GetReturn()->GetTypeDescriptor()); - } - return Value(); - } - - void SetValueInternal(Value& thisObject, const Value& newValue)override - { - TClass* object=UnboxValue(thisObject); - if(object) - { - UnboxParameter(newValue, object->*fieldRef, GetReturn()->GetTypeDescriptor(), L"newValue"); - } - } - public: - CustomFieldInfoImpl(ITypeDescriptor* _ownerTypeDescriptor, const WString& _name, TField TClass::* _fieldRef) - :FieldInfoImpl(_ownerTypeDescriptor, _name, TypeInfoRetriver::CreateTypeInfo()) - , fieldRef(_fieldRef) - { - } - - IPropertyInfo::ICpp* GetCpp()override - { - return nullptr; - } - }; - -#endif - -/*********************************************************************** -PrimitiveTypeDescriptor -***********************************************************************/ - -#ifndef VCZH_DEBUG_NO_REFLECTION - - template - class SerializableValueType : public Object, public virtual IValueType - { - public: - Value CreateDefault()override - { - return BoxValue(TypedValueSerializerProvider::GetDefaultValue()); - } - - IBoxedValue::CompareResult Compare(const Value& a, const Value& b)override - { - auto va = UnboxValue(a); - auto vb = UnboxValue(b); - return TypedValueSerializerProvider::Compare(va, vb); - } - }; - - template - class SerializableType : public Object, public virtual ISerializableType - { - public: - bool Serialize(const Value& input, WString& output)override - { - return TypedValueSerializerProvider::Serialize(UnboxValue(input), output); - } - - bool Deserialize(const WString& input, Value& output)override - { - T value; - if (!TypedValueSerializerProvider::Deserialize(input, value)) - { - return false; - } - output = BoxValue(value); - return true; - } - }; - -#endif - -#ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA - - template - class PrimitiveTypeDescriptor : public TypedValueTypeDescriptorBase - { - protected: - void LoadInternal()override - { - this->valueType = new SerializableValueType(); - this->serializableType = new SerializableType(); - } - }; - -/*********************************************************************** -EnumTypeDescriptor -***********************************************************************/ - - template - class EnumValueType : public Object, public virtual IValueType - { - public: - Value CreateDefault()override - { - return BoxValue(static_cast(0)); - } - - IBoxedValue::CompareResult Compare(const Value& a, const Value& b)override - { - auto ea = static_cast(UnboxValue(a)); - auto eb = static_cast(UnboxValue(b)); - if (ea < eb) return IBoxedValue::Smaller; - if (ea > eb)return IBoxedValue::Greater; - return IBoxedValue::Equal; - } - }; - - template - class EnumType : public Object, public virtual IEnumType - { - protected: - collections::Dictionary candidates; - - public: - void AddItem(WString name, T value) - { - candidates.Add(name, value); - } - - bool IsFlagEnum()override - { - return Flag; - } - - vint GetItemCount()override - { - return candidates.Count(); - } - - WString GetItemName(vint index)override - { - if (index < 0 || index >= candidates.Count()) - { - return L""; - } - return candidates.Keys()[index]; - } - - vuint64_t GetItemValue(vint index)override - { - if (index < 0 || index >= candidates.Count()) - { - return 0; - } - return static_cast(candidates.Values()[index]); - } - - vint IndexOfItem(WString name)override - { - return candidates.Keys().IndexOf(name); - } - - Value ToEnum(vuint64_t value)override - { - return BoxValue(static_cast(value)); - } - - vuint64_t FromEnum(const Value& value)override - { - return static_cast(UnboxValue(value)); - } - }; - - template - class EnumTypeDescriptor : public TypedValueTypeDescriptorBase - { - using TEnumType = EnumType; - protected: - Ptr enumType; - - void LoadInternal()override - { - this->enumType = new TEnumType; - this->valueType = new EnumValueType(); - TypedValueTypeDescriptorBase::enumType = enumType; - } - }; - -/*********************************************************************** -StructTypeDescriptor -***********************************************************************/ - - template - class StructValueType : public Object, public virtual IValueType - { - public: - Value CreateDefault()override - { - return BoxValue(T{}); - } - - IBoxedValue::CompareResult Compare(const Value& a, const Value& b)override - { - return IBoxedValue::NotComparable; - } - }; - - template - class StructTypeDescriptor : public TypedValueTypeDescriptorBase - { - protected: - template - class StructFieldInfo : public FieldInfoImpl - { - protected: - TField T::* field; - - Value GetValueInternal(const Value& thisObject)override - { - auto structValue = thisObject.GetBoxedValue().Cast>(); - if (!structValue) - { - throw ArgumentTypeMismtatchException(L"thisObject", GetOwnerTypeDescriptor(), Value::BoxedValue, thisObject); - } - return BoxValue(structValue->value.*field); - } - - void SetValueInternal(Value& thisObject, const Value& newValue)override - { - auto structValue = thisObject.GetBoxedValue().Cast>(); - if (!structValue) - { - throw ArgumentTypeMismtatchException(L"thisObject", GetOwnerTypeDescriptor(), Value::BoxedValue, thisObject); - } - (structValue->value.*field) = UnboxValue(newValue); - } - public: - StructFieldInfo(ITypeDescriptor* _ownerTypeDescriptor, TField T::* _field, const WString& _name) - :field(_field) - , FieldInfoImpl(_ownerTypeDescriptor, _name, TypeInfoRetriver::CreateTypeInfo()) - { - } - - IPropertyInfo::ICpp* GetCpp()override - { - return nullptr; - } - }; - - protected: - collections::Dictionary> fields; - - public: - StructTypeDescriptor() - { - this->valueType = new StructValueType(); - } - - vint GetPropertyCount()override - { - this->Load(); - return fields.Count(); - } - - IPropertyInfo* GetProperty(vint index)override - { - this->Load(); - if (index < 0 || index >= fields.Count()) - { - return nullptr; - } - return fields.Values()[index].Obj(); - } - - bool IsPropertyExists(const WString& name, bool inheritable)override - { - this->Load(); - return fields.Keys().Contains(name); - } - - IPropertyInfo* GetPropertyByName(const WString& name, bool inheritable)override - { - this->Load(); - vint index = fields.Keys().IndexOf(name); - if (index == -1) return nullptr; - return fields.Values()[index].Obj(); - } - }; -#endif - } - } -} - -#endif - - -/*********************************************************************** -.\GUITYPEDESCRIPTORBUILDER_FUNCTION.H -***********************************************************************/ -/*********************************************************************** -Author: Zihan Chen (vczh) -Licensed under https://github.com/vczh-libraries/License -***********************************************************************/ - -#ifndef VCZH_REFLECTION_GUITYPEDESCRIPTORBUILDER_FUNCTION -#define VCZH_REFLECTION_GUITYPEDESCRIPTORBUILDER_FUNCTION - - -namespace vl -{ - namespace reflection - { - namespace description - { - template - struct EventHelper - { - using Handler = const Func&; - - class EventHandlerImpl : public Object, public reflection::description::IEventHandler - { - public: - Ptr handler; - - EventHandlerImpl(Ptr _handler) - :handler(_handler) - { - } - - bool IsAttached()override - { - return handler->IsAttached(); - } - }; - - static Ptr Attach(Event& e, Handler handler) - { - return MakePtr(e.Add(handler)); - } - - static bool Detach(Event& e, Ptr handler) - { - auto impl = handler.Cast(); - if (!impl) return false; - return e.Remove(impl->handler); - } - - static Event& Invoke(Event& e) - { - return e; - } - }; - -/*********************************************************************** -DetailTypeInfoRetriver> -***********************************************************************/ - -#ifndef VCZH_DEBUG_NO_REFLECTION - namespace internal_helper - { - template - struct GenericArgumentAdder - { - static void Add(Ptr genericType) - { - } - }; - - template - struct GenericArgumentAdder> - { - static void Add(Ptr genericType) - { - genericType->AddGenericArgument(TypeInfoRetriver::CreateTypeInfo()); - GenericArgumentAdder>::Add(genericType); - } - }; - } -#endif - - template - struct DetailTypeInfoRetriver, TypeFlags::FunctionType> - { - typedef DetailTypeInfoRetriver, TypeFlags::NonGenericType> UpLevelRetriver; - - static const ITypeInfo::Decorator Decorator=UpLevelRetriver::Decorator; - typedef IValueList Type; - typedef typename UpLevelRetriver::TempValueType TempValueType; - typedef typename UpLevelRetriver::ResultReferenceType ResultReferenceType; - typedef typename UpLevelRetriver::ResultNonReferenceType ResultNonReferenceType; - -#ifndef VCZH_DEBUG_NO_REFLECTION - static Ptr CreateTypeInfo(TypeInfoHint hint) - { - auto functionType = MakePtr(GetTypeDescriptor(), hint); - - auto genericType = MakePtr(functionType); - genericType->AddGenericArgument(TypeInfoRetriver::CreateTypeInfo()); - internal_helper::GenericArgumentAdder>::Add(genericType); - - auto type = MakePtr(genericType); - return type; - } -#endif - }; - - template - struct DetailTypeInfoRetriver, TypeFlags::FunctionType> - : DetailTypeInfoRetriver, TypeFlags::FunctionType> - { - }; - -/*********************************************************************** -ValueFunctionProxyWrapper> -***********************************************************************/ - - template - class ValueFunctionProxyWrapper - { - }; - - namespace internal_helper - { - extern void UnboxSpecifiedParameter(Ptr arguments, vint index); - - template - void UnboxSpecifiedParameter(Ptr arguments, vint index, T0& p0, TArgs& ...args) - { - UnboxParameter(arguments->Get(index), p0, 0, itow(index + 1) + L"-th argument"); - UnboxSpecifiedParameter(arguments, index + 1, args...); - } - - template - struct BoxedFunctionInvoker - { - static Value Invoke(const Func& function, Ptr arguments, std::remove_cvref_t&& ...args) - { - UnboxSpecifiedParameter(arguments, 0, args...); - R result = function(args...); - return BoxParameter(result); - } - }; - - template - struct BoxedFunctionInvoker - { - static Value Invoke(const Func& function, Ptr arguments, std::remove_cvref_t&& ...args) - { - UnboxSpecifiedParameter(arguments, 0, args...); - function(args...); - return Value(); - } - }; - } - - template - class ValueFunctionProxyWrapper : public Object, public virtual IValueFunctionProxy - { - typedef Func FunctionType; - protected: - FunctionType function; - - public: - ValueFunctionProxyWrapper(const FunctionType& _function) - :function(_function) - { - } - - FunctionType GetFunction() - { - return function; - } - - Value Invoke(Ptr arguments)override - { - if (!arguments || arguments->GetCount() != sizeof...(TArgs)) - { -#ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA - throw ArgumentCountMismtatchException(); -#else - CHECK_FAIL(L"Argument count mismatch."); -#endif - } - return internal_helper::BoxedFunctionInvoker::Invoke(function, arguments, std::remove_cvref_t()...); - } - }; - -/*********************************************************************** -ParameterAccessor> -***********************************************************************/ - - namespace internal_helper - { - extern void AddValueToList(Ptr arguments); - - template - void AddValueToList(Ptr arguments, T0&& p0, TArgs&& ...args) - { - arguments->Add(description::BoxParameter(p0)); - AddValueToList(arguments, args...); - } - } - - template - struct ParameterAccessor, TypeFlags::FunctionType> - { - static Value BoxParameter(const Func& object, ITypeDescriptor* typeDescriptor) - { - typedef R(RawFunctionType)(TArgs...); - Ptr result=new ValueFunctionProxyWrapper(object); - - ITypeDescriptor* td = nullptr; -#ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA - td = Description::GetAssociatedTypeDescriptor(); -#endif - return BoxValue>(result, td); - } - - static void UnboxParameter(const Value& value, Func& result, ITypeDescriptor* typeDescriptor, const WString& valueName) - { - typedef R(RawFunctionType)(TArgs...); - typedef ValueFunctionProxyWrapper ProxyType; - Ptr functionProxy=UnboxValue>(value, typeDescriptor, valueName); - if(functionProxy) - { - if(Ptr proxy=functionProxy.Cast()) - { - result=proxy->GetFunction(); - } - else - { - result=[functionProxy](TArgs ...args) - { - Ptr arguments = IValueList::Create(); - internal_helper::AddValueToList(arguments, std::forward(args)...); - typedef typename TypeInfoRetriver::TempValueType ResultType; - ResultType proxyResult; - description::UnboxParameter(functionProxy->Invoke(arguments), proxyResult); - return proxyResult; - }; - } - } - } - }; - - template - struct ParameterAccessor, TypeFlags::FunctionType> : ParameterAccessor, TypeFlags::FunctionType> - { - }; - -#ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA - -/*********************************************************************** -MethodInfoImpl -***********************************************************************/ - - template - class CustomConstructorInfoImpl{}; - - template - class CustomMethodInfoImpl{}; - - template - class CustomExternalMethodInfoImpl{}; - - template - class CustomStaticMethodInfoImpl{}; - - template - class CustomEventInfoImpl{}; - -/*********************************************************************** -CustomConstructorInfoImpl -***********************************************************************/ - - namespace internal_helper - { - extern void UnboxSpecifiedParameter(MethodInfoImpl* methodInfo, collections::Array& arguments, vint index); - - template - void UnboxSpecifiedParameter(MethodInfoImpl* methodInfo, collections::Array& arguments, vint index, T0& p0, TArgs& ...args) - { - UnboxParameter(arguments[index], p0, methodInfo->GetParameter(index)->GetType()->GetTypeDescriptor(), itow(index) + L"-th argument"); - UnboxSpecifiedParameter(methodInfo, arguments, index + 1, args...); - } - - template - struct BoxedConstructorInvoker - { - static Value Invoke(MethodInfoImpl* methodInfo, collections::Array& arguments, std::remove_cvref_t&& ...args) - { - UnboxSpecifiedParameter(methodInfo, arguments, 0, args...); - R result = new typename TypeInfoRetriver::Type(args...); - return BoxParameter(result); - } - }; - - template - struct ConstructorArgumentAdder - { - static void Add(MethodInfoImpl* methodInfo, const wchar_t* parameterNames[], vint index) - { - } - }; - - template - struct ConstructorArgumentAdder> - { - static void Add(MethodInfoImpl* methodInfo, const wchar_t* parameterNames[], vint index) - { - methodInfo->AddParameter(new ParameterInfoImpl(methodInfo, parameterNames[index], TypeInfoRetriver::CreateTypeInfo())); - ConstructorArgumentAdder>::Add(methodInfo, parameterNames, index + 1); - } - }; - } - - template - class CustomConstructorInfoImpl : public MethodInfoImpl - { - protected: - Value InvokeInternal(const Value& thisObject, collections::Array& arguments)override - { - return internal_helper::BoxedConstructorInvoker::Invoke(this, arguments, std::remove_cvref_t()...); - } - - Value CreateFunctionProxyInternal(const Value& thisObject)override - { - Func proxy( - LAMBDA([](TArgs ...args)->R - { - R result = new typename TypeInfoRetriver::Type(args...); - return result; - }) - ); - return BoxParameter(proxy); - } - public: - CustomConstructorInfoImpl(const wchar_t* parameterNames[]) - :MethodInfoImpl(0, TypeInfoRetriver::CreateTypeInfo(), true) - { - internal_helper::ConstructorArgumentAdder>::Add(this, parameterNames, 0); - } - - IMethodInfo::ICpp* GetCpp()override - { - return nullptr; - } - }; - -/*********************************************************************** -CustomMethodInfoImpl -CustomStaticMethodInfoImpl -***********************************************************************/ - - namespace internal_helper - { - template - struct BoxedMethodInvoker - { - static Value Invoke(TClass* object, R(__thiscall TClass::* method)(TArgs...), MethodInfoImpl* methodInfo, collections::Array& arguments, std::remove_cvref_t&& ...args) - { - UnboxSpecifiedParameter(methodInfo, arguments, 0, args...); - R result = (object->*method)(args...); - return BoxParameter(result, methodInfo->GetReturn()->GetTypeDescriptor()); - } - }; - - template - struct BoxedMethodInvoker - { - static Value Invoke(TClass* object, void(__thiscall TClass::* method)(TArgs...), MethodInfoImpl* methodInfo, collections::Array& arguments, std::remove_cvref_t&& ...args) - { - UnboxSpecifiedParameter(methodInfo, arguments, 0, args...); - (object->*method)(args...); - return Value(); - } - }; - - template - struct BoxedExternalMethodInvoker - { - static Value Invoke(TClass* object, R(*method)(TClass*, TArgs...), MethodInfoImpl* methodInfo, collections::Array& arguments, std::remove_cvref_t&& ...args) - { - UnboxSpecifiedParameter(methodInfo, arguments, 0, args...); - R result = method(object, args...); - return BoxParameter(result, methodInfo->GetReturn()->GetTypeDescriptor()); - } - }; - - template - struct BoxedExternalMethodInvoker - { - static Value Invoke(TClass* object, void(*method)(TClass*, TArgs...), MethodInfoImpl* methodInfo, collections::Array& arguments, std::remove_cvref_t&& ...args) - { - UnboxSpecifiedParameter(methodInfo, arguments, 0, args...); - method(object, args...); - return Value(); - } - }; - } - class MethodInfoImpl_StaticCpp : public MethodInfoImpl, private IMethodInfo::ICpp - { - private: - WString invokeTemplate; - WString closureTemplate; - - const WString& GetInvokeTemplate()override - { - return invokeTemplate; - } - - const WString& GetClosureTemplate()override - { - return closureTemplate; - } - public: - MethodInfoImpl_StaticCpp(IMethodGroupInfo* _ownerMethodGroup, Ptr _return, bool _isStatic, const wchar_t* _invokeTemplate, const wchar_t* _closureTemplate) - :MethodInfoImpl(_ownerMethodGroup, _return, _isStatic) - { - CHECK_ERROR((_invokeTemplate == nullptr) == (_closureTemplate == nullptr), L"MethodInfoImpl_StaticCpp::MethodInfoImpl_StaticCpp()#Templates should all be set or default at the same time."); - if (_invokeTemplate) - { - invokeTemplate = WString::Unmanaged(_invokeTemplate); - } - if (_closureTemplate) - { - closureTemplate = WString::Unmanaged(_closureTemplate); - } - } - - IMethodInfo::ICpp* GetCpp()override - { - return invokeTemplate.Length() == 0 || closureTemplate.Length() == 0 ? nullptr : this; - } - }; - - template - class CustomMethodInfoImpl : public MethodInfoImpl_StaticCpp - { - protected: - R(__thiscall TClass::* method)(TArgs...); - - Value InvokeInternal(const Value& thisObject, collections::Array& arguments)override - { - TClass* object=UnboxValue(thisObject, GetOwnerTypeDescriptor(), L"thisObject"); - return internal_helper::BoxedMethodInvoker::Invoke(object, method, this, arguments, std::remove_cvref_t()...); - } - - Value CreateFunctionProxyInternal(const Value& thisObject)override - { - TClass* object=UnboxValue(thisObject, GetOwnerTypeDescriptor(), L"thisObject"); - Func proxy(object, method); - return BoxParameter(proxy); - } - public: - CustomMethodInfoImpl(const wchar_t* parameterNames[], R(__thiscall TClass::* _method)(TArgs...), const wchar_t* _invokeTemplate, const wchar_t* _closureTemplate) - :MethodInfoImpl_StaticCpp(0, TypeInfoRetriver::CreateTypeInfo(), false, _invokeTemplate, _closureTemplate) - ,method(_method) - { - internal_helper::ConstructorArgumentAdder>::Add(this, parameterNames, 0); - } - }; - - template - class CustomExternalMethodInfoImpl : public MethodInfoImpl_StaticCpp - { - protected: - R(*method)(TClass*, TArgs...); - - Value InvokeInternal(const Value& thisObject, collections::Array& arguments)override - { - TClass* object=UnboxValue(thisObject, GetOwnerTypeDescriptor(), L"thisObject"); - return internal_helper::BoxedExternalMethodInvoker::Invoke(object, method, this, arguments, std::remove_cvref_t()...); - } - - Value CreateFunctionProxyInternal(const Value& thisObject)override - { - TClass* object=UnboxValue(thisObject, GetOwnerTypeDescriptor(), L"thisObject"); - Func proxy = Curry(Func(method))(object); - return BoxParameter(proxy); - } - public: - CustomExternalMethodInfoImpl(const wchar_t* parameterNames[], R(*_method)(TClass*, TArgs...), const wchar_t* _invokeTemplate, const wchar_t* _closureTemplate) - :MethodInfoImpl_StaticCpp(0, TypeInfoRetriver::CreateTypeInfo(), false, _invokeTemplate, _closureTemplate) - ,method(_method) - { - internal_helper::ConstructorArgumentAdder>::Add(this, parameterNames, 0); - } - }; - -/*********************************************************************** -CustomStaticMethodInfoImpl -***********************************************************************/ - - namespace internal_helper - { - template - struct BoxedStaticMethodInvoker - { - static Value Invoke(R(* method)(TArgs...), MethodInfoImpl* methodInfo, collections::Array& arguments, std::remove_cvref_t&& ...args) - { - UnboxSpecifiedParameter(methodInfo, arguments, 0, args...); - R result = method(args...); - return BoxParameter(result, methodInfo->GetReturn()->GetTypeDescriptor()); - } - }; - - template - struct BoxedStaticMethodInvoker - { - static Value Invoke(void(* method)(TArgs...), MethodInfoImpl* methodInfo, collections::Array& arguments, std::remove_cvref_t&& ...args) - { - UnboxSpecifiedParameter(methodInfo, arguments, 0, args...); - method(args...); - return Value(); - } - }; - } - - template - class CustomStaticMethodInfoImpl : public MethodInfoImpl_StaticCpp - { - protected: - R(* method)(TArgs...); - - Value InvokeInternal(const Value& thisObject, collections::Array& arguments)override - { - return internal_helper::BoxedStaticMethodInvoker::Invoke(method, this, arguments, std::remove_cvref_t()...); - } - - Value CreateFunctionProxyInternal(const Value& thisObject)override - { - Func proxy(method); - return BoxParameter(proxy); - } - public: - CustomStaticMethodInfoImpl(const wchar_t* parameterNames[], R(* _method)(TArgs...), const wchar_t* _invokeTemplate, const wchar_t* _closureTemplate) - :MethodInfoImpl_StaticCpp(0, TypeInfoRetriver::CreateTypeInfo(), true, _invokeTemplate, _closureTemplate) - ,method(_method) - { - internal_helper::ConstructorArgumentAdder>::Add(this, parameterNames, 0); - } - }; - -/*********************************************************************** -CustomEventInfoImpl -***********************************************************************/ - - namespace internal_helper - { - template - struct BoxedEventInvoker - { - static void Invoke(Event& eventObject, Ptr arguments, std::remove_cvref_t&& ...args) - { - UnboxSpecifiedParameter(arguments, 0, args...); - eventObject(args...); - } - }; - } - - template - class CustomEventInfoImpl : public EventInfoImpl - { - protected: - Event TClass::* eventRef; - - Ptr AttachInternal(DescriptableObject* thisObject, Ptr handler)override - { - TClass* object = UnboxValue(Value::From(thisObject), GetOwnerTypeDescriptor(), L"thisObject"); - Event& eventObject = object->*eventRef; - auto func = Func([=](TArgs ...args) - { - auto arguments = IValueList::Create(); - internal_helper::AddValueToList(arguments, std::forward(args)...); - handler->Invoke(arguments); - }); - return EventHelper::Attach(eventObject, func); - } - - bool DetachInternal(DescriptableObject* thisObject, Ptr handler)override - { - TClass* object = UnboxValue(Value::From(thisObject), GetOwnerTypeDescriptor(), L"thisObject"); - Event& eventObject = object->*eventRef; - return EventHelper::Detach(eventObject, handler); - } - - void InvokeInternal(DescriptableObject* thisObject, Ptr arguments)override - { - TClass* object = UnboxValue(Value::From(thisObject), GetOwnerTypeDescriptor(), L"thisObject"); - Event& eventObject = object->*eventRef; - internal_helper::BoxedEventInvoker::Invoke(eventObject, arguments, typename std::remove_cvref_t()...); - } - - Ptr GetHandlerTypeInternal()override - { - return TypeInfoRetriver>::CreateTypeInfo(); - } - public: - CustomEventInfoImpl(ITypeDescriptor* _ownerTypeDescriptor, const WString& _name, Event TClass::* _eventRef) - :EventInfoImpl(_ownerTypeDescriptor, _name) - , eventRef(_eventRef) - { - } - - ~CustomEventInfoImpl() - { - } - - IEventInfo::ICpp* GetCpp()override - { - return nullptr; - } - }; - - template - struct CustomEventFunctionTypeRetriver - { - typedef vint Type; - }; - - template - struct CustomEventFunctionTypeRetriver TClass::*> - { - typedef TEvent Type; - }; -#endif - } - } -} - -#endif - -/*********************************************************************** -.\GUITYPEDESCRIPTORBUILDER_STRUCT.H -***********************************************************************/ -/*/*********************************************************************** -Author: Zihan Chen (vczh) -Licensed under https://github.com/vczh-libraries/License -***********************************************************************/ - -#ifndef VCZH_REFLECTION_GUITYPEDESCRIPTORBUILDER_STRUCT -#define VCZH_REFLECTION_GUITYPEDESCRIPTORBUILDER_STRUCT - - -namespace vl -{ - namespace reflection - { - namespace description - { - -/*********************************************************************** -DetailTypeInfoRetriver -***********************************************************************/ - - template - struct DetailTypeInfoRetriver - { - static const ITypeInfo::Decorator Decorator=ITypeInfo::TypeDescriptor; - typedef T Type; - typedef T TempValueType; - typedef T& ResultReferenceType; - typedef T ResultNonReferenceType; - -#ifndef VCZH_DEBUG_NO_REFLECTION - static Ptr CreateTypeInfo(TypeInfoHint hint) - { - return MakePtr(GetTypeDescriptor(), hint); - } -#endif - }; - - template - struct DetailTypeInfoRetriver - { - typedef DetailTypeInfoRetriver UpLevelRetriver; - - static const ITypeInfo::Decorator Decorator=UpLevelRetriver::Decorator; - typedef typename UpLevelRetriver::Type Type; - typedef T TempValueType; - typedef const T& ResultReferenceType; - typedef const T ResultNonReferenceType; - -#ifndef VCZH_DEBUG_NO_REFLECTION - static Ptr CreateTypeInfo(TypeInfoHint hint) - { - return TypeInfoRetriver::CreateTypeInfo(); - } -#endif - }; - - template - struct DetailTypeInfoRetriver - { - typedef DetailTypeInfoRetriver UpLevelRetriver; - - static const ITypeInfo::Decorator Decorator=UpLevelRetriver::Decorator; - typedef typename UpLevelRetriver::Type Type; - typedef T TempValueType; - typedef T& ResultReferenceType; - typedef T ResultNonReferenceType; - -#ifndef VCZH_DEBUG_NO_REFLECTION - static Ptr CreateTypeInfo(TypeInfoHint hint) - { - return TypeInfoRetriver::CreateTypeInfo(); - } -#endif - }; - - template - struct DetailTypeInfoRetriver - { - typedef DetailTypeInfoRetriver UpLevelRetriver; - - static const ITypeInfo::Decorator Decorator=ITypeInfo::RawPtr; - typedef typename UpLevelRetriver::Type Type; - typedef T* TempValueType; - typedef T*& ResultReferenceType; - typedef T* ResultNonReferenceType; - -#ifndef VCZH_DEBUG_NO_REFLECTION - static Ptr CreateTypeInfo(TypeInfoHint hint) - { - return MakePtr(TypeInfoRetriver::CreateTypeInfo()); - } -#endif - }; - - template - struct DetailTypeInfoRetriver, TypeFlags::NonGenericType> - { - typedef DetailTypeInfoRetriver UpLevelRetriver; - - static const ITypeInfo::Decorator Decorator=ITypeInfo::SharedPtr; - typedef typename UpLevelRetriver::Type Type; - typedef Ptr TempValueType; - typedef Ptr& ResultReferenceType; - typedef Ptr ResultNonReferenceType; - -#ifndef VCZH_DEBUG_NO_REFLECTION - static Ptr CreateTypeInfo(TypeInfoHint hint) - { - return MakePtr(TypeInfoRetriver::CreateTypeInfo()); - } -#endif - }; - - template - struct DetailTypeInfoRetriver, TypeFlags::NonGenericType> - { - typedef DetailTypeInfoRetriver UpLevelRetriver; - - static const ITypeInfo::Decorator Decorator=ITypeInfo::Nullable; - typedef typename UpLevelRetriver::Type Type; - typedef Nullable TempValueType; - typedef Nullable& ResultReferenceType; - typedef Nullable ResultNonReferenceType; - -#ifndef VCZH_DEBUG_NO_REFLECTION - static Ptr CreateTypeInfo(TypeInfoHint hint) - { - return MakePtr(TypeInfoRetriver::CreateTypeInfo()); - } -#endif - }; - - template - struct DetailTypeInfoRetriver - { - typedef DetailTypeInfoRetriver UpLevelRetriver; - - static const ITypeInfo::Decorator Decorator=UpLevelRetriver::Decorator; - typedef typename UpLevelRetriver::Type Type; - typedef typename UpLevelRetriver::TempValueType TempValueType; - typedef T& ResultReferenceType; - typedef T ResultNonReferenceType; - -#ifndef VCZH_DEBUG_NO_REFLECTION - static Ptr CreateTypeInfo(TypeInfoHint hint) - { - return TypeInfoRetriver::CreateTypeInfo(); - } -#endif - }; - - template<> - struct TypeInfoRetriver : public TypeInfoRetriver - { - }; - -/*********************************************************************** -ParameterAccessor -***********************************************************************/ - - template - struct ParameterAccessor - { - static Value BoxParameter(const T& object, ITypeDescriptor* typeDescriptor) - { - return BoxValue(object, typeDescriptor); - } - - static void UnboxParameter(const Value& value, T& result, ITypeDescriptor* typeDescriptor, const WString& valueName) - { - result=UnboxValue(value, typeDescriptor, valueName); - } - }; - template struct ValueAccessor { @@ -5738,13 +5145,13 @@ ParameterAccessor { static Value BoxValue(const T& object, ITypeDescriptor* typeDescriptor) { + using Type = std::remove_cvref_t; #ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA if(!typeDescriptor) { - typeDescriptor = GetTypeDescriptor::Type>(); + typeDescriptor = GetTypeDescriptor(); } #endif - using Type = std::remove_cvref_t; return Value::From(new IValueType::TypedBox(object), typeDescriptor); } @@ -5760,7 +5167,7 @@ ParameterAccessor #ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA if (!typeDescriptor) { - typeDescriptor = GetTypeDescriptor::Type>(); + typeDescriptor = GetTypeDescriptor(); } throw ArgumentTypeMismtatchException(valueName, typeDescriptor, Value::BoxedValue, value); #else @@ -5803,16 +5210,369 @@ ParameterAccessor #endif + /*********************************************************************** -.\GUITYPEDESCRIPTORWRAPPERS.H +.\BOXING\BOXINGPARAMETER.H +***********************************************************************/ +/*********************************************************************** +Author: Zihan Chen (vczh) +Licensed under https://github.com/vczh-libraries/License +***********************************************************************/ + +#ifndef VCZH_REFLECTION_BOXING_BOXINGPARAMETER +#define VCZH_REFLECTION_BOXING_BOXINGPARAMETER + + +namespace vl +{ + namespace reflection + { + namespace description + { +/*********************************************************************** +BoxParameter, UnboxParameter +***********************************************************************/ + + template + struct ParameterAccessor + { + }; + + /// Box an reflectable object. It supports generic types such as containers, functions (should be Func<T>), etc. + /// The boxed value. + /// Type of the object. + /// The object to box. + /// The type descriptor of the object (optional). + template + Value BoxParameter(T&& object, ITypeDescriptor* typeDescriptor = nullptr) + { + using TIR = TypeInfoRetriver>; + return ParameterAccessor, TIR::TypeFlag>::BoxParameter(object, typeDescriptor); + } + + /// + /// A reference holder to an unboxed object. + /// + /// The type of the unboxed object. + template + struct Unboxed + { + private: + T* object; + bool owned; + + public: + Unboxed(T* _object, bool _owned) : object(_object), owned(_owned) {} + Unboxed(Unboxed&& unboxed) : object(unboxed.object), owned(unboxed.owned) { unboxed.object = nullptr; } + ~Unboxed() { if (object && owned) { delete object; } } + + Unboxed() = delete; + Unboxed(const Unboxed&&) = delete; + Unboxed& operator=(const Unboxed&) = delete; + Unboxed& operator=(Unboxed&&) = delete; + + /// + /// Get the reference of the unboxed object. + /// It is recommended only to use this reference when the is still alive. + /// + /// The unboxed object. + T& Ref() const { CHECK_ERROR(object, L"vl::reflection::description::Unboxed::Ref()#The object has been moved away."); return *object; } + + /// + /// Test if the unboxed object is owned. + /// + /// + bool IsOwned() const + { + return owned; + } + }; + + /// Box an reflectable object. It supports generic types such as containers, functions (should be Func<T>), etc. + /// Type of the object. + /// The unboxed object. It could be the same object that is boxed, or it could be a new object. + /// The value to unbox. + /// The type descriptor of the object (optional). + /// The name of the object to provide a friendly exception message if the conversion is failed (optional). + template + Unboxed UnboxParameter(const Value& value, ITypeDescriptor* typeDescriptor = nullptr, const WString& valueName = WString::Unmanaged(L"value")) + { + using TIR = TypeInfoRetriver>; + return ParameterAccessor::UnboxParameter(value, typeDescriptor, valueName); + } + +/*********************************************************************** +BoxParametersToList +***********************************************************************/ + + inline void BoxParametersToList(Ptr arguments) {} + + template + void BoxParametersToList(Ptr arguments, T0&& p0, TArgs&& ...args) + { + arguments->Add(description::BoxParameter(p0)); + BoxParametersToList(arguments, args...); + } + + class Value_xs + { + protected: + collections::Array arguments; + public: + Value_xs() + { + } + + template + Value_xs& operator,(T& value) + { + arguments.Resize(arguments.Count() + 1); + arguments[arguments.Count() - 1] = BoxParameter(value); + return *this; + } + + Value_xs& operator,(const Value& value) + { + arguments.Resize(arguments.Count() + 1); + arguments[arguments.Count() - 1] = value; + return *this; + } + + operator collections::Array& () + { + return arguments; + } + }; + +/*********************************************************************** +Basic Types +***********************************************************************/ + + template + struct ParameterAccessor + { + static Value BoxParameter(const T& object, ITypeDescriptor* typeDescriptor) + { + return BoxValue(object, typeDescriptor); + } + + static Unboxed UnboxParameter(const Value& value, ITypeDescriptor* typeDescriptor, const WString& valueName) + { + return { new T(std::move(UnboxValue(value, typeDescriptor, valueName))), true }; + } + }; + } + } +} + +#endif + + +/*********************************************************************** +.\BOXING\INVOKEWITHBOXEDPARAMETERS.H ***********************************************************************/ /*********************************************************************** Author: Zihan Chen (vczh) Licensed under https://github.com/vczh-libraries/License ***********************************************************************/ -#ifndef VCZH_REFLECTION_GUITYPEDESCRIPTORBUILDER_WRAPPERS -#define VCZH_REFLECTION_GUITYPEDESCRIPTORBUILDER_WRAPPERS +#ifndef VCZH_REFLECTION_BOXING_INVOKEWITHBOXEDPARAMETERS +#define VCZH_REFLECTION_BOXING_INVOKEWITHBOXEDPARAMETERS + + +namespace vl +{ + namespace reflection + { + namespace description + { +/*********************************************************************** +UnboxAndCall +***********************************************************************/ + + namespace unboxcall_helper + { + template + struct ArgPack + { + using TArg = T; + static const vint Index = I; + }; + + template + struct ArgPacks + { + }; + + template + struct MakeArgPacks_; + + template + struct MakeArgPacks_> + { + using Type = ArgPacks; + }; + + template + struct MakeArgPacks_, T0, TArgs...> + { + using Type = typename MakeArgPacks_>, TArgs...>::Type; + }; + } + + template + using MakeArgPacks = typename unboxcall_helper::MakeArgPacks_, TArgs...>::Type; + + namespace unboxcall_helper + { + template + struct Unbox; + + template + struct Unbox> + { + template + static auto AndCallObject(TFunction&& function, IMethodInfo* methodInfo, const Ptr& arguments) -> decltype(function(std::declval()...)) + { + // function(arguments) + return function(UnboxParameter>( + arguments->Get(TArgPacks::Index), + (methodInfo ? methodInfo->GetParameter(TArgPacks::Index)->GetType()->GetTypeDescriptor() : nullptr) + ).Ref()...); + } + + template + static auto AndCallFunction(TFunction function, IMethodInfo* methodInfo, collections::Array& arguments) -> decltype(function(std::declval()...)) + { + // function(arguments) + return function(UnboxParameter>( + arguments[TArgPacks::Index], + (methodInfo ? methodInfo->GetParameter(TArgPacks::Index)->GetType()->GetTypeDescriptor() : nullptr) + ).Ref()...); + } + + template + static auto AndCallMethod(TFunction function, IMethodInfo* methodInfo, collections::Array& arguments, TClass* object) -> decltype((object->*function)(std::declval()...)) + { + // (object->*function)(arguments) + return (object->*function)(UnboxParameter>( + arguments[TArgPacks::Index], + (methodInfo ? methodInfo->GetParameter(TArgPacks::Index)->GetType()->GetTypeDescriptor() : nullptr) + ).Ref()...); + } + + template + static auto AndCallExternal(TFunction function, IMethodInfo* methodInfo, collections::Array& arguments, TClass* object) -> decltype(function(object, std::declval()...)) + { + // function(object, arguments) + return function( + object, + UnboxParameter>( + arguments[TArgPacks::Index], + (methodInfo ? methodInfo->GetParameter(TArgPacks::Index)->GetType()->GetTypeDescriptor() : nullptr) + ).Ref()... + ); + } + + template + static R AndNew(IMethodInfo* methodInfo, collections::Array& arguments) + { + // new TClass(arguments) + return R(new TClass(UnboxParameter>( + arguments[TArgPacks::Index], + (methodInfo ? methodInfo->GetParameter(TArgPacks::Index)->GetType()->GetTypeDescriptor() : nullptr) + ).Ref()...)); + } + }; + } + +/*********************************************************************** +Invoke +***********************************************************************/ + + namespace invoke_helper + { + template + Value InvokeMethod(TClass* object, R(__thiscall TClass::* method)(TArgs...), IMethodInfo* methodInfo, collections::Array& arguments) + { + using TArgPacks = MakeArgPacks; + if constexpr (std::is_same_v) + { + unboxcall_helper::Unbox::AndCallMethod(method, methodInfo, arguments, object); + return {}; + } + else + { + auto td = methodInfo ? methodInfo->GetReturn()->GetTypeDescriptor() : nullptr; + return BoxParameter(unboxcall_helper::Unbox::AndCallMethod(method, methodInfo, arguments, object), td); + } + } + + template + Value InvokeExternal(TClass* object, R(*method)(TClass*, TArgs...), IMethodInfo* methodInfo, collections::Array& arguments) + { + using TArgPacks = MakeArgPacks; + if constexpr (std::is_same_v) + { + unboxcall_helper::Unbox::AndCallExternal(method, methodInfo, arguments, object); + return {}; + } + else + { + auto td = methodInfo ? methodInfo->GetReturn()->GetTypeDescriptor() : nullptr; + return BoxParameter(unboxcall_helper::Unbox::AndCallExternal(method, methodInfo, arguments, object), td); + } + } + + template + Value InvokeFunction(R(*method)(TArgs...), IMethodInfo* methodInfo, collections::Array& arguments) + { + using TArgPacks = MakeArgPacks; + if constexpr (std::is_same_v) + { + unboxcall_helper::Unbox::AndCallFunction(method, methodInfo, arguments); + return {}; + } + else + { + auto td = methodInfo ? methodInfo->GetReturn()->GetTypeDescriptor() : nullptr; + return BoxParameter(unboxcall_helper::Unbox::AndCallFunction(method, methodInfo, arguments), td); + } + } + + template + Value InvokeObject(TFunction& function, IMethodInfo* methodInfo, const Ptr& arguments) + { + using TArgPacks = MakeArgPacks; + using TResult = decltype(unboxcall_helper::Unbox::AndCallObject(function, methodInfo, arguments)); + if constexpr (std::is_same_v) + { + unboxcall_helper::Unbox::AndCallObject(function, methodInfo, arguments); + return {}; + } + else + { + auto td = methodInfo ? methodInfo->GetReturn()->GetTypeDescriptor() : nullptr; + return BoxParameter(unboxcall_helper::Unbox::AndCallObject(function, methodInfo, arguments), td); + } + } + } + } + } +} + +#endif + +/*********************************************************************** +.\WRAPPERS\CONTAINERWRAPPERS.H +***********************************************************************/ +/*********************************************************************** +Author: Zihan Chen (vczh) +Licensed under https://github.com/vczh-libraries/License +***********************************************************************/ + +#ifndef VCZH_REFLECTION_WRAPPERS_CONTAINERWRAPPERS +#define VCZH_REFLECTION_WRAPPERS_CONTAINERWRAPPERS namespace vl @@ -6314,30 +6074,9 @@ Collection Wrappers #pragma warning(pop) } } -} -#endif - -/*********************************************************************** -.\GUITYPEDESCRIPTORBUILDER_CONTAINER.H -***********************************************************************/ -/*********************************************************************** -Author: Zihan Chen (vczh) -Licensed under https://github.com/vczh-libraries/License -***********************************************************************/ - -#ifndef VCZH_REFLECTION_GUITYPEDESCRIPTORBUILDER_CONTAINER -#define VCZH_REFLECTION_GUITYPEDESCRIPTORBUILDER_CONTAINER - - -namespace vl -{ namespace collections { -/*********************************************************************** -DetailTypeInfoRetriver -***********************************************************************/ - template void ObservableList::NotifyUpdateInternal(vint start, vint count, vint newCount) { @@ -6347,113 +6086,30 @@ DetailTypeInfoRetriver } } } +} +#endif + +/*********************************************************************** +.\BOXING\BOXINGPARAMETER_CONTAINERS.H +***********************************************************************/ +/*********************************************************************** +Author: Zihan Chen (vczh) +Licensed under https://github.com/vczh-libraries/License +***********************************************************************/ + +#ifndef VCZH_REFLECTION_BOXING_BOXINGPARAMETER_CONTAINERS +#define VCZH_REFLECTION_BOXING_BOXINGPARAMETER_CONTAINERS + + +namespace vl +{ namespace reflection { namespace description { - /*********************************************************************** -DetailTypeInfoRetriver -***********************************************************************/ - - template - struct DetailTypeInfoRetriver_Template1 - { - typedef DetailTypeInfoRetriver UpLevelRetriver; - - static const ITypeInfo::Decorator Decorator = UpLevelRetriver::Decorator; - typedef TCollectionType Type; - typedef typename UpLevelRetriver::TempValueType TempValueType; - typedef typename UpLevelRetriver::ResultReferenceType ResultReferenceType; - typedef typename UpLevelRetriver::ResultNonReferenceType ResultNonReferenceType; - -#ifndef VCZH_DEBUG_NO_REFLECTION - static Ptr CreateTypeInfo(TypeInfoHint hint) - { - typedef typename DetailTypeInfoRetriver::Type ContainerType; - typedef typename ContainerType::ElementType ElementType; - - auto arrayType = MakePtr(GetTypeDescriptor(), hint); - - auto genericType = MakePtr(arrayType); - genericType->AddGenericArgument(TypeInfoRetriver::CreateTypeInfo()); - - auto type = MakePtr(genericType); - return type; - } -#endif - }; - - template - struct DetailTypeInfoRetriver_Template2 - { - typedef DetailTypeInfoRetriver UpLevelRetriver; - - static const ITypeInfo::Decorator Decorator = UpLevelRetriver::Decorator; - typedef TCollectionType Type; - typedef typename UpLevelRetriver::TempValueType TempValueType; - typedef typename UpLevelRetriver::ResultReferenceType ResultReferenceType; - typedef typename UpLevelRetriver::ResultNonReferenceType ResultNonReferenceType; - -#ifndef VCZH_DEBUG_NO_REFLECTION - static Ptr CreateTypeInfo(TypeInfoHint hint) - { - typedef typename DetailTypeInfoRetriver::Type ContainerType; - typedef typename ContainerType::KeyContainer KeyContainer; - typedef typename ContainerType::ValueContainer ValueContainer; - typedef typename KeyContainer::ElementType KeyType; - typedef typename ValueContainer::ElementType ValueType; - - auto arrayType = MakePtr(GetTypeDescriptor(), hint); - - auto genericType = MakePtr(arrayType); - genericType->AddGenericArgument(TypeInfoRetriver::CreateTypeInfo()); - genericType->AddGenericArgument(TypeInfoRetriver::CreateTypeInfo()); - - auto type = MakePtr(genericType); - return type; - } -#endif - }; - - template - struct DetailTypeInfoRetriver : DetailTypeInfoRetriver_Template1 - { - }; - - template - struct DetailTypeInfoRetriver : DetailTypeInfoRetriver_Template1 - { - }; - - template - struct DetailTypeInfoRetriver : DetailTypeInfoRetriver_Template1 - { - }; - - template - struct DetailTypeInfoRetriver : DetailTypeInfoRetriver_Template1 - { - }; - - template - struct DetailTypeInfoRetriver : DetailTypeInfoRetriver_Template1 - { - }; - - template - struct DetailTypeInfoRetriver : DetailTypeInfoRetriver_Template2 - { - }; - - template - struct DetailTypeInfoRetriver : DetailTypeInfoRetriver_Template2 - { - }; - -/*********************************************************************** -ParameterAccessor +Containers ***********************************************************************/ template class TValueImpl, typename T> @@ -6541,6 +6197,27 @@ ParameterAccessor return BoxValue(result, td); } + template + Unboxed UnboxCollection(const Ptr& colref) + { + auto collection = new TCollection(); + auto lazyList = GetLazyList(colref); + collections::CopyFrom(*collection, lazyList); + return { collection, true }; + } + + template + Unboxed UnboxDictionary(const Ptr& colref) + { + auto collection = new TCollection(); + auto lazyList = GetLazyList< + typename TCollection::KeyContainer::ElementType, + typename TCollection::ValueContainer::ElementType + >(colref); + collections::CopyFrom(*collection, lazyList); + return { collection, true }; + } + template struct ParameterAccessor, TypeFlags::EnumerableType> { @@ -6570,11 +6247,11 @@ ParameterAccessor return ParameterAccessor, TypeFlags::EnumerableType>::BoxParameter(object, typeDescriptor); } - static void UnboxParameter(const Value& value, collections::LazyList& result, ITypeDescriptor* typeDescriptor, const WString& valueName) + static Unboxed> UnboxParameter(const Value& value, ITypeDescriptor* typeDescriptor, const WString& valueName) { typedef typename collections::LazyList::ElementType ElementType; Ptr listProxy = UnboxValue>(value, typeDescriptor, valueName); - result = GetLazyList(listProxy); + return { new collections::LazyList(std::move(GetLazyList(listProxy))), true }; } }; @@ -6586,12 +6263,9 @@ ParameterAccessor return GetValueFromEnumerable(object); } - static void UnboxParameter(const Value& value, T& result, ITypeDescriptor* typeDescriptor, const WString& valueName) + static Unboxed UnboxParameter(const Value& value, ITypeDescriptor* typeDescriptor, const WString& valueName) { - typedef typename T::ElementType ElementType; - Ptr listProxy = UnboxValue>(value, typeDescriptor, valueName); - collections::LazyList lazyList = GetLazyList(listProxy); - collections::CopyFrom(result, lazyList); + return UnboxCollection(UnboxValue>(value, typeDescriptor, valueName)); } }; @@ -6603,12 +6277,9 @@ ParameterAccessor return GetValueFromEnumerable(object); } - static void UnboxParameter(const Value& value, T& result, ITypeDescriptor* typeDescriptor, const WString& valueName) + static Unboxed UnboxParameter(const Value& value, ITypeDescriptor* typeDescriptor, const WString& valueName) { - typedef typename T::ElementType ElementType; - Ptr arrayProxy = UnboxValue>(value, typeDescriptor, valueName); - collections::LazyList lazyList = GetLazyList(arrayProxy); - collections::CopyFrom(result, lazyList); + return UnboxCollection(UnboxValue>(value, typeDescriptor, valueName)); } }; @@ -6620,12 +6291,9 @@ ParameterAccessor return GetValueFromEnumerable(object); } - static void UnboxParameter(const Value& value, T& result, ITypeDescriptor* typeDescriptor, const WString& valueName) + static Unboxed UnboxParameter(const Value& value, ITypeDescriptor* typeDescriptor, const WString& valueName) { - typedef typename T::ElementType ElementType; - Ptr listProxy = UnboxValue>(value, typeDescriptor, valueName); - collections::LazyList lazyList = GetLazyList(listProxy); - collections::CopyFrom(result, lazyList); + return UnboxCollection(UnboxValue>(value, typeDescriptor, valueName)); } }; @@ -6637,12 +6305,9 @@ ParameterAccessor return GetValueFromEnumerable(object); } - static void UnboxParameter(const Value& value, T& result, ITypeDescriptor* typeDescriptor, const WString& valueName) + static Unboxed UnboxParameter(const Value& value, ITypeDescriptor* typeDescriptor, const WString& valueName) { - typedef typename T::ElementType ElementType; - Ptr listProxy = UnboxValue>(value, typeDescriptor, valueName); - collections::LazyList lazyList = GetLazyList(listProxy); - collections::CopyFrom(result, lazyList); + return UnboxCollection(UnboxValue>(value, typeDescriptor, valueName)); } }; @@ -6654,16 +6319,9 @@ ParameterAccessor return GetValueFromEnumerable(object); } - static void UnboxParameter(const Value& value, T& result, ITypeDescriptor* typeDescriptor, const WString& valueName) + static Unboxed UnboxParameter(const Value& value, ITypeDescriptor* typeDescriptor, const WString& valueName) { - typedef typename T::KeyContainer KeyContainer; - typedef typename T::ValueContainer ValueContainer; - typedef typename KeyContainer::ElementType KeyType; - typedef typename ValueContainer::ElementType ValueType; - - Ptr dictionaryProxy = UnboxValue>(value, typeDescriptor, valueName); - collections::LazyList> lazyList = GetLazyList(dictionaryProxy); - collections::CopyFrom(result, lazyList); + return UnboxDictionary(UnboxValue>(value, typeDescriptor, valueName)); } }; @@ -6675,16 +6333,74 @@ ParameterAccessor return GetValueFromEnumerable(object); } - static void UnboxParameter(const Value& value, T& result, ITypeDescriptor* typeDescriptor, const WString& valueName) + static Unboxed UnboxParameter(const Value& value, ITypeDescriptor* typeDescriptor, const WString& valueName) { - typedef typename T::KeyContainer KeyContainer; - typedef typename T::ValueContainer ValueContainer; - typedef typename KeyContainer::ElementType KeyType; - typedef typename ValueContainer::ElementType ValueType; + return UnboxDictionary(UnboxValue>(value, typeDescriptor, valueName)); + } + }; + } + } +} - Ptr dictionaryProxy = UnboxValue>(value, typeDescriptor, valueName); - collections::LazyList> lazyList = GetLazyList(dictionaryProxy); - collections::CopyFrom(result, lazyList); +#endif + + +/*********************************************************************** +.\WRAPPERS\FUNCTIONWRAPPERS.H +***********************************************************************/ +/*********************************************************************** +Author: Zihan Chen (vczh) +Licensed under https://github.com/vczh-libraries/License +***********************************************************************/ + +#ifndef VCZH_REFLECTION_WRAPPERS_FUNCTIONWRAPPERS +#define VCZH_REFLECTION_WRAPPERS_FUNCTIONWRAPPERS + + +namespace vl +{ + namespace reflection + { + namespace description + { +/*********************************************************************** +Function Wrappers +***********************************************************************/ + + template + class ValueFunctionProxyWrapper + { + }; + + template + class ValueFunctionProxyWrapper : public Object, public virtual IValueFunctionProxy + { + typedef Func FunctionType; + protected: + FunctionType function; + + public: + ValueFunctionProxyWrapper(const FunctionType& _function) + :function(_function) + { + } + + FunctionType GetFunction() + { + return function; + } + + Value Invoke(Ptr arguments)override + { + if (!arguments || arguments->GetCount() != sizeof...(TArgs)) + { +#ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA + throw ArgumentCountMismtatchException(); +#else + CHECK_FAIL(L"Argument count mismatch."); +#endif + } + return invoke_helper::InvokeObject(function, nullptr, arguments); } }; } @@ -6694,15 +6410,512 @@ ParameterAccessor #endif /*********************************************************************** -.\GUITYPEDESCRIPTORMACROS.H +.\BOXING\BOXINGPARAMETER_FUNCTIONS.H ***********************************************************************/ /*********************************************************************** Author: Zihan Chen (vczh) Licensed under https://github.com/vczh-libraries/License ***********************************************************************/ -#ifndef VCZH_REFLECTION_GUITYPEDESCRIPTORMACROS -#define VCZH_REFLECTION_GUITYPEDESCRIPTORMACROS +#ifndef VCZH_REFLECTION_BOXING_BOXINGPARAMETER_FUNCTIONS +#define VCZH_REFLECTION_BOXING_BOXINGPARAMETER_FUNCTIONS + + +namespace vl +{ + namespace reflection + { + namespace description + { +/*********************************************************************** +Functions +***********************************************************************/ + + template + struct ParameterAccessor, TypeFlags::FunctionType> + { + static Value BoxParameter(const Func& object, ITypeDescriptor* typeDescriptor) + { + typedef R(RawFunctionType)(TArgs...); + Ptr result=new ValueFunctionProxyWrapper(object); + + ITypeDescriptor* td = nullptr; +#ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA + td = Description::GetAssociatedTypeDescriptor(); +#endif + return BoxValue>(result, td); + } + + static Unboxed> UnboxParameter(const Value& value, ITypeDescriptor* typeDescriptor, const WString& valueName) + { + typedef R(RawFunctionType)(TArgs...); + typedef Func FunctionType; + typedef ValueFunctionProxyWrapper ProxyType; + if (auto functionProxy = UnboxValue>(value, typeDescriptor, valueName)) + { + if (auto proxy = functionProxy.Cast()) + { + return { new FunctionType(std::move(proxy->GetFunction())), true }; + } + else + { + return { new FunctionType([functionProxy](TArgs ...args) + { + Ptr arguments = IValueList::Create(); + BoxParametersToList(arguments, std::forward(args)...); + auto result = functionProxy->Invoke(arguments); + if constexpr (!std::is_same_v) + { + auto unboxed = description::UnboxParameter>(result); + if (std::is_reference_v) + { + CHECK_ERROR(!unboxed.IsOwned(), L"It is impossible to return a reference from a unboxed value, when the unboxing has to call new T(...)."); + } + return unboxed.Ref(); + } + }), true }; + } + } + else + { + return { new FunctionType(),true }; + } + } + }; + + template + struct ParameterAccessor, TypeFlags::FunctionType> : ParameterAccessor, TypeFlags::FunctionType> + { + }; + } + } +} + +#endif + + +/*********************************************************************** +.\BOXING\BOXING.H +***********************************************************************/ +/*********************************************************************** +Author: Zihan Chen (vczh) +Licensed under https://github.com/vczh-libraries/License +***********************************************************************/ + +#ifndef VCZH_REFLECTION_BOXING_BOXING +#define VCZH_REFLECTION_BOXING_BOXING + + +#endif + + +/*********************************************************************** +.\METADATA\METADATA_MEMBER.H +***********************************************************************/ +/*********************************************************************** +Author: Zihan Chen (vczh) +Licensed under https://github.com/vczh-libraries/License +***********************************************************************/ + +#ifndef VCZH_REFLECTION_METADATA_METADATA_MEMBER +#define VCZH_REFLECTION_METADATA_METADATA_MEMBER + + +namespace vl +{ + namespace reflection + { + namespace description + { +/*********************************************************************** +ConstructorArgumentAdder +***********************************************************************/ + +#ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA + + namespace internal_helper + { + template + struct ConstructorArgumentAdder + { + static void Add(MethodInfoImpl* methodInfo, const wchar_t* parameterNames[], vint index) + { + } + }; + + template + struct ConstructorArgumentAdder> + { + static void Add(MethodInfoImpl* methodInfo, const wchar_t* parameterNames[], vint index) + { + methodInfo->AddParameter(new ParameterInfoImpl(methodInfo, parameterNames[index], TypeInfoRetriver::CreateTypeInfo())); + ConstructorArgumentAdder>::Add(methodInfo, parameterNames, index + 1); + } + }; + } + +/*********************************************************************** +MethodInfoImpl +***********************************************************************/ + + template + class CustomConstructorInfoImpl{}; + + template + class CustomMethodInfoImpl{}; + + template + class CustomExternalMethodInfoImpl{}; + + template + class CustomStaticMethodInfoImpl{}; + + template + class CustomEventInfoImpl{}; + +#endif + } + } +} + +#endif + + +/*********************************************************************** +.\METADATA\METADATA_EVENT.H +***********************************************************************/ +/*********************************************************************** +Author: Zihan Chen (vczh) +Licensed under https://github.com/vczh-libraries/License +***********************************************************************/ + +#ifndef VCZH_REFLECTION_METADATA_METADATA_EVENT +#define VCZH_REFLECTION_METADATA_METADATA_EVENT + + +namespace vl +{ + namespace reflection + { + namespace description + { + template + struct EventHelper + { + using Handler = const Func&; + + class EventHandlerImpl : public Object, public reflection::description::IEventHandler + { + public: + Ptr handler; + + EventHandlerImpl(Ptr _handler) + :handler(_handler) + { + } + + bool IsAttached()override + { + return handler->IsAttached(); + } + }; + + static Ptr Attach(Event& e, Handler handler) + { + return MakePtr(e.Add(handler)); + } + + static bool Detach(Event& e, Ptr handler) + { + auto impl = handler.Cast(); + if (!impl) return false; + return e.Remove(impl->handler); + } + + static Event& Invoke(Event& e) + { + return e; + } + }; + +#ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA + +/*********************************************************************** +CustomEventInfoImpl +***********************************************************************/ + + template + class CustomEventInfoImpl : public EventInfoImpl + { + protected: + Event TClass::* eventRef; + + Ptr AttachInternal(DescriptableObject* thisObject, Ptr handler)override + { + TClass* object = UnboxValue(Value::From(thisObject), GetOwnerTypeDescriptor(), L"thisObject"); + Event& eventObject = object->*eventRef; + auto func = Func([=](TArgs ...args) + { + auto arguments = IValueList::Create(); + BoxParametersToList(arguments, std::forward(args)...); + handler->Invoke(arguments); + }); + return EventHelper::Attach(eventObject, func); + } + + bool DetachInternal(DescriptableObject* thisObject, Ptr handler)override + { + TClass* object = UnboxValue(Value::From(thisObject), GetOwnerTypeDescriptor(), L"thisObject"); + Event& eventObject = object->*eventRef; + return EventHelper::Detach(eventObject, handler); + } + + void InvokeInternal(DescriptableObject* thisObject, Ptr arguments)override + { + TClass* object = UnboxValue(Value::From(thisObject), GetOwnerTypeDescriptor(), L"thisObject"); + Event& eventObject = object->*eventRef; + invoke_helper::InvokeObject, TArgs...>(eventObject, nullptr, arguments); + } + + Ptr GetHandlerTypeInternal()override + { + return TypeInfoRetriver>::CreateTypeInfo(); + } + public: + CustomEventInfoImpl(ITypeDescriptor* _ownerTypeDescriptor, const WString& _name, Event TClass::* _eventRef) + :EventInfoImpl(_ownerTypeDescriptor, _name) + , eventRef(_eventRef) + { + } + + ~CustomEventInfoImpl() + { + } + + IEventInfo::ICpp* GetCpp()override + { + return nullptr; + } + }; + + template + struct CustomEventFunctionTypeRetriver + { + typedef vint Type; + }; + + template + struct CustomEventFunctionTypeRetriver TClass::*> + { + typedef TEvent Type; + }; +#endif + } + } +} + +#endif + +/*********************************************************************** +.\METADATA\METADATA_FUNCTION.H +***********************************************************************/ +/*********************************************************************** +Author: Zihan Chen (vczh) +Licensed under https://github.com/vczh-libraries/License +***********************************************************************/ + +#ifndef VCZH_REFLECTION_METADATA_METADATA_FUNCTION +#define VCZH_REFLECTION_METADATA_METADATA_FUNCTION + + +namespace vl +{ + namespace reflection + { + namespace description + { + +#ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA + +/*********************************************************************** +CustomConstructorInfoImpl +***********************************************************************/ + + template + class CustomConstructorInfoImpl : public MethodInfoImpl + { + using TClass = typename trait_helper::RemovePtr>::Type; + protected: + + Value InvokeInternal(const Value& thisObject, collections::Array& arguments)override + { + return BoxParameter(unboxcall_helper::Unbox>::template AndNew(this, arguments)); + } + + Value CreateFunctionProxyInternal(const Value& thisObject)override + { + Func proxy( + LAMBDA([](TArgs ...args)->R + { + R result = new TClass(args...); + return result; + }) + ); + return BoxParameter(proxy); + } + public: + CustomConstructorInfoImpl(const wchar_t* parameterNames[]) + :MethodInfoImpl(0, TypeInfoRetriver::CreateTypeInfo(), true) + { + internal_helper::ConstructorArgumentAdder>::Add(this, parameterNames, 0); + } + + IMethodInfo::ICpp* GetCpp()override + { + return nullptr; + } + }; + +/*********************************************************************** +CustomMethodInfoImpl +CustomExternalMethodInfoImpl +***********************************************************************/ + + class MethodInfoImpl_StaticCpp : public MethodInfoImpl, private IMethodInfo::ICpp + { + private: + WString invokeTemplate; + WString closureTemplate; + + const WString& GetInvokeTemplate()override + { + return invokeTemplate; + } + + const WString& GetClosureTemplate()override + { + return closureTemplate; + } + public: + MethodInfoImpl_StaticCpp(IMethodGroupInfo* _ownerMethodGroup, Ptr _return, bool _isStatic, const wchar_t* _invokeTemplate, const wchar_t* _closureTemplate) + :MethodInfoImpl(_ownerMethodGroup, _return, _isStatic) + { + CHECK_ERROR((_invokeTemplate == nullptr) == (_closureTemplate == nullptr), L"MethodInfoImpl_StaticCpp::MethodInfoImpl_StaticCpp()#Templates should all be set or default at the same time."); + if (_invokeTemplate) + { + invokeTemplate = WString::Unmanaged(_invokeTemplate); + } + if (_closureTemplate) + { + closureTemplate = WString::Unmanaged(_closureTemplate); + } + } + + IMethodInfo::ICpp* GetCpp()override + { + return invokeTemplate.Length() == 0 || closureTemplate.Length() == 0 ? nullptr : this; + } + }; + + template + class CustomMethodInfoImpl : public MethodInfoImpl_StaticCpp + { + protected: + R(__thiscall TClass::* method)(TArgs...); + + Value InvokeInternal(const Value& thisObject, collections::Array& arguments)override + { + TClass* object = UnboxValue(thisObject, GetOwnerTypeDescriptor(), L"thisObject"); + return invoke_helper::InvokeMethod(object, method, this, arguments); + } + + Value CreateFunctionProxyInternal(const Value& thisObject)override + { + TClass* object = UnboxValue(thisObject, GetOwnerTypeDescriptor(), L"thisObject"); + Func proxy(object, method); + return BoxParameter(proxy); + } + public: + CustomMethodInfoImpl(const wchar_t* parameterNames[], R(__thiscall TClass::* _method)(TArgs...), const wchar_t* _invokeTemplate, const wchar_t* _closureTemplate) + :MethodInfoImpl_StaticCpp(0, TypeInfoRetriver::CreateTypeInfo(), false, _invokeTemplate, _closureTemplate) + , method(_method) + { + internal_helper::ConstructorArgumentAdder>::Add(this, parameterNames, 0); + } + }; + + template + class CustomExternalMethodInfoImpl : public MethodInfoImpl_StaticCpp + { + protected: + R(*method)(TClass*, TArgs...); + + Value InvokeInternal(const Value& thisObject, collections::Array& arguments)override + { + TClass* object = UnboxValue(thisObject, GetOwnerTypeDescriptor(), L"thisObject"); + return invoke_helper::InvokeExternal(object, method, this, arguments); + } + + Value CreateFunctionProxyInternal(const Value& thisObject)override + { + TClass* object = UnboxValue(thisObject, GetOwnerTypeDescriptor(), L"thisObject"); + Func proxy = Curry(Func(method))(object); + return BoxParameter(proxy); + } + public: + CustomExternalMethodInfoImpl(const wchar_t* parameterNames[], R(*_method)(TClass*, TArgs...), const wchar_t* _invokeTemplate, const wchar_t* _closureTemplate) + :MethodInfoImpl_StaticCpp(0, TypeInfoRetriver::CreateTypeInfo(), false, _invokeTemplate, _closureTemplate) + , method(_method) + { + internal_helper::ConstructorArgumentAdder>::Add(this, parameterNames, 0); + } + }; + +/*********************************************************************** +CustomStaticMethodInfoImpl +***********************************************************************/ + + template + class CustomStaticMethodInfoImpl : public MethodInfoImpl_StaticCpp + { + protected: + R(* method)(TArgs...); + + Value InvokeInternal(const Value& thisObject, collections::Array& arguments)override + { + return invoke_helper::InvokeFunction(method, this, arguments); + } + + Value CreateFunctionProxyInternal(const Value& thisObject)override + { + Func proxy(method); + return BoxParameter(proxy); + } + public: + CustomStaticMethodInfoImpl(const wchar_t* parameterNames[], R(* _method)(TArgs...), const wchar_t* _invokeTemplate, const wchar_t* _closureTemplate) + :MethodInfoImpl_StaticCpp(0, TypeInfoRetriver::CreateTypeInfo(), true, _invokeTemplate, _closureTemplate) + ,method(_method) + { + internal_helper::ConstructorArgumentAdder>::Add(this, parameterNames, 0); + } + }; +#endif + } + } +} + +#endif + +/*********************************************************************** +.\REFLECTION\MACROS.H +***********************************************************************/ +/*********************************************************************** +Author: Zihan Chen (vczh) +Licensed under https://github.com/vczh-libraries/License +***********************************************************************/ + +#ifndef VCZH_REFLECTION_REFLECTION_MACROS +#define VCZH_REFLECTION_REFLECTION_MACROS #ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA @@ -7270,15 +7483,15 @@ Property /*********************************************************************** -.\GUITYPEDESCRIPTORREFLECTION.H +.\REFLECTION\REFLECTION.H ***********************************************************************/ /*********************************************************************** Author: Zihan Chen (vczh) Licensed under https://github.com/vczh-libraries/License ***********************************************************************/ -#ifndef VCZH_REFLECTION_GUITYPEDESCRIPTORREFLECTION -#define VCZH_REFLECTION_GUITYPEDESCRIPTORREFLECTION +#ifndef VCZH_REFLECTION_REFLECTION_REFLECTION +#define VCZH_REFLECTION_REFLECTION_REFLECTION namespace vl @@ -7356,6 +7569,9 @@ Predefined Types #endif + template + struct TypedValueSerializerProvider; + #define DEFINE_TYPED_VALUE_SERIALIZER_PROVIDER(TYPENAME)\ template<>\ struct TypedValueSerializerProvider\ diff --git a/Import/VlppWorkflowCompiler.cpp b/Import/VlppWorkflowCompiler.cpp index 9efdccc1..9c443187 100644 --- a/Import/VlppWorkflowCompiler.cpp +++ b/Import/VlppWorkflowCompiler.cpp @@ -19117,20 +19117,13 @@ WfGenerateExpressionVisitor template void WriteInvokeTemplate(vint count, ITypeInfo* returnType, const TType& typeCallback, const TInvoke& invokeCallback, const TArgument& argumentCallback, TInfo* info, bool castReturnValue) { - if (Range(0, count).Any([&](vint index) {return IsCppRefGenericType(typeCallback(index)); })) + auto unboxedArgumentCallback = [&](vint index) { - writer.WriteString(L"[&]()->decltype(auto){"); - for (vint i = 0; i < count; i++) + auto type = typeCallback(index); + if (IsCppRefGenericType(type)) { - auto type = typeCallback(i); - if (IsCppRefGenericType(type)) + writer.WriteString(L"::vl::reflection::description::UnboxParameter<"); { - writer.WriteString(L" auto __vwsn_temp_x"); - writer.WriteString(itow(i)); - writer.WriteString(L" = ::vl::__vwsn::Box("); - argumentCallback(info, i); - writer.WriteString(L"); "); - switch (type->GetHint()) { case TypeInfoHint::Array: @@ -19157,38 +19150,24 @@ WfGenerateExpressionVisitor if (i > 0) writer.WriteString(L", "); writer.WriteString(config->ConvertType(type->GetElementType()->GetGenericArgument(i))); } - writer.WriteString(L"> __vwsn_temp_"); - writer.WriteString(itow(i)); - writer.WriteString(L"; ::vl::reflection::description::UnboxParameter(__vwsn_temp_x"); - writer.WriteString(itow(i)); - writer.WriteString(L", __vwsn_temp_"); - writer.WriteString(itow(i)); - writer.WriteString(L");"); - } - else - { - writer.WriteString(L" auto __vwsn_temp_"); - writer.WriteString(itow(i)); - writer.WriteString(L" = "); - argumentCallback(info, i); - writer.WriteString(L";"); } + writer.WriteString(L">>(::vl::__vwsn::Box("); + argumentCallback(info, index); + writer.WriteString(L")).Ref()"); } - writer.WriteString(L" return "); - WriteReturnValue(returnType, [&]() { invokeCallback(true); }, castReturnValue); - writer.WriteString(L"; }()"); - } - else - { - WriteReturnValue(returnType, [&]() { invokeCallback(false); }, castReturnValue); - } + else + { + argumentCallback(info, index); + } + }; + WriteReturnValue(returnType, [&]() { invokeCallback(unboxedArgumentCallback); }, castReturnValue); } template void WriteMethodTemplate(const WString& templateValue, IMethodInfo* methodInfo, const TThis& thisCallback, const TArgument& argumentCallback, bool castReturnValue) { WriteInvokeTemplate(methodInfo->GetParameterCount(), methodInfo->GetReturn(), [&](vint index) { return methodInfo->GetParameter(index)->GetType(); }, - [&](bool useTemporaryArgument) + [&](auto&& unboxedArgumentCallback) { WriteTemplate(templateValue, [&](const WString& item) { @@ -19251,15 +19230,7 @@ WfGenerateExpressionVisitor for (vint i = 0; i < count; i++) { if (i > 0) writer.WriteString(L", "); - if (useTemporaryArgument) - { - writer.WriteString(L"__vwsn_temp_"); - writer.WriteString(itow(i)); - } - else - { - argumentCallback(methodInfo, i); - } + unboxedArgumentCallback(i); } if (cp == CommaPosition::Right) writer.WriteString(L", "); } @@ -19300,7 +19271,7 @@ WfGenerateExpressionVisitor { auto handlerType = eventInfo->GetHandlerType()->GetElementType(); WriteInvokeTemplate(handlerType->GetGenericArgumentCount() - 1, handlerType->GetGenericArgument(0), [&](vint index) { return handlerType->GetGenericArgument(index + 1); }, - [&](bool useTemporaryArgument) + [&](auto&& unboxedArgumentCallback) { WriteTemplate(templateValue, [&](const WString& item) { @@ -19354,15 +19325,7 @@ WfGenerateExpressionVisitor for (vint i = 0; i < count; i++) { if (i > 0) writer.WriteString(L", "); - if (useTemporaryArgument) - { - writer.WriteString(L"__vwsn_temp_"); - writer.WriteString(itow(i)); - } - else - { - argumentCallback(eventInfo, i); - } + unboxedArgumentCallback(i); } if (cp == CommaPosition::Right) writer.WriteString(L", "); } diff --git a/Import/VlppWorkflowCompiler.h b/Import/VlppWorkflowCompiler.h index 669b0754..588ea15e 100644 --- a/Import/VlppWorkflowCompiler.h +++ b/Import/VlppWorkflowCompiler.h @@ -5,8 +5,8 @@ DEVELOPER: Zihan Chen(vczh) #include "VlppWorkflowLibrary.h" #include "VlppWorkflowRuntime.h" #include "VlppReflection.h" -#include "Vlpp.h" #include "VlppOS.h" +#include "Vlpp.h" #include "VlppRegex.h" #include "VlppParser.h" diff --git a/Import/VlppWorkflowLibrary.h b/Import/VlppWorkflowLibrary.h index 479017ca..47f85531 100644 --- a/Import/VlppWorkflowLibrary.h +++ b/Import/VlppWorkflowLibrary.h @@ -3,8 +3,8 @@ THIS FILE IS AUTOMATICALLY GENERATED. DO NOT MODIFY DEVELOPER: Zihan Chen(vczh) ***********************************************************************/ #include "VlppReflection.h" -#include "Vlpp.h" #include "VlppOS.h" +#include "Vlpp.h" #include "VlppRegex.h" /*********************************************************************** @@ -157,9 +157,12 @@ namespace vl template T Unbox(const reflection::description::Value& value) { - T result; - reflection::description::UnboxParameter(value, result); - return result; + auto unboxed = reflection::description::UnboxParameter>(value); + if (std::is_reference_v) + { + CHECK_ERROR(!unboxed.IsOwned(), L"It is impossible to return a reference from a unboxed value, when the unboxing has to call new T(...)."); + } + return unboxed.Ref(); } template @@ -227,18 +230,14 @@ namespace vl Ptr UnboxCollection(U&& value) { auto boxedValue = reflection::description::BoxParameter(value); - Ptr result; - reflection::description::UnboxParameter(boxedValue, result); - return result; + return reflection::description::UnboxParameter>(boxedValue).Ref(); } template Ptr UnboxCollection(const collections::LazyList& value) { auto boxedValue = reflection::description::BoxParameter(const_cast&>(value)); - Ptr result; - reflection::description::UnboxParameter(boxedValue, result); - return result; + return reflection::description::UnboxParameter>(boxedValue).Ref(); } struct CreateArray diff --git a/Import/VlppWorkflowRuntime.cpp b/Import/VlppWorkflowRuntime.cpp index a8249e40..a7bea6c8 100644 --- a/Import/VlppWorkflowRuntime.cpp +++ b/Import/VlppWorkflowRuntime.cpp @@ -2349,12 +2349,12 @@ WfRuntimeLambda { } - Value WfRuntimeLambda::Invoke(Ptr arguments) + Value WfRuntimeLambda::Invoke(Ptr arguments) { return Invoke(globalContext, capturedVariables, functionIndex, arguments); } - Value WfRuntimeLambda::Invoke(Ptr globalContext, Ptr capturedVariables, vint functionIndex, Ptr arguments) + Value WfRuntimeLambda::Invoke(Ptr globalContext, Ptr capturedVariables, vint functionIndex, Ptr arguments) { WfRuntimeThreadContext context(globalContext); vint count = arguments->GetCount(); @@ -2388,7 +2388,7 @@ WfRuntimeLambda WfRuntimeInterfaceInstance ***********************************************************************/ - Value WfRuntimeInterfaceInstance::Invoke(IMethodInfo* methodInfo, Ptr arguments) + Value WfRuntimeInterfaceInstance::Invoke(IMethodInfo* methodInfo, Ptr arguments) { vint index = functions.Keys().IndexOf(methodInfo); if (index == -1) @@ -4679,12 +4679,10 @@ WfMethodProxy { } - Value WfMethodProxy::Invoke(Ptr arguments) + Value WfMethodProxy::Invoke(Ptr arguments) { #ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA - Array values; - UnboxParameter(Value::From(arguments), values); - return methodInfo->Invoke(thisObject, values); + return methodInfo->Invoke(thisObject, UnboxParameter>(Value::From(arguments)).Ref()); #else CHECK_FAIL(L"Not Implemented under VCZH_DEBUG_METAONLY_REFLECTION!"); #endif @@ -4994,7 +4992,7 @@ WfEvent #endif } - void WfEvent::InvokeInternal(DescriptableObject* thisObject, Ptr arguments) + void WfEvent::InvokeInternal(DescriptableObject* thisObject, Ptr arguments) { #ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA auto record = GetEventRecord(thisObject, false); diff --git a/Import/VlppWorkflowRuntime.h b/Import/VlppWorkflowRuntime.h index 7b7b8f6e..f6c1443f 100644 --- a/Import/VlppWorkflowRuntime.h +++ b/Import/VlppWorkflowRuntime.h @@ -4,8 +4,8 @@ DEVELOPER: Zihan Chen(vczh) ***********************************************************************/ #include "VlppParser.h" #include "VlppReflection.h" -#include "Vlpp.h" #include "VlppOS.h" +#include "Vlpp.h" #include "VlppRegex.h" /*********************************************************************** @@ -385,7 +385,7 @@ Method class WfMethodProxy : public Object, public virtual reflection::description::IValueFunctionProxy { typedef reflection::description::IMethodInfo IMethodInfo; - typedef reflection::description::IValueList IValueList; + typedef reflection::description::IValueReadonlyList IValueReadonlyList; typedef reflection::description::Value Value; protected: Value thisObject; @@ -395,7 +395,7 @@ Method WfMethodProxy(const Value& _thisObject, IMethodInfo* _methodInfo); ~WfMethodProxy(); - Value Invoke(Ptr arguments)override; + Value Invoke(Ptr arguments)override; }; class WfMethodBase : public reflection::description::MethodInfoImpl @@ -495,7 +495,7 @@ Event typedef reflection::description::ITypeInfo ITypeInfo; typedef reflection::description::IEventHandler IEventHandler; typedef reflection::description::IValueFunctionProxy IValueFunctionProxy; - typedef reflection::description::IValueList IValueList; + typedef reflection::description::IValueReadonlyList IValueReadonlyList; typedef reflection::description::Value Value; class EventHandlerImpl : public Object, public IEventHandler @@ -528,7 +528,7 @@ Event Ptr GetEventRecord(DescriptableObject* thisObject, bool createIfNotExist); Ptr AttachInternal(DescriptableObject* thisObject, Ptr handler)override; bool DetachInternal(DescriptableObject* thisObject, Ptr handler)override; - void InvokeInternal(DescriptableObject* thisObject, Ptr arguments)override; + void InvokeInternal(DescriptableObject* thisObject, Ptr arguments)override; Ptr GetHandlerTypeInternal()override; public: WfEvent(ITypeDescriptor* ownerTypeDescriptor, const WString& name); @@ -1066,8 +1066,8 @@ Lambda WfRuntimeLambda(Ptr _globalContext, Ptr _capturedVariables, vint _functionIndex); - Value Invoke(Ptr arguments)override; - static Value Invoke(Ptr globalContext, Ptr capturedVariables, vint functionIndex, Ptr arguments); + Value Invoke(Ptr arguments)override; + static Value Invoke(Ptr globalContext, Ptr capturedVariables, vint functionIndex, Ptr arguments); }; /*********************************************************************** @@ -1079,14 +1079,14 @@ InterfaceInstance typedef reflection::description::Value Value; typedef reflection::description::IMethodInfo IMethodInfo; typedef reflection::description::IValueFunctionProxy IValueFunctionProxy; - typedef reflection::description::IValueList IValueList; + typedef reflection::description::IValueReadonlyList IValueReadonlyList; typedef collections::Dictionary FunctionMap; public: Ptr globalContext; Ptr capturedVariables; FunctionMap functions; - Value Invoke(IMethodInfo* methodInfo, Ptr arguments)override; + Value Invoke(IMethodInfo* methodInfo, Ptr arguments)override; }; } } @@ -1816,9 +1816,7 @@ Helper Functions Func LoadFunction(Ptr context, const WString& name) { auto proxy = LoadFunction(context, name); - Func function; - reflection::description::UnboxParameter(reflection::description::Value::From(proxy), function); - return function; + return reflection::description::UnboxParameter>(reflection::description::Value::From(proxy)).Ref(); } } } diff --git a/Tools/GacGen32.exe b/Tools/GacGen32.exe index ad277626..1cd78543 100644 Binary files a/Tools/GacGen32.exe and b/Tools/GacGen32.exe differ diff --git a/Tools/GacGen64.exe b/Tools/GacGen64.exe index 8f53707d..d249cf13 100644 Binary files a/Tools/GacGen64.exe and b/Tools/GacGen64.exe differ diff --git a/Tools/Reflection32.bin b/Tools/Reflection32.bin index 0aad7b2d..2ae85d07 100644 Binary files a/Tools/Reflection32.bin and b/Tools/Reflection32.bin differ diff --git a/Tools/Reflection64.bin b/Tools/Reflection64.bin index 28a045c0..bec8ea02 100644 Binary files a/Tools/Reflection64.bin and b/Tools/Reflection64.bin differ