summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-03-27 20:27:30 +0100
committerAmlal El Mahrouss <amlal@el-mahrouss-logic.com>2024-03-27 20:27:30 +0100
commit3d798c5fc738768493df925d1f5d72256f2dec4e (patch)
treee78c06e956a2ef1c917f2faa96d06fe2b80761ac
parent1ce16b83dba0326b13dfa3399c1497ac6b1af14d (diff)
Encoder: Encoder::As requires the object to implement the As method.
Signed-off-by: Amlal El Mahrouss <amlal@el-mahrouss-logic.com>
-rw-r--r--Private/NewKit/Defines.hpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/Private/NewKit/Defines.hpp b/Private/NewKit/Defines.hpp
index 18506e8f..af87e377 100644
--- a/Private/NewKit/Defines.hpp
+++ b/Private/NewKit/Defines.hpp
@@ -88,7 +88,8 @@ inline Args &&move(Args &&arg) {
return static_cast<Args &&>(arg);
}
-/// @brief Encoding class
+/// @brief Encoder class
+/// Used to cast A to B or B to A.
class Encoder final {
public:
explicit Encoder() = default;
@@ -98,14 +99,23 @@ public:
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 reinterpret_cast<Y>(type);
+ return type.template As<Y>();
}
};