00001
00002 #ifndef _hyp_std_smart_pointercom_h_
00003 #define _hyp_std_smart_pointercom_h_
00004
00005 #ifndef hyp_KERNEL_INSIDE
00006 #error Inclusion not allowed (include hyp.std.kernel.h instead)
00007 #endif
00008
00009
00010 #undef TRACE0
00011 #define TRACE0( args )
00012
00013 #undef ASSERT
00014 #define ASSERT( args ) hyp_ASSERT( args )
00015
00016
00017
00018
00025 template <class I>
00026 class CSmartInterface
00027 {
00028 public:
00029
00030 CSmartInterface(I* pI = NULL) ;
00031
00032
00033 CSmartInterface(const CSmartInterface<I>& rSI) ;
00034
00035
00036 ~CSmartInterface() ;
00037
00038
00039
00040
00041
00042
00043 CSmartInterface<I>& operator=(I* pI) ;
00044
00045
00046
00047
00048
00049
00050 operator I*() ;
00051
00052
00053 I* operator->() ;
00054
00055
00056 I** operator&() ;
00057
00058
00059 BOOL operator==(I* pI) const;
00060
00061
00062 BOOL operator!=(I* pI) const;
00063
00064
00065 BOOL operator!() const ;
00066
00067 #if 0
00068
00069
00070
00071 ULONG Release() ;
00072 #endif
00073
00074 protected:
00075 I* m_pI ;
00076 };
00077
00079
00080
00081
00082
00083
00084
00085
00086
00087 template <class I> inline
00088 CSmartInterface<I>::CSmartInterface(I* pI )
00089 : m_pI(pI)
00090 {
00091 TRACE0("SmartInterface Ctor\r\n") ;
00092 if (m_pI != NULL)
00093 {
00094
00095 m_pI->AddRef() ;
00096 }
00097 }
00098
00099
00100
00101
00102 template <class I> inline
00103 CSmartInterface<I>::CSmartInterface(const CSmartInterface<I>& rSI)
00104 : m_pI(rSI.m_pI)
00105 {
00106 if (m_pI != NULL)
00107 m_pI->AddRef() ;
00108 }
00109
00110
00111
00112
00113 template <class I> inline
00114 CSmartInterface<I>::~CSmartInterface()
00115 {
00116 TRACE0("SmartInterface Dtor\r\n") ;
00117 if (m_pI != NULL)
00118 {
00119 m_pI->Release();
00120 }
00121 }
00122
00123
00124
00125
00126 template <class I> inline
00127 CSmartInterface<I>& CSmartInterface<I>::operator=(I* pI)
00128 {
00129 TRACE0("Assignment from I*\r\n") ;
00130 if (m_pI != pI)
00131 {
00132 if (m_pI != NULL)
00133 m_pI->Release() ;
00134
00135 m_pI = pI ;
00136
00137 if (m_pI != NULL)
00138 m_pI->AddRef() ;
00139 }
00140 return *this ;
00141 }
00142
00143
00144
00145
00146
00147
00148 template <class I> inline
00149 CSmartInterface<I>::operator I*()
00150 {
00151 TRACE0("Conversion operator\r\n") ;
00152 return m_pI;
00153 }
00154
00155
00156
00157
00158 template <class I> inline
00159 I* CSmartInterface<I>::operator->()
00160 {
00161 TRACE0("operartor ->\r\n") ;
00162 ASSERT(m_pI != NULL) ;
00163 return m_pI ;
00164 }
00165
00166
00167
00168
00169 template <class I> inline
00170 I** CSmartInterface<I>::operator&()
00171 {
00172 TRACE0("operator & \r\n") ;
00173
00174 return &m_pI ;
00175 }
00176
00177
00178
00179
00180 template <class I> inline
00181 BOOL CSmartInterface<I>::operator==(I* pI) const
00182 {
00183 TRACE0("operator ==\r\n") ;
00184 return (m_pI == pI) ;
00185 }
00186
00187
00188
00189
00190 template <class I> inline
00191 BOOL CSmartInterface<I>::operator!=(I* pI) const
00192 {
00193 TRACE0("operator !=\r\n") ;
00194 return (m_pI != pI) ;
00195 }
00196
00197
00198
00199
00200 template <class I> inline
00201 BOOL CSmartInterface<I>::operator!() const
00202 {
00203 TRACE0("operator ! \r\n") ;
00204 return !m_pI ;
00205 }
00206
00207
00208
00209
00210 #if 0
00211
00212
00213
00214
00215
00216
00217 template <class I> inline
00218 ULONG CSmartInterface<I>::Release()
00219 {
00220
00221 TRACE0("Calling release shouldn't be needed????\r\n") ;
00222 m_pI->Release() ;
00223 m_pI = NULL ;
00224 }
00225 #endif // 0
00226
00228
00229
00230 #if 0
00231
00232 template <class I> inline
00233 CSmartInterface<I>& CSmartInterface<I>::operator=(IUnknown* pI)
00234 {
00235
00236
00237 TRACE0("Assignment from IUnknown*\r\n") ;
00238 if (m_pI != pI)
00239 {
00240 if (m_pI != NULL)
00241 m_pI->Release() ;
00242
00243 if (pIUnknown != NULL)
00244 pI->QueryInteface( , (void*)&
00245
00246 if (m_pI != NULL)
00247 m_pI->AddRef() ;
00248 }
00249 return *this ;
00250 }
00251 #endif
00252
00253 #endif