|
Last change
on this file since 93 was 89, checked in by morasjul, 12 years ago |
|
PACPUS 2.0 Beta deployed in new branch
Major changes:
-Add communication interface between components
-Add examples for communications interface (TestComponents)
-Move to Qt5 support
|
-
Property svn:executable
set to
*
|
|
File size:
1.5 KB
|
| Line | |
|---|
| 1 | #ifndef qwt3d_autoptr_h__2004_05_14_18_57_begin_guarded_code
|
|---|
| 2 | #define qwt3d_autoptr_h__2004_05_14_18_57_begin_guarded_code
|
|---|
| 3 |
|
|---|
| 4 | namespace Qwt3D
|
|---|
| 5 | {
|
|---|
| 6 |
|
|---|
| 7 | //! Simple Auto pointer providing deep copies for raw pointer
|
|---|
| 8 | /*!
|
|---|
| 9 | Requirements: \n
|
|---|
| 10 | virtual T* T::clone() const;\n
|
|---|
| 11 | T::destroy() const;
|
|---|
| 12 | virtual ~T() private/protected\n\n
|
|---|
| 13 | clone() is necessary for the pointer to preserve polymorphic behaviour.
|
|---|
| 14 | The pointer requires also heap based objects with regard to the template
|
|---|
| 15 | argument in order to be able to get ownership and control over destruction.
|
|---|
| 16 | */
|
|---|
| 17 | template <typename T>
|
|---|
| 18 | class qwt3d_ptr
|
|---|
| 19 | {
|
|---|
| 20 | public:
|
|---|
| 21 | //! Standard ctor
|
|---|
| 22 | explicit qwt3d_ptr(T* ptr = 0)
|
|---|
| 23 | :rawptr_(ptr)
|
|---|
| 24 | {
|
|---|
| 25 | }
|
|---|
| 26 | //! Dtor (calls T::destroy)
|
|---|
| 27 | ~qwt3d_ptr()
|
|---|
| 28 | {
|
|---|
| 29 | destroyRawPtr();
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 | //! Copy ctor (calls (virtual) clone())
|
|---|
| 33 | qwt3d_ptr(qwt3d_ptr const& val)
|
|---|
| 34 | {
|
|---|
| 35 | rawptr_ = val.rawptr_->clone();
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | //! Assignment in the same spirit as copy ctor
|
|---|
| 39 | qwt3d_ptr<T>& operator=(qwt3d_ptr const& val)
|
|---|
| 40 | {
|
|---|
| 41 | if (this == &val)
|
|---|
| 42 | return *this;
|
|---|
| 43 |
|
|---|
| 44 | destroyRawPtr();
|
|---|
| 45 | rawptr_ = val.rawptr_->clone();
|
|---|
| 46 |
|
|---|
| 47 | return *this;
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | //! It's a pointerlike object, isn't it ?
|
|---|
| 51 | T* operator->() const
|
|---|
| 52 | {
|
|---|
| 53 | return rawptr_;
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | //! Dereferencing
|
|---|
| 57 | T& operator*() const
|
|---|
| 58 | {
|
|---|
| 59 | return *rawptr_;
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 | private:
|
|---|
| 64 | T* rawptr_;
|
|---|
| 65 | void destroyRawPtr()
|
|---|
| 66 | {
|
|---|
| 67 | if (rawptr_)
|
|---|
| 68 | rawptr_->destroy();
|
|---|
| 69 | rawptr_ = 0;
|
|---|
| 70 | }
|
|---|
| 71 | };
|
|---|
| 72 |
|
|---|
| 73 | } // ns
|
|---|
| 74 |
|
|---|
| 75 | #endif /* include guarded */
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.