QWT API (中文) 7.0.1
Qt绘图库 - 中文API文档
载入中...
搜索中...
未找到
qwt3d_autoptr.h
1#ifndef qwt3d_autoptr_h
2#define qwt3d_autoptr_h
3
4namespace Qwt3D {
5
29template<typename T>
31{
32public:
33 // Standard ctor
34 explicit qwt3d_ptr(T *ptr = 0) : rawptr_(ptr) { }
35 // Dtor (calls T::destroy)
36 ~qwt3d_ptr() { destroyRawPtr(); }
37
38 // Copy ctor (calls (virtual) clone())
39 qwt3d_ptr(qwt3d_ptr const &val) { rawptr_ = val.rawptr_->clone(); }
40
41 // Assignment in the same spirit as copy ctor
42 qwt3d_ptr<T> &operator=(qwt3d_ptr const &val)
43 {
44 if (this == &val)
45 return *this;
46
47 destroyRawPtr();
48 rawptr_ = val.rawptr_->clone();
49
50 return *this;
51 }
52
53 // Pointer-like access operator
54 T *operator->() const { return rawptr_; }
55
56 // Dereferencing operator
57 T &operator*() const { return *rawptr_; }
58
59private:
60 T *rawptr_;
61 void destroyRawPtr()
62 {
63 if (rawptr_)
64 rawptr_->destroy();
65 rawptr_ = 0;
66 }
67};
68
69} // ns
70
71#endif /* include guarded */
提供原始指针深拷贝的简单自动指针
Definition qwt3d_autoptr.h:31