From 4b86554a0354d78efeb40e551eaccaac0fecd1d1 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 25 Sep 2018 13:08:40 +0800 Subject: Change the structure of project. --- src/base.h | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 src/base.h (limited to 'src/base.h') diff --git a/src/base.h b/src/base.h new file mode 100644 index 00000000..7ef78014 --- /dev/null +++ b/src/base.h @@ -0,0 +1,107 @@ +#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 + +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)...); + } + + 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); +} -- cgit v1.2.3