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
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00048 #ifndef COMSTL_INCL_COMSTL_SMARTPTR_HPP_INTERFACE_PTR
00049 #define COMSTL_INCL_COMSTL_SMARTPTR_HPP_INTERFACE_PTR
00050
00051 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00052 # define COMSTL_VER_COMSTL_SMARTPTR_HPP_INTERFACE_PTR_MAJOR 7
00053 # define COMSTL_VER_COMSTL_SMARTPTR_HPP_INTERFACE_PTR_MINOR 2
00054 # define COMSTL_VER_COMSTL_SMARTPTR_HPP_INTERFACE_PTR_REVISION 2
00055 # define COMSTL_VER_COMSTL_SMARTPTR_HPP_INTERFACE_PTR_EDIT 498
00056 #endif
00057
00058
00059
00060
00061
00062 #ifndef COMSTL_INCL_COMSTL_H_COMSTL
00063 # include <comstl/comstl.h>
00064 #endif
00065
00066 #ifdef STLSOFT_CF_PRAGMA_MESSAGE_SUPPORT
00067 # pragma message("This file (comstl/smartptr/interface_ptr.hpp) is now obsolete. Include stlsoft/smartptr/ref_ptr.hpp and use stlsoft::ref_ptr<>")
00068 #endif
00069
00070 #ifndef STLSOFT_INCL_STLSOFT_UTIL_HPP_OPERATOR_BOOL
00071 # include <stlsoft/util/operator_bool.hpp>
00072 #endif
00073 #ifndef STLSOFT_INCL_STLSOFT_SMARTPTR_HPP_REF_PTR
00074 # include <stlsoft/smartptr/ref_ptr.hpp>
00075 #endif
00076
00077
00078
00079
00080
00081 #ifndef _COMSTL_NO_NAMESPACE
00082 # if defined(_STLSOFT_NO_NAMESPACE) || \
00083 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00084
00085 namespace comstl
00086 {
00087 # else
00088
00089
00090 namespace stlsoft
00091 {
00092
00093 namespace comstl_project
00094 {
00095
00096 # endif
00097 #endif
00098
00099
00100
00101
00102
00109 template <ss_typename_param_k T>
00110 class interface_ptr
00111 : public stlsoft_ns_qual(ref_ptr)<T>
00112 {
00115 private:
00116 typedef stlsoft_ns_qual(ref_ptr)<T> parent_class_type;
00117 public:
00118 typedef interface_ptr<T> class_type;
00119
00120 typedef T value_type;
00121 typedef value_type* pointer;
00122 typedef value_type const* const_pointer;
00123 typedef value_type& reference;
00124 typedef value_type const& const_reference;
00126
00129 public:
00130 interface_ptr();
00131 interface_ptr(pointer p, cs_bool_t bAddRef);
00132 interface_ptr(reference r, cs_bool_t bAddRef);
00133 interface_ptr(class_type const& rhs);
00134 ~interface_ptr() stlsoft_throw_0();
00135
00136 class_type& operator =(class_type const& rhs);
00138
00141 public:
00142 void set(pointer p, cs_bool_t bAddRef);
00143 void set(reference r, cs_bool_t bAddRef);
00144 void release();
00145 void release(cs_bool_t bDecRef );
00146 pointer detach();
00147 void swap(class_type& rhs);
00149
00152 public:
00153 cs_bool_t operator ==(class_type const& rhs) const;
00154 cs_bool_t operator !=(class_type const& rhs) const;
00156
00159 private:
00160 STLSOFT_DEFINE_OPERATOR_BOOL_TYPES_T(class_type, operator_bool_generator_type, operator_bool_type);
00161 public:
00162 operator operator_bool_type() const;
00163
00164
00166
00169 public:
00170 pointer get_interface_ptr() const;
00172 };
00173
00174
00175
00176
00177
00178 template <ss_typename_param_k T>
00179 inline void swap(interface_ptr<T>& lhs, interface_ptr<T>& rhs)
00180 {
00181 lhs.swap(rhs);
00182 }
00183
00184
00185
00186
00187
00188 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00189
00190 template <ss_typename_param_k T>
00191 inline cs_bool_t is_empty(interface_ptr<T> const& p)
00192 {
00193 return NULL == p.get_interface_ptr();
00194 }
00195
00196 #endif
00197
00198
00199
00200
00201
00205 template <ss_typename_param_k T>
00206 inline T* get_ptr(interface_ptr<T> const& p)
00207 {
00208 return p.get_interface_ptr();
00209 }
00210
00211
00212
00213
00214
00215 #ifdef STLSOFT_UNITTEST
00216 # include "./unittest/interface_ptr_unittest_.h"
00217 #endif
00218
00219
00220
00221
00222
00223
00224
00225 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00226
00227 template <ss_typename_param_k T>
00228 inline void interface_ptr<T>::swap(interface_ptr<T>& rhs)
00229 {
00230 parent_class_type::swap(rhs);
00231 }
00232
00233 template <ss_typename_param_k T>
00234 inline interface_ptr<T>::interface_ptr()
00235 : parent_class_type()
00236 {}
00237
00238 template <ss_typename_param_k T>
00239 inline interface_ptr<T>::interface_ptr(ss_typename_type_k interface_ptr<T>::pointer p, cs_bool_t bAddRef)
00240 : parent_class_type(p, bAddRef)
00241 {}
00242
00243 template <ss_typename_param_k T>
00244 inline interface_ptr<T>::interface_ptr(ss_typename_type_k interface_ptr<T>::reference r, cs_bool_t bAddRef)
00245 : parent_class_type(&r, bAddRef)
00246 {}
00247
00248 template <ss_typename_param_k T>
00249 inline interface_ptr<T>::interface_ptr(ss_typename_type_k interface_ptr<T>::class_type const& rhs)
00250 : parent_class_type(rhs)
00251 {}
00252
00253 template <ss_typename_param_k T>
00254 inline void interface_ptr<T>::release()
00255 {
00256 parent_class_type::close();
00257 }
00258
00259 template <ss_typename_param_k T>
00260 inline void interface_ptr<T>::release(cs_bool_t bDecRef )
00261 {
00262 bDecRef ? parent_class_type::close() : static_cast<void>(parent_class_type::detach());
00263 }
00264
00265 template <ss_typename_param_k T>
00266 inline interface_ptr<T>::~interface_ptr() stlsoft_throw_0()
00267 {
00268 release();
00269 }
00270
00271 template <ss_typename_param_k T>
00272 inline ss_typename_type_ret_k interface_ptr<T>::class_type& interface_ptr<T>::operator =(ss_typename_type_k interface_ptr<T>::class_type const& rhs)
00273 {
00274 class_type t(rhs);
00275
00276 swap(t);
00277
00278 return *this;
00279 }
00280
00281 template <ss_typename_param_k T>
00282 inline void interface_ptr<T>::set(ss_typename_type_k interface_ptr<T>::pointer p, cs_bool_t bAddRef)
00283 {
00284 class_type t(p, bAddRef);
00285
00286 swap(t);
00287 }
00288
00289 template <ss_typename_param_k T>
00290 inline void interface_ptr<T>::set(ss_typename_type_k interface_ptr<T>::reference r, cs_bool_t bAddRef)
00291 {
00292 COMSTL_MESSAGE_ASSERT("Attempting to dereference a null pointer", &r != NULL);
00293
00294 class_type t(&r, bAddRef);
00295
00296 swap(t);
00297 }
00298
00299 template <ss_typename_param_k T>
00300 inline ss_typename_type_ret_k interface_ptr<T>::pointer interface_ptr<T>::detach()
00301 {
00302 return parent_class_type::detach();
00303 }
00304
00305 template <ss_typename_param_k T>
00306 inline cs_bool_t interface_ptr<T>::operator ==(ss_typename_type_k interface_ptr<T>::class_type const& rhs) const
00307 {
00308 return parent_class_type::equal(rhs);
00309 }
00310
00311 template <ss_typename_param_k T>
00312 inline cs_bool_t interface_ptr<T>::operator !=(ss_typename_type_k interface_ptr<T>::class_type const& rhs) const
00313 {
00314 return !parent_class_type::equal(rhs);
00315 }
00316
00317 template <ss_typename_param_k T>
00318 inline interface_ptr<T>::operator ss_typename_type_k interface_ptr<T>::operator_bool_type() const
00319 {
00320 return operator_bool_generator_type::translate(parent_class_type::empty());
00321 }
00322
00323 template <ss_typename_param_k T>
00324 inline ss_typename_type_ret_k interface_ptr<T>::pointer interface_ptr<T>::get_interface_ptr() const
00325 {
00326 return parent_class_type::get();
00327 }
00328
00329 #endif
00330
00331
00332
00333 #ifndef _COMSTL_NO_NAMESPACE
00334 # if defined(_STLSOFT_NO_NAMESPACE) || \
00335 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00336 }
00337 # else
00338 }
00339 }
00340 # endif
00341 #endif
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351 #ifndef _COMSTL_NO_NAMESPACE
00352 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00353 !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00354 namespace stlsoft
00355 {
00356 # else
00357
00358 # endif
00359
00360 using ::comstl::get_ptr;
00361
00362 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00363
00364 using ::comstl::is_empty;
00365
00366 #endif
00367
00368 # if !defined(_STLSOFT_NO_NAMESPACE) && \
00369 !defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00370 }
00371 # else
00372
00373 # endif
00374 #endif
00375
00376
00377
00378
00379 #if defined(STLSOFT_CF_std_NAMESPACE)
00380 # if ( ( defined(STLSOFT_COMPILER_IS_INTEL) && \
00381 defined(_MSC_VER))) && \
00382 _MSC_VER < 1310
00383 namespace std
00384 {
00385 template <ss_typename_param_k T>
00386 inline void swap(comstl_ns_qual(interface_ptr)<T>& lhs, comstl_ns_qual(interface_ptr)<T>& rhs)
00387 {
00388 lhs.swap(rhs);
00389 }
00390 }
00391 # endif
00392 #endif
00393
00394
00395
00396 #endif
00397
00398