diff options
| author | Amlal <amlal@nekernel.org> | 2025-04-25 13:08:33 +0200 |
|---|---|---|
| committer | Amlal <amlal@nekernel.org> | 2025-04-25 13:08:33 +0200 |
| commit | fb790b07aeba8e22e4190cf3e1834d11ecde6c96 (patch) | |
| tree | 4cec7d1b321307b1d5935577631dae116a658a37 /public/frameworks/CoreFoundation.fwrk | |
| parent | 63a2d92c5dfe976175cda024ec01905d11b43738 (diff) | |
dev: better .clang-format, ran format command.
Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'public/frameworks/CoreFoundation.fwrk')
8 files changed, 254 insertions, 331 deletions
diff --git a/public/frameworks/CoreFoundation.fwrk/headers/Array.h b/public/frameworks/CoreFoundation.fwrk/headers/Array.h index e9a36ac4..0b4a8dbf 100644 --- a/public/frameworks/CoreFoundation.fwrk/headers/Array.h +++ b/public/frameworks/CoreFoundation.fwrk/headers/Array.h @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ @@ -8,64 +8,45 @@ #include <user/SystemCalls.h> -namespace CF -{ - 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[](SizeT at) - { - MUST_PASS(at < this->Count()); - return fArray[at]; - } - - Bool Empty() - { - return this->Count() > 0; - } - - SizeT Capacity() - { - return N; - } - - SizeT Count() - { - auto cnt = 0UL; - - for (auto i = 0UL; i < N; ++i) - { - if (fArray[i]) - ++cnt; - } - - return cnt; - } - - const T* CData() - { - return fArray; - } - - operator bool() - { - return !Empty(); - } - - private: - T fArray[N] = {nullptr}; - }; - - template <typename ValueType> - auto make_array(ValueType val) - { - return CFArray<ValueType, ARRAY_SIZE(val)>{val}; - } -} // namespace CF +namespace CF { +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[](SizeT at) { + MUST_PASS(at < this->Count()); + return fArray[at]; + } + + Bool Empty() { return this->Count() > 0; } + + SizeT Capacity() { return N; } + + SizeT Count() { + auto cnt = 0UL; + + for (auto i = 0UL; i < N; ++i) { + if (fArray[i]) ++cnt; + } + + return cnt; + } + + const T* CData() { return fArray; } + + operator bool() { return !Empty(); } + + private: + T fArray[N] = {nullptr}; +}; + +template <typename ValueType> +auto make_array(ValueType val) { + return CFArray<ValueType, ARRAY_SIZE(val)>{val}; +} +} // namespace CF diff --git a/public/frameworks/CoreFoundation.fwrk/headers/Atom.h b/public/frameworks/CoreFoundation.fwrk/headers/Atom.h index 923d6bce..f279f0b1 100644 --- a/public/frameworks/CoreFoundation.fwrk/headers/Atom.h +++ b/public/frameworks/CoreFoundation.fwrk/headers/Atom.h @@ -1,47 +1,33 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ #pragma once #include <CoreFoundation.fwrk/headers/Foundation.h> -namespace CF -{ - template <typename T> - class CFAtom final - { - public: - explicit CFAtom() = default; - ~CFAtom() = default; - - public: - CFAtom& operator=(const CFAtom&) = delete; - CFAtom(const CFAtom&) = delete; - - public: - T operator[](SizeT bit) - { - return (fArrayOfAtoms & (1 << bit)); - } - - void operator|(SizeT bit) - { - fArrayOfAtoms |= (1 << bit); - } - - friend Boolean operator==(CFAtom<T>& atomic, const T& idx) - { - return atomic[idx] == idx; - } - - friend Boolean operator!=(CFAtom<T>& atomic, const T& idx) - { - return atomic[idx] == idx; - } - - private: - T fArrayOfAtoms; - }; -} // namespace CF +namespace CF { +template <typename T> +class CFAtom final { + public: + explicit CFAtom() = default; + ~CFAtom() = default; + + public: + CFAtom& operator=(const CFAtom&) = delete; + CFAtom(const CFAtom&) = delete; + + public: + T operator[](SizeT bit) { return (fArrayOfAtoms & (1 << bit)); } + + void operator|(SizeT bit) { fArrayOfAtoms |= (1 << bit); } + + friend Boolean operator==(CFAtom<T>& atomic, const T& idx) { return atomic[idx] == idx; } + + friend Boolean operator!=(CFAtom<T>& atomic, const T& idx) { return atomic[idx] == idx; } + + private: + T fArrayOfAtoms; +}; +} // namespace CF diff --git a/public/frameworks/CoreFoundation.fwrk/headers/Foundation.h b/public/frameworks/CoreFoundation.fwrk/headers/Foundation.h index b1c37635..194b7bb7 100644 --- a/public/frameworks/CoreFoundation.fwrk/headers/Foundation.h +++ b/public/frameworks/CoreFoundation.fwrk/headers/Foundation.h @@ -1,10 +1,10 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. - FILE: Foundation.h - PURPOSE: Foundation header of the CF framework. + FILE: Foundation.h + PURPOSE: Foundation header of the CF framework. ------------------------------------------- */ @@ -12,68 +12,64 @@ #include <user/SystemCalls.h> -namespace CF -{ - class CFString; - class CFGUID; - class CFProperty; - class CFObject; +namespace CF { +class CFString; +class CFGUID; +class CFProperty; +class CFObject; - template <typename T> - class CFRef; - class CFFont; - struct CFPoint; - struct CFRect; - struct CFColor; +template <typename T> +class CFRef; +class CFFont; +struct CFPoint; +struct CFRect; +struct CFColor; #ifndef __LP64__ - typedef SInt32 CFInteger; - typedef float CFReal; +typedef SInt32 CFInteger; +typedef float CFReal; #else - typedef SInt64 CFInteger; - typedef double CFReal; +typedef SInt64 CFInteger; +typedef double CFReal; #endif - typedef SInt32 CFInteger32; - typedef SInt64 CFInteger64; +typedef SInt32 CFInteger32; +typedef SInt64 CFInteger64; - typedef Char CFChar8; - typedef char16_t CFChar16; +typedef Char CFChar8; +typedef char16_t CFChar16; - struct CFPoint - { - CFInteger64 x_1{0UL}; - CFInteger64 y_1{0UL}; +struct CFPoint { + CFInteger64 x_1{0UL}; + CFInteger64 y_1{0UL}; - CFInteger64 x_2{0UL}; - CFInteger64 y_2{0UL}; - CFReal ang{0UL}; + CFInteger64 x_2{0UL}; + CFInteger64 y_2{0UL}; + CFReal ang{0UL}; - operator bool(); + operator bool(); - /// @brief Check if point is within the current CFPoint. - /// @param point the current point to check. - /// @retval true if point is within this point. - /// @retval validations failed. - bool IsWithin(CFPoint& point); - }; + /// @brief Check if point is within the current CFPoint. + /// @param point the current point to check. + /// @retval true if point is within this point. + /// @retval validations failed. + bool IsWithin(CFPoint& point); +}; - struct CFColor final - { - CFInteger64 r, g, b, a{0}; - }; +struct CFColor final { + CFInteger64 r, g, b, a{0}; +}; - struct CFRect final - { - CFInteger64 x{0UL}; - CFInteger64 y{0UL}; +struct CFRect final { + CFInteger64 x{0UL}; + CFInteger64 y{0UL}; - CFInteger64 width{0UL}; - CFInteger64 height{0UL}; + CFInteger64 width{0UL}; + CFInteger64 height{0UL}; - operator bool(); + operator bool(); - BOOL SizeMatches(CFRect& rect) noexcept; - BOOL PositionMatches(CFRect& rect) noexcept; - }; -} // namespace CF
\ No newline at end of file + BOOL SizeMatches(CFRect& rect) noexcept; + BOOL PositionMatches(CFRect& rect) noexcept; +}; +} // namespace CF
\ No newline at end of file diff --git a/public/frameworks/CoreFoundation.fwrk/headers/Object.h b/public/frameworks/CoreFoundation.fwrk/headers/Object.h index 733512b1..1692f20e 100644 --- a/public/frameworks/CoreFoundation.fwrk/headers/Object.h +++ b/public/frameworks/CoreFoundation.fwrk/headers/Object.h @@ -1,7 +1,7 @@ /* ------------------------------------------- - Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ @@ -11,16 +11,14 @@ #define CF_OBJECT : public CF::CFObject -namespace CF -{ - class CFObject; +namespace CF { +class CFObject; - class CFObject - { - public: - explicit CFObject() = default; - virtual ~CFObject() = default; +class CFObject { + public: + explicit CFObject() = default; + virtual ~CFObject() = default; - SCI_COPY_DEFAULT(CFObject); - }; -} // namespace CF
\ No newline at end of file + SCI_COPY_DEFAULT(CFObject); +}; +} // namespace CF
\ No newline at end of file diff --git a/public/frameworks/CoreFoundation.fwrk/headers/Property.h b/public/frameworks/CoreFoundation.fwrk/headers/Property.h index b999c54e..58e881e5 100644 --- a/public/frameworks/CoreFoundation.fwrk/headers/Property.h +++ b/public/frameworks/CoreFoundation.fwrk/headers/Property.h @@ -1,53 +1,51 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ #ifndef _PROPS_H #define _PROPS_H -#include <user/SystemCalls.h> #include <CoreFoundation.fwrk/headers/Ref.h> +#include <user/SystemCalls.h> #define kMaxPropLen (256U) -namespace CF -{ - 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 final CF_OBJECT - { - 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 CF - -#endif // !CFKIT_PROPS_H +namespace CF { +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 final CF_OBJECT { + 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 CF + +#endif // !CFKIT_PROPS_H diff --git a/public/frameworks/CoreFoundation.fwrk/headers/Ref.h b/public/frameworks/CoreFoundation.fwrk/headers/Ref.h index 2a4ec452..c18c6161 100644 --- a/public/frameworks/CoreFoundation.fwrk/headers/Ref.h +++ b/public/frameworks/CoreFoundation.fwrk/headers/Ref.h @@ -1,110 +1,81 @@ /* ------------------------------------------- - Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ #ifndef _REF_H_ #define _REF_H_ -#include <user/SystemCalls.h> #include <CoreFoundation.fwrk/headers/Object.h> +#include <user/SystemCalls.h> + +namespace CF { +template <typename T> +class CFRef; + +template <typename T> +class CFRef final CF_OBJECT { + public: + CFRef() = default; + + ~CFRef() { + if (MmGetHeapFlags(fClass) != -1) delete fClass; + } + + public: + CFRef(T* cls) : fClass(cls) {} + + CFRef(T cls) : fClass(&cls) {} + + CFRef& 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 CFNonNullRef final { + public: + CFNonNullRef() = delete; + CFNonNullRef(nullPtr) = delete; + + CFNonNullRef(T* ref) : fRef(ref) { MUST_PASS(ref); } + + CFRef<T>& operator->() { + MUST_PASS(fRef); + return fRef; + } + + CFNonNullRef& operator=(const CFNonNullRef<T>& ref) = delete; + CFNonNullRef(const CFNonNullRef<T>& ref) = default; + + private: + CFRef<T> fRef{nullptr}; +}; +} // namespace CF -namespace CF -{ - template <typename T> - class CFRef; - - template <typename T> - class CFRef final CF_OBJECT - { - public: - CFRef() = default; - - ~CFRef() - { - if (MmGetHeapFlags(fClass) != -1) - delete fClass; - } - - public: - CFRef(T* cls) - : fClass(cls) - { - } - - CFRef(T cls) - : fClass(&cls) - { - } - - CFRef& 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 CFNonNullRef final - { - public: - CFNonNullRef() = delete; - CFNonNullRef(nullPtr) = delete; - - CFNonNullRef(T* ref) - : fRef(ref) - { - MUST_PASS(ref); - } - - CFRef<T>& operator->() - { - MUST_PASS(fRef); - return fRef; - } - - CFNonNullRef& operator=(const CFNonNullRef<T>& ref) = delete; - CFNonNullRef(const CFNonNullRef<T>& ref) = default; - - private: - CFRef<T> fRef{nullptr}; - }; -} // namespace CF - -#endif // ifndef _NEWKIT_REF_H_ +#endif // ifndef _NEWKIT_REF_H_ diff --git a/public/frameworks/CoreFoundation.fwrk/headers/String.h b/public/frameworks/CoreFoundation.fwrk/headers/String.h index e420ac91..c28c05cd 100644 --- a/public/frameworks/CoreFoundation.fwrk/headers/String.h +++ b/public/frameworks/CoreFoundation.fwrk/headers/String.h @@ -1,7 +1,7 @@ /* ------------------------------------------- - Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. ------------------------------------------- */ @@ -9,12 +9,10 @@ #include <CoreFoundation.fwrk/headers/Object.h> -namespace CF -{ - class CFString; +namespace CF { +class CFString; - class CFString final CF_OBJECT - { - public: - }; -} // namespace CF
\ No newline at end of file +class CFString final CF_OBJECT { + public: +}; +} // namespace CF
\ No newline at end of file diff --git a/public/frameworks/CoreFoundation.fwrk/src/Foundation.cc b/public/frameworks/CoreFoundation.fwrk/src/Foundation.cc index 89adf665..a4b84abf 100644 --- a/public/frameworks/CoreFoundation.fwrk/src/Foundation.cc +++ b/public/frameworks/CoreFoundation.fwrk/src/Foundation.cc @@ -1,6 +1,6 @@ /* ------------------------------------------- - Copyright (C) 2024 Amlal El Mahrouss, all rights reserved + Copyright (C) 2024 Amlal El Mahrouss, all rights reserved ------------------------------------------- */ @@ -9,25 +9,22 @@ /***********************************************************************************/ /// @brief returns true if the proportions are valid. /***********************************************************************************/ -CF::CFRect::operator bool() -{ - return width > 0 && height > 0; +CF::CFRect::operator bool() { + return width > 0 && height > 0; } /***********************************************************************************/ /// @brief returns true if size matches. /***********************************************************************************/ -BOOL CF::CFRect::SizeMatches(CF::CFRect& rect) noexcept -{ - return rect.height == height && rect.width == width; +BOOL CF::CFRect::SizeMatches(CF::CFRect& rect) noexcept { + return rect.height == height && rect.width == width; } /***********************************************************************************/ /// @brief returns true if position matches. /***********************************************************************************/ -BOOL CF::CFRect::PositionMatches(CF::CFRect& rect) noexcept -{ - return rect.y == y && rect.x == x; +BOOL CF::CFRect::PositionMatches(CF::CFRect& rect) noexcept { + return rect.y == y && rect.x == x; } /***********************************************************************************/ @@ -36,16 +33,14 @@ BOOL CF::CFRect::PositionMatches(CF::CFRect& rect) noexcept /// @retval true if point is within this point. /// @retval the validations have failed, false otherwise true. /***********************************************************************************/ -BOOL CF::CFPoint::IsWithin(CF::CFPoint& withinOf) -{ - return x_1 >= withinOf.x_1 && x_2 <= (withinOf.x_2) && - y_1 >= withinOf.y_1 && y_2 <= (withinOf.y_2); +BOOL CF::CFPoint::IsWithin(CF::CFPoint& withinOf) { + return x_1 >= withinOf.x_1 && x_2 <= (withinOf.x_2) && y_1 >= withinOf.y_1 && + y_2 <= (withinOf.y_2); } /***********************************************************************************/ /// @brief if Point object is correctly set up. /***********************************************************************************/ -CF::CFPoint::operator bool() -{ - return x_1 > x_2 && y_1 > y_2; +CF::CFPoint::operator bool() { + return x_1 > x_2 && y_1 > y_2; }
\ No newline at end of file |
