#pragma once // ReSharper disable once CppUnusedIncludeDirective #include "global_macros.h" #ifdef CRU_DEBUG #include #include #else #include #include #endif #include #include #include #include #include #include #include #include namespace cru { template struct is_shared_ptr : std::false_type {}; template struct is_shared_ptr> : std::true_type {}; template constexpr bool is_shared_ptr_v = is_shared_ptr::value; enum class FlowControl { Continue, Break }; #ifdef CRU_DEBUG using String = std::wstring; using MultiByteString = std::string; #else using String = folly::basic_fbstring; using MultiByteString = folly::fbstring; #endif using StringView = std::wstring_view; using MultiByteStringView = std::string_view; template using Function = folly::Function; template using FunctionPtr = std::shared_ptr>; using Action = Function; using ActionPtr = FunctionPtr; template Type CreatePtr(Args&&... args) { static_assert(is_shared_ptr_v); return std::make_shared(std::forward(args)...); } template FunctionPtr CreateFunctionPtr(Function&& function) { return std::make_shared>(std::move(function)); } inline ActionPtr CreateActionPtr(Action&& action) { return std::make_shared(std::move(action)); } #ifdef CRU_DEBUG template using Vector = std::vector; #else template using Vector = folly::fbvector; #endif using FloatSecond = std::chrono::duration; class Object { public: Object() = default; Object(const Object&) = default; Object& operator = (const Object&) = default; Object(Object&&) = default; Object& operator = (Object&&) = default; virtual ~Object() = default; }; struct Interface { virtual ~Interface() = default; }; [[noreturn]] inline void UnreachableCode() { throw std::logic_error("Unreachable code."); } struct ICancelable : virtual Interface { virtual void Cancel() = 0; }; using CancelablePtr = std::shared_ptr; MultiByteString ToUtf8String(const StringView& string); class PropertyChangedNotifyObject : public Object { public: PropertyChangedNotifyObject() = default; PropertyChangedNotifyObject(const PropertyChangedNotifyObject& other) = delete; PropertyChangedNotifyObject(PropertyChangedNotifyObject&& other) = delete; PropertyChangedNotifyObject& operator = (const PropertyChangedNotifyObject& other) = delete; PropertyChangedNotifyObject& operator = (PropertyChangedNotifyObject&& other) = delete; ~PropertyChangedNotifyObject() override = default; void AddPropertyChangedListener(FunctionPtr listener); void RemovePropertyChangedListener(const FunctionPtr& listener); protected: void RaisePropertyChangedEvent(String property_name); private: std::list> listeners_; }; }