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
00041
00042
00043
00044
00052 #ifndef STLSOFT_INCL_STLSOFT_SMARTPTR_HPP_SCOPED_HANDLE_BORLAND_
00053 #define STLSOFT_INCL_STLSOFT_SMARTPTR_HPP_SCOPED_HANDLE_BORLAND_
00054
00055 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00056 # define STLSOFT_VER_STLSOFT_SMARTPTR_HPP_SCOPED_HANDLE_BORLAND__MAJOR 6
00057 # define STLSOFT_VER_STLSOFT_SMARTPTR_HPP_SCOPED_HANDLE_BORLAND__MINOR 1
00058 # define STLSOFT_VER_STLSOFT_SMARTPTR_HPP_SCOPED_HANDLE_BORLAND__REVISION 2
00059 # define STLSOFT_VER_STLSOFT_SMARTPTR_HPP_SCOPED_HANDLE_BORLAND__EDIT 670
00060 #endif
00061
00062
00063
00064
00065
00066 #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT
00067 # include <stlsoft/stlsoft.h>
00068 #endif
00069
00070
00071
00072
00073
00074
00075 #if !defined(STLSOFT_COMPILER_IS_BORLAND)
00076
00077 # error This file is only defined for Borland C/C++ compiler versions
00078 #endif
00079
00080
00081
00082
00083
00084 #ifndef _STLSOFT_NO_NAMESPACE
00085 namespace stlsoft
00086 {
00087 #endif
00088
00089
00090
00091
00092
00093 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00094
00095 # define USE_INTERNAL_MEMORY
00096
00097 struct scoped_handle_borland_impl_
00098 {
00099 template <ss_typename_param_k H>
00100 struct function_type
00101 {
00102 public:
00103 typedef H resource_type;
00104
00105 public:
00106 virtual void destroy(resource_type h) = 0;
00107 virtual void release() = 0;
00108 };
00109
00110 struct void_function_type
00111 {
00112 public:
00113 virtual void destroy() = 0;
00114 virtual void release() = 0;
00115 };
00116
00117
00118
00119
00120
00121
00122 template< ss_typename_param_k H
00123 , ss_typename_param_k R
00124 >
00125 struct cdecl_function_type
00126 : function_type<H>
00127 {
00128 public:
00129 typedef H resource_type;
00130 typedef cdecl_function_type<H, R> class_type;
00131 typedef R (STLSOFT_CDECL* function_type)(H);
00132
00133 private:
00134 cdecl_function_type(function_type fn)
00135 : m_fn(fn)
00136 {}
00137 cdecl_function_type(class_type const&);
00138 class_type& operator =(class_type const&);
00139 private:
00140 void* operator new(size_t cb, void* p, size_t n)
00141 {
00142 STLSOFT_ASSERT(cb <= n);
00143
00144 #ifdef USE_INTERNAL_MEMORY
00145 return p;
00146 #else
00147 return ::operator new(cb);
00148 #endif
00149 }
00150 void operator delete(void* pv)
00151 {
00152 #ifndef USE_INTERNAL_MEMORY
00153 ::operator delete(pv);
00154 #else
00155 STLSOFT_SUPPRESS_UNUSED(pv);
00156 #endif
00157 }
00158 #ifndef __BORLANDC__
00159 void operator delete(void* pv, void* p, size_t n)
00160 {
00161 operator delete(pv);
00162 }
00163 #endif
00164
00165 public:
00166 static class_type* create(void* p, size_t n, function_type fn)
00167 {
00168 return new(p, n) class_type(fn);
00169 }
00170
00171 public:
00172 virtual void destroy(resource_type h)
00173 {
00174 m_fn(h);
00175 }
00176 virtual void release()
00177 {
00178 delete this;
00179 }
00180
00181
00182 private:
00183 function_type m_fn;
00184 };
00185
00186
00187
00188
00189
00190 template< ss_typename_param_k H
00191 , ss_typename_param_k R
00192 >
00193 struct fastcall_function_type
00194 : function_type<H>
00195 {
00196 public:
00197 typedef H resource_type;
00198 typedef fastcall_function_type<H, R> class_type;
00199 typedef R (STLSOFT_FASTCALL* function_type)(H);
00200
00201 private:
00202 fastcall_function_type(function_type fn)
00203 : m_fn(fn)
00204 {}
00205 fastcall_function_type(class_type const&);
00206 class_type& operator =(class_type const&);
00207 private:
00208 void* operator new(size_t cb, void* p, size_t n)
00209 {
00210 STLSOFT_ASSERT(cb <= n);
00211
00212 #ifdef USE_INTERNAL_MEMORY
00213 return p;
00214 #else
00215 return ::operator new(cb);
00216 #endif
00217 }
00218 void operator delete(void* pv)
00219 {
00220 #ifndef USE_INTERNAL_MEMORY
00221 ::operator delete(pv);
00222 #else
00223 STLSOFT_SUPPRESS_UNUSED(pv);
00224 #endif
00225 }
00226 #ifndef __BORLANDC__
00227 void operator delete(void* pv, void* p, size_t n)
00228 {
00229 operator delete(pv);
00230 }
00231 #endif
00232
00233 public:
00234 static class_type* create(void* p, size_t n, function_type fn)
00235 {
00236 return new(p, n) class_type(fn);
00237 }
00238
00239 public:
00240 virtual void destroy(resource_type h)
00241 {
00242 m_fn(h);
00243 }
00244 virtual void release()
00245 {
00246 delete this;
00247 }
00248
00249
00250 private:
00251 function_type m_fn;
00252 };
00253
00254
00255
00256
00257
00258 template< ss_typename_param_k H
00259 , ss_typename_param_k R
00260 >
00261 struct stdcall_function_type
00262 : function_type<H>
00263 {
00264 public:
00265 typedef H resource_type;
00266 typedef stdcall_function_type<H, R> class_type;
00267 typedef R (STLSOFT_STDCALL* function_type)(H);
00268
00269 private:
00270 stdcall_function_type(function_type fn)
00271 : m_fn(fn)
00272 {}
00273 stdcall_function_type(class_type const&);
00274 class_type& operator =(class_type const&);
00275 private:
00276 void* operator new(size_t cb, void* p, size_t n)
00277 {
00278 STLSOFT_ASSERT(cb <= n);
00279
00280 #ifdef USE_INTERNAL_MEMORY
00281 return p;
00282 #else
00283 return ::operator new(cb);
00284 #endif
00285 }
00286 void operator delete(void* pv)
00287 {
00288 #ifndef USE_INTERNAL_MEMORY
00289 ::operator delete(pv);
00290 #else
00291 STLSOFT_SUPPRESS_UNUSED(pv);
00292 #endif
00293 }
00294 #ifndef __BORLANDC__
00295 void operator delete(void* pv, void* p, size_t n)
00296 {
00297 operator delete(pv);
00298 }
00299 #endif
00300
00301 public:
00302 static class_type* create(void* p, size_t n, function_type fn)
00303 {
00304 return new(p, n) class_type(fn);
00305 }
00306
00307 public:
00308 virtual void destroy(resource_type h)
00309 {
00310 m_fn(h);
00311 }
00312 virtual void release()
00313 {
00314 delete this;
00315 }
00316
00317
00318 private:
00319 function_type m_fn;
00320 };
00321
00322
00323
00324
00325
00326 template <ss_typename_param_k H>
00327 struct cdecl_function_type_v
00328 : function_type<H>
00329 {
00330 public:
00331 typedef H resource_type;
00332 typedef cdecl_function_type_v<H> class_type;
00333 typedef void (STLSOFT_CDECL* function_type)(H);
00334
00335 public:
00336 cdecl_function_type_v(function_type fn)
00337 : m_fn(fn)
00338 {}
00339 cdecl_function_type_v(class_type const&);
00340 class_type& operator =(class_type const&);
00341 private:
00342 void* operator new(size_t cb, void* p, size_t n)
00343 {
00344 STLSOFT_ASSERT(cb <= n);
00345
00346 #ifdef USE_INTERNAL_MEMORY
00347 return p;
00348 #else
00349 return ::operator new(cb);
00350 #endif
00351 }
00352 void operator delete(void* pv)
00353 {
00354 #ifndef USE_INTERNAL_MEMORY
00355 ::operator delete(pv);
00356 #else
00357 STLSOFT_SUPPRESS_UNUSED(pv);
00358 #endif
00359 }
00360 #ifndef __BORLANDC__
00361 void operator delete(void* pv, void* p, size_t n)
00362 {
00363 operator delete(pv);
00364 }
00365 #endif
00366
00367 public:
00368 static class_type* create(void* p, size_t n, function_type fn)
00369 {
00370 return new(p, n) class_type(fn);
00371 }
00372
00373 public:
00374 virtual void destroy(resource_type h)
00375 {
00376 m_fn(h);
00377 }
00378 virtual void release()
00379 {
00380 delete this;
00381 }
00382
00383 private:
00384 function_type m_fn;
00385 };
00386
00387
00388
00389
00390
00391 template <ss_typename_param_k H>
00392 struct fastcall_function_type_v
00393 : function_type<H>
00394 {
00395 public:
00396 typedef H resource_type;
00397 typedef fastcall_function_type_v<H> class_type;
00398 typedef void (STLSOFT_FASTCALL* function_type)(H);
00399
00400 public:
00401 fastcall_function_type_v(function_type fn)
00402 : m_fn(fn)
00403 {}
00404 fastcall_function_type_v(class_type const&);
00405 class_type& operator =(class_type const&);
00406 private:
00407 void* operator new(size_t cb, void* p, size_t n)
00408 {
00409 STLSOFT_ASSERT(cb <= n);
00410
00411 #ifdef USE_INTERNAL_MEMORY
00412 return p;
00413 #else
00414 return ::operator new(cb);
00415 #endif
00416 }
00417 void operator delete(void* pv)
00418 {
00419 #ifndef USE_INTERNAL_MEMORY
00420 ::operator delete(pv);
00421 #else
00422 STLSOFT_SUPPRESS_UNUSED(pv);
00423 #endif
00424 }
00425 #ifndef __BORLANDC__
00426 void operator delete(void* pv, void* p, size_t n)
00427 {
00428 operator delete(pv);
00429 }
00430 #endif
00431
00432 public:
00433 static class_type* create(void* p, size_t n, function_type fn)
00434 {
00435 return new(p, n) class_type(fn);
00436 }
00437
00438 public:
00439 virtual void destroy(resource_type h)
00440 {
00441 m_fn(h);
00442 }
00443 virtual void release()
00444 {
00445 delete this;
00446 }
00447
00448 private:
00449 function_type m_fn;
00450 };
00451
00452
00453
00454
00455
00456 template <ss_typename_param_k H>
00457 struct stdcall_function_type_v
00458 : function_type<H>
00459 {
00460 public:
00461 typedef H resource_type;
00462 typedef stdcall_function_type_v<H> class_type;
00463 typedef void (STLSOFT_STDCALL* function_type)(H);
00464
00465 public:
00466 stdcall_function_type_v(function_type fn)
00467 : m_fn(fn)
00468 {}
00469 stdcall_function_type_v(class_type const&);
00470 class_type& operator =(class_type const&);
00471 private:
00472 void* operator new(size_t cb, void* p, size_t n)
00473 {
00474 STLSOFT_ASSERT(cb <= n);
00475
00476 #ifdef USE_INTERNAL_MEMORY
00477 return p;
00478 #else
00479 return ::operator new(cb);
00480 #endif
00481 }
00482 void operator delete(void* pv)
00483 {
00484 #ifndef USE_INTERNAL_MEMORY
00485 ::operator delete(pv);
00486 #else
00487 STLSOFT_SUPPRESS_UNUSED(pv);
00488 #endif
00489 }
00490 #ifndef __BORLANDC__
00491 void operator delete(void* pv, void* p, size_t n)
00492 {
00493 operator delete(pv);
00494 }
00495 #endif
00496
00497 public:
00498 static class_type* create(void* p, size_t n, function_type fn)
00499 {
00500 return new(p, n) class_type(fn);
00501 }
00502
00503 public:
00504 virtual void destroy(resource_type h)
00505 {
00506 m_fn(h);
00507 }
00508 virtual void release()
00509 {
00510 delete this;
00511 }
00512
00513 private:
00514 function_type m_fn;
00515 };
00516
00517
00518
00519
00520
00521
00522 template <ss_typename_param_k R>
00523 struct cdecl_void_function_type
00524 : void_function_type
00525 {
00526 public:
00527 typedef cdecl_void_function_type<R> class_type;
00528 typedef R (STLSOFT_CDECL* function_type)();
00529
00530 private:
00531 cdecl_void_function_type(function_type fn)
00532 : m_fn(fn)
00533 {}
00534 cdecl_void_function_type(class_type const&);
00535 class_type& operator =(class_type const&);
00536 private:
00537 void* operator new(size_t cb, void* p, size_t n)
00538 {
00539 STLSOFT_ASSERT(cb <= n);
00540
00541 #ifdef USE_INTERNAL_MEMORY
00542 return p;
00543 #else
00544 return ::operator new(cb);
00545 #endif
00546 }
00547 void operator delete(void* pv)
00548 {
00549 #ifndef USE_INTERNAL_MEMORY
00550 ::operator delete(pv);
00551 #else
00552 STLSOFT_SUPPRESS_UNUSED(pv);
00553 #endif
00554 }
00555 #ifndef __BORLANDC__
00556 void operator delete(void* pv, void* p, size_t n)
00557 {
00558 operator delete(pv);
00559 }
00560 #endif
00561
00562 public:
00563 static class_type* create(void* p, size_t n, function_type fn)
00564 {
00565 return new(p, n) class_type(fn);
00566 }
00567
00568 public:
00569 virtual void destroy()
00570 {
00571 m_fn();
00572 }
00573 virtual void release()
00574 {
00575 delete this;
00576 }
00577
00578
00579 private:
00580 function_type m_fn;
00581 };
00582
00583
00584
00585
00586
00587 template <ss_typename_param_k R>
00588 struct fastcall_void_function_type
00589 : void_function_type
00590 {
00591 public:
00592 typedef fastcall_void_function_type<R> class_type;
00593 typedef R (STLSOFT_FASTCALL* function_type)();
00594
00595 private:
00596 fastcall_void_function_type(function_type fn)
00597 : m_fn(fn)
00598 {}
00599 fastcall_void_function_type(class_type const&);
00600 class_type& operator =(class_type const&);
00601 private:
00602 void* operator new(size_t cb, void* p, size_t n)
00603 {
00604 STLSOFT_ASSERT(cb <= n);
00605
00606 #ifdef USE_INTERNAL_MEMORY
00607 return p;
00608 #else
00609 return ::operator new(cb);
00610 #endif
00611 }
00612 void operator delete(void* pv)
00613 {
00614 #ifndef USE_INTERNAL_MEMORY
00615 ::operator delete(pv);
00616 #else
00617 STLSOFT_SUPPRESS_UNUSED(pv);
00618 #endif
00619 }
00620 #ifndef __BORLANDC__
00621 void operator delete(void* pv, void* p, size_t n)
00622 {
00623 operator delete(pv);
00624 }
00625 #endif
00626
00627 public:
00628 static class_type* create(void* p, size_t n, function_type fn)
00629 {
00630 return new(p, n) class_type(fn);
00631 }
00632
00633 public:
00634 virtual void destroy()
00635 {
00636 m_fn();
00637 }
00638 virtual void release()
00639 {
00640 delete this;
00641 }
00642
00643
00644 private:
00645 function_type m_fn;
00646 };
00647
00648
00649
00650
00651
00652 template <ss_typename_param_k R>
00653 struct stdcall_void_function_type
00654 : void_function_type
00655 {
00656 public:
00657 typedef stdcall_void_function_type<R> class_type;
00658 typedef R (STLSOFT_STDCALL* function_type)();
00659
00660 private:
00661 stdcall_void_function_type(function_type fn)
00662 : m_fn(fn)
00663 {}
00664 stdcall_void_function_type(class_type const&);
00665 class_type& operator =(class_type const&);
00666 private:
00667 void* operator new(size_t cb, void* p, size_t n)
00668 {
00669 STLSOFT_ASSERT(cb <= n);
00670
00671 #ifdef USE_INTERNAL_MEMORY
00672 return p;
00673 #else
00674 return ::operator new(cb);
00675 #endif
00676 }
00677 void operator delete(void* pv)
00678 {
00679 #ifndef USE_INTERNAL_MEMORY
00680 ::operator delete(pv);
00681 #else
00682 STLSOFT_SUPPRESS_UNUSED(pv);
00683 #endif
00684 }
00685 #ifndef __BORLANDC__
00686 void operator delete(void* pv, void* p, size_t n)
00687 {
00688 operator delete(pv);
00689 }
00690 #endif
00691
00692 public:
00693 static class_type* create(void* p, size_t n, function_type fn)
00694 {
00695 return new(p, n) class_type(fn);
00696 }
00697
00698 public:
00699 virtual void destroy()
00700 {
00701 m_fn();
00702 }
00703 virtual void release()
00704 {
00705 delete this;
00706 }
00707
00708
00709 private:
00710 function_type m_fn;
00711 };
00712
00713
00714
00715
00716
00717 struct cdecl_void_function_type_v
00718 : void_function_type
00719 {
00720 public:
00721 typedef cdecl_void_function_type_v class_type;
00722 typedef void (STLSOFT_CDECL* function_type)();
00723
00724 public:
00725 cdecl_void_function_type_v(function_type fn)
00726 : m_fn(fn)
00727 {}
00728 cdecl_void_function_type_v(class_type const&);
00729 class_type& operator =(class_type const&);
00730 private:
00731 void* operator new(size_t cb, void* p, size_t n)
00732 {
00733 STLSOFT_ASSERT(cb <= n);
00734
00735 #ifdef USE_INTERNAL_MEMORY
00736 return p;
00737 #else
00738 return ::operator new(cb);
00739 #endif
00740 }
00741 void operator delete(void* pv)
00742 {
00743 #ifndef USE_INTERNAL_MEMORY
00744 ::operator delete(pv);
00745 #else
00746 STLSOFT_SUPPRESS_UNUSED(pv);
00747 #endif
00748 }
00749 #ifndef __BORLANDC__
00750 void operator delete(void* pv, void* p, size_t n)
00751 {
00752 operator delete(pv);
00753 }
00754 #endif
00755
00756 public:
00757 static class_type* create(void* p, size_t n, function_type fn)
00758 {
00759 return new(p, n) class_type(fn);
00760 }
00761
00762 public:
00763 virtual void destroy()
00764 {
00765 m_fn();
00766 }
00767 virtual void release()
00768 {
00769 delete this;
00770 }
00771
00772 private:
00773 function_type m_fn;
00774 };
00775
00776
00777
00778
00779
00780 struct fastcall_void_function_type_v
00781 : void_function_type
00782 {
00783 public:
00784 typedef fastcall_void_function_type_v class_type;
00785 typedef void (STLSOFT_FASTCALL* function_type)();
00786
00787 public:
00788 fastcall_void_function_type_v(function_type fn)
00789 : m_fn(fn)
00790 {}
00791 fastcall_void_function_type_v(class_type const&);
00792 class_type& operator =(class_type const&);
00793 private:
00794 void* operator new(size_t cb, void* p, size_t n)
00795 {
00796 STLSOFT_ASSERT(cb <= n);
00797
00798 #ifdef USE_INTERNAL_MEMORY
00799 return p;
00800 #else
00801 return ::operator new(cb);
00802 #endif
00803 }
00804 void operator delete(void* pv)
00805 {
00806 #ifndef USE_INTERNAL_MEMORY
00807 ::operator delete(pv);
00808 #else
00809 STLSOFT_SUPPRESS_UNUSED(pv);
00810 #endif
00811 }
00812 #ifndef __BORLANDC__
00813 void operator delete(void* pv, void* p, size_t n)
00814 {
00815 operator delete(pv);
00816 }
00817 #endif
00818
00819 public:
00820 static class_type* create(void* p, size_t n, function_type fn)
00821 {
00822 return new(p, n) class_type(fn);
00823 }
00824
00825 public:
00826 virtual void destroy()
00827 {
00828 m_fn();
00829 }
00830 virtual void release()
00831 {
00832 delete this;
00833 }
00834
00835 private:
00836 function_type m_fn;
00837 };
00838
00839
00840
00841
00842
00843 struct stdcall_void_function_type_v
00844 : void_function_type
00845 {
00846 public:
00847 typedef stdcall_void_function_type_v class_type;
00848 typedef void (STLSOFT_STDCALL* function_type)();
00849
00850 public:
00851 stdcall_void_function_type_v(function_type fn)
00852 : m_fn(fn)
00853 {}
00854 stdcall_void_function_type_v(class_type const&);
00855 class_type& operator =(class_type const&);
00856 private:
00857 void* operator new(size_t cb, void* p, size_t n)
00858 {
00859 STLSOFT_ASSERT(cb <= n);
00860
00861 #ifdef USE_INTERNAL_MEMORY
00862 return p;
00863 #else
00864 return ::operator new(cb);
00865 #endif
00866 }
00867 void operator delete(void* pv)
00868 {
00869 #ifndef USE_INTERNAL_MEMORY
00870 ::operator delete(pv);
00871 #else
00872 STLSOFT_SUPPRESS_UNUSED(pv);
00873 #endif
00874 }
00875 #ifndef __BORLANDC__
00876 void operator delete(void* pv, void* p, size_t n)
00877 {
00878 operator delete(pv);
00879 }
00880 #endif
00881
00882 public:
00883 static class_type* create(void* p, size_t n, function_type fn)
00884 {
00885 return new(p, n) class_type(fn);
00886 }
00887
00888 public:
00889 virtual void destroy()
00890 {
00891 m_fn();
00892 }
00893 virtual void release()
00894 {
00895 delete this;
00896 }
00897
00898 private:
00899 function_type m_fn;
00900 };
00901
00902 };
00903
00904 #endif
00905
00906
00907
00908
00909
00910 template <ss_typename_param_k H>
00911 class scoped_handle
00912 {
00913 public:
00914 typedef H resource_type;
00915 typedef H handle_type;
00916 typedef scoped_handle<H> class_type;
00917 private:
00918 typedef scoped_handle_borland_impl_::function_type<H> function_type;
00919
00920 public:
00921 enum
00922 {
00923 cdecl_function_type_v_size = sizeof(scoped_handle_borland_impl_::cdecl_function_type_v<H>)
00924 , cdecl_function_type_size = sizeof(scoped_handle_borland_impl_::cdecl_function_type<H, int>)
00925 };
00926
00927 public:
00928 #ifdef STLSOFT_CF_CDECL_SUPPORTED
00929 # if !defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT) || \
00930 defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_OVERLOAD_DISCRIMINATED)
00931 scoped_handle(
00932 resource_type h
00933 , void (STLSOFT_CDECL *fn)(resource_type)
00934 , resource_type hNull = 0
00935 )
00936 : m_handle(h)
00937 , m_hNull(hNull)
00938 , m_fn(scoped_handle_borland_impl_::cdecl_function_type_v<H>::create(&m_bytes, sizeof(m_bytes), fn))
00939 {}
00940
00941 scoped_handle( resource_type* ph
00942 , void (STLSOFT_CDECL *fn)(resource_type*)
00943 , resource_type hNull = 0);
00944 # endif
00945
00946 # if defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT)
00947 template <ss_typename_param_k R>
00948 scoped_handle(
00949 resource_type h
00950 , R (STLSOFT_CDECL *fn)(resource_type)
00951 , resource_type hNull = 0
00952 )
00953 : m_handle(h)
00954 , m_hNull(hNull)
00955 , m_fn(scoped_handle_borland_impl_::cdecl_function_type<H, R>::create(&m_bytes, sizeof(m_bytes), fn))
00956 {}
00957 template <ss_typename_param_k R>
00958 scoped_handle( resource_type* ph
00959 , R (STLSOFT_CDECL *fn)(resource_type*)
00960 , resource_type hNull = 0);
00961 # endif
00962 #endif
00963
00964 #ifdef STLSOFT_CF_FASTCALL_SUPPORTED
00965 # if !defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT) || \
00966 defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_OVERLOAD_DISCRIMINATED)
00967 scoped_handle( resource_type h
00968 , void (STLSOFT_FASTCALL *fn)(resource_type)
00969 , resource_type hNull = 0)
00970 : m_handle(h)
00971 , m_hNull(hNull)
00972 , m_fn(scoped_handle_borland_impl_::fastcall_function_type_v<H>::create(&m_bytes, sizeof(m_bytes), fn))
00973 {}
00974
00975 scoped_handle( resource_type h
00976 , void (STLSOFT_FASTCALL *fn)(resource_type *)
00977 , resource_type hNull = 0);
00978 # endif
00979
00980 # if defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT)
00981 template <ss_typename_param_k R>
00982 scoped_handle( resource_type h
00983 , R (STLSOFT_FASTCALL *fn)(resource_type)
00984 , resource_type hNull = 0)
00985 : m_handle(h)
00986 , m_hNull(hNull)
00987 , m_fn(scoped_handle_borland_impl_::fastcall_function_type<H, R>::create(&m_bytes, sizeof(m_bytes), fn))
00988 {}
00989 template <ss_typename_param_k R>
00990 scoped_handle( resource_type* ph
00991 , R (STLSOFT_FASTCALL *fn)(resource_type*)
00992 , resource_type hNull = 0);
00993 # endif
00994 #endif
00995
00996
00997 #ifdef STLSOFT_CF_STDCALL_SUPPORTED
00998 # if !defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT) || \
00999 defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_OVERLOAD_DISCRIMINATED)
01000 scoped_handle( resource_type h
01001 , void (STLSOFT_STDCALL *fn)(resource_type)
01002 , resource_type hNull = 0)
01003 : m_handle(h)
01004 , m_hNull(hNull)
01005 , m_fn(scoped_handle_borland_impl_::stdcall_function_type_v<H>::create(&m_bytes, sizeof(m_bytes), fn))
01006 {}
01007
01008 scoped_handle( resource_type *ph
01009 , void (STLSOFT_STDCALL *fn)(resource_type*)
01010 , resource_type hNull = 0);
01011 # endif
01012
01013 # if defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT)
01014 template <ss_typename_param_k R>
01015 scoped_handle( resource_type h
01016 , R (STLSOFT_STDCALL *fn)(resource_type)
01017 , resource_type hNull = 0)
01018 : m_handle(h)
01019 , m_hNull(hNull)
01020 , m_fn(scoped_handle_borland_impl_::stdcall_function_type<H, R>::create(&m_bytes, sizeof(m_bytes), fn))
01021 {}
01022
01023 template <ss_typename_param_k R>
01024 scoped_handle( resource_type* ph
01025 , R (STLSOFT_STDCALL *fn)(resource_type*)
01026 , resource_type hNull = 0);
01027 # endif
01028 #endif
01029
01030 ~scoped_handle()
01031 {
01032 STLSOFT_MESSAGE_ASSERT("Invariant violation: function pointer must not be NULL", NULL != m_fn);
01033
01034 if(!empty())
01035 {
01036 m_fn->destroy(m_handle);
01037 }
01038
01039 m_fn->release();
01040 }
01041
01042 public:
01043 bool empty() const
01044 {
01045 STLSOFT_MESSAGE_ASSERT("Invariant violation: function pointer must not be NULL", NULL != m_fn);
01046
01047 return get_null_value_() == m_handle;
01048 }
01049
01050 public:
01051 void close()
01052 {
01053 STLSOFT_MESSAGE_ASSERT("Invariant violation: function pointer must not be NULL", NULL != m_fn);
01054
01055 if(!empty())
01056 {
01057 m_fn->destroy(m_handle);
01058
01059 m_handle = get_null_value_();
01060 }
01061 }
01062
01063 resource_type detach()
01064 {
01065 STLSOFT_MESSAGE_ASSERT("Invariant violation: function pointer must not be NULL", NULL != m_fn);
01066
01067 resource_type h = m_handle;
01068
01069 m_handle = get_null_value_();
01070
01071 return h;
01072 }
01073
01074 public:
01075 resource_type handle() const
01076 {
01077 return m_handle;
01078 }
01079 resource_type get() const
01080 {
01081 return m_handle;
01082 }
01083
01084 private:
01085 resource_type get_null_value_() const
01086 {
01087 return m_hNull;
01088 }
01089
01090 private:
01091 handle_type m_handle;
01092 const resource_type m_hNull;
01093 function_type* const m_fn;
01094 union
01095 {
01096 long double ld;
01097 #if !defined(STLSOFT_COMPILER_IS_BORLAND) || \
01098 __BORLANDC__ > 0x0560
01099 ss_byte_t cdecl_R[cdecl_function_type_size];
01100 #endif
01101
01102 } m_bytes;
01103
01104 private:
01105 scoped_handle(class_type const&);
01106 class_type& operator =(class_type const&);
01107 };
01108
01109 STLSOFT_TEMPLATE_SPECIALISATION
01110 class scoped_handle<void>
01111 {
01112 public:
01113 typedef void resource_type;
01114 typedef void handle_type;
01115 typedef scoped_handle<void> class_type;
01116 private:
01117 typedef scoped_handle_borland_impl_::void_function_type function_type;
01118 public:
01119 enum
01120 {
01121 cdecl_function_type_size = sizeof(function_type)
01122 };
01123
01124 public:
01125 #ifdef STLSOFT_CF_CDECL_SUPPORTED
01126 # if !defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT) || \
01127 defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_OVERLOAD_DISCRIMINATED)
01128 scoped_handle( void (STLSOFT_CDECL *fn)())
01129 : m_bInvoked(false)
01130 , m_fn(scoped_handle_borland_impl_::cdecl_void_function_type_v::create(&m_bytes, sizeof(m_bytes), fn))
01131 {}
01132 # endif
01133
01134 # if defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT)
01135 template <ss_typename_param_k R>
01136 scoped_handle( R (STLSOFT_CDECL *fn)())
01137 : m_bInvoked(false)
01138 , m_fn(scoped_handle_borland_impl_::cdecl_void_function_type<R>::create(&m_bytes, sizeof(m_bytes), fn))
01139 {}
01140 # endif
01141 #endif
01142
01143 #ifdef STLSOFT_CF_FASTCALL_SUPPORTED
01144 # if !defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT) || \
01145 defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_OVERLOAD_DISCRIMINATED)
01146 scoped_handle( void (STLSOFT_FASTCALL *fn)())
01147 : m_bInvoked(false)
01148 , m_fn(scoped_handle_borland_impl_::fastcall_void_function_type_v::create(&m_bytes, sizeof(m_bytes), fn))
01149 {}
01150 # endif
01151
01152 # if defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT)
01153 template <ss_typename_param_k R>
01154 scoped_handle( R (STLSOFT_FASTCALL *fn)())
01155 : m_bInvoked(false)
01156 , m_fn(scoped_handle_borland_impl_::fastcall_void_function_type<R>::create(&m_bytes, sizeof(m_bytes), fn))
01157 {}
01158 # endif
01159 #endif
01160
01161
01162 #ifdef STLSOFT_CF_STDCALL_SUPPORTED
01163 # if !defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT) || \
01164 defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_OVERLOAD_DISCRIMINATED)
01165 scoped_handle( void (STLSOFT_STDCALL *fn)())
01166 : m_bInvoked(false)
01167 , m_fn(scoped_handle_borland_impl_::stdcall_void_function_type_v::create(&m_bytes, sizeof(m_bytes), fn))
01168 {}
01169 # endif
01170
01171 # if defined(STLSOFT_CF_MEMBER_TEMPLATE_CTOR_SUPPORT)
01172 template <ss_typename_param_k R>
01173 scoped_handle( R (STLSOFT_STDCALL *fn)())
01174 : m_bInvoked(false)
01175 , m_fn(scoped_handle_borland_impl_::stdcall_void_function_type<R>::create(&m_bytes, sizeof(m_bytes), fn))
01176 {}
01177 # endif
01178 #endif
01179
01180 ~scoped_handle()
01181 {
01182 close();
01183 }
01184
01185 public:
01186 bool empty() const
01187 {
01188 return m_bInvoked;
01189 }
01190
01191 public:
01192 void close()
01193 {
01194 if(!empty())
01195 {
01196 m_fn->destroy();
01197 m_bInvoked = true;
01198 }
01199 }
01200
01201 resource_type detach()
01202 {
01203 m_bInvoked = true;
01204 }
01205
01206 public:
01207 resource_type handle() const
01208 {
01209 }
01210 resource_type get() const
01211 {
01212 }
01213
01214 private:
01215 ss_bool_t m_bInvoked;
01216 function_type* const m_fn;
01217 union
01218 {
01219 long double ld;
01220 ss_byte_t cdecl_R[cdecl_function_type_size];
01221
01222 } m_bytes;
01223
01224 private:
01225 scoped_handle(class_type const&);
01226 class_type& operator =(class_type const&);
01227 };
01228
01229
01230
01231
01232
01233 template< ss_typename_param_k H
01234 >
01235 inline void swap(scoped_handle<H>& lhs, scoped_handle<H>& rhs)
01236 {
01237 lhs.swap(rhs);
01238 }
01239
01241
01242
01243 template<ss_typename_param_k H>
01244 #if defined(STLSOFT_COMPILER_IS_WATCOM)
01245 inline H get_handle(scoped_handle<H> const& h)
01246 #else
01247 inline ss_typename_type_ret_k scoped_handle<H>::handle_type get_handle(scoped_handle<H> const& h)
01248 #endif
01249 {
01250 return h.get();
01251 }
01252
01253
01254
01255
01256
01257 #ifdef STLSOFT_UNITTEST
01258 # include "./unittest/scoped_handle_unittest_.h"
01259 #endif
01260
01261
01262
01263 #ifndef _STLSOFT_NO_NAMESPACE
01264 }
01265 #endif
01266
01267
01268
01269
01270
01271
01272
01273 #endif
01274
01275