summaryrefslogtreecommitdiff
path: root/libs/python/doc/html/reference/utility_and_infrastructure/boost_python_type_id_hpp.html
blob: 3e8787488534cb3d72a1a7bcaaa953261054e71f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>boost/python/type_id.hpp</title>
<link rel="stylesheet" href="../../boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.76.1">
<link rel="home" href="../index.html" title="Boost.Python Reference Manual">
<link rel="up" href="../utility_and_infrastructure.html" title="Chapter&#160;7.&#160;Utility and Infrastructure">
<link rel="prev" href="boost_python_handle_hpp.html" title="boost/python/handle.hpp">
<link rel="next" href="boost_python_ssize_t_hpp.html" title="boost/python/ssize_t.hpp">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_handle_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../utility_and_infrastructure.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_ssize_t_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="utility_and_infrastructure.boost_python_type_id_hpp"></a><a class="link" href="boost_python_type_id_hpp.html" title="boost/python/type_id.hpp">boost/python/type_id.hpp</a>
</h2></div></div></div>
<div class="toc"><dl>
<dt><span class="section"><a href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.introduction">Introduction</a></span></dt>
<dt><span class="section"><a href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info">Class
        template <code class="computeroutput"><span class="identifier">type_info</span></code></a></span></dt>
<dt><span class="section"><a href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.functions">Functions</a></span></dt>
<dt><span class="section"><a href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.example">Example</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_type_id_hpp.introduction"></a><a class="link" href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.introduction" title="Introduction">Introduction</a>
</h3></div></div></div>
<p>
          &lt;boost/python/type_id.hpp&gt; provides types and functions for runtime
          type identification like those of of <code class="computeroutput"><span class="special">&lt;</span><span class="identifier">typeinfo</span><span class="special">&gt;</span></code>.
          It exists mostly to work around certain compiler bugs and platform-dependent
          interactions with shared libraries.
        </p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info"></a><a class="link" href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info" title="Class template type_info">Class
        template <code class="computeroutput"><span class="identifier">type_info</span></code></a>
</h3></div></div></div>
<div class="toc"><dl>
<dt><span class="section"><a href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info.class_template_type_info_constru">Class
          template <code class="computeroutput"><span class="identifier">type_info</span></code> constructor</a></span></dt>
<dt><span class="section"><a href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info.class_template_type_info_compari">Class
          template <code class="computeroutput"><span class="identifier">type_info</span></code> comparison</a></span></dt>
<dt><span class="section"><a href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info.class_template_type_info_observe">Class
          template <code class="computeroutput"><span class="identifier">type_info</span></code> observers</a></span></dt>
</dl></div>
<p>
          <code class="computeroutput"><span class="identifier">type_info</span></code> instances identify
          a type. As <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">type_info</span></code> is specified to (but unlike
          its implementation in some compilers), <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">type_info</span></code>
          never represents top-level references or cv-qualification (see section
          5.2.8 in the C++ standard). Unlike <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">type_info</span></code>,
          <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">type_info</span></code> instances are copyable, and
          comparisons always work reliably across shared library boundaries.
        </p>
<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">python</span>
<span class="special">{</span>
  <span class="keyword">class</span> <span class="identifier">type_info</span> <span class="special">:</span> <span class="identifier">totally_ordered</span><span class="special">&lt;</span><span class="identifier">type_info</span><span class="special">&gt;</span>
  <span class="special">{</span>
  <span class="keyword">public</span><span class="special">:</span>
    <span class="comment">// constructor</span>
    <span class="identifier">type_info</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">type_info</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="special">=</span> <span class="keyword">typeid</span><span class="special">(</span><span class="keyword">void</span><span class="special">));</span>

    <span class="comment">// comparisons</span>
    <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">&lt;(</span><span class="identifier">type_info</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">rhs</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
    <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==(</span><span class="identifier">type_info</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="identifier">rhs</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>

    <span class="comment">// observers</span>
    <span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="special">};</span>
<span class="special">}}</span>
</pre>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info.class_template_type_info_constru"></a><a class="link" href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info.class_template_type_info_constru" title="Class template type_info constructor">Class
          template <code class="computeroutput"><span class="identifier">type_info</span></code> constructor</a>
</h4></div></div></div>
<pre class="programlisting"><span class="identifier">type_info</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">type_info</span> <span class="keyword">const</span><span class="special">&amp;</span> <span class="special">=</span> <span class="keyword">typeid</span><span class="special">(</span><span class="keyword">void</span><span class="special">));</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl>
<dt><span class="term">Effects</span></dt>
<dd><p>
                  constructs a <code class="computeroutput"><span class="identifier">type_info</span></code>
                  object which identifies the same type as its argument.
                </p></dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
                  Since it is occasionally necessary to make an array of <code class="computeroutput"><span class="identifier">type_info</span></code> objects a benign default
                  argument is supplied. Note: this constructor does not correct for
                  non-conformance of compiler <code class="computeroutput"><span class="keyword">typeid</span><span class="special">()</span></code> implementations. See <code class="computeroutput"><span class="identifier">type_id</span></code>, below.
                </p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info.class_template_type_info_compari"></a><a class="link" href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info.class_template_type_info_compari" title="Class template type_info comparison">Class
          template <code class="computeroutput"><span class="identifier">type_info</span></code> comparison</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">&lt;(</span><span class="identifier">type_info</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="identifier">rhs</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl>
<dt><span class="term">Effects</span></dt>
<dd><p>
                  yields a total order over <code class="computeroutput"><span class="identifier">type_info</span></code>
                  objects.
                </p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==(</span><span class="identifier">type_info</span> <span class="keyword">const</span> <span class="special">&amp;</span><span class="identifier">rhs</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl>
<dt><span class="term">Returns</span></dt>
<dd><p>
                  <code class="computeroutput"><span class="keyword">true</span></code> iff the two values
                  describe the same type.
                </p></dd>
<dt><span class="term">Note</span></dt>
<dd><p>
                  The use of <code class="computeroutput"><span class="identifier">totally_ordered</span><span class="special">&lt;</span><span class="identifier">type_info</span><span class="special">&gt;</span></code> as a private base class supplies
                  operators <code class="computeroutput"><span class="special">&lt;=</span></code>,
                  <code class="computeroutput"><span class="special">&gt;=</span></code>, <code class="computeroutput"><span class="special">&gt;</span></code>, and <code class="computeroutput"><span class="special">!=</span></code>
                </p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info.class_template_type_info_observe"></a><a class="link" href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.class_template_type_info.class_template_type_info_observe" title="Class template type_info observers">Class
          template <code class="computeroutput"><span class="identifier">type_info</span></code> observers</a>
</h4></div></div></div>
<pre class="programlisting"><span class="keyword">char</span> <span class="keyword">const</span><span class="special">*</span> <span class="identifier">name</span><span class="special">()</span> <span class="keyword">const</span><span class="special">;</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl>
<dt><span class="term">Returns</span></dt>
<dd><p>
                  The result of calling <code class="computeroutput"><span class="identifier">name</span><span class="special">()</span></code> on the argument used to construct
                  the object.
                </p></dd>
</dl>
</div>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_type_id_hpp.functions"></a><a class="link" href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.functions" title="Functions">Functions</a>
</h3></div></div></div>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">ostream</span><span class="special">&amp;</span> <span class="keyword">operator</span><span class="special">&lt;&lt;(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">ostream</span><span class="special">&amp;</span><span class="identifier">s</span><span class="special">,</span> <span class="identifier">type_info</span> <span class="keyword">const</span><span class="special">&amp;</span><span class="identifier">x</span><span class="special">);</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl>
<dt><span class="term">Effects</span></dt>
<dd><p>
                Writes a description of the type described by to <code class="computeroutput"><span class="identifier">x</span></code>
                into s.
              </p></dd>
<dt><span class="term">Rationale</span></dt>
<dd><p>
                Not every C++ implementation provides a truly human-readable <code class="computeroutput"><span class="identifier">type_info</span><span class="special">::</span><span class="identifier">name</span><span class="special">()</span></code>
                string, but for some we may be able to decode the string and produce
                a reasonable representation.
              </p></dd>
<dt><span class="term">Note</span></dt>
<dd><p>
                On some non-conforming C++ implementations, the code is not actually
                as simple as described above; the semantics are adjusted to work
                as-if the C++ implementation were conforming.
              </p></dd>
</dl>
</div>
<pre class="programlisting"><span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span> <span class="identifier">type_info</span> <span class="identifier">type_id</span><span class="special">()</span>
</pre>
<div class="variablelist">
<p class="title"><b></b></p>
<dl>
<dt><span class="term">Returns</span></dt>
<dd><p>
                <code class="computeroutput"><span class="identifier">type_info</span><span class="special">(</span><span class="keyword">typeid</span><span class="special">(</span><span class="identifier">T</span><span class="special">))</span></code>
              </p></dd>
<dt><span class="term">Note</span></dt>
<dd><p>
                On some non-conforming C++ implementations, the code is not actually
                as simple as described above; the semantics are adjusted to work
                as-if the C++ implementation were conforming.
              </p></dd>
</dl>
</div>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="utility_and_infrastructure.boost_python_type_id_hpp.example"></a><a class="link" href="boost_python_type_id_hpp.html#utility_and_infrastructure.boost_python_type_id_hpp.example" title="Example">Example</a>
</h3></div></div></div>
<p>
          The following example, though silly, illustrates how the type_id facility
          might be used
        </p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">python</span><span class="special">/</span><span class="identifier">type_id</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>

<span class="comment">// Returns true iff the user passes an int argument</span>
<span class="keyword">template</span> <span class="special">&lt;</span><span class="keyword">class</span> <span class="identifier">T</span><span class="special">&gt;</span>
<span class="keyword">bool</span> <span class="identifier">is_int</span><span class="special">(</span><span class="identifier">T</span> <span class="identifier">x</span><span class="special">)</span>
<span class="special">{</span>
   <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">python</span><span class="special">::</span><span class="identifier">type_id</span><span class="special">;</span>
   <span class="keyword">return</span> <span class="identifier">type_id</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;()</span> <span class="special">==</span> <span class="identifier">type_id</span><span class="special">&lt;</span><span class="keyword">int</span><span class="special">&gt;();</span>
<span class="special">}</span>
</pre>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2002-2005, 2015 David Abrahams, Stefan Seefeld<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        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>
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="boost_python_handle_hpp.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../utility_and_infrastructure.html"><img src="../../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../images/home.png" alt="Home"></a><a accesskey="n" href="boost_python_ssize_t_hpp.html"><img src="../../images/next.png" alt="Next"></a>
</div>
</body>
</html>