ACF $AcfVersion:0$
TSmartPtr.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// STD includes
6#include <memory>
7
8// ACF includes
9#include <istd/TTransPtr.h>
10
11
12namespace istd
13{
14
15
20template <class Type>
21class TSmartPtr: public TTransPtr<Type>
22{
23public:
25
26 explicit TSmartPtr(Type* pointer);
27
29
30 void SetPtr(Type* pointer);
31 bool operator==(const TSmartPtr& other) const;
32
37 template <class SourceType>
38 bool SetCastedOrRemove(SourceType* pointer)
39 {
40 Type* castedPtr = dynamic_cast<Type*>(pointer);
41
42 SetPtr(castedPtr);
43
44 if (castedPtr != NULL){
45 return true;
46 }
47 else{
48 if (pointer != NULL){
49 delete pointer;
50 }
51
52 return false;
53 }
54 }
55
56 using TTransPtr<Type>::m_impl;
57};
58
59
60template <class Type>
62{
63}
64
65
66template <class Type>
67inline TSmartPtr<Type>::TSmartPtr(Type* pointer)
68{
69 m_impl.reset(pointer);
70}
71
72
73template<class Type>
75{
76 m_impl = trans.m_impl;
77}
78
79
80template <class Type>
81inline void TSmartPtr<Type>::SetPtr(Type* pointer)
82{
83 m_impl.reset(pointer);
84}
85
86
87template <class Type>
88inline bool TSmartPtr<Type>::operator==(const TSmartPtr<Type>& other) const
89{
90 return this->GetPtr() == other.GetPtr();
91}
92
93
94} // namespace istd
95
96
97
98
TSmartPtr(const TTransPtr< Type > &trans)
Definition TSmartPtr.h:74
bool operator==(const TSmartPtr &other) const
Definition TSmartPtr.h:88
void SetPtr(Type *pointer)
Definition TSmartPtr.h:81
bool SetCastedOrRemove(SourceType *pointer)
Set this pointer using casted pointer of other type.
Definition TSmartPtr.h:38
TSmartPtr(Type *pointer)
Definition TSmartPtr.h:67
Implementation of data transfer smart pointer.
Definition TTransPtr.h:22
const Type * GetPtr() const
Get access to pointed object.
Definition TTransPtr.h:80
QSharedPointer< Type > m_impl
Definition TTransPtr.h:63
#define NULL
Definition istd.h:74
Standard library.
Definition IComponent.h:17