DocumentationOverviewBuilding ASL Documentation Library Wiki Docs Indices Browse Perforce More InfoRelease NotesWiki Site Search License Success Stories Contributors MediaDownloadPerforce Depots SupportASL SourceForge HomeMailing Lists Discussion Forums Report Bugs Suggest Features Contribute to ASL RSSShort-text newsFull-text news File releases Other Adobe ProjectsAdobe AirAdobe GIL Adobe Labs Adobe Media Gallery Adobe XMP Tamarin project (Mozilla Foundation) Other ResourcesBoostRIAForge SGI STL |
dng_auto_ptr.hGo to the documentation of this file.00001 /*****************************************************************************/ 00002 // Copyright 2006 Adobe Systems Incorporated 00003 // All Rights Reserved. 00004 // 00005 // NOTICE: Adobe permits you to use, modify, and distribute this file in 00006 // accordance with the terms of the Adobe license agreement accompanying it. 00007 /*****************************************************************************/ 00008 00009 /* $Id: //mondo/workarea/stern/camera_raw/dng_sdk/source/dng_auto_ptr.h#6 $ */ 00010 /* $DateTime: 2006/04/18 23:24:08 $ */ 00011 /* $Change: 217478 $ */ 00012 /* $Author: stern $ */ 00013 00018 /*****************************************************************************/ 00019 00020 #ifndef __dng_auto_ptr__ 00021 #define __dng_auto_ptr__ 00022 00023 /*****************************************************************************/ 00024 00025 // The following template has similar functionality to the STL auto_ptr, 00026 // without requiring all the weight of STL. 00027 00028 /*****************************************************************************/ 00029 00031 00032 template<class T> 00033 class AutoPtr 00034 { 00035 00036 private: 00037 00038 T *p_; 00039 00040 public: 00041 00043 00044 AutoPtr () : p_ (0) { } 00045 00048 00049 explicit AutoPtr (T *p) : p_( p ) { } 00050 00052 00053 ~AutoPtr (); 00054 00056 00057 void Alloc (); 00058 00060 00061 T *Get () const { return p_; } 00062 00064 00065 T *Release (); 00066 00068 00069 void Reset (T *p); 00070 00072 00073 void Reset (); 00074 00076 00077 T *operator-> () const { return p_; } 00078 00080 00081 T &operator* () const { return *p_; } 00082 00083 private: 00084 00085 // Hidden copy constructor and assignment operator. I don't 00086 // think the STL "feature" of grabbing ownership of the pointer 00087 // is a good idea. 00088 00089 AutoPtr (AutoPtr<T> &rhs); 00090 00091 AutoPtr<T> & operator= (AutoPtr<T> &rhs); 00092 00093 }; 00094 00095 /*****************************************************************************/ 00096 00097 template<class T> 00098 AutoPtr<T>::~AutoPtr () 00099 { 00100 00101 delete p_; 00102 p_ = 0; 00103 00104 } 00105 00106 /*****************************************************************************/ 00107 00108 template<class T> 00109 T *AutoPtr<T>::Release () 00110 { 00111 T *result = p_; 00112 p_ = 0; 00113 return result; 00114 } 00115 00116 /*****************************************************************************/ 00117 00118 template<class T> 00119 void AutoPtr<T>::Reset (T *p) 00120 { 00121 00122 if (p_ != p) 00123 { 00124 if (p_ != 0) 00125 delete p_; 00126 p_ = p; 00127 } 00128 00129 } 00130 00131 /*****************************************************************************/ 00132 00133 template<class T> 00134 void AutoPtr<T>::Reset () 00135 { 00136 00137 if (p_ != 0) 00138 { 00139 delete p_; 00140 p_ = 0; 00141 } 00142 00143 } 00144 00145 /*****************************************************************************/ 00146 00147 template<class T> 00148 void AutoPtr<T>::Alloc () 00149 { 00150 this->Reset (new T); 00151 } 00152 00153 /*****************************************************************************/ 00154 00155 #endif 00156 00157 /*****************************************************************************/ |