File: mask.html

package info (click to toggle)
boost1.42 1.42.0-4
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 277,864 kB
  • ctags: 401,076
  • sloc: cpp: 1,235,659; xml: 74,142; ansic: 41,313; python: 26,756; sh: 11,840; cs: 2,118; makefile: 655; perl: 494; yacc: 456; asm: 353; csh: 6
file content (375 lines) | stat: -rw-r--r-- 19,156 bytes parent folder | download
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Integer Masks</title>
<link rel="stylesheet" href="../../../../../doc/html/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.74.0">
<link rel="home" href="../index.html" title="Boost.Integer">
<link rel="up" href="../index.html" title="Boost.Integer">
<link rel="prev" href="integer.html" title="Integer Type Selection">
<link rel="next" href="log2.html" title="Compile Time log2 Calculation">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
<td align="center"><a href="../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="integer.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="log2.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="boost_integer.mask"></a><a class="link" href="mask.html" title="Integer Masks"> Integer Masks</a>
</h2></div></div></div>
<div class="toc"><dl>
<dt><span class="section"><a href="mask.html#boost_integer.mask.overview">Overview</a></span></dt>
<dt><span class="section"><a href="mask.html#boost_integer.mask.synopsis">Synopsis</a></span></dt>
<dt><span class="section"><a href="mask.html#boost_integer.mask.single_bit_mask_class_template">Single
      Bit-Mask Class Template</a></span></dt>
<dt><span class="section"><a href="mask.html#boost_integer.mask.group_bit_mask_class_template">Group
      Bit-Mask Class Template</a></span></dt>
<dt><span class="section"><a href="mask.html#boost_integer.mask.implementation_notes">Implementation
      Notes</a></span></dt>
<dt><span class="section"><a href="mask.html#boost_integer.mask.example">Example</a></span></dt>
<dt><span class="section"><a href="mask.html#boost_integer.mask.demonstration_program">Demonstration
      Program</a></span></dt>
<dt><span class="section"><a href="mask.html#boost_integer.mask.rationale">Rationale</a></span></dt>
<dt><span class="section"><a href="mask.html#boost_integer.mask.credits">Credits</a></span></dt>
</dl></div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_integer.mask.overview"></a><a class="link" href="mask.html#boost_integer.mask.overview" title="Overview">Overview</a>
</h3></div></div></div>
<p>
        The class templates in <a href="../../../../../boost/integer/integer_mask.hpp" target="_top">&lt;boost/integer/integer_mask.hpp&gt;</a>
        provide bit masks for a certain bit position or a contiguous-bit pack of
        a certain size. The types of the masking constants come from the <a class="link" href="integer.html" title="Integer Type Selection">integer
        type selection templates</a> header.
      </p>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_integer.mask.synopsis"></a><a class="link" href="mask.html#boost_integer.mask.synopsis" title="Synopsis">Synopsis</a>
</h3></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">cstddef</span><span class="special">&gt;</span>  <span class="comment">// for std::size_t
</span>
<span class="keyword">namespace</span> <span class="identifier">boost</span>
<span class="special">{</span>

<span class="keyword">template</span> <span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">Bit</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">high_bit_mask_t</span>
<span class="special">{</span>
    <span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span>  <span class="identifier">least</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span>  <span class="identifier">fast</span><span class="special">;</span>

    <span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">least</span>       <span class="identifier">high_bit</span>       <span class="special">=</span> <span class="emphasis"><em>implementation-defined</em></span><span class="special">;</span>
    <span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">fast</span>        <span class="identifier">high_bit_fast</span>  <span class="special">=</span> <span class="emphasis"><em>implementation-defined</em></span><span class="special">;</span>

    <span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">bit_position</span>   <span class="special">=</span> <span class="identifier">Bit</span><span class="special">;</span>
<span class="special">};</span>

<span class="keyword">template</span> <span class="special">&lt;</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">Bits</span><span class="special">&gt;</span>
<span class="keyword">struct</span> <span class="identifier">low_bits_mask_t</span>
<span class="special">{</span>
    <span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span>  <span class="identifier">least</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="emphasis"><em>implementation-defined-type</em></span>  <span class="identifier">fast</span><span class="special">;</span>

    <span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">least</span>       <span class="identifier">sig_bits</span>       <span class="special">=</span> <span class="emphasis"><em>implementation-defined</em></span><span class="special">;</span>
    <span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">fast</span>        <span class="identifier">sig_bits_fast</span>  <span class="special">=</span> <span class="emphasis"><em>implementation-defined</em></span><span class="special">;</span>

    <span class="keyword">static</span> <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">bit_count</span>      <span class="special">=</span> <span class="identifier">Bits</span><span class="special">;</span>
<span class="special">};</span>

<span class="comment">// Specializations for low_bits_mask_t exist for certain bit counts.
</span>
<span class="special">}</span>  <span class="comment">// namespace boost
</span></pre>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_integer.mask.single_bit_mask_class_template"></a><a class="link" href="mask.html#boost_integer.mask.single_bit_mask_class_template" title="Single Bit-Mask Class Template">Single
      Bit-Mask Class Template</a>
</h3></div></div></div>
<p>
        The <code class="literal">boost::high_bit_mask_t</code> class template provides constants
        for bit masks representing the bit at a certain position. The masks are equivalent
        to the value 2<sup>Bit</sup>, where <code class="literal">Bit</code> is the template parameter.
        The bit position must be a nonnegative number from zero to <span class="emphasis"><em>Max</em></span>,
        where Max is one less than the number of bits supported by the largest unsigned
        built-in integral type. The following table describes the members of an instantiation
        of <code class="literal">high_bit_mask_t</code>.
      </p>
<div class="table">
<a name="id782866"></a><p class="title"><b>Table&#160;2.&#160;Members of the `boost::high_bit_mask_t` Class Template</b></p>
<div class="table-contents"><table class="table" summary="Members of the `boost::high_bit_mask_t` Class Template">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
            <p>
              Member
            </p>
            </th>
<th>
            <p>
              Meaning
            </p>
            </th>
</tr></thead>
<tbody>
<tr>
<td>
            <p>
              <code class="literal">least</code>
            </p>
            </td>
<td>
            <p>
              The smallest, unsigned, built-in type that supports the given bit position.
            </p>
            </td>
</tr>
<tr>
<td>
            <p>
              <code class="literal">fast</code>
            </p>
            </td>
<td>
            <p>
              The easiest-to-manipulate analog of <code class="literal">least</code>.
            </p>
            </td>
</tr>
<tr>
<td>
            <p>
              <code class="literal">high_bit</code>
            </p>
            </td>
<td>
            <p>
              A <code class="literal">least</code> constant of the value 2<sup>Bit</sup>.
            </p>
            </td>
</tr>
<tr>
<td>
            <p>
              <code class="literal">high_bit_fast</code>
            </p>
            </td>
<td>
            <p>
              A <code class="literal">fast</code> analog of <code class="literal">high_bit</code>.
            </p>
            </td>
</tr>
<tr>
<td>
            <p>
              <code class="literal">bit_position</code>
            </p>
            </td>
<td>
            <p>
              The value of the template parameter, in case its needed from a renamed
              instantiation of the class template.
            </p>
            </td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break">
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_integer.mask.group_bit_mask_class_template"></a><a class="link" href="mask.html#boost_integer.mask.group_bit_mask_class_template" title="Group Bit-Mask Class Template">Group
      Bit-Mask Class Template</a>
</h3></div></div></div>
<p>
        The <code class="literal">boost::low_bits_mask_t</code> class template provides constants
        for bit masks equivalent to the value (2<sup>Bits</sup> - 1), where <code class="literal">Bits</code>
        is the template parameter. The parameter <code class="literal">Bits</code> must be
        a non-negative integer from zero to <span class="emphasis"><em>Max</em></span>, where Max is
        the number of bits supported by the largest, unsigned, built-in integral
        type. The following table describes the members of <code class="literal">low_bits_mask_t</code>.
      </p>
<div class="table">
<a name="id783074"></a><p class="title"><b>Table&#160;3.&#160;Members of the [^boost::low_bits_mask_t] Class Template</b></p>
<div class="table-contents"><table class="table" summary="Members of the [^boost::low_bits_mask_t] Class Template">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
            <p>
              Member
            </p>
            </th>
<th>
            <p>
              Meaning
            </p>
            </th>
</tr></thead>
<tbody>
<tr>
<td>
            <p>
              <code class="literal">least</code>
            </p>
            </td>
<td>
            <p>
              The smallest, unsigned built-in type that supports the given bit count.
            </p>
            </td>
</tr>
<tr>
<td>
            <p>
              <code class="literal">fast</code>
            </p>
            </td>
<td>
            <p>
              The easiest-to-manipulate analog of <code class="literal">least</code>.
            </p>
            </td>
</tr>
<tr>
<td>
            <p>
              <code class="literal">sig_bits</code>
            </p>
            </td>
<td>
            <p>
              A <code class="literal">least</code> constant of the desired bit-masking value.
            </p>
            </td>
</tr>
<tr>
<td>
            <p>
              <code class="literal">sig_bits_fast</code>
            </p>
            </td>
<td>
            <p>
              A <code class="literal">fast</code> analog of <code class="literal">sig_bits</code>.
            </p>
            </td>
</tr>
<tr>
<td>
            <p>
              <code class="literal">bit_count</code>
            </p>
            </td>
<td>
            <p>
              The value of the template parameter, in case its needed from a renamed
              instantiation of the class template.
            </p>
            </td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break">
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_integer.mask.implementation_notes"></a><a class="link" href="mask.html#boost_integer.mask.implementation_notes" title="Implementation Notes">Implementation
      Notes</a>
</h3></div></div></div>
<p>
        When <code class="literal">Bits</code> is the exact size of a built-in unsigned type,
        the implementation has to change to prevent undefined behavior. Therefore,
        there are specializations of <code class="literal">low_bits_mask_t</code> at those
        bit counts.
      </p>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_integer.mask.example"></a><a class="link" href="mask.html#boost_integer.mask.example" title="Example">Example</a>
</h3></div></div></div>
<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">integer</span><span class="special">/</span><span class="identifier">integer_mask</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>

<span class="comment">//...
</span>
<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
<span class="special">{</span>
    <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">high_bit_mask_t</span><span class="special">&lt;</span><span class="number">29</span><span class="special">&gt;</span>  <span class="identifier">mask1_type</span><span class="special">;</span>
    <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">low_bits_mask_t</span><span class="special">&lt;</span><span class="number">15</span><span class="special">&gt;</span>  <span class="identifier">mask2_type</span><span class="special">;</span>

    <span class="identifier">mask1_type</span><span class="special">::</span><span class="identifier">least</span>  <span class="identifier">my_var1</span><span class="special">;</span>
    <span class="identifier">mask2_type</span><span class="special">::</span><span class="identifier">fast</span>   <span class="identifier">my_var2</span><span class="special">;</span>
    <span class="comment">//...
</span>
    <span class="identifier">my_var1</span> <span class="special">|=</span> <span class="identifier">mask1_type</span><span class="special">::</span><span class="identifier">high_bit</span><span class="special">;</span>
    <span class="identifier">my_var2</span> <span class="special">&amp;=</span> <span class="identifier">mask2_type</span><span class="special">::</span><span class="identifier">sig_bits_fast</span><span class="special">;</span>

    <span class="comment">//...
</span><span class="special">}</span>
</pre>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_integer.mask.demonstration_program"></a><a class="link" href="mask.html#boost_integer.mask.demonstration_program" title="Demonstration Program">Demonstration
      Program</a>
</h3></div></div></div>
<p>
        The program <a href="../../../test/integer_mask_test.cpp" target="_top">integer_mask_test.cpp</a>
        is a simplistic demonstration of the results from instantiating various examples
        of the bit mask class templates.
      </p>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_integer.mask.rationale"></a><a class="link" href="mask.html#boost_integer.mask.rationale" title="Rationale">Rationale</a>
</h3></div></div></div>
<p>
        The class templates in this header are an extension of the <a class="link" href="integer.html" title="Integer Type Selection">integer
        type selection class templates</a>. The new class templates provide the
        same sized types, but also convenient masks to use when extracting the highest
        or all the significant bits when the containing built-in type contains more
        bits. This prevents contamination of values by the higher, unused bits.
      </p>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_integer.mask.credits"></a><a class="link" href="mask.html#boost_integer.mask.credits" title="Credits">Credits</a>
</h3></div></div></div>
<p>
        The author of the Boost bit mask class templates is <a href="http://www.boost.org/people/daryle_walker.html" target="_top">Daryle
        Walker</a>.
      </p>
</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; 2001 -2009 Beman Dawes, Daryle Walker, Gennaro Prota,
      John Maddock<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="integer.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="log2.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
</div>
</body>
</html>