/*********************************************************************** THIS FILE IS AUTOMATICALLY GENERATED. DO NOT MODIFY DEVELOPER: Zihan Chen(vczh) ***********************************************************************/ #include "VlppReflection.h" #include "VlppOS.h" #include "Vlpp.h" #include "VlppRegex.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 std::move(pointer); } template Nullable Ensure(Nullable&& nullable) { CHECK_ERROR(nullable, L"The pointer cannot be null."); return std::move(nullable); } template Nullable& Ensure(Nullable& nullable) { CHECK_ERROR(nullable, L"The pointer cannot be null."); return nullable; } template WString ToString(const T& value) { WString str; CHECK_ERROR(reflection::description::TypedValueSerializerProvider>::Serialize(value, str), L"Failed to serialize."); return str; } template T Parse(const WString& str) { 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 Ptr(pointer->template SafeAggregationCast()); } template reflection::description::Value Box(T&& value) { return reflection::description::BoxParameter(value); } template T Unbox(const reflection::description::Value& value) { 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 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 Ptr(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) { 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); return reflection::description::UnboxParameter>(boxedValue).Ref(); } template Ptr UnboxCollection(const collections::LazyList& value) { auto boxedValue = reflection::description::BoxParameter(const_cast&>(value)); return reflection::description::UnboxParameter>(boxedValue).Ref(); } struct CreateArray { using IValueArray = reflection::description::IValueArray; Ptr list; CreateArray(); CreateArray(Ptr _list); CreateArray Resize(vint size) { list->Resize(size); return{ list }; } template CreateArray Set(vint index, const T& value) { list->Set(index, Box(value)); return{ list }; } }; 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 Ptr(new EventHandlerImpl(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 ***********************************************************************/ /// Status of a coroutine. enum class CoroutineStatus { /// The coroutine is waiting for resuming. Waiting, /// The coroutine is being executed. Executing, /// The coroutine has stopped. Stopped, }; /// An object providing input information when resuming a coroutine. class CoroutineResult : public virtual IDescriptable, public Description { protected: Value result; Ptr failure; public: /// Get the object provided to the coroutine. This object is the return value for the pending async operation, like $Await. /// The object provided to the coroutine. Value GetResult(); /// Set the object provided to the coroutine. /// The object provided to the coroutine. void SetResult(const Value& value); /// Get the error provided to the coroutine. When it is not nullptr, the return value of is ignored. /// The error provided to the coroutine. Ptr GetFailure(); /// Set the error provided to the coroutine. /// The error provided to the coroutine. void SetFailure(Ptr value); }; /// A coroutine. This is typically created by a Workflow script. class ICoroutine : public virtual IDescriptable, public Description { public: /// Resume the coroutine. /// Set to true to raise an exception that the coroutine encountered. The same exception is accessible by . /// Input for the coroutine in this resuming. virtual void Resume(bool raiseException, Ptr output) = 0; /// Returns the current exception. /// The current exception. It could cause by the Workflow script that creates this coroutine, or by calling when this coroutine is in an inappropriate state. virtual Ptr GetFailure() = 0; /// Returns the status of the coroutine. /// The status of the coroutine. can be called only when this function returns . 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) ***********************************************************************/ /// Status of am async operation. enum class AsyncStatus { /// The async operation is ready to execute. Ready, /// The async operation is being executed. Executing, /// The async operation has stopped. Stopped, }; /// A context providing communication between the caller and the async operation. class AsyncContext : public virtual IDescriptable, public Description { protected: SpinLock lock; bool cancelled = false; Value context; public: /// Create a context. /// Set the initial return value for (optional).. AsyncContext(const Value& _context = {}); ~AsyncContext(); /// Test if the current async operation is expected to cancel. /// Returns true if the current async operation is expected to cancel. /// /// This function is accessible by "$.IsCancelled" in an $Async coroutine. /// A cancelable async operation should check this value when it is able to stop properly, and stop when it is true. /// bool IsCancelled(); /// Set to true. /// Returns true when this operation succeeded. bool Cancel(); /// Returns a value that is accessible in Workflow script by "$.Context" in an $Async coroutine. /// A value that is accessible in Workflow script by "$.Context" in an $Async coroutine. const description::Value& GetContext(); /// Set a value that is accessible F /// A value that is accessible in Workflow script by "$.Context" in an $Async coroutine. void SetContext(const description::Value& value); }; /// An async operation. class IAsync : public virtual IDescriptable, public Description { public: /// Get the status of this async operation. /// The status of this async operation. virtual AsyncStatus GetStatus() = 0; /// Run this async operation. /// Returns true when this operation succeeded. This function cannot be called twice on the same object. /// A callback to execute when the async operation finished. /// A context object that is accessible in Workflow script by "$" in an $Async coroutine (optional). virtual bool Execute(const Func)>& callback, Ptr context = nullptr) = 0; /// Create an async operation that finished after a specified moment of time. /// Returns the created async operation. /// The time in milliseconds to wait. It counts from when this function is called, not from when this async operation is executed. static Ptr Delay(vint milliseconds); }; /// A promise object that controls a object. class IPromise : public virtual IDescriptable, public Description { public: /// Mark the object as finished by providing a value. /// Returns true when this operation succeeded. Multiple calls to and cause a failure. /// The result of the object. virtual bool SendResult(const Value& result) = 0; /// Mark the object as finished by providing an exception. /// Returns true when this operation succeeded. Multiple calls to and cause a failure. /// The exception of the object. virtual bool SendFailure(Ptr failure) = 0; }; /// An async operation in the future-promise pattern. class IFuture : public virtual IAsync, public Description { public: /// Get the that controls this future object. /// The that controls this future object. virtual Ptr GetPromise() = 0; /// Create a future object. /// The created future object. static Ptr Create(); }; /// A scheduler that controls how async operations are executed. It needs to be implemented and attached to threads that run async operations. /// See Async Coroutine for more information. class IAsyncScheduler : public virtual IDescriptable, public Description { public: /// Called when a callback needs to be executed in any thread. /// The callback to execute. /// /// You can decide which thread to execute. /// For GacUI, the scheduler that attached to the UI thread will execute this callback in the UI thread. /// virtual void Execute(const Func& callback) = 0; /// Called when a callback needs to be executed in another thread. /// The callback to execute. /// /// You can decide which thread to execute except the current one. /// For GacUI, the scheduler that attached to any thread will execute this callback in a random background thread. /// virtual void ExecuteInBackground(const Func& callback) = 0; /// Called when a callback needs to be executed in any thread after a specified moment of time. /// The callback to execute. /// The time in milliseconds to wait. /// /// You can decide which thread to execute. /// For GacUI, the scheduler that attached to the UI thread will execute this callback in the UI thread. /// virtual void DelayExecute(const Func& callback, vint milliseconds) = 0; /// Attach a scheduler for all threads. /// The scheduler to attach. static void RegisterDefaultScheduler(Ptr scheduler); /// Attach a scheduler for the current thread. /// The scheduler to attach. static void RegisterSchedulerForCurrentThread(Ptr scheduler); /// Detach the scheduler for all threads. /// The previously attached scheduler. static Ptr UnregisterDefaultScheduler(); /// Detach the scheduler for the current thread. /// The previously attached scheduler. static Ptr UnregisterSchedulerForCurrentThread(); /// Get the attached scheduler for the current thread. /// The attached scheduler. If there is no scheduler that is attached to this particular thread, the default scheduler kicks in. 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 { #ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA friend struct CustomTypeDescriptorSelector; #endif protected: bool stateMachineInitialized = false; bool stateMachineStopped = false; vint stateMachineInput = -1; Ptr stateMachineCoroutine; void ResumeStateMachine(); public: StateMachine(); ~StateMachine(); CoroutineStatus GetStateMachineStatus(); }; /*********************************************************************** Libraries ***********************************************************************/ /// system::Sys includes a lot of utility functions for type conversion, string operations and date time operations for a Workflow script. class Sys : public Description { public: static vint Int32ToInt(vint32_t value) { return (vint)value; } static vint Int64ToInt(vint64_t value) { return (vint)value; } static vint32_t IntToInt32(vint value) { return (vint32_t)value; } static vint64_t IntToInt64(vint value) { return (vint64_t)value; } static vuint UInt32ToUInt(vuint32_t value) { return (vuint)value; } static vuint UInt64ToUInt(vuint64_t value) { return (vuint)value; } static vuint32_t UIntToUInt32(vuint value) { return (vuint32_t)value; } static vuint64_t UIntToUInt64(vuint value) { return (vuint64_t)value; } 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 Ptr ReverseEnumerable(Ptr value); }; /// system::Math includes math functions for a Workflow script. 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); } }; /// system::Math includes localization awared formatting operations for a Workflow script. /// ///

/// There are three locales that reflect the configuration of the operating system: ///

    ///
  • Invariant: An invariant locale for general languages.
  • ///
  • System: Locale for the operating system, including the file system.
  • ///
  • User: Locale for UI of the operating system.
  • ///
///

/// 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) ***********************************************************************/ #ifdef VCZH_DESCRIPTABLEOBJECT_WITH_METADATA #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