/*********************************************************************** THIS FILE IS AUTOMATICALLY GENERATED. DO NOT MODIFY DEVELOPER: Zihan Chen(vczh) ***********************************************************************/ #include "Vlpp.h" /*********************************************************************** .\WFLIBRARYCPPHELPER.H ***********************************************************************/ /*********************************************************************** Vczh Library++ 3.0 Developer: Zihan Chen(vczh) Framework::Reflection Interfaces: ***********************************************************************/ #ifndef VCZH_WORKFLOW_LIBRARY_CPPLIBRARY #define VCZH_WORKFLOW_LIBRARY_CPPLIBRARY namespace vl { namespace __vwsn { template struct RunOnExit { T* function; RunOnExit(T* _function) :function(_function) { } ~RunOnExit() { function->operator()(); } }; template T* This(T* thisValue) { CHECK_ERROR(thisValue != nullptr, L"The this pointer cannot be null."); return thisValue; } template T* Ensure(T* pointer) { CHECK_ERROR(pointer != nullptr, L"The pointer cannot be null."); return pointer; } template Ptr& Ensure(Ptr& pointer) { CHECK_ERROR(pointer != nullptr, L"The pointer cannot be null."); return pointer; } template Ptr Ensure(Ptr&& pointer) { CHECK_ERROR(pointer != nullptr, L"The pointer cannot be null."); return MoveValue(pointer); } template Nullable Ensure(Nullable&& nullable) { CHECK_ERROR(nullable, L"The pointer cannot be null."); return MoveValue(nullable); } template Nullable& Ensure(Nullable& nullable) { CHECK_ERROR(nullable, L"The pointer cannot be null."); return nullable; } template WString ToString(const T& value) { using Type = typename RemoveCVR::Type; WString str; CHECK_ERROR(reflection::description::TypedValueSerializerProvider::Serialize(value, str), L"Failed to serialize."); return str; } template T Parse(const WString& str) { using Type = typename RemoveCVR::Type; T value; CHECK_ERROR(reflection::description::TypedValueSerializerProvider::Deserialize(str, value), L"Failed to serialize."); return value; } template struct NullableCastHelper { static Nullable Cast(Nullable nullable) { return Nullable(static_cast(nullable.Value())); } }; template struct NullableCastHelper { static Nullable Cast(Nullable nullable) { return Nullable(ToString(nullable.Value())); } }; template struct NullableCastHelper { static Nullable Cast(Nullable nullable) { return Nullable(Parse(nullable.Value())); } }; template Nullable NullableCast(Nullable nullable) { if (!nullable) return Nullable(); return NullableCastHelper::Cast(nullable); } template TTo* RawPtrCast(TFrom* pointer) { if (!pointer) return nullptr; return pointer->template SafeAggregationCast(); } template Ptr SharedPtrCast(TFrom* pointer) { if (!pointer) return nullptr; return pointer->template SafeAggregationCast(); } template reflection::description::Value Box(const T& value) { using Type = typename RemoveCVR::Type; return reflection::description::BoxParameter(const_cast(value)); } template T Unbox(const reflection::description::Value& value) { using Type = typename RemoveCVR::Type; T result; reflection::description::UnboxParameter(value, result); return result; } template struct UnboxWeakHelper { }; template struct UnboxWeakHelper { static T* Unbox(const reflection::description::Value& value) { if (value.IsNull()) return nullptr; return value.GetRawPtr()->SafeAggregationCast(); } }; template struct UnboxWeakHelper> { static Ptr Unbox(const reflection::description::Value& value) { if (value.IsNull()) return nullptr; return value.GetRawPtr()->SafeAggregationCast(); } }; template struct UnboxWeakHelper> { static Nullable Unbox(const reflection::description::Value& value) { if (value.IsNull()) return Nullable(); auto boxed = value.GetBoxedValue().Cast>(); if (!boxed) return Nullable(); return Nullable(boxed->value); } }; template T UnboxWeak(const reflection::description::Value& value) { using Type = typename RemoveCVR::Type; return UnboxWeakHelper::Unbox(value); } template collections::LazyList Range(T begin, T end) { return collections::Range(begin, end - begin); } template bool InSet(const T& value, const collections::LazyList& collection) { return collection.Any([&](const T& element) {return element == value; }); } template bool InSet(const T& value, Ptr collection) { return InSet(value, reflection::description::GetLazyList(collection)); } template Ptr UnboxCollection(U& value) { auto boxedValue = reflection::description::BoxParameter(value); Ptr result; reflection::description::UnboxParameter>(boxedValue, result); return result; } template Ptr UnboxCollection(const collections::LazyList& value) { auto boxedValue = reflection::description::BoxParameter>(const_cast&>(value)); Ptr result; reflection::description::UnboxParameter>(boxedValue, result); return result; } struct CreateList { using IValueList = reflection::description::IValueList; Ptr list; CreateList(); CreateList(Ptr _list); template CreateList Add(const T& value) { list->Add(Box(value)); return{ list }; } }; struct CreateObservableList { using IValueObservableList = reflection::description::IValueObservableList; Ptr list; CreateObservableList(); CreateObservableList(Ptr _list); template CreateObservableList Add(const T& value) { list->Add(Box(value)); return{ list }; } }; struct CreateDictionary { using IValueDictionary = reflection::description::IValueDictionary; Ptr dictionary; CreateDictionary(); CreateDictionary(Ptr _dictionary); template CreateDictionary Add(const K& key, const V& value) { dictionary->Set(Box(key), Box(value)); return{ dictionary }; } }; template struct EventHelper { }; template Ptr EventAttach(T& e, typename EventHelper::Handler handler) { return EventHelper::Attach(e, handler); } template bool EventDetach(T& e, Ptr handler) { return EventHelper::Detach(e, handler); } template decltype(auto) EventInvoke(T& e) { return EventHelper::Invoke(e); } 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; } }; } } #endif /*********************************************************************** .\WFLIBRARYPREDEFINED.H ***********************************************************************/ /*********************************************************************** Vczh Library++ 3.0 Developer: Zihan Chen(vczh) Framework::Reflection Interfaces: ***********************************************************************/ #ifndef VCZH_WORKFLOW_LIBRARY_PREDEFINED #define VCZH_WORKFLOW_LIBRARY_PREDEFINED #include namespace vl { namespace reflection { namespace description { /*********************************************************************** Coroutine ***********************************************************************/ enum class CoroutineStatus { Waiting, Executing, Stopped, }; class CoroutineResult : public virtual IDescriptable, public Description { protected: Value result; Ptr failure; public: Value GetResult(); void SetResult(const Value& value); Ptr GetFailure(); void SetFailure(Ptr value); }; class ICoroutine : public virtual IDescriptable, public Description { public: virtual void Resume(bool raiseException, Ptr output) = 0; virtual Ptr GetFailure() = 0; virtual CoroutineStatus GetStatus() = 0; }; /*********************************************************************** Coroutine (Enumerable) ***********************************************************************/ class EnumerableCoroutine : public Object, public Description { public: class IImpl : public virtual IValueEnumerator, public Description { public: virtual void OnYield(const Value& value) = 0; virtual void OnJoin(Ptr value) = 0; }; typedef Func(IImpl*)> Creator; static void YieldAndPause(IImpl* impl, const Value& value); static void JoinAndPause(IImpl* impl, Ptr value); static void ReturnAndExit(IImpl* impl); static Ptr Create(const Creator& creator); }; /*********************************************************************** Coroutine (Async) ***********************************************************************/ enum class AsyncStatus { Ready, Executing, Stopped, }; class AsyncContext : public virtual IDescriptable, public Description { protected: SpinLock lock; bool cancelled = false; Value context; public: AsyncContext(const Value& _context = {}); ~AsyncContext(); bool IsCancelled(); bool Cancel(); const description::Value& GetContext(); void SetContext(const description::Value& value); }; class IAsync : public virtual IDescriptable, public Description { public: virtual AsyncStatus GetStatus() = 0; virtual bool Execute(const Func)>& callback, Ptr context = nullptr) = 0; static Ptr Delay(vint milliseconds); }; class IPromise : public virtual IDescriptable, public Description { public: virtual bool SendResult(const Value& result) = 0; virtual bool SendFailure(Ptr failure) = 0; }; class IFuture : public virtual IAsync, public Description { public: virtual Ptr GetPromise() = 0; static Ptr Create(); }; class IAsyncScheduler : public virtual IDescriptable, public Description { public: virtual void Execute(const Func& callback) = 0; virtual void ExecuteInBackground(const Func& callback) = 0; virtual void DelayExecute(const Func& callback, vint milliseconds) = 0; static void RegisterDefaultScheduler(Ptr scheduler); static void RegisterSchedulerForCurrentThread(Ptr scheduler); static Ptr UnregisterDefaultScheduler(); static Ptr UnregisterSchedulerForCurrentThread(); static Ptr GetSchedulerForCurrentThread(); }; class AsyncCoroutine : public Object, public Description { public: class IImpl : public virtual IAsync, public Description { public: virtual Ptr GetScheduler() = 0; virtual Ptr GetContext() = 0; virtual void OnContinue(Ptr output) = 0; virtual void OnReturn(const Value& value) = 0; }; typedef Func(IImpl*)> Creator; static void AwaitAndRead(IImpl* impl, Ptr value); static void ReturnAndExit(IImpl* impl, const Value& value); static Ptr QueryContext(IImpl* impl); static Ptr Create(const Creator& creator); static void CreateAndRun(const Creator& creator); }; /*********************************************************************** Coroutine (State Machine) ***********************************************************************/ class StateMachine : public Object, public AggregatableDescription { #ifndef VCZH_DEBUG_NO_REFLECTION friend struct CustomTypeDescriptorSelector; #endif protected: bool stateMachineInitialized = false; bool stateMachineStopped = false; vint stateMachineInput = -1; Ptr stateMachineCoroutine; void ResumeStateMachine(); public: StateMachine(); ~StateMachine(); CoroutineStatus GetStateMachineStatus(); }; /*********************************************************************** Libraries ***********************************************************************/ class Sys : public Description { public: static vint Len(const WString& value) { return value.Length(); } static WString Left(const WString& value, vint length) { return value.Left(length); } static WString Right(const WString& value, vint length) { return value.Right(length); } static WString Mid(const WString& value, vint start, vint length) { return value.Sub(start, length); } static vint Find(const WString& value, const WString& substr) { return INVLOC.FindFirst(value, substr, Locale::Normalization::None).key; } static WString UCase(const WString& value) { return wupper(value); } static WString LCase(const WString& value) { return wlower(value); } static WString LoremIpsumTitle(vint bestLength) { return vl::LoremIpsumTitle(bestLength); } static WString LoremIpsumSentence(vint bestLength) { return vl::LoremIpsumSentence(bestLength); } static WString LoremIpsumParagraph(vint bestLength) { return vl::LoremIpsumParagraph(bestLength); } #define DEFINE_COMPARE(TYPE) static vint Compare(TYPE a, TYPE b); REFLECTION_PREDEFINED_PRIMITIVE_TYPES(DEFINE_COMPARE) DEFINE_COMPARE(DateTime) #undef DEFINE_COMPARE static DateTime GetLocalTime(); static DateTime GetUtcTime(); static DateTime ToLocalTime(DateTime dt); static DateTime ToUtcTime(DateTime dt); static DateTime Forward(DateTime dt, vuint64_t milliseconds); static DateTime Backward(DateTime dt, vuint64_t milliseconds); static DateTime CreateDateTime(vint year, vint month, vint day); static DateTime CreateDateTime(vint year, vint month, vint day, vint hour, vint minute, vint second, vint milliseconds); static DateTime CreateDateTime(vuint64_t filetime); static Ptr ReverseEnumerable(Ptr value); }; class Math : public Description { public: static double Pi() { return ASin(1) * 2; } static vint8_t Abs(vint8_t value) { return value > 0 ? value : -value; } static vint16_t Abs(vint16_t value) { return value > 0 ? value : -value; } static vint32_t Abs(vint32_t value) { return value > 0 ? value : -value; } static vint64_t Abs(vint64_t value) { return value > 0 ? value : -value; } static float Abs(float value) { return value > 0 ? value : -value; } static double Abs(double value) { return value > 0 ? value : -value; } #define DEFINE_MINMAX(TYPE)\ static TYPE Min(TYPE a, TYPE b);\ static TYPE Max(TYPE a, TYPE b);\ REFLECTION_PREDEFINED_PRIMITIVE_TYPES(DEFINE_MINMAX) DEFINE_MINMAX(DateTime) #undef DEFINE_MINMAX static double Sin(double value) { return sin(value); } static double Cos(double value) { return cos(value); } static double Tan(double value) { return tan(value); } static double ASin(double value) { return asin(value); } static double ACos(double value) { return acos(value); } static double ATan(double value) { return atan(value); } static double ATan2(double x, double y) { return atan2(y, x); } static double Exp(double value) { return exp(value); } static double LogN(double value) { return log(value); } static double Log10(double value) { return log10(value); } static double Log(double value, double base) { return log(value) / log(base); } static double Pow(double value, double power) { return pow(value, power); } static double Ceil(double value) { return ceil(value); } static double Floor(double value) { return floor(value); } static double Round(double value) { return round(value); } static double Trunc(double value) { return trunc(value); } }; class Localization : public Description { public: static Locale Invariant(); static Locale System(); static Locale User(); static collections::LazyList Locales(); static collections::LazyList GetShortDateFormats(Locale locale); static collections::LazyList GetLongDateFormats(Locale locale); static collections::LazyList GetYearMonthDateFormats(Locale locale); static collections::LazyList GetLongTimeFormats(Locale locale); static collections::LazyList GetShortTimeFormats(Locale locale); static WString GetShortDayOfWeekName(Locale locale, vint dayOfWeek); static WString GetLongDayOfWeekName(Locale locale, vint dayOfWeek); static WString GetShortMonthName(Locale locale, vint month); static WString GetLongMonthName(Locale locale, vint month); static WString FormatDate(Locale locale, const WString& format, DateTime date); static WString FormatTime(Locale locale, const WString& format, DateTime date); static WString FormatNumber(Locale locale, const WString& number); static WString FormatCurrency(Locale locale, const WString& number); }; } } } #endif /*********************************************************************** .\WFLIBRARYREFLECTION.H ***********************************************************************/ /*********************************************************************** Vczh Library++ 3.0 Developer: Zihan Chen(vczh) Framework::Reflection Interfaces: ***********************************************************************/ #ifndef VCZH_WORKFLOW_LIBRARY_REFLECTION #define VCZH_WORKFLOW_LIBRARY_REFLECTION namespace vl { namespace reflection { namespace description { /*********************************************************************** Predefined Types ***********************************************************************/ #ifndef VCZH_DEBUG_NO_REFLECTION #define WORKFLOW_LIBRARY_TYPES(F)\ F(Sys) \ F(Math) \ F(Localization) \ F(CoroutineStatus) \ F(CoroutineResult) \ F(ICoroutine) \ F(EnumerableCoroutine::IImpl) \ F(EnumerableCoroutine) \ F(AsyncStatus) \ F(AsyncContext) \ F(IAsync) \ F(IPromise) \ F(IFuture) \ F(IAsyncScheduler) \ F(AsyncCoroutine::IImpl) \ F(AsyncCoroutine) \ F(StateMachine) \ WORKFLOW_LIBRARY_TYPES(DECL_TYPE_INFO) #endif /*********************************************************************** Interface Implementation Proxy (Implement) ***********************************************************************/ #ifndef VCZH_DEBUG_NO_REFLECTION #pragma warning(push) #pragma warning(disable:4250) BEGIN_INTERFACE_PROXY_NOPARENT_SHAREDPTR(ICoroutine) void Resume(bool raiseException, Ptr output)override { INVOKE_INTERFACE_PROXY(Resume, raiseException, output); } Ptr GetFailure()override { INVOKEGET_INTERFACE_PROXY_NOPARAMS(GetFailure); } CoroutineStatus GetStatus()override { INVOKEGET_INTERFACE_PROXY_NOPARAMS(GetStatus); } END_INTERFACE_PROXY(ICoroutine) BEGIN_INTERFACE_PROXY_NOPARENT_SHAREDPTR(IAsync) AsyncStatus GetStatus()override { INVOKEGET_INTERFACE_PROXY_NOPARAMS(GetStatus); } bool Execute(const Func)>& callback, Ptr context)override { INVOKEGET_INTERFACE_PROXY(Execute, callback, context); } END_INTERFACE_PROXY(IAsync) #pragma warning(pop) #endif /*********************************************************************** LoadPredefinedTypes ***********************************************************************/ extern bool WfLoadLibraryTypes(); } } } #endif