diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-21 09:09:33 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-11-21 09:25:16 +0100 |
| commit | 463e7472e737fb8259a30304e729772041ea5498 (patch) | |
| tree | 0cd4aee9d7d0eea2d5279f76bf37fd6887fbc65d /dev/kernel/NeKit | |
| parent | c464e5800961c809c73d4180f8a66885b53c63d7 (diff) | |
feat: kernel: NeKit improvements and new TOML file.
feat: frameworks: CoreFoundation improvements and new KTest framework.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/kernel/NeKit')
| -rw-r--r-- | dev/kernel/NeKit/ErrorOr.h | 3 | ||||
| -rw-r--r-- | dev/kernel/NeKit/Function.h | 9 | ||||
| -rw-r--r-- | dev/kernel/NeKit/Json.h | 51 | ||||
| -rw-r--r-- | dev/kernel/NeKit/Ref.h | 1 | ||||
| -rw-r--r-- | dev/kernel/NeKit/TOML.h | 15 | ||||
| -rw-r--r-- | dev/kernel/NeKit/Variant.h | 18 |
6 files changed, 71 insertions, 26 deletions
diff --git a/dev/kernel/NeKit/ErrorOr.h b/dev/kernel/NeKit/ErrorOr.h index 2e3afb46..4c924957 100644 --- a/dev/kernel/NeKit/ErrorOr.h +++ b/dev/kernel/NeKit/ErrorOr.h @@ -15,6 +15,9 @@ namespace Kernel { using ErrorT = Int32; +/// ================================================================================ +/// @brief ErrorOr class for error handling. +/// ================================================================================ template <typename T> class ErrorOr final { public: diff --git a/dev/kernel/NeKit/Function.h b/dev/kernel/NeKit/Function.h index 45b1a5af..70242bc3 100644 --- a/dev/kernel/NeKit/Function.h +++ b/dev/kernel/NeKit/Function.h @@ -4,13 +4,15 @@ ======================================== */ -#ifndef _INC_FUNCTION_H_ -#define _INC_FUNCTION_H_ +#pragma once #include <NeKit/Defines.h> #include <NeKit/ErrorOr.h> namespace Kernel { +/// ================================================================================ +/// @brief Function wrapper class. +/// ================================================================================ template <typename T, typename... Args> class Function final { public: @@ -40,11 +42,10 @@ class Function final { private: T(*fFn) - (Args... args); + (Args... args){nullptr}; }; template <typename T, typename... Args> using FunctionOr = ErrorOr<Function<T, Args...>>; } // namespace Kernel -#endif // !_INC_FUNCTION_H__ diff --git a/dev/kernel/NeKit/Json.h b/dev/kernel/NeKit/Json.h index 836a0995..1e804354 100644 --- a/dev/kernel/NeKit/Json.h +++ b/dev/kernel/NeKit/Json.h @@ -19,54 +19,68 @@ #define kNeJsonLen (256) #define kNeJsonNullArr "[]" #define kNeJsonNullObj "{}" +#define kNeJsonNullKey "null" +#define kNeJsonNullValue kNeJsonNullKey namespace Kernel { -/// @brief JavaScript object class +/// ================================================================================ +/// @brief JSON object representation. +/// ================================================================================ +template <typename CharKind = Char> class JsonObject final { public: explicit JsonObject() { - auto len = kNeJsonMaxLen; - KBasicString<> key = KString(len); - key += kNeJsonNullObj; + KBasicString<CharKind> key = KString(kNeJsonMaxLen); + key += kNeJsonNullValue; this->AsKey() = key; - this->AsValue() = key; + this->AsValue() = key; } - explicit JsonObject(SizeT lhsLen, SizeT rhsLen) : fKey(lhsLen), fValue(rhsLen) {} + explicit JsonObject(SizeT lhsLen, SizeT rhsLen) : fKey(lhsLen), fValue(rhsLen) { + + KBasicString<CharKind> key = KString(lhsLen); + this->AsKey() = key; + + KBasicString<CharKind> value = KString(rhsLen); + this->AsValue() = value; + } ~JsonObject() = default; NE_COPY_DEFAULT(JsonObject) + NE_MOVE_DEFAULT(JsonObject) Bool& IsUndefined() { return fUndefined; } private: Bool fUndefined; // is this instance undefined? - KBasicString<> fKey; - KBasicString<> fValue; + KBasicString<CharKind> fKey; + KBasicString<CharKind> fValue; public: /// @brief returns the key of the json /// @return the key as string view. - KBasicString<>& AsKey() { return fKey; } + KBasicString<CharKind>& AsKey() { return fKey; } /// @brief returns the value of the json. /// @return the key as string view. - KBasicString<>& AsValue() { return fValue; } + KBasicString<CharKind>& AsValue() { return fValue; } - static JsonObject kNull; + STATIC JsonObject<CharKind> kNull; }; -/// @brief JsonObject stream reader helper. -struct JsonStreamReader final { - STATIC JsonObject In(const Char* full_array) { +/// ================================================================================ +/// @brief JsonObject stream reader helper for ASCII. +/// ================================================================================ +struct AsciiJsonStreamReader final { + STATIC JsonObject<Char> In(const Char* full_array) { auto start_val = '{'; auto end_val = '}'; Boolean probe_value = false; if (full_array[0] != start_val) { - if (full_array[0] != '[') return JsonObject::kNull; + if (full_array[0] != '[') return JsonObject<Char>{0, 0}; start_val = '['; end_val = ']'; @@ -79,7 +93,7 @@ struct JsonStreamReader final { SizeT key_len = 0; SizeT value_len = 0; - JsonObject type(kNeJsonMaxLen, kNeJsonMaxLen); + JsonObject<Char> type(kNeJsonMaxLen, kNeJsonMaxLen); for (SizeT i = 1; i < len; ++i) { if (full_array[i] == '\r' || full_array[i] == '\n') continue; @@ -125,5 +139,8 @@ struct JsonStreamReader final { } }; -using JsonStream = Stream<JsonStreamReader, JsonObject>; +/// ================================================================================ +/// @brief AsciiJsonStream type definition. +/// ================================================================================ +using AsciiJsonStream = Stream<AsciiJsonStreamReader, JsonObject<Char>>; } // namespace Kernel diff --git a/dev/kernel/NeKit/Ref.h b/dev/kernel/NeKit/Ref.h index 9c244be5..dac701e0 100644 --- a/dev/kernel/NeKit/Ref.h +++ b/dev/kernel/NeKit/Ref.h @@ -56,6 +56,7 @@ class NonNullRef final { NonNullRef(nullPtr) = delete; NonNullRef(T* ref) : fRef(ref) { MUST_PASS(ref); } + NonNullRef(Ref<T> ref) : fRef(ref) { MUST_PASS(ref); } Ref<T>& operator->() { MUST_PASS(fRef); diff --git a/dev/kernel/NeKit/TOML.h b/dev/kernel/NeKit/TOML.h new file mode 100644 index 00000000..dee273ad --- /dev/null +++ b/dev/kernel/NeKit/TOML.h @@ -0,0 +1,15 @@ +/* ======================================== + + Copyright (C) 2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. + +======================================== */ + +#pragma once + +namespace Kernel { +class TOMLObject final { + public: + explicit TOMLObject() = delete; + ~TOMLObject() = default; +}; +} // namespace Kernel
\ No newline at end of file diff --git a/dev/kernel/NeKit/Variant.h b/dev/kernel/NeKit/Variant.h index 42a47bc0..7bcd0dff 100644 --- a/dev/kernel/NeKit/Variant.h +++ b/dev/kernel/NeKit/Variant.h @@ -8,6 +8,7 @@ #include <NeKit/Defines.h> #include <NeKit/Json.h> +#include <NeKit/TOML.h> #include <NeKit/KString.h> #include <SwapKit/DiskSwap.h> @@ -15,13 +16,13 @@ namespace Kernel { class Variant final { public: enum class VariantKind { - kString, + kInvalid = 0, + kString = 200, kBlob, kNull, kJson, - kXML, + kTOML, kSwap, - kInvalid, }; public: @@ -37,7 +38,9 @@ class Variant final { explicit Variant(KBasicString<CharKind>* stringView) : fPtr((VoidPtr) stringView), fKind(VariantKind::kString) {} - explicit Variant(JsonObject* json) : fPtr((VoidPtr) json), fKind(VariantKind::kJson) {} + explicit Variant(JsonObject<>* json) : fPtr((VoidPtr) json), fKind(VariantKind::kJson) {} + + explicit Variant(TOMLObject* toml) : fPtr((VoidPtr) toml), fKind(VariantKind::kTOML) {} explicit Variant(nullPtr ptr) : fPtr(ptr), fKind(VariantKind::kNull) {} @@ -47,10 +50,15 @@ class Variant final { public: const Char* ToString(); + + /// ======================================================================== + /// @brief Returns the underlying pointer. + /// @return the underlying pointer. + /// ======================================================================== VoidPtr Leak(); template <typename T> - T* As() { + T* As() noexcept { return reinterpret_cast<T*>(fPtr); } |
