diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2025-02-11 08:51:02 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2025-02-11 08:51:02 +0100 |
| commit | f511ab3c1e840e1568dec67c4988f42e67d527b7 (patch) | |
| tree | 7ee9decdcc95c43d41d6d6e289e8bc4cc116888f /dev/Usr/LibCF | |
| parent | 5a221a0ba51b55e671efac8f8708a4ab28414816 (diff) | |
ADD: LibCF
Diffstat (limited to 'dev/Usr/LibCF')
| -rw-r--r-- | dev/Usr/LibCF/Array.h | 63 | ||||
| -rw-r--r-- | dev/Usr/LibCF/Property.h | 53 | ||||
| -rw-r--r-- | dev/Usr/LibCF/Ref.h | 106 |
3 files changed, 222 insertions, 0 deletions
diff --git a/dev/Usr/LibCF/Array.h b/dev/Usr/LibCF/Array.h new file mode 100644 index 00000000..8533b649 --- /dev/null +++ b/dev/Usr/LibCF/Array.h @@ -0,0 +1,63 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal EL Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include <LibSCI/SCI.h> + +namespace LibCF +{ + template <typename T, SizeT N> + class CFArray final + { + public: + explicit CFArray() = default; + ~CFArray() = default; + + CFArray& operator=(const CFArray&) = default; + CFArray(const CFArray&) = default; + + T& operator[](const SizeT& at) + { + MUST_PASS(at < this->Count()); + return fArray[at]; + } + + Bool Empty() + { + return this->Count() > 0; + } + + const SizeT Capacity() + { + return N; + } + + const SizeT Count() + { + return N; + } + + const T* CData() + { + return fArray; + } + + operator bool() + { + return !Empty(); + } + + private: + T fArray[N]; + }; + + template <typename ValueType> + auto make_list(ValueType val) + { + return CFArray<ValueType, ARRAY_SIZE(val)>{val}; + } +} // namespace Kernel diff --git a/dev/Usr/LibCF/Property.h b/dev/Usr/LibCF/Property.h new file mode 100644 index 00000000..629dba27 --- /dev/null +++ b/dev/Usr/LibCF/Property.h @@ -0,0 +1,53 @@ +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal EL Mahrouss, all rights reserved. + +------------------------------------------- */ + +#ifndef CFKIT_PROPS_H +#define CFKIT_PROPS_H + +#include <LibSCI/SCI.h> +#include <LibCF/Ref.h> + +#define kMaxPropLen (256U) + +namespace LibCF +{ + class CFString; + class CFProperty; + class CFGUID; + + template<typename Cls, SizeT N> + class CFArray; + + /// @brief handle to anything (number, ptr, string...) + using CFPropertyId = UIntPtr; + + /// @brief User property class. + /// @example /prop/foo or /prop/bar + class CFProperty + { + public: + CFProperty(); + virtual ~CFProperty(); + + public: + CFProperty& operator=(const CFProperty&) = default; + CFProperty(const CFProperty&) = default; + + Bool StringEquals(CFString& name); + CFPropertyId& GetValue(); + CFString& GetKey(); + + private: + CFString* fName{nullptr}; + CFPropertyId fValue{0UL}; + Ref<CFGUID> fGUID{}; + }; + + template <SizeT N> + using CFPropertyArray = CFArray<CFProperty, N>; +} // namespace CFKit + +#endif // !CFKIT_PROPS_H diff --git a/dev/Usr/LibCF/Ref.h b/dev/Usr/LibCF/Ref.h new file mode 100644 index 00000000..faad67c5 --- /dev/null +++ b/dev/Usr/LibCF/Ref.h @@ -0,0 +1,106 @@ + +/* ------------------------------------------- + + Copyright (C) 2024-2025, Amlal EL Mahrouss, all rights reserved. + +------------------------------------------- */ + +#ifndef _NEWKIT_REF_H_ +#define _NEWKIT_REF_H_ + +#include <LibSCI/SCI.h> + +namespace LibCF +{ + template <typename T> + class Ref final + { + public: + Ref() = default; + + ~Ref() + { + if (MmGetHeapFlags(fClass) != -1) + delete fClass; + } + + public: + Ref(T* cls) + : fClass(cls) + { + } + + Ref(T cls) + : fClass(&cls) + { + } + + Ref& operator=(T ref) + { + if (!fClass) + return *this; + + fClass = &ref; + return *this; + } + + public: + T operator->() const + { + MUST_PASS(*fClass); + return *fClass; + } + + T& Leak() noexcept + { + return *fClass; + } + + T& TryLeak() const noexcept + { + MUST_PASS(*fClass); + return *fClass; + } + + T operator*() + { + return *fClass; + } + + operator bool() noexcept + { + return fClass; + } + + private: + T* fClass{nullptr}; + }; + + template <typename T> + class NonNullRef final + { + public: + NonNullRef() = delete; + NonNullRef(nullPtr) = delete; + + NonNullRef(T* ref) + : fRef(ref) + { + MUST_PASS(ref); + } + + Ref<T>& operator->() + { + MUST_PASS(fRef); + return fRef; + } + + NonNullRef& operator=(const NonNullRef<T>& ref) = delete; + NonNullRef(const NonNullRef<T>& ref) = default; + + private: + Ref<T> fRef{nullptr}; + }; +} // namespace Kernel + +#endif // ifndef _NEWKIT_REF_H_ |
