Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/integer/doc/integer_mask.html @ 14

Last change on this file since 14 was 12, checked in by landauf, 17 years ago

added boost

File size: 6.7 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
2<html>
3<head>
4<title>Integer Bit Mask Templates</title>
5</head>
6
7<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">
8<h1><img src="../../../boost.png" alt="boost.png (6897 bytes)"
9align="middle" width="277" height="86">Integer Bit Mask Templates</h1>
10
11<p>The class templates in <cite><a href="../../../boost/integer/integer_mask.hpp">&lt;boost/integer/integer_mask.hpp&gt;</a></cite> 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 href="../integer.htm">integer type selection templates</a> header.</p>
12
13<h2><a name="contents">Contents</a></h2>
14
15<ul>
16        <li><a href="#contents">Contents</a></li>
17        <li><a href="#synopsis">Synopsis</a></li>
18        <li><a href="#single">Single Bit-Mask Class Template</a></li>
19        <li><a href="#group">Group Bit-Mask Class Template</a></li>
20        <li><a href="#example">Example</a></li>
21        <li><a href="#demo">Demonstration Program</a></li>
22        <li><a href="#rationale">Rationale</a></li>
23        <li><a href="#credits">Credits</a></li>
24</ul>
25
26<h2><a name="synopsis">Synopsis</a></h2>
27
28<blockquote><pre>
29#include &lt;cstddef&gt;  <i>// for std::size_t</i>
30
31namespace boost
32{
33
34template &lt; std::size_t Bit &gt;
35struct high_bit_mask_t
36{
37    typedef <em>implementation_supplied</em>  least;
38    typedef <em>implementation_supplied</em>   fast;
39
40    static const least  high_bit = <em>implementation_defined</em>;
41    static const fast   high_bit_fast = <em>implementation_defined</em>;
42
43    static const std::size_t  bit_position = Bit;
44
45};
46
47template &lt; std::size_t Bits &gt;
48struct low_bits_mask_t
49{
50    typedef <em>implementation_supplied</em>  least;
51    typedef <em>implementation_supplied</em>   fast;
52
53    static const least  sig_bits = <em>implementation_defined</em>;
54    static const fast   sig_bits_fast = <em>implementation_defined</em>;
55
56    static const std::size_t  bit_count = Bits;
57
58};
59
60// Specializations for low_bits_mask_t exist for certain bit counts.
61
62}  // namespace boost
63</pre></blockquote>
64
65<h2><a name="single">Single Bit-Mask Class Template</a></h2>
66
67<p>The <code>boost::high_bit_mask_t</code> class template provides
68constants for bit masks representing the bit at a certain position.  The
69masks are equivalent to the value 2<sup><code>Bit</code></sup>, where
70<code>Bit</code> is the template parameter.  The bit position must be a
71nonnegative number from zero to <i>Max</i>, where <dfn>Max</dfn> is one
72less than the number of bits supported by the largest unsigned built-in
73integral type.  The following table describes the members of an
74instantiation of <code>high_bit_mask_t</code>.</p>
75
76<table border="1" cellpadding="5">
77        <caption>Members of the <code>boost::high_bit_mask_t</code> Class
78                Template</caption>
79        <tr>
80                <th>Member</th>
81                <th>Meaning</th>
82        </tr>
83        <tr>
84                <td><code>least</code></td>
85                <td>The smallest unsigned built-in type that supports the given
86                        bit position.</td>
87        </tr>
88        <tr>
89                <td><code>fast</code></td>
90                <td>The quick-to-manipulate analog of <code>least</code>.</td>
91        </tr>
92        <tr>
93                <td><code>high_bit</code></td>
94                <td>A <code>least</code> constant of the desired bit-masking
95                        value.</td>
96        </tr>
97        <tr>
98                <td><code>high_bit_fast</code></td>
99                <td>A <code>fast</code> analog of <code>high_bit</code>.</td>
100        </tr>
101        <tr>
102                <td><code>bit_position</code></td>
103                <td>The value of the template parameter, in case its needed from
104                        a renamed instantiation of the class template.</td>
105        </tr>
106</table>
107
108<h2><a name="group">Group Bit-Mask Class Template</a></h2>
109
110<p>The <code>boost::low_bits_mask_t</code> class template provides
111constants for bit masks representing the lowest bits of a certain
112amount.  The masks are equivalent to the value
113(2<sup><code>Bits</code></sup> - 1), where <code>Bits</code> is the
114template parameter.  The bit amount must be a nonnegative number from
115zero to <i>Max</i>, where <dfn>Max</dfn> is the number of bits supported
116by the largest unsigned built-in integral type.  The following table
117describes the members of an instantiation of
118<code>low_bits_mask_t</code>.</p>
119
120<table border="1" cellpadding="5">
121        <caption>Members of the <code>boost::low_bits_mask_t</code> Class
122                Template</caption>
123        <tr>
124                <th>Member</th>
125                <th>Meaning</th>
126        </tr>
127        <tr>
128                <td><code>least</code></td>
129                <td>The smallest unsigned built-in type that supports the given
130                        bit count.</td>
131        </tr>
132        <tr>
133                <td><code>fast</code></td>
134                <td>The quick-to-manipulate analog of <code>least</code>.</td>
135        </tr>
136        <tr>
137                <td><code>sig_bits</code></td>
138                <td>A <code>least</code> constant of the desired bit-masking
139                        value.</td>
140        </tr>
141        <tr>
142                <td><code>sig_bits_fast</code></td>
143                <td>A <code>fast</code> analog of <code>sig_bits</code>.</td>
144        </tr>
145        <tr>
146                <td><code>bit_count</code></td>
147                <td>The value of the template parameter, in case its needed from
148                        a renamed instantiation of the class template.</td>
149        </tr>
150</table>
151
152<p><strong>Implementation Note</strong><br>
153When <code>Bits</code> is the exact size of a built-in unsigned type,
154the implementation has to change to prevent undefined behavior.
155Therefore, there are specializations of <code>low_bits_mask_t</code> at
156those bit counts.</p>
157
158<h2><a name="example">Example</a></h2>
159
160<blockquote><pre>
161#include &lt;boost/integer/integer_mask.hpp&gt;
162
163//...
164
165int main()
166{
167    typedef boost::high_bit_mask_t&lt;29&gt;  mask1_type;
168    typedef boost::low_bits_mask_t&lt;15&gt;  mask2_type;
169
170    mask1_type::least  my_var1;
171    mask2_type::fast   my_var2;
172    //...
173
174    my_var1 |= mask1_type::high_bit;
175    my_var2 &amp;= mask2_type::sig_bits_fast;
176
177    //...
178}
179</pre></blockquote>
180
181<h2><a name="demo">Demonstration Program</a></h2>
182
183<p>The program <a href="../test/integer_mask_test.cpp">integer_mask_test.cpp</a>
184is a simplistic demonstration of the results from instantiating various
185examples of the bit mask class templates.</p>
186
187<h2><a name="rationale">Rationale</a></h2>
188
189<p>The class templates in this header are an extension of the <a
190href="../integer.htm">integer type selection class templates</a>.  The new
191class templates provide the same sized types, but also convienent masks
192to use when extracting the highest or all the significant bits when the
193containing built-in type contains more bits.  This prevents
194contaimination of values by the higher, unused bits.</p>
195
196<h2><a name="credits">Credits</a></h2>
197
198<p>The author of the Boost bit mask class templates is <a
199href="../../../people/daryle_walker.html">Daryle Walker</a>.</p>
200
201<hr>
202
203<p>Revised September 23, 2001</p>
204
205<p>&copy; Copyright Daryle Walker 2001.  Permission to copy, use,
206modify, sell and distribute this document is granted provided this
207copyright notice appears in all copies.  This document is provided
208&quot;as is&quot; without express or implied warranty, and with no claim
209as to its suitability for any purpose.</p>
210</body>
211</html>
Note: See TracBrowser for help on using the repository browser.