• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5<title>Safe hooks</title>
6<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
7<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
8<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
9<link rel="up" href="../intrusive.html" title="Chapter 19. Boost.Intrusive">
10<link rel="prev" href="presenting_containers.html" title="Presenting Boost.Intrusive containers">
11<link rel="next" href="auto_unlink_hooks.html" title="Auto-unlink hooks">
12</head>
13<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
14<table cellpadding="2" width="100%"><tr>
15<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
16<td align="center"><a href="../../../index.html">Home</a></td>
17<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
18<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
19<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
20<td align="center"><a href="../../../more/index.htm">More</a></td>
21</tr></table>
22<hr>
23<div class="spirit-nav">
24<a accesskey="p" href="presenting_containers.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../intrusive.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="auto_unlink_hooks.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
25</div>
26<div class="section">
27<div class="titlepage"><div><div><h2 class="title" style="clear: both">
28<a name="intrusive.safe_hook"></a><a class="link" href="safe_hook.html" title="Safe hooks">Safe hooks</a>
29</h2></div></div></div>
30<div class="toc"><dl class="toc">
31<dt><span class="section"><a href="safe_hook.html#intrusive.safe_hook.features">Features of the safe mode</a></span></dt>
32<dt><span class="section"><a href="safe_hook.html#intrusive.safe_hook.configuring">Configuring safe-mode
33      assertions</a></span></dt>
34</dl></div>
35<div class="section">
36<div class="titlepage"><div><div><h3 class="title">
37<a name="intrusive.safe_hook.features"></a><a class="link" href="safe_hook.html#intrusive.safe_hook.features" title="Features of the safe mode">Features of the safe mode</a>
38</h3></div></div></div>
39<p>
40        <span class="bold"><strong>Boost.Intrusive</strong></span> hooks can be configured
41        to operate in safe-link mode. The safe mode is activated by default, but
42        it can be also explicitly activated:
43      </p>
44<pre class="programlisting"><span class="comment">//Configuring the safe mode explicitly</span>
45<span class="keyword">class</span> <span class="identifier">Foo</span> <span class="special">:</span> <span class="keyword">public</span> <span class="identifier">list_base_hook</span><span class="special">&lt;</span> <span class="identifier">link_mode</span><span class="special">&lt;</span><span class="identifier">safe_link</span><span class="special">&gt;</span> <span class="special">&gt;</span>
46<span class="special">{};</span>
47</pre>
48<p>
49        With the safe mode the user can detect if the object is actually inserted
50        in a container without any external reference. Let's review the basic features
51        of the safe mode:
52      </p>
53<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
54<li class="listitem">
55            Hook's constructor puts the hook in a well-known default state.
56          </li>
57<li class="listitem">
58            Hook's destructor checks if the hook is in the well-known default state.
59            If not, an assertion is raised.
60          </li>
61<li class="listitem">
62            Every time an object is inserted in the intrusive container, the container
63            checks if the hook is in the well-known default state. If not, an assertion
64            is raised.
65          </li>
66<li class="listitem">
67            Every time an object is being erased from the intrusive container, the
68            container puts the erased object in the well-known default state.
69          </li>
70</ul></div>
71<p>
72        With these features, without any external reference the user can know if
73        the object has been inserted in a container by calling the <code class="computeroutput"><span class="identifier">is_linked</span><span class="special">()</span></code>
74        member function. If the object is not actually inserted in a container, the
75        hook is in the default state, and if it is inserted in a container, the hook
76        is not in the default state.
77      </p>
78</div>
79<div class="section">
80<div class="titlepage"><div><div><h3 class="title">
81<a name="intrusive.safe_hook.configuring"></a><a class="link" href="safe_hook.html#intrusive.safe_hook.configuring" title="Configuring safe-mode assertions">Configuring safe-mode
82      assertions</a>
83</h3></div></div></div>
84<p>
85        By default, all safe-mode assertions raised by <span class="bold"><strong>Boost-Intrusive</strong></span>
86        hooks and containers in are implemented using <code class="computeroutput"><span class="identifier">BOOST_ASSERT</span></code>,
87        which can be configured by the user. See <a href="http://www.boost.org/libs/utility/assert.html" target="_top">http://www.boost.org/libs/utility/assert.html</a>
88        for more information about <code class="computeroutput"><span class="identifier">BOOST_ASSERT</span></code>.
89      </p>
90<p>
91        <code class="computeroutput"><span class="identifier">BOOST_ASSERT</span></code> is globally
92        configured, so the user might want to redefine intrusive safe-mode assertions
93        without modifying the global <code class="computeroutput"><span class="identifier">BOOST_ASSERT</span></code>.
94        This can be achieved redefining the following macros:
95      </p>
96<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
97<li class="listitem">
98            <code class="computeroutput"><span class="identifier">BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT</span></code>:
99            This assertion will be used in insertion functions of the intrusive containers
100            to check that the hook of the value to be inserted is default constructed.
101          </li>
102<li class="listitem">
103            <code class="computeroutput"><span class="identifier">BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT</span></code>:
104            This assertion will be used in hooks' destructors to check that the hook
105            is in a default state.
106          </li>
107</ul></div>
108<p>
109        If any of these macros is not redefined, the assertion will default to <code class="computeroutput"><span class="identifier">BOOST_ASSERT</span></code>. If <code class="computeroutput"><span class="identifier">BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT</span></code>
110        or <code class="computeroutput"><span class="identifier">BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT</span></code>
111        is defined and the programmer needs to include a file to configure that assertion,
112        it can define <code class="computeroutput"><span class="identifier">BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT_INCLUDE</span></code>
113        or <code class="computeroutput"><span class="identifier">BOOST_INTRUSIVE_SAFE_HOOK_DEFAULT_ASSERT_INCLUDE</span></code>
114        with the name of the file to include:
115      </p>
116<pre class="programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT</span>          <span class="identifier">MYASSERT</span>
117<span class="preprocessor">#define</span> <span class="identifier">BOOST_INTRUSIVE_SAFE_HOOK_DESTRUCTOR_ASSERT_INCLUDE</span> <span class="special">&lt;</span><span class="identifier">myassert</span><span class="special">.</span><span class="identifier">h</span><span class="special">&gt;</span>
118</pre>
119</div>
120</div>
121<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
122<td align="left"></td>
123<td align="right"><div class="copyright-footer">Copyright © 2005 Olaf Krzikalla<br>Copyright © 2006-2015 Ion Gaztanaga<p>
124        Distributed under the Boost Software License, Version 1.0. (See accompanying
125        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
126      </p>
127</div></td>
128</tr></table>
129<hr>
130<div class="spirit-nav">
131<a accesskey="p" href="presenting_containers.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../intrusive.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="auto_unlink_hooks.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
132</div>
133</body>
134</html>
135