QWT API (中文) 7.3.0
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
qwt3d_autoptr.h
1#ifndef QWT3D_AUTOPTR_H
2#define QWT3D_AUTOPTR_H
3
4
5
16template< typename T >
18{
19public:
20 // Standard ctor
21 explicit Qwt3DClonePtr(T* ptr = nullptr) : rawptr_(ptr)
22 {
23 }
24 // Dtor (calls T::destroy)
26 {
27 destroyRawPtr();
28 }
29
30 // Copy ctor (calls (virtual) clone())
32 {
33 rawptr_ = val.rawptr_->clone();
34 }
35
36 // Assignment in the same spirit as copy ctor
37 Qwt3DClonePtr< T >& operator=(Qwt3DClonePtr const& val)
38 {
39 if (this == &val)
40 return *this;
41
42 destroyRawPtr();
43 rawptr_ = val.rawptr_->clone();
44
45 return *this;
46 }
47
48 // Pointer-like access operator
49 T* operator->() const
50 {
51 return rawptr_;
52 }
53
54 // Dereferencing operator
55 T& operator*() const
56 {
57 return *rawptr_;
58 }
59
60private:
61 T* rawptr_;
62 void destroyRawPtr()
63 {
64 if (rawptr_)
65 rawptr_->destroy();
66 rawptr_ = nullptr;
67 }
68};
69
70
71#endif // QWT3D_AUTOPTR_H
Simple auto pointer providing deep copies for raw pointer
Definition qwt3d_autoptr.h:18