Imported Upstream version 1.64.0
[platform/upstream/boost.git] / doc / html / BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS.html
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=US-ASCII">
5 <title>Macro BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS</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="boost_typeindex_header_reference.html#header.boost.type_index.runtime_cast.register_runtime_class_hpp" title="Header &lt;boost/type_index/runtime_cast/register_runtime_class.hpp&gt;">
10 <link rel="prev" href="boost/typeindex/runtime_cast_idp760991072.html" title="Function template runtime_cast">
11 <link rel="next" href="BOOST_TYPE_INDEX_IMPLEMENT_RUNTIME_CAST.html" title="Macro BOOST_TYPE_INDEX_IMPLEMENT_RUNTIME_CAST">
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="boost/typeindex/runtime_cast_idp760991072.html"><img src="../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="boost_typeindex_header_reference.html#header.boost.type_index.runtime_cast.register_runtime_class_hpp"><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="BOOST_TYPE_INDEX_IMPLEMENT_RUNTIME_CAST.html"><img src="../../doc/src/images/next.png" alt="Next"></a>
25 </div>
26 <div class="refentry">
27 <a name="BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS"></a><div class="titlepage"></div>
28 <div class="refnamediv">
29 <h2><span class="refentrytitle">Macro BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS</span></h2>
30 <p>BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS &#8212; Macro used to make a class compatible with boost::typeindex::runtime_cast. </p>
31 </div>
32 <h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
33 <div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="boost_typeindex_header_reference.html#header.boost.type_index.runtime_cast.register_runtime_class_hpp" title="Header &lt;boost/type_index/runtime_cast/register_runtime_class.hpp&gt;">boost/type_index/runtime_cast/register_runtime_class.hpp</a>&gt;
34
35 </span>BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS(base_class_seq)</pre></div>
36 <div class="refsect1">
37 <a name="idp571150080"></a><h2>Description</h2>
38 <p>BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS generates a virtual function in the current class that, when combined with the supplied base class information, allows boost::typeindex::runtime_cast to accurately convert between dynamic types of instances of the current class.</p>
39 <p>BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS also adds support for boost::typeindex::type_id_runtime by including BOOST_TYPE_INDEX_REGISTER_CLASS. It is typical that these features are used together, but in the event that BOOST_TYPE_INDEX_REGISTER_CLASS is undesirable in the current class, BOOST_TYPE_INDEX_IMPLEMENT_RUNTIME_CAST is provided.</p>
40 <p><span class="bold"><strong>Example:</strong></span> </p>
41 <pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">base1</span> <span class="special">{</span>
42     <span class="identifier">BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS</span><span class="special">(</span><span class="identifier">BOOST_TYPE_INDEX_NO_BASE_CLASS</span><span class="special">)</span>
43     <span class="keyword">virtual</span> <span class="special">~</span><span class="identifier">base1</span><span class="special">(</span><span class="special">)</span><span class="special">;</span>
44 <span class="special">}</span><span class="special">;</span>
45
46 <span class="keyword">struct</span> <span class="identifier">base2</span> <span class="special">{</span>
47     <span class="identifier">BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS</span><span class="special">(</span><span class="identifier">BOOST_TYPE_INDEX_NO_BASE_CLASS</span><span class="special">)</span>
48     <span class="keyword">virtual</span> <span class="special">~</span><span class="identifier">base2</span><span class="special">(</span><span class="special">)</span><span class="special">;</span>
49 <span class="special">}</span><span class="special">;</span>
50
51 <span class="keyword">struct</span> <span class="identifier">derived1</span> <span class="special">:</span> <span class="identifier">base1</span> <span class="special">{</span>
52     <span class="identifier">BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS</span><span class="special">(</span><span class="special">(</span><span class="identifier">base1</span><span class="special">)</span><span class="special">)</span>
53 <span class="special">}</span><span class="special">;</span>
54
55 <span class="keyword">struct</span> <span class="identifier">derived2</span> <span class="special">:</span> <span class="identifier">base1</span><span class="special">,</span> <span class="identifier">base2</span> <span class="special">{</span>
56     <span class="identifier">BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS</span><span class="special">(</span><span class="special">(</span><span class="identifier">base1</span><span class="special">)</span><span class="special">(</span><span class="identifier">base2</span><span class="special">)</span><span class="special">)</span>
57 <span class="special">}</span><span class="special">;</span>
58
59 <span class="special">...</span>
60
61 <span class="identifier">base1</span><span class="special">*</span> <span class="identifier">pb1</span> <span class="special">=</span> <span class="identifier">get_object</span><span class="special">(</span><span class="special">)</span><span class="special">;</span>
62 <span class="keyword">if</span><span class="special">(</span><span class="identifier">derived2</span><span class="special">*</span> <span class="identifier">pb2</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">typeindex</span><span class="special">::</span><span class="identifier">runtime_cast</span><span class="special">&lt;</span><span class="identifier">derived2</span><span class="special">*</span><span class="special">&gt;</span><span class="special">(</span><span class="identifier">pb1</span><span class="special">)</span><span class="special">)</span> <span class="special">{</span>
63     <span class="identifier">assert</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">typeindex</span><span class="special">::</span><span class="identifier">type_id_runtime</span><span class="special">(</span><span class="special">*</span><span class="identifier">pb1</span><span class="special">)</span><span class="special">)</span> <span class="special">==</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">typeindex</span><span class="special">::</span><span class="identifier">type_id</span><span class="special">&lt;</span><span class="identifier">derived2</span><span class="special">&gt;</span><span class="special">(</span><span class="special">)</span><span class="special">)</span><span class="special">;</span>
64 <span class="special">}</span>
65 </pre>
66 <p>
67 </p>
68 <div class="variablelist"><table border="0" class="variablelist compact">
69 <colgroup>
70 <col align="left" valign="top">
71 <col>
72 </colgroup>
73 <tbody><tr>
74 <td><p><span class="term">Parameters:</span></p></td>
75 <td><div class="variablelist"><table border="0" class="variablelist compact">
76 <colgroup>
77 <col align="left" valign="top">
78 <col>
79 </colgroup>
80 <tbody><tr>
81 <td><p><span class="term"><code class="computeroutput">base_class_seq</code></span></p></td>
82 <td><p>A Boost.Preprocessor sequence of the current class' direct bases, or BOOST_TYPE_INDEX_NO_BASE_CLASS if this class has no direct base classes. </p></td>
83 </tr></tbody>
84 </table></div></td>
85 </tr></tbody>
86 </table></div>
87 </div>
88 </div>
89 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
90 <td align="left"></td>
91 <td align="right"><div class="copyright-footer">Copyright &#169; 2012-2016 Antony Polukhin<p>
92         Distributed under the Boost Software License, Version 1.0. (See accompanying
93         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>)
94       </p>
95 </div></td>
96 </tr></table>
97 <hr>
98 <div class="spirit-nav">
99 <a accesskey="p" href="boost/typeindex/runtime_cast_idp760991072.html"><img src="../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="boost_typeindex_header_reference.html#header.boost.type_index.runtime_cast.register_runtime_class_hpp"><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="BOOST_TYPE_INDEX_IMPLEMENT_RUNTIME_CAST.html"><img src="../../doc/src/images/next.png" alt="Next"></a>
100 </div>
101 </body>
102 </html>