summaryrefslogtreecommitdiffhomepage
path: root/public/frameworks/CoreFoundation.fwrk/headers/Ref.h
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-03-23 19:13:48 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2025-03-23 19:15:17 +0100
commita13e1c0911c0627184bc38f18c7fdda64447b3ad (patch)
tree073a62c09bf216e85a3f310376640fa1805147f9 /public/frameworks/CoreFoundation.fwrk/headers/Ref.h
parent149fa096eb306d03686b3b67e813cf1a78e08cd0 (diff)
meta(kernel): Reworked repository's filesystem structure.
Removing useless parts of the project too. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'public/frameworks/CoreFoundation.fwrk/headers/Ref.h')
-rw-r--r--public/frameworks/CoreFoundation.fwrk/headers/Ref.h110
1 files changed, 110 insertions, 0 deletions
diff --git a/public/frameworks/CoreFoundation.fwrk/headers/Ref.h b/public/frameworks/CoreFoundation.fwrk/headers/Ref.h
new file mode 100644
index 00000000..074b5086
--- /dev/null
+++ b/public/frameworks/CoreFoundation.fwrk/headers/Ref.h
@@ -0,0 +1,110 @@
+
+/* -------------------------------------------
+
+ Copyright (C) 2024-2025, Amlal EL Mahrouss, all rights reserved.
+
+------------------------------------------- */
+
+#ifndef _REF_H_
+#define _REF_H_
+
+#include <SCIKit/SCI.h>
+#include <CoreFoundation.fwrk/headers/Object.h>
+
+namespace LibCF
+{
+ 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 LibCF
+
+#endif // ifndef _NEWKIT_REF_H_