exception_disposer.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2014-2014
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // See http://www.boost.org/libs/intrusive for documentation.
  10. //
  11. /////////////////////////////////////////////////////////////////////////////
  12. #ifndef BOOST_INTRUSIVE_DETAIL_EXCEPTION_DISPOSER_HPP
  13. #define BOOST_INTRUSIVE_DETAIL_EXCEPTION_DISPOSER_HPP
  14. #ifndef BOOST_CONFIG_HPP
  15. # include <boost/config.hpp>
  16. #endif
  17. #if defined(BOOST_HAS_PRAGMA_ONCE)
  18. # pragma once
  19. #endif
  20. #include <boost/intrusive/detail/workaround.hpp>
  21. namespace boost {
  22. namespace intrusive {
  23. namespace detail {
  24. template<class Container, class Disposer>
  25. class exception_disposer
  26. {
  27. Container *cont_;
  28. Disposer &disp_;
  29. exception_disposer(const exception_disposer&);
  30. exception_disposer &operator=(const exception_disposer&);
  31. public:
  32. exception_disposer(Container &cont, Disposer &disp)
  33. : cont_(&cont), disp_(disp)
  34. {}
  35. BOOST_INTRUSIVE_FORCEINLINE void release()
  36. { cont_ = 0; }
  37. ~exception_disposer()
  38. {
  39. if(cont_){
  40. cont_->clear_and_dispose(disp_);
  41. }
  42. }
  43. };
  44. template<class Container, class Disposer, class SizeType>
  45. class exception_array_disposer
  46. {
  47. Container *cont_;
  48. Disposer &disp_;
  49. SizeType &constructed_;
  50. exception_array_disposer(const exception_array_disposer&);
  51. exception_array_disposer &operator=(const exception_array_disposer&);
  52. public:
  53. exception_array_disposer
  54. (Container &cont, Disposer &disp, SizeType &constructed)
  55. : cont_(&cont), disp_(disp), constructed_(constructed)
  56. {}
  57. BOOST_INTRUSIVE_FORCEINLINE void release()
  58. { cont_ = 0; }
  59. ~exception_array_disposer()
  60. {
  61. SizeType n = constructed_;
  62. if(cont_){
  63. while(n--){
  64. cont_[n].clear_and_dispose(disp_);
  65. }
  66. }
  67. }
  68. };
  69. } //namespace detail{
  70. } //namespace intrusive{
  71. } //namespace boost{
  72. #endif //BOOST_INTRUSIVE_DETAIL_EXCEPTION_DISPOSER_HPP