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
13#ifndef BOOST_INTRUSIVE_DETAIL_EXCEPTION_DISPOSER_HPP
14#define BOOST_INTRUSIVE_DETAIL_EXCEPTION_DISPOSER_HPP
15
16#ifndef BOOST_CONFIG_HPP
17# include <boost/config.hpp>
18#endif
19
20#if defined(BOOST_HAS_PRAGMA_ONCE)
21# pragma once
22#endif
23
24namespace boost {
25namespace intrusive {
26namespace detail {
27
28template<class Container, class Disposer>
29class exception_disposer
30{
31 Container *cont_;
32 Disposer &disp_;
33
34 exception_disposer(const exception_disposer&);
35 exception_disposer &operator=(const exception_disposer&);
36
37 public:
38 exception_disposer(Container &cont, Disposer &disp)
39 : cont_(&cont), disp_(disp)
40 {}
41
42 void release()
43 { cont_ = 0; }
44
45 ~exception_disposer()
46 {
47 if(cont_){
48 cont_->clear_and_dispose(disp_);
49 }
50 }
51};
52
53template<class Container, class Disposer, class SizeType>
54class exception_array_disposer
55{
56 Container *cont_;
57 Disposer &disp_;
58 SizeType &constructed_;
59
60 exception_array_disposer(const exception_array_disposer&);
61 exception_array_disposer &operator=(const exception_array_disposer&);
62
63 public:
64
65 exception_array_disposer
66 (Container &cont, Disposer &disp, SizeType &constructed)
67 : cont_(&cont), disp_(disp), constructed_(constructed)
68 {}
69
70 void release()
71 { cont_ = 0; }
72
73 ~exception_array_disposer()
74 {
75 SizeType n = constructed_;
76 if(cont_){
77 while(n--){
78 cont_[n].clear_and_dispose(disp_);
79 }
80 }
81 }
82};
83
84} //namespace detail{
85} //namespace intrusive{
86} //namespace boost{
87
88#endif //BOOST_INTRUSIVE_DETAIL_EXCEPTION_DISPOSER_HPP
89