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