summaryrefslogtreecommitdiffhomepage
path: root/src/kernel/NeKit/Config.h
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-12-14 02:38:37 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2025-12-14 02:38:37 +0100
commit2d56cc149fa8c07a92c9ee71950f3ec415590267 (patch)
tree218bf47aa7a23db7b6c3f69cafccbe68fd4a935a /src/kernel/NeKit/Config.h
parent74b02a538770b9646cd861c82430ad5fadea93eb (diff)
chore: improve Vettable pattern, add new concepts in Config.h
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'src/kernel/NeKit/Config.h')
-rw-r--r--src/kernel/NeKit/Config.h40
1 files changed, 32 insertions, 8 deletions
diff --git a/src/kernel/NeKit/Config.h b/src/kernel/NeKit/Config.h
index bb21ba5c..40d2ede5 100644
--- a/src/kernel/NeKit/Config.h
+++ b/src/kernel/NeKit/Config.h
@@ -15,6 +15,8 @@
#error !!! NeKernel compiles with C++20 as of December 4, 2025 !!!
#endif
+#define NE_ICODEC final : public ::Kernel::ICodec
+
/// @brief The **Kernel** namespace.
namespace Kernel {
using voidPtr = void*;
@@ -105,6 +107,16 @@ inline Args&& move(Args&& arg) {
return static_cast<Args&&>(arg);
}
+template <class Type>
+concept IsSerializable = requires() {
+ { Type::kValue };
+};
+
+template <class Type>
+concept IsNotSerializable = requires() {
+ { !Type::kValue };
+};
+
/// @brief Encoding interface, used as a proxy to convert T to Char*
/// Used to cast A to B or B to A.
class ICodec {
@@ -138,17 +150,18 @@ class ICodec {
/// @brief Convert T to a Y type.
/// @note The class must be serializable, otherwise this will fail.
- /// @tparam T the class type of type.
- /// @tparam Y the result class.
+ /// @tparam Concept the class type of type.
+ /// @tparam RetType the result class.
/// @param type the class to cast.
/// @return the class as Y.
- template <typename T, typename Y>
- Y As(T type) {
- if (type.template IsSerializable()) {
- return type.template Error();
- }
+ template <IsSerializable Concept, typename RetType>
+ RetType As(Concept& type) {
+ return type.template As<RetType>();
+ }
- return type.template As<Y>();
+ template <IsNotSerializable Concept>
+ Void As(Concept& type) {
+ static_assert(type, "Concept is not serializable.");
}
};
@@ -171,4 +184,15 @@ class ISchedulable {
/// @brief Is this object offloading to another CPU?
virtual Bool HasMP() { return NO; }
};
+
+template <class Type>
+struct FalseResult final {};
+
+template <class Type>
+struct TrueResult final {
+ using ResultType = Type;
+ using ResultTypeRef = ResultType&;
+
+ static constexpr bool kValue = true;
+};
} // namespace Kernel