File: a00110.html

package info (click to toggle)
bmagic 3.4.0-4
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,208 kB
  • ctags: 2,500
  • sloc: cpp: 9,399; ansic: 3,142; sh: 2,430; makefile: 340
file content (375 lines) | stat: -rw-r--r-- 27,617 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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>BitMagic: encoding.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.1 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="examples.html">Examples</a></div>
<div class="nav">
<a class="el" href="dir_000000.html">src</a></div>
<h1>encoding.h</h1><a href="a00082.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*</span>
00002 <span class="comment">Copyright(c) 2002-2005 Anatoliy Kuznetsov(anatoliy_kuznetsov at yahoo.com)</span>
00003 <span class="comment"></span>
00004 <span class="comment"></span>
00005 <span class="comment">Permission is hereby granted, free of charge, to any person </span>
00006 <span class="comment">obtaining a copy of this software and associated documentation </span>
00007 <span class="comment">files (the "Software"), to deal in the Software without restriction, </span>
00008 <span class="comment">including without limitation the rights to use, copy, modify, merge, </span>
00009 <span class="comment">publish, distribute, sublicense, and/or sell copies of the Software, </span>
00010 <span class="comment">and to permit persons to whom the Software is furnished to do so, </span>
00011 <span class="comment">subject to the following conditions:</span>
00012 <span class="comment"></span>
00013 <span class="comment">The above copyright notice and this permission notice shall be included </span>
00014 <span class="comment">in all copies or substantial portions of the Software.</span>
00015 <span class="comment"></span>
00016 <span class="comment">THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, </span>
00017 <span class="comment">EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES </span>
00018 <span class="comment">OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. </span>
00019 <span class="comment">IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, </span>
00020 <span class="comment">DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, </span>
00021 <span class="comment">ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR </span>
00022 <span class="comment">OTHER DEALINGS IN THE SOFTWARE.</span>
00023 <span class="comment"></span>
00024 <span class="comment"></span>
00025 <span class="comment">For more information please visit:   http://bmagic.sourceforge.net</span>
00026 <span class="comment"></span>
00027 <span class="comment">*/</span>
00028 
00029 <span class="preprocessor">#ifndef ENCODING_H__INCLUDED__</span>
00030 <span class="preprocessor"></span><span class="preprocessor">#define ENCODING_H__INCLUDED__</span>
00031 <span class="preprocessor"></span>
00032 <span class="preprocessor">#include &lt;memory.h&gt;</span>
00033 
00034 <span class="keyword">namespace </span>bm
00035 {
00036 
00037 <span class="comment">// ----------------------------------------------------------------</span><span class="comment"></span>
00038 <span class="comment">/*!</span>
00039 <span class="comment">   \brief Memory encoding.</span>
00040 <span class="comment">   </span>
00041 <span class="comment">   Class for encoding data into memory. </span>
00042 <span class="comment">   Properly handles aligment issues with integer data types.</span>
00043 <span class="comment">*/</span>
<a name="l00044"></a><a class="code" href="a00066.html">00044</a> <span class="keyword">class </span><a class="code" href="a00066.html">encoder</a>
00045 {
00046 <span class="keyword">public</span>:
00047     <a class="code" href="a00066.html#a0">encoder</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* buf, <span class="keywordtype">unsigned</span> <a class="code" href="a00066.html#a6">size</a>);
00048     <span class="keywordtype">void</span> <a class="code" href="a00066.html#a1">put_8</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c);
00049     <span class="keywordtype">void</span> <a class="code" href="a00066.html#a2">put_16</a>(bm::short_t  s);
00050     <span class="keywordtype">void</span> <a class="code" href="a00066.html#a2">put_16</a>(<span class="keyword">const</span> bm::short_t* s, <span class="keywordtype">unsigned</span> count);
00051     <span class="keywordtype">void</span> <a class="code" href="a00066.html#a4">put_32</a>(bm::word_t  w);
00052     <span class="keywordtype">void</span> <a class="code" href="a00066.html#a4">put_32</a>(<span class="keyword">const</span> bm::word_t* w, <span class="keywordtype">unsigned</span> count);
00053     <span class="keywordtype">unsigned</span> <a class="code" href="a00066.html#a6">size</a>() <span class="keyword">const</span>;
00054 <span class="keyword">private</span>:
00055     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*  buf_;
00056     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*  start_;
00057     <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>    size_;
00058 };
00059 
00060 <span class="comment">// ----------------------------------------------------------------</span><span class="comment"></span>
00061 <span class="comment">/**</span>
00062 <span class="comment">    Base class for all decoding functionality</span>
00063 <span class="comment">*/</span>
<a name="l00064"></a><a class="code" href="a00063.html">00064</a> <span class="keyword">class </span><a class="code" href="a00063.html">decoder_base</a>
00065 {
00066 <span class="keyword">public</span>:
<a name="l00067"></a><a class="code" href="a00063.html#a0">00067</a>     <a class="code" href="a00063.html#a0">decoder_base</a>(<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* buf) { <a class="code" href="a00063.html#p0">buf_</a> = <a class="code" href="a00063.html#p1">start_</a> = buf; }<span class="comment"></span>
00068 <span class="comment">    /// Reads character from the decoding buffer. </span>
<a name="l00069"></a><a class="code" href="a00063.html#a1">00069</a> <span class="comment"></span>    <a class="code" href="a00077.html#a12">BMFORCEINLINE</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> <a class="code" href="a00063.html#a1">get_8</a>() { <span class="keywordflow">return</span> *<a class="code" href="a00063.html#p0">buf_</a>++; }<span class="comment"></span>
00070 <span class="comment">    /// Returns size of the current decoding stream.</span>
00071 <span class="comment"></span>    <a class="code" href="a00077.html#a12">BMFORCEINLINE</a> 
<a name="l00072"></a><a class="code" href="a00063.html#a2">00072</a>     <span class="keywordtype">unsigned</span> <a class="code" href="a00063.html#a2">size</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> (<span class="keywordtype">unsigned</span>)(<a class="code" href="a00063.html#p0">buf_</a> - <a class="code" href="a00063.html#p1">start_</a>); }
00073 <span class="keyword">protected</span>:
<a name="l00074"></a><a class="code" href="a00063.html#p0">00074</a>    <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*   <a class="code" href="a00063.html#p0">buf_</a>;
<a name="l00075"></a><a class="code" href="a00063.html#p1">00075</a>    <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*   <a class="code" href="a00063.html#p1">start_</a>;
00076 };
00077 
00078 
00079 <span class="comment">// ----------------------------------------------------------------</span><span class="comment"></span>
00080 <span class="comment">/**</span>
00081 <span class="comment">   Class for decoding data from memory buffer.</span>
00082 <span class="comment">   Properly handles aligment issues with integer data types.</span>
00083 <span class="comment">*/</span>
<a name="l00084"></a><a class="code" href="a00062.html">00084</a> <span class="keyword">class </span><a class="code" href="a00062.html">decoder</a> : <span class="keyword">public</span> <a class="code" href="a00063.html">decoder_base</a>
00085 {
00086 <span class="keyword">public</span>:
00087     <a class="code" href="a00062.html#a0">decoder</a>(<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* buf);
00088     bm::short_t <a class="code" href="a00062.html#a1">get_16</a>();
00089     bm::word_t <a class="code" href="a00062.html#a2">get_32</a>();
00090     <span class="keywordtype">void</span> <a class="code" href="a00062.html#a2">get_32</a>(bm::word_t* w, <span class="keywordtype">unsigned</span> count);
00091     <span class="keywordtype">void</span> <a class="code" href="a00062.html#a1">get_16</a>(bm::short_t* s, <span class="keywordtype">unsigned</span> count);
00092 };
00093 
00094 <span class="comment">// ----------------------------------------------------------------</span><span class="comment"></span>
00095 <span class="comment">/**</span>
00096 <span class="comment">   Class for decoding data from memory buffer.</span>
00097 <span class="comment">   Properly handles aligment issues with integer data types.</span>
00098 <span class="comment">   Converts data to big endian architecture </span>
00099 <span class="comment">   (presumed it was encoded as little endian)</span>
00100 <span class="comment">*/</span>
<a name="l00101"></a><a class="code" href="a00092.html#a7">00101</a> <span class="keyword">typedef</span> <a class="code" href="a00062.html">decoder</a> <a class="code" href="a00062.html">decoder_big_endian</a>;
00102 
00103 
00104 <span class="comment">// ----------------------------------------------------------------</span><span class="comment"></span>
00105 <span class="comment">/**</span>
00106 <span class="comment">   Class for decoding data from memory buffer.</span>
00107 <span class="comment">   Properly handles aligment issues with integer data types.</span>
00108 <span class="comment">   Converts data to little endian architecture </span>
00109 <span class="comment">   (presumed it was encoded as big endian)</span>
00110 <span class="comment">*/</span>
<a name="l00111"></a><a class="code" href="a00064.html">00111</a> <span class="keyword">class </span><a class="code" href="a00064.html">decoder_little_endian</a> : <span class="keyword">public</span> <a class="code" href="a00063.html">decoder_base</a>
00112 {
00113 <span class="keyword">public</span>:
00114     <a class="code" href="a00064.html#a0">decoder_little_endian</a>(<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* buf);
00115     bm::short_t <a class="code" href="a00064.html#a1">get_16</a>();
00116     bm::word_t <a class="code" href="a00064.html#a2">get_32</a>();
00117     <span class="keywordtype">void</span> <a class="code" href="a00064.html#a2">get_32</a>(bm::word_t* w, <span class="keywordtype">unsigned</span> count);
00118     <span class="keywordtype">void</span> <a class="code" href="a00064.html#a1">get_16</a>(bm::short_t* s, <span class="keywordtype">unsigned</span> count);
00119 };
00120 
00121 
00122 
00123 <span class="comment">// ----------------------------------------------------------------</span>
00124 <span class="comment">// Implementation details. </span>
00125 <span class="comment">// ----------------------------------------------------------------</span>
00126 <span class="comment"></span>
00127 <span class="comment">/*! </span>
00128 <span class="comment">    \fn encoder::encoder(unsigned char* buf, unsigned size) </span>
00129 <span class="comment">    \brief Construction.</span>
00130 <span class="comment">    \param buf - memory buffer pointer.</span>
00131 <span class="comment">    \param size - size of the buffer</span>
00132 <span class="comment">*/</span>
<a name="l00133"></a><a class="code" href="a00066.html#a0">00133</a> <span class="keyword">inline</span> encoder::encoder(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* buf, <span class="keywordtype">unsigned</span> size)
00134 : buf_(buf), start_(buf), size_(size)
00135 {
00136 }
00137 <span class="comment"></span>
00138 <span class="comment">/*!</span>
00139 <span class="comment">   \fn void encoder::put_8(unsigned char c) </span>
00140 <span class="comment">   \brief Puts one character into the encoding buffer.</span>
00141 <span class="comment">   \param c - character to encode</span>
00142 <span class="comment">*/</span>
<a name="l00143"></a><a class="code" href="a00066.html#a1">00143</a> <a class="code" href="a00077.html#a12">BMFORCEINLINE</a> <span class="keywordtype">void</span> encoder::put_8(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c)
00144 {
00145     *buf_++ = c;
00146 }
00147 <span class="comment"></span>
00148 <span class="comment">/*!</span>
00149 <span class="comment">   \fn encoder::put_16(bm::short_t s)</span>
00150 <span class="comment">   \brief Puts short word (16 bits) into the encoding buffer.</span>
00151 <span class="comment">   \param s - short word to encode</span>
00152 <span class="comment">*/</span>
<a name="l00153"></a><a class="code" href="a00066.html#a2">00153</a> <a class="code" href="a00077.html#a12">BMFORCEINLINE</a> <span class="keywordtype">void</span> encoder::put_16(bm::short_t s)
00154 {
00155     *buf_++ = (<span class="keywordtype">unsigned</span> char) s;
00156     s &gt;&gt;= 8;
00157     *buf_++ = (<span class="keywordtype">unsigned</span> char) s;
00158 }
00159 <span class="comment"></span>
00160 <span class="comment">/*!</span>
00161 <span class="comment">   \brief Method puts array of short words (16 bits) into the encoding buffer.</span>
00162 <span class="comment">*/</span>
<a name="l00163"></a><a class="code" href="a00066.html#a3">00163</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> encoder::put_16(<span class="keyword">const</span> bm::short_t* s, <span class="keywordtype">unsigned</span> count)
00164 {
00165     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* buf = buf_;
00166     <span class="keyword">const</span> bm::short_t* s_end = s + count;
00167     <span class="keywordflow">do</span> 
00168     {
00169         bm::short_t w16 = *s++;
00170         <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> a = (<span class="keywordtype">unsigned</span> char)  w16;
00171         <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> b = (<span class="keywordtype">unsigned</span> char) (w16 &gt;&gt; 8);
00172         
00173         *buf++ = a;
00174         *buf++ = b;
00175                 
00176     } <span class="keywordflow">while</span> (s &lt; s_end);
00177     
00178     buf_ = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*)buf;
00179 }
00180 
00181 <span class="comment"></span>
00182 <span class="comment">/*!</span>
00183 <span class="comment">   \fn unsigned encoder::size() const</span>
00184 <span class="comment">   \brief Returns size of the current encoding stream.</span>
00185 <span class="comment">*/</span>
<a name="l00186"></a><a class="code" href="a00066.html#a6">00186</a> <span class="keyword">inline</span> <span class="keywordtype">unsigned</span> encoder::size()<span class="keyword"> const</span>
00187 <span class="keyword"></span>{
00188     <span class="keywordflow">return</span> (<span class="keywordtype">unsigned</span>)(buf_ - start_);
00189 }
00190 <span class="comment"></span>
00191 <span class="comment">/*!</span>
00192 <span class="comment">   \fn void encoder::put_32(bm::word_t w)</span>
00193 <span class="comment">   \brief Puts 32 bits word into encoding buffer.</span>
00194 <span class="comment">   \param w - word to encode.</span>
00195 <span class="comment">*/</span>
<a name="l00196"></a><a class="code" href="a00066.html#a4">00196</a> <a class="code" href="a00077.html#a12">BMFORCEINLINE</a> <span class="keywordtype">void</span> encoder::put_32(bm::word_t w)
00197 {
00198     *buf_++ = (<span class="keywordtype">unsigned</span> char) w;
00199     *buf_++ = (<span class="keywordtype">unsigned</span> char) (w &gt;&gt; 8);
00200     *buf_++ = (<span class="keywordtype">unsigned</span> char) (w &gt;&gt; 16);
00201     *buf_++ = (<span class="keywordtype">unsigned</span> char) (w &gt;&gt; 24);
00202 }
00203 <span class="comment"></span>
00204 <span class="comment">/*!</span>
00205 <span class="comment">    \brief Encodes array of 32-bit words</span>
00206 <span class="comment">*/</span>
<a name="l00207"></a><a class="code" href="a00066.html#a5">00207</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> encoder::put_32(<span class="keyword">const</span> bm::word_t* w, <span class="keywordtype">unsigned</span> count)
00208 {
00209     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* buf = buf_;
00210     <span class="keyword">const</span> bm::word_t* w_end = w + count;
00211     <span class="keywordflow">do</span> 
00212     {
00213         bm::word_t w32 = *w++;
00214         <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> a = (<span class="keywordtype">unsigned</span> char) w32;
00215         <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> b = (<span class="keywordtype">unsigned</span> char) (w32 &gt;&gt; 8);
00216         <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c = (<span class="keywordtype">unsigned</span> char) (w32 &gt;&gt; 16);
00217         <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> d = (<span class="keywordtype">unsigned</span> char) (w32 &gt;&gt; 24);
00218 
00219         *buf++ = a;
00220         *buf++ = b;
00221         *buf++ = c;
00222         *buf++ = d;
00223     } <span class="keywordflow">while</span> (w &lt; w_end);
00224     
00225     buf_ = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*)buf;
00226 }
00227 
00228 
00229 <span class="comment">// ---------------------------------------------------------------------</span>
00230 <span class="comment"></span>
00231 <span class="comment">/*!</span>
00232 <span class="comment">   \fn decoder::decoder(const unsigned char* buf) </span>
00233 <span class="comment">   \brief Construction</span>
00234 <span class="comment">   \param buf - pointer to the decoding memory. </span>
00235 <span class="comment">*/</span>
<a name="l00236"></a><a class="code" href="a00062.html#a0">00236</a> <span class="keyword">inline</span> decoder::decoder(<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* buf) 
00237 : <a class="code" href="a00063.html">decoder_base</a>(buf)
00238 {
00239 }
00240 <span class="comment"></span>
00241 <span class="comment">/*!</span>
00242 <span class="comment">   \fn bm::short_t decoder::get_16()</span>
00243 <span class="comment">   \brief Reads 16bit word from the decoding buffer.</span>
00244 <span class="comment">*/</span>
<a name="l00245"></a><a class="code" href="a00062.html#a1">00245</a> <a class="code" href="a00077.html#a12">BMFORCEINLINE</a> bm::short_t decoder::get_16() 
00246 {
00247     bm::short_t a = (bm::short_t)(buf_[0] + ((bm::short_t)buf_[1] &lt;&lt; 8));
00248     buf_ += <span class="keyword">sizeof</span>(a);
00249     <span class="keywordflow">return</span> a;
00250 }
00251 <span class="comment"></span>
00252 <span class="comment">/*!</span>
00253 <span class="comment">   \fn bm::word_t decoder::get_32()</span>
00254 <span class="comment">   \brief Reads 32 bit word from the decoding buffer.</span>
00255 <span class="comment">*/</span>
<a name="l00256"></a><a class="code" href="a00062.html#a2">00256</a> <a class="code" href="a00077.html#a12">BMFORCEINLINE</a> bm::word_t decoder::get_32() 
00257 {
00258     bm::word_t a = buf_[0]+ ((unsigned)buf_[1] &lt;&lt; 8) +
00259                    ((unsigned)buf_[2] &lt;&lt; 16) + ((unsigned)buf_[3] &lt;&lt; 24);
00260     buf_+=<span class="keyword">sizeof</span>(a);
00261     <span class="keywordflow">return</span> a;
00262 }
00263 
00264 <span class="comment"></span>
00265 <span class="comment">/*!</span>
00266 <span class="comment">   \fn void decoder::get_32(bm::word_t* w, unsigned count)</span>
00267 <span class="comment">   \brief Reads block of 32-bit words from the decoding buffer.</span>
00268 <span class="comment">   \param w - pointer on memory block to read into.</span>
00269 <span class="comment">   \param count - size of memory block in words.</span>
00270 <span class="comment">*/</span>
<a name="l00271"></a><a class="code" href="a00062.html#a3">00271</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> decoder::get_32(bm::word_t* w, <span class="keywordtype">unsigned</span> count)
00272 {
00273 
00274     <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* buf = buf_;
00275     <span class="keyword">const</span> bm::word_t* w_end = w + count;
00276     <span class="keywordflow">do</span> 
00277     {
00278         bm::word_t a = buf[0]+ ((unsigned)buf[1] &lt;&lt; 8) +
00279                    ((unsigned)buf[2] &lt;&lt; 16) + ((unsigned)buf[3] &lt;&lt; 24);
00280         *w++ = a;
00281         buf += <span class="keyword">sizeof</span>(a);
00282     } <span class="keywordflow">while</span> (w &lt; w_end);
00283     buf_ = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*)buf;
00284 }
00285 <span class="comment"></span>
00286 <span class="comment">/*!</span>
00287 <span class="comment">   \fn void decoder::get_16(bm::short_t* s, unsigned count)</span>
00288 <span class="comment">   \brief Reads block of 32-bit words from the decoding buffer.</span>
00289 <span class="comment">   \param s - pointer on memory block to read into.</span>
00290 <span class="comment">   \param count - size of memory block in words.</span>
00291 <span class="comment">*/</span>
<a name="l00292"></a><a class="code" href="a00062.html#a4">00292</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> decoder::get_16(bm::short_t* s, <span class="keywordtype">unsigned</span> count)
00293 {
00294     <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* buf = buf_;
00295     <span class="keyword">const</span> bm::short_t* s_end = s + count;
00296     <span class="keywordflow">do</span> 
00297     {
00298         bm::short_t a = (bm::short_t)(buf[0] + ((bm::short_t)buf[1] &lt;&lt; 8));
00299         *s++ = a;
00300         buf += <span class="keyword">sizeof</span>(a);
00301     } <span class="keywordflow">while</span> (s &lt; s_end);
00302     buf_ = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*)buf;
00303 }
00304 
00305 
00306 
00307 <span class="comment">// ---------------------------------------------------------------------</span>
00308 
<a name="l00309"></a><a class="code" href="a00064.html#a0">00309</a> <span class="keyword">inline</span> decoder_little_endian::decoder_little_endian(<span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* buf)
00310 : <a class="code" href="a00063.html">decoder_base</a>(buf)
00311 {
00312 }
00313 
<a name="l00314"></a><a class="code" href="a00064.html#a1">00314</a> <a class="code" href="a00077.html#a12">BMFORCEINLINE</a> bm::short_t decoder_little_endian::get_16()
00315 {
00316     bm::short_t a = ((bm::short_t)buf_[0] &lt;&lt; 8) + ((bm::short_t)buf_[1]);
00317     buf_ += <span class="keyword">sizeof</span>(a);
00318     <span class="keywordflow">return</span> a;
00319 }
00320 
<a name="l00321"></a><a class="code" href="a00064.html#a2">00321</a> <a class="code" href="a00077.html#a12">BMFORCEINLINE</a> bm::word_t decoder_little_endian::get_32() 
00322 {
00323     bm::word_t a = ((unsigned)buf_[0] &lt;&lt; 24)+ ((unsigned)buf_[1] &lt;&lt; 16) +
00324                    ((unsigned)buf_[2] &lt;&lt; 8) + ((unsigned)buf_[3]);
00325     buf_+=<span class="keyword">sizeof</span>(a);
00326     <span class="keywordflow">return</span> a;
00327 }
00328 
<a name="l00329"></a><a class="code" href="a00064.html#a3">00329</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> decoder_little_endian::get_32(bm::word_t* w, <span class="keywordtype">unsigned</span> count)
00330 {
00331     <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* buf = buf_;
00332     <span class="keyword">const</span> bm::word_t* w_end = w + count;
00333     <span class="keywordflow">do</span> 
00334     {
00335         bm::word_t a = ((unsigned)buf[0] &lt;&lt; 24)+ ((unsigned)buf[1] &lt;&lt; 16) +
00336                        ((unsigned)buf[2] &lt;&lt; 8) + ((unsigned)buf[3]);
00337         *w++ = a;
00338         buf += <span class="keyword">sizeof</span>(a);
00339     } <span class="keywordflow">while</span> (w &lt; w_end);
00340     buf_ = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*)buf;
00341 }
00342 
<a name="l00343"></a><a class="code" href="a00064.html#a4">00343</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> decoder_little_endian::get_16(bm::short_t* s, <span class="keywordtype">unsigned</span> count)
00344 {
00345     <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>* buf = buf_;
00346     <span class="keyword">const</span> bm::short_t* s_end = s + count;
00347     <span class="keywordflow">do</span> 
00348     {
00349         bm::short_t a = ((bm::short_t)buf[0] &lt;&lt; 8) + ((bm::short_t)buf[1]);
00350         *s++ = a;
00351         buf += <span class="keyword">sizeof</span>(a);
00352     } <span class="keywordflow">while</span> (s &lt; s_end);
00353     buf_ = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span>*)buf;
00354 }
00355 
00356 
00357 } <span class="comment">// namespace bm</span>
00358 
00359 <span class="preprocessor">#endif</span>
00360 <span class="preprocessor"></span>
00361 
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu Apr 20 13:28:46 2006 for BitMagic by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.1 </small></address>
</body>
</html>