aboutsummaryrefslogtreecommitdiff
path: root/src/base.h
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-11-07 21:40:04 +0800
committercrupest <crupest@outlook.com>2018-11-07 21:40:04 +0800
commitefdce672123284847bd7fb6f12ac1ec96f28f3ef (patch)
tree298e6313e9a48c5867b2355242b78d3cd23fdc61 /src/base.h
parent634dab6ad2c9e4675beacfb77ac02b2d43cab132 (diff)
downloadcru-efdce672123284847bd7fb6f12ac1ec96f28f3ef.tar.gz
cru-efdce672123284847bd7fb6f12ac1ec96f28f3ef.tar.bz2
cru-efdce672123284847bd7fb6f12ac1ec96f28f3ef.zip
Make all header *.hpp .
Diffstat (limited to 'src/base.h')
-rw-r--r--src/base.h94
1 files changed, 0 insertions, 94 deletions
diff --git a/src/base.h b/src/base.h
deleted file mode 100644
index 9b3b50a1..00000000
--- a/src/base.h
+++ /dev/null
@@ -1,94 +0,0 @@
-#pragma once
-
-// ReSharper disable once CppUnusedIncludeDirective
-#include "global_macros.h"
-
-
-#include <string>
-#include <type_traits>
-#include <stdexcept>
-#include <memory>
-#include <string_view>
-#include <chrono>
-#include <optional>
-
-namespace cru
-{
- template<typename T> struct is_shared_ptr : std::false_type {};
- template<typename T> struct is_shared_ptr<std::shared_ptr<T>> : std::true_type {};
- template<typename T> constexpr bool is_shared_ptr_v = is_shared_ptr<T>::value;
-
- template<typename T> struct type_tag {};
-
- //typedefs
- using String = std::wstring;
- using MultiByteString = std::string;
-
- using StringView = std::wstring_view;
- using MultiByteStringView = std::string_view;
-
- using FloatSecond = std::chrono::duration<double, std::chrono::seconds::period>;
-
- enum class FlowControl
- {
- Continue,
- Break
- };
-
-
- 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.");
- }
-
- MultiByteString ToUtf8String(const StringView& string);
-
- inline void Require(const bool condition, const MultiByteStringView& error_message)
- {
- if (!condition)
- throw std::invalid_argument(error_message.data());
- }
-
- template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
- float Coerce(const T n, const std::optional<T> min, const std::optional<T> max)
- {
- if (min.has_value() && n < min.value())
- return min.value();
- if (max.has_value() && n > max.value())
- return max.value();
- return n;
- }
-
- template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
- float Coerce(const T n, const std::nullopt_t, const std::optional<T> max)
- {
- if (max.has_value() && n > max.value())
- return max.value();
- return n;
- }
-
- template <typename T, typename = std::enable_if_t<std::is_arithmetic_v<T>>>
- float Coerce(const T n, const std::optional<T> min, const std::nullopt_t)
- {
- if (min.has_value() && n < min.value())
- return min.value();
- return n;
- }
-
-}