summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/NeKit
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-11-21 03:30:40 -0500
committerGitHub <noreply@github.com>2025-11-21 03:30:40 -0500
commite3fa27827e7647a0ecc466f4d92097fe48fbbb43 (patch)
tree33ba30655f555d37e3c970707b27413936e5a9ad /dev/kernel/NeKit
parentc739255b48b3a5b2e184ca1a637f9f1f95c978ff (diff)
parentefefa7221a3fea3636a64f2bf067e2af75626f34 (diff)
Merge pull request #79 from nekernel-org/devv0.0.61
Kernel: OpenHeFS fixes and new components.
Diffstat (limited to 'dev/kernel/NeKit')
-rw-r--r--dev/kernel/NeKit/ErrorOr.h3
-rw-r--r--dev/kernel/NeKit/Function.h9
-rw-r--r--dev/kernel/NeKit/Json.h51
-rw-r--r--dev/kernel/NeKit/Ref.h1
-rw-r--r--dev/kernel/NeKit/TOML.h15
-rw-r--r--dev/kernel/NeKit/Variant.h18
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);
}