summaryrefslogtreecommitdiffhomepage
path: root/Kernel/NewKit/Defines.hpp
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-09 00:42:44 +0200
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-05-09 00:42:44 +0200
commitaf8a516fc22865abd80d6e26f1541fa3d6bebfdc (patch)
tree96d42a10945fc03df022389aef54708383c1d616 /Kernel/NewKit/Defines.hpp
parenta874e9cc98df994178d55996943fe81799c61d2f (diff)
MHR-23: :boom:, refactors.
- Move NewBoot to /Boot, thus making Kernel directory only containing the kernel. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Kernel/NewKit/Defines.hpp')
-rw-r--r--Kernel/NewKit/Defines.hpp150
1 files changed, 150 insertions, 0 deletions
diff --git a/Kernel/NewKit/Defines.hpp b/Kernel/NewKit/Defines.hpp
new file mode 100644
index 00000000..f32e873a
--- /dev/null
+++ b/Kernel/NewKit/Defines.hpp
@@ -0,0 +1,150 @@
+/* -------------------------------------------
+
+ Copyright SoftwareLabs
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Macros.hpp>
+
+#define NEWKIT_VERSION "1.01"
+
+#if !defined(_INC_NO_STDC_HEADERS) && defined(__GNUC__)
+#include <CRT/__mpcc_defines.hxx>
+#endif
+
+#ifdef __has_feature
+#if !__has_feature(cxx_nullptr)
+#if !__has_nullptr
+#error You must at least have nullptr featured on your C++ compiler.
+#endif
+#endif
+#endif
+
+/// @brief NewOS namespace.
+namespace NewOS
+{
+ using voidPtr = void*;
+ using VoidPtr = void*;
+ using nullPtr = decltype(nullptr);
+ using NullPtr = decltype(nullptr);
+
+ using Int = int;
+ using Int32 = int;
+ using UShort = unsigned short;
+ using UInt16 = unsigned short;
+ using Short = short;
+ using Int16 = short;
+ using UInt = unsigned int;
+ using UInt32 = unsigned int;
+ using Long = __INT64_TYPE__;
+ using Int64 = __INT64_TYPE__;
+ using ULong = __UINT64_TYPE__;
+ using UInt64 = __UINT64_TYPE__;
+ using Boolean = bool;
+ using Bool = bool;
+ using Char = char;
+ using UChar = unsigned char;
+ using UInt8 = unsigned char;
+
+ using SSize = Int64;
+ using SSizeT = Int64;
+ using Size = __SIZE_TYPE__;
+ using SizeT = __SIZE_TYPE__;
+ using IntPtr = __INTPTR_TYPE__;
+ using UIntPtr = __UINTPTR_TYPE__;
+ using IntFast = __INT_FAST32_TYPE__;
+ using IntFast64 = __INT_FAST64_TYPE__;
+ using PtrDiff = __PTRDIFF_TYPE__;
+
+ typedef UIntPtr* Ptr64;
+ typedef UInt32* Ptr32;
+
+ using Utf8Char = char8_t;
+ using Utf16Char = char16_t;
+ using WideChar = wchar_t;
+ using Utf32Char = char32_t;
+
+ using Void = void;
+
+ using Lba = UInt64;
+
+ enum class Endian : UChar
+ {
+ kEndianLittle,
+ kEndianBig,
+ kEndianMixed,
+ kCount
+ };
+
+ /// @brief Forward object.
+ /// @tparam Args the object type.
+ /// @param arg the object.
+ /// @return object's rvalue
+ template <typename Args>
+ inline Args&& forward(Args& arg)
+ {
+ return static_cast<Args&&>(arg);
+ }
+
+ /// @brief Move object.
+ /// @tparam Args the object type.
+ /// @param arg the object.
+ /// @return object's rvalue
+ template <typename Args>
+ inline Args&& move(Args&& arg)
+ {
+ return static_cast<Args&&>(arg);
+ }
+
+ /// @brief Encoder class
+ /// Used to cast A to B or B to A.
+ class Encoder final
+ {
+ public:
+ explicit Encoder() = default;
+ ~Encoder() = default;
+
+ Encoder& operator=(const Encoder&) = default;
+ Encoder(const Encoder&) = default;
+
+ public:
+ /// @brief Convert type to bytes.
+ /// @tparam T the type.
+ /// @param type (a1) the data.
+ /// @return a1 as Char*
+ template <typename T>
+ Char* AsBytes(T type) noexcept
+ {
+ return reinterpret_cast<Char*>(type);
+ }
+
+ /// @brief Convert T class to Y class.
+ /// @tparam T the class type of type.
+ /// @tparam Y the result class.
+ /// @param type the class to cast.
+ /// @return the class as Y.
+ template <typename T, typename Y>
+ Y As(T type) noexcept
+ {
+ return type.template As<Y>();
+ }
+ };
+} // namespace NewOS
+
+#define DEDUCE_ENDIAN(address, value) \
+ (((reinterpret_cast<NewOS::Char*>(address)[0]) == (value)) \
+ ? (NewOS::Endian::kEndianBig) \
+ : (NewOS::Endian::kEndianLittle))
+
+#define Yes (true)
+#define No (false)
+
+#define VoidStar NewOS::voidPtr
+
+#ifdef INIT
+#undef INIT
+#endif // ifdef INIT
+
+#define INIT(OBJ, TYPE, ...) TYPE OBJ = TYPE(__VA_ARGS__)