From 64c23b15059649aeee6d08c7940d0ff1b56512b5 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 9 Dec 2025 05:12:57 +0100 Subject: feat: New `InitializerList` class, and `LHGetLaunchInfo` implementation on `LaunchHelpers.fwrk`. fix: Fix operator!= in the `Atom` class. Signed-off-by: Amlal El Mahrouss --- src/kernel/NeKit/Array.h | 11 +++++----- src/kernel/NeKit/ArrayList.h | 44 -------------------------------------- src/kernel/NeKit/Atom.h | 2 +- src/kernel/NeKit/InitializerList.h | 42 ++++++++++++++++++++++++++++++++++++ src/kernel/NeKit/NeKit.h | 2 +- 5 files changed, 49 insertions(+), 52 deletions(-) delete mode 100644 src/kernel/NeKit/ArrayList.h create mode 100644 src/kernel/NeKit/InitializerList.h (limited to 'src/kernel/NeKit') diff --git a/src/kernel/NeKit/Array.h b/src/kernel/NeKit/Array.h index f4673b68..179b8e4e 100644 --- a/src/kernel/NeKit/Array.h +++ b/src/kernel/NeKit/Array.h @@ -20,26 +20,25 @@ class Array final { Array& operator=(const Array&) = default; Array(const Array&) = default; - T& operator[](SizeT at) { return fArray[at]; } + T& operator[](const SizeT& at) { return fArray[at]; } + const T& operator[](const SizeT& at) const { return fArray[at]; } Boolean Empty() { return this->Count() > 0; } SizeT Capacity() { return N; } - SizeT Count() { - return N; // avoid constexpr error. - } + SizeT Count() { return N; } const T* CData() { return fArray; } - operator bool() { return !Empty(); } + explicit operator bool() { return !this->Empty(); } private: T fArray[N]; }; template -auto make_list(ValueType val) { +inline auto make_array(ValueType& val) -> auto { return Array{val}; } } // namespace Kernel diff --git a/src/kernel/NeKit/ArrayList.h b/src/kernel/NeKit/ArrayList.h deleted file mode 100644 index 5787fe98..00000000 --- a/src/kernel/NeKit/ArrayList.h +++ /dev/null @@ -1,44 +0,0 @@ -/* ======================================== - - Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. - -======================================== */ - -#pragma once - -#include - -namespace Kernel { -template -class ArrayList final { - public: - explicit ArrayList(T* list, SizeT length) : fList(reinterpret_cast(list)), fLen(length) {} - - ~ArrayList() = default; - - ArrayList& operator=(const ArrayList&) = default; - ArrayList(const ArrayList&) = default; - - T* Data() { return fList; } - - const T* CData() { return fList; } - - T& operator[](SizeT index) const { - MUST_PASS(index < this->Count()); - return fList[index]; - } - - explicit operator bool() { return fList; } - - SizeT Count() const { return fLen; } - - private: - T* fList{nullptr}; - SizeT fLen{0}; -}; - -template -ArrayList make_list(ValueType val) { - return ArrayList{val}; -} -} // namespace Kernel diff --git a/src/kernel/NeKit/Atom.h b/src/kernel/NeKit/Atom.h index 51808a0a..7c4ebb5b 100644 --- a/src/kernel/NeKit/Atom.h +++ b/src/kernel/NeKit/Atom.h @@ -25,7 +25,7 @@ class Atom final { friend Boolean operator==(Atom& atomic, const T& idx) { return atomic[idx] == idx; } - friend Boolean operator!=(Atom& atomic, const T& idx) { return atomic[idx] == idx; } + friend Boolean operator!=(Atom& atomic, const T& idx) { return atomic[idx] != idx; } private: T fArrayOfAtoms; diff --git a/src/kernel/NeKit/InitializerList.h b/src/kernel/NeKit/InitializerList.h new file mode 100644 index 00000000..158b88ed --- /dev/null +++ b/src/kernel/NeKit/InitializerList.h @@ -0,0 +1,42 @@ +/* ======================================== + + Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license. + +======================================== */ + +#pragma once + +#include + +namespace Kernel { +template +class InitializerList final { + public: + explicit InitializerList(const T* list) { + if constexpr (N > 0) { + for (auto i = 0UL; i < N; ++i) { + fList[i] = list[i]; + } + } + } + + ~InitializerList() = default; + + InitializerList& operator=(const InitializerList&) = default; + InitializerList(const InitializerList&) = default; + + T* begin() { return fList; } + T* operator->() { return fList; } + T* operator*() { return fList; } + T* end() { return fList + N; } + constexpr SizeT size() const { return N; } + + private: + T fList[N]; +}; + +template +inline InitializerList make_list(ValueType& val) { + return InitializerList{val}; +} +} // namespace Kernel diff --git a/src/kernel/NeKit/NeKit.h b/src/kernel/NeKit/NeKit.h index 4b1e64ca..9bf74e57 100644 --- a/src/kernel/NeKit/NeKit.h +++ b/src/kernel/NeKit/NeKit.h @@ -8,8 +8,8 @@ #pragma once #include -#include #include +#include #include #include #include -- cgit v1.2.3