| 76 | |
| 77 | template <class Type> |
| 78 | class DUChainPointer |
| 79 | { |
| 80 | template <class OtherType> |
| 81 | friend class DUChainPointer; |
| 82 | |
| 83 | public: |
| 84 | DUChainPointer() : d(QExplicitlySharedDataPointer<DUChainPointerData>(nullptr)) |
| 85 | { |
| 86 | } |
| 87 | |
| 88 | DUChainPointer(const DUChainPointer&) = default; |
| 89 | DUChainPointer(DUChainPointer&&) = default; |
| 90 | |
| 91 | ///This constructor includes dynamic casting. If the object cannot be casted to the type, the constructed DUChainPointer will have value zero. |
| 92 | template <class OtherType> |
| 93 | explicit DUChainPointer(OtherType* rhs) |
| 94 | { |
| 95 | if (dynamic_cast<Type*>(rhs)) |
| 96 | d = rhs->weakPointer(); |
| 97 | } |
| 98 | |
| 99 | template <class OtherType> |
| 100 | explicit DUChainPointer(DUChainPointer<OtherType> rhs) |
| 101 | { |
| 102 | if (dynamic_cast<Type*>(rhs.data())) |
| 103 | d = rhs.d; |
| 104 | } |
| 105 | |
| 106 | explicit DUChainPointer(QExplicitlySharedDataPointer<DUChainPointerData> rhs) |
| 107 | { |
| 108 | if (dynamic_cast<Type*>(rhs->base())) |
| 109 | d = rhs; |
| 110 | } |
| 111 | |
| 112 | explicit DUChainPointer(Type* rhs) |
| 113 | { |
| 114 | if (rhs) |
| 115 | d = rhs->weakPointer(); |
| 116 | } |
| 117 | |
| 118 | ~DUChainPointer() = default; |
| 119 | |
| 120 | bool operator ==(const DUChainPointer<Type>& rhs) const |
| 121 | { |
| 122 | return d.data() == rhs.d.data(); |
| 123 | } |
| 124 | |
| 125 | bool operator !=(const DUChainPointer<Type>& rhs) const |
| 126 | { |
| 127 | return d.data() != rhs.d.data(); |
| 128 | } |
| 129 | |
| 130 | ///Returns whether the pointed object is still existing |
| 131 | operator bool() const { |
| 132 | return d && d->base(); |
| 133 | } |
| 134 | |
| 135 | Type& operator*() const |