00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef OFAPTR_H
00031 #define OFAPTR_H
00032
00033 #include "dcmtk/config/osconfig.h"
00034
00035 #if defined(HAVE_STL) || defined(HAVE_STL_AUTO_PTR)
00036
00037 #include <memory>
00038 #define OFauto_ptr std::auto_ptr
00039
00040 #else
00041
00042 #define INCLUDE_CSTDDEF
00043 #include "dcmtk/ofstd/ofstdinc.h"
00044
00058 template <class T> class OFauto_ptr_ref
00059 {
00060 public:
00062 T *ptr;
00063
00067 explicit OFauto_ptr_ref(T* p) : ptr(p)
00068 {
00069 }
00070 };
00071
00076 template <class T> class OFauto_ptr
00077 {
00078 protected:
00080 T *ptr;
00081
00082 public:
00087 explicit OFauto_ptr(T* p = NULL) : ptr(p)
00088 {
00089 }
00090
00095 OFauto_ptr(OFauto_ptr<T>& other) : ptr(other.release())
00096 {
00097 }
00098
00102 OFauto_ptr(OFauto_ptr_ref<T> other) : ptr(other.ptr)
00103 {
00104 }
00105
00109 ~OFauto_ptr()
00110 {
00111 reset();
00112 }
00113
00118 void reset(T* p = NULL)
00119 {
00120 if (this->ptr)
00121 delete this->ptr;
00122 this->ptr = p;
00123 }
00124
00128 T* get() const { return this->ptr; }
00129
00133 T* operator->() const { return get(); }
00134
00138 T& operator*() const { return *get(); }
00139
00143 operator OFauto_ptr_ref<T>()
00144 {
00145 return OFauto_ptr_ref<T>(release());
00146 }
00147
00152 OFauto_ptr& operator=(OFauto_ptr<T>& other)
00153 {
00154 reset(other.release());
00155 return *this;
00156 }
00157
00162 OFauto_ptr& operator=(OFauto_ptr_ref<T> other)
00163 {
00164 reset(other.ptr);
00165 return *this;
00166 }
00167
00172 T* release()
00173 {
00174 T* tmp = this->ptr;
00175 this->ptr = NULL;
00176 return tmp;
00177 }
00178 };
00179
00180 #endif
00181
00182 #endif
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217