FCT
载入中...
搜索中...
未找到
SharePtr.h
浏览该文件的文档.
1//
2// Created by Administrator on 2025/5/7.
3//
4
5#ifndef SHAREPTR_H
6#define SHAREPTR_H
7#include "./RefCount.h"
8namespace FCT {
9template<typename T>
11 private:
12 static constexpr bool test(const RefCount*) { return true; }
13 static constexpr bool test(...) { return false; }
14 public:
15 static constexpr bool ret = test(static_cast<T*>(nullptr));
16 };
17 template<typename T,bool isRefCountBase = IsRefCountBase<T>::ret>
19 public:
20 void addRef() {
21
22 }
23 void release() {
24
25 }
26 private:
27 T* ptr;
28 };
29 template<typename T>
30 class RefCountPolicy<T,false> {
31 public:
32 void addRef() {
33
34 }
35 void release() {
36
37 }
38 private:
39
40 };
41 template<typename T>
42 class SharePtr{
43 private:
46 public:
47 SharePtr(T* ptr) : m_ptr(ptr)
48 {
49
50 }
52 m_policy.release();
53 }
54 SharePtr(const SharePtr& other) : m_ptr(other.m_ptr), m_policy(other.m_policy)
55 {
56 m_policy.addRef();
57 }
59 {
60 if (this!= &other) {
61 m_policy.release();
62 m_ptr = other.m_ptr;
63 m_policy = other.m_policy;
64 m_policy.addRef();
65 }
66 return *this;
67 }
68 T& operator*() const {
69 return *m_ptr;
70 }
71 T* operator->() const {
72 return m_ptr;
73 }
74 };
75 template<typename T>
76 class WeakPtr
77 {
78 private:
81 public:
82 WeakPtr(const SharePtr<T>& other) : m_ptr(other.m_ptr), m_policy(other.m_policy)
83 {
84
85 }
86 bool expired() const
87 {
88
89 }
90 operator bool() const
91 {
92
93 }
94 };
95 /*
96 template<template T,typename... Args>
97 SharePtr<T> MakeShared(Args&&... args) {
98 return SharePtr<T>(FCT_NEW(T,std::forward<Args>(args)...));
99 }*/
100}
101#endif //SHAREPTR_H
RefCountPolicy< T > m_policy
SharePtr(const SharePtr &other)
SharePtr & operator=(const SharePtr &other)
T * operator->() const
T & operator*() const
RefCountPolicy< T > m_policy
WeakPtr(const SharePtr< T > &other)
bool expired() const
static constexpr bool test(...)
static constexpr bool test(const RefCount *)
static constexpr bool ret