aboutsummaryrefslogtreecommitdiff
path: root/docs/doxygen/nel/string__stream_8cpp-source.html
blob: 2195d6671fa2d9d4091d18fc73cbf9e6bab030fc (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
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>
	<TITLE>nevrax.org : docs</TITLE>
	<LINK REL=stylesheet TYPE="text/css" HREF="/inc/css/nevrax.css">
	<link href="doxygen.css" rel="stylesheet" type="text/css">
</HEAD>
<BODY MARGINHEIGHT="0" MARGINWIDTH="0">

<!-- uplinks -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0>
 <TR>
        <TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD WIDTH=140 BGCOLOR=#dddddd><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
        <TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF=><b>Home</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
        <TD><IMG  width=6 height=14  SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle>&nbsp;<A CLASS=uplinks HREF=><b>nevrax.com</B></FONT></A>&nbsp;&nbsp;&nbsp;</TD>
 </TR>
</TABLE> 

<!-- banner Nevrax -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0 WIDTH=100%>
 <TR><TD  BGCOLOR="#000000" BACKGROUND="/inc/img/black_banner.jpg"><A HREF=""><IMG  SRC="/inc/img/nevrax.gif" WIDTH="170" HEIGHT="45" BORDER=0 ALT="Nevrax" ></A></TD></TR>
</TABLE>

<!-- main table -->
<TABLE CELLSPACING=0 CELLPADDING=0  BORDER=0 height=100%>
 <TR>
	<TD WIDTH=16><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD>
	<TD WIDTH=140   BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">

		<!------ Begin Box ------>
		<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=black><TR><TD><TABLE border=0  cellspacing=2 cellpadding=0 width=120><tr><TD ALIGN=middle bgcolor=black>
		<FONT COLOR=white FACE="sans-serif"><B>Nevrax.org</B></FONT></TD></TR><tr><td  colspan=2 bgcolor=#FFFFFF>
		<TABLE cellspacing=0 cellpadding=1 border=0>
			<tr><td ALIGN=middle><a  class='linkbox' href="/news/" TITLE="Rubrique news"><img width=13 height=15  hspace=5 border=0 src=/inc/img/picto-news.gif ALT=#></A></td><td><a  class='linkbox' href="/news/" TITLE="News">News</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/mail/" TITLE="Rubrique mail"><img width=15 height=11  hspace=5 border=0 src=/inc/img/picto-mail.gif ALT=#></A></td><td><a  class='linkbox' href="/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/docs/" TITLE="Rubrique docs"><img width=14 height=16  hspace=5 border=0 src=/inc/img/picto-docs.gif ALT=#></A></td><td><a  class='linkbox' href="/docs/" TITLE="Documentation">Documentation</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/cvs/" TITLE="Rubrique cvs"><img width=13 height=17  hspace=5 border=0 src=/inc/img/picto-cvs.gif ALT=#></A></td><td><a  class='linkbox' href="/cvs/" TITLE="CVS Web">CVS</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/bugs/" TITLE="Rubrique bugs"><img width=20 height=16  hspace=5 border=0 src=/inc/img/picto-bugs.gif ALT=#></A></td><td><a  class='linkbox' href="/bugs/" TITLE="Bugtracking">Bugs</a></td></tr>
			<tr><td ALIGN=middle><a  class='linkbox' href="/GPL.php3" TITLE="Rubrique license"><img  width=18 height=12   hspace=5 border=0 src=/inc/img/picto-gpl.gif ALT=#></A></td><td><a  class='linkbox' href="/GPL.php3" TITLE="License">License</a></td></tr>
		</TABLE>
		</TD></TR></TABLE></TD></TR></TABLE>
		<!------ End Box  ------>

	</TD>
	<TD WIDTH=15><IMG  SRC="/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD>
	<TD ALIGN=left valign=top><IMG  SRC="/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT="">

<!-- title -->
<TABLE  background="/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0  BORDER=0 width=100%><tr><td>
<A HREF="/docs/"><img src="/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A>
</td><td><IMG  SRC="/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT="">
</td></tr></table>
&nbsp;

<!-- block -->
<TABLE  bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0  BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="/inc/img/reddots.gif"></TD>
	<TD><B>Documentation</B></TD>
	<TD ALIGN=RIGHT>&nbsp;</td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="namespacemembers.html">Namespace Members</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; <a class="qindex" href="pages.html">Related Pages</a> &nbsp; <a class="qindexRef" doxygen="_cgi:/cgi-bin/nel-search.cgi" href="/cgi-bin/nel-search.cgi">Search</a> &nbsp; </center>
<hr><h1>string_stream.cpp</h1><a href="string__stream_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 
00007 <font class="comment">/* Copyright, 2001 Nevrax Ltd.</font>
00008 <font class="comment"> *</font>
00009 <font class="comment"> * This file is part of NEVRAX NEL.</font>
00010 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font>
00011 <font class="comment"> * it under the terms of the GNU General Public License as published by</font>
00012 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font>
00013 <font class="comment"> * any later version.</font>
00014 <font class="comment"></font>
00015 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font>
00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font>
00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font>
00018 <font class="comment"> * General Public License for more details.</font>
00019 <font class="comment"></font>
00020 <font class="comment"> * You should have received a copy of the GNU General Public License</font>
00021 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font>
00022 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font>
00023 <font class="comment"> * MA 02111-1307, USA.</font>
00024 <font class="comment"> */</font>
00025 
00026 <font class="preprocessor">#include "<a class="code" href="string__stream_8h.html">nel/misc/string_stream.h</a>"</font>
00027 
00028 <font class="preprocessor">#include &lt;vector&gt;</font>
00029 
00030 <font class="keyword">namespace </font>NLMISC {
00031 
00032 
00033 <font class="keyword">const</font> <font class="keywordtype">char</font> <a class="code" href="namespaceNLMISC.html#a169">SEPARATOR</a> = <font class="charliteral">' '</font>;
00034 <font class="keyword">const</font> <font class="keywordtype">int</font> <a class="code" href="namespaceNLMISC.html#a170">SEP_SIZE</a> = 1; <font class="comment">// the code is easier to read with that</font>
00035 
00036 
00037 
00038 <font class="comment">/*</font>
00039 <font class="comment"> * Input: read from the stream until the next separator, and return the number of bytes read. The separator is then skipped.</font>
00040 <font class="comment"> */</font>
<a name="l00041"></a><a class="code" href="classNLMISC_1_1CStringStream.html#a3">00041</a> uint CStringStream::serialSeparatedBufferIn( uint8 *buf, uint len )
00042 {
00043         <a class="code" href="debug_8h.html#a6">nlassert</a>( <a class="code" href="classNLMISC_1_1IStream.html#a4">isReading</a>() );
00044 
00045         <font class="comment">// Check that we don't read more than there is to read</font>
00046         <font class="keywordflow">if</font> ( ( <a class="code" href="classNLMISC_1_1CMemStream.html#n1">_BufPos</a> == <a class="code" href="classNLMISC_1_1CMemStream.html#n0">_Buffer</a>.end() ) || <font class="comment">// we are at the end</font>
00047                  ( <a class="code" href="classNLMISC_1_1CMemStream.html#b0">lengthS</a>()+len+<a class="code" href="namespaceNLMISC.html#a170">SEP_SIZE</a> &gt; <a class="code" href="classNLMISC_1_1CMemStream.html#b1">lengthR</a>() ) &amp;&amp; (<a class="code" href="classNLMISC_1_1CMemStream.html#n0">_Buffer</a>[<a class="code" href="classNLMISC_1_1CMemStream.html#n0">_Buffer</a>.size()-1] != <a class="code" href="namespaceNLMISC.html#a169">SEPARATOR</a> ) ) <font class="comment">// we are before the end</font>
00048         {
00049                 <font class="keywordflow">throw</font> EStreamOverflow();
00050         }
00051         <font class="comment">// Serialize in</font>
00052         uint32 i = 0;
00053         <font class="keywordflow">while</font> ( (i&lt;len) &amp;&amp; (*_BufPos) != <a class="code" href="namespaceNLMISC.html#a169">SEPARATOR</a> )
00054         {
00055                 *(buf+i) = *<a class="code" href="classNLMISC_1_1CMemStream.html#n1">_BufPos</a>;
00056                 i++;
00057                 <a class="code" href="classNLMISC_1_1CMemStream.html#n1">_BufPos</a>++;
00058         }
00059         <font class="comment">// Exceeds len</font>
00060         <font class="keywordflow">if</font> ( (*_BufPos) != <a class="code" href="namespaceNLMISC.html#a169">SEPARATOR</a> )
00061         {
00062                 <font class="keywordflow">throw</font> EStreamOverflow();
00063         }
00064         <a class="code" href="classNLMISC_1_1CMemStream.html#n1">_BufPos</a> += <a class="code" href="namespaceNLMISC.html#a170">SEP_SIZE</a>;
00065         <font class="keywordflow">return</font> i;
00066 }
00067 
00068 <font class="comment">/*</font>
00069 <font class="comment"> * Output: writes len bytes from buf into the stream</font>
00070 <font class="comment"> */</font>
<a name="l00071"></a><a class="code" href="classNLMISC_1_1CStringStream.html#a4">00071</a> <font class="keywordtype">void</font> CStringStream::serialSeparatedBufferOut( uint8 *buf, uint len )
00072 {
00073         <a class="code" href="debug_8h.html#a6">nlassert</a>( ! <a class="code" href="classNLMISC_1_1IStream.html#a4">isReading</a>() );
00074         
00075         <font class="comment">// Serialize out</font>
00076         <a class="code" href="classNLMISC_1_1CMemStream.html#n0">_Buffer</a>.resize( <a class="code" href="classNLMISC_1_1CMemStream.html#n0">_Buffer</a>.size() + len + <a class="code" href="namespaceNLMISC.html#a170">SEP_SIZE</a> );
00077         <a class="code" href="classNLMISC_1_1CMemStream.html#n1">_BufPos</a> = <a class="code" href="classNLMISC_1_1CMemStream.html#n0">_Buffer</a>.end() - len - <a class="code" href="namespaceNLMISC.html#a170">SEP_SIZE</a>;
00078         memcpy( &amp;(*<a class="code" href="classNLMISC_1_1CMemStream.html#n1">_BufPos</a>), buf, len );
00079         <a class="code" href="classNLMISC_1_1CMemStream.html#n0">_Buffer</a>[<a class="code" href="classNLMISC_1_1CMemStream.html#n0">_Buffer</a>.size()-1] = <a class="code" href="namespaceNLMISC.html#a169">SEPARATOR</a>;
00080         <a class="code" href="classNLMISC_1_1CMemStream.html#n1">_BufPos</a> = <a class="code" href="classNLMISC_1_1CMemStream.html#n0">_Buffer</a>.end();
00081 }
00082 
00083 
00084 <font class="comment">// Input</font>
<a name="l00085"></a><a class="code" href="string__stream_8cpp.html#a0">00085</a> <font class="preprocessor">#define readnumber(dest,thetype,digits,convfunc) \</font>
00086 <font class="preprocessor">        char number_as_cstring [digits+1]; \</font>
00087 <font class="preprocessor">        uint realdigits = serialSeparatedBufferIn( (uint8*)&amp;number_as_cstring, digits ); \</font>
00088 <font class="preprocessor">        number_as_cstring[realdigits] = '\0'; \</font>
00089 <font class="preprocessor">        dest = (thetype)convfunc( number_as_cstring );</font>
00090 <font class="preprocessor"></font>
00091 <font class="comment">// Output</font>
<a name="l00092"></a><a class="code" href="string__stream_8cpp.html#a1">00092</a> <font class="preprocessor">#define writenumber(src,format,digits) \</font>
00093 <font class="preprocessor">        char number_as_cstring [digits+1]; \</font>
00094 <font class="preprocessor">        sprintf( number_as_cstring, format, src ); \</font>
00095 <font class="preprocessor">        serialSeparatedBufferOut( (uint8*)&amp;number_as_cstring, strlen(number_as_cstring) );</font>
00096 <font class="preprocessor"></font>
00098 
00099 <font class="comment">/*</font>
00100 <font class="comment"> * atoihex</font>
00101 <font class="comment"> */</font>
00102 <font class="keyword">inline</font> <font class="keywordtype">int</font> <a class="code" href="namespaceNLMISC.html#a271">atoihex</a>( <font class="keyword">const</font> <font class="keywordtype">char</font>* ident )
00103 {
00104         <font class="keywordtype">int</font> number;
00105         sscanf( ident, <font class="stringliteral">"%x"</font>, &amp;number );
00106         <font class="keywordflow">return</font> number;
00107 }
00108 
00109 <font class="keyword">inline</font> uint32 <a class="code" href="namespaceNLMISC.html#a272">atoui</a>( <font class="keyword">const</font> <font class="keywordtype">char</font> *ident)
00110 {
00111         <font class="keywordflow">return</font> (uint32) strtoul (ident, NULL, 10);
00112 }
00113 
00114 <font class="comment">// ======================================================================================================</font>
<a name="l00115"></a><a class="code" href="classNLMISC_1_1CStringStream.html#z328_0">00115</a> <font class="keywordtype">void</font>            CStringStream::serial(uint8 &amp;b) 
00116 {
00117         <font class="keywordflow">if</font> ( <a class="code" href="classNLMISC_1_1IStream.html#a4">isReading</a>() )
00118         {
00119                 <a class="code" href="mem__stream_8h.html#a0">readnumber</a>( b, uint8, 3, atoi ); <font class="comment">// 255</font>
00120         }
00121         <font class="keywordflow">else</font>
00122         {
00123                 <a class="code" href="mem__stream_8h.html#a1">writenumber</a>( (uint16)b,<font class="stringliteral">"%hu"</font>, 3 );
00124         }
00125 }
00126 
00127 <font class="comment">// ======================================================================================================</font>
<a name="l00128"></a><a class="code" href="classNLMISC_1_1CStringStream.html#z328_1">00128</a> <font class="keywordtype">void</font>            CStringStream::serial(sint8 &amp;b) 
00129 {
00130         <font class="keywordflow">if</font> ( <a class="code" href="classNLMISC_1_1IStream.html#a4">isReading</a>() )
00131         {
00132                 <a class="code" href="mem__stream_8h.html#a0">readnumber</a>( b, sint8, 4, atoi ); <font class="comment">// -128</font>
00133         }
00134         <font class="keywordflow">else</font>
00135         {
00136                 <a class="code" href="mem__stream_8h.html#a1">writenumber</a>( (sint16)b, <font class="stringliteral">"%hd"</font>, 4 );
00137         }
00138 }
00139 
00140 <font class="comment">// ======================================================================================================</font>
<a name="l00141"></a><a class="code" href="classNLMISC_1_1CStringStream.html#z328_2">00141</a> <font class="keywordtype">void</font>            CStringStream::serial(uint16 &amp;b) 
00142 {
00143         <font class="comment">// No byte swapping in text mode</font>
00144         <font class="keywordflow">if</font> ( <a class="code" href="classNLMISC_1_1IStream.html#a4">isReading</a>() )
00145         {
00146                 <a class="code" href="mem__stream_8h.html#a0">readnumber</a>( b, uint16, 5, atoi ); <font class="comment">// 65535</font>
00147         }
00148         <font class="keywordflow">else</font>
00149         {
00150                 <a class="code" href="mem__stream_8h.html#a1">writenumber</a>( b, <font class="stringliteral">"%hu"</font>, 5 );
00151         }
00152 }
00153 
00154 <font class="comment">// ======================================================================================================</font>
<a name="l00155"></a><a class="code" href="classNLMISC_1_1CStringStream.html#z328_3">00155</a> <font class="keywordtype">void</font>            CStringStream::serial(sint16 &amp;b) 
00156 {
00157         <font class="keywordflow">if</font> ( <a class="code" href="classNLMISC_1_1IStream.html#a4">isReading</a>() )
00158         {
00159                 <a class="code" href="mem__stream_8h.html#a0">readnumber</a>( b, sint16, 6, atoi ); <font class="comment">// -32768</font>
00160         }
00161         <font class="keywordflow">else</font>
00162         {
00163                 <a class="code" href="mem__stream_8h.html#a1">writenumber</a>( b, <font class="stringliteral">"%hd"</font>, 6 );
00164         }
00165 }
00166 
00167 <font class="comment">// ======================================================================================================</font>
<a name="l00168"></a><a class="code" href="classNLMISC_1_1CStringStream.html#z328_4">00168</a> <font class="keywordtype">void</font>            CStringStream::serial(uint32 &amp;b) 
00169 {
00170         <font class="keywordflow">if</font> ( <a class="code" href="classNLMISC_1_1IStream.html#a4">isReading</a>() )
00171         {
00172                 <a class="code" href="mem__stream_8h.html#a0">readnumber</a>( b, uint32, 10, <a class="code" href="namespaceNLMISC.html#a272">atoui</a> ); <font class="comment">// 4294967295</font>
00173         }
00174         <font class="keywordflow">else</font>
00175         {
00176                 <a class="code" href="mem__stream_8h.html#a1">writenumber</a>( b, <font class="stringliteral">"%u"</font>, 10 );
00177         }
00178 }
00179 
00180 <font class="comment">// ======================================================================================================</font>
<a name="l00181"></a><a class="code" href="classNLMISC_1_1CStringStream.html#z328_5">00181</a> <font class="keywordtype">void</font>            CStringStream::serial(sint32 &amp;b) 
00182 {
00183         <font class="keywordflow">if</font> ( <a class="code" href="classNLMISC_1_1IStream.html#a4">isReading</a>() )
00184         {
00185                 <a class="code" href="mem__stream_8h.html#a0">readnumber</a>( b, sint32, 11, atoi ); <font class="comment">// -2147483648</font>
00186         }
00187         <font class="keywordflow">else</font>
00188         {
00189                 <a class="code" href="mem__stream_8h.html#a1">writenumber</a>( b, <font class="stringliteral">"%d"</font>, 11 );
00190         }
00191 }
00192 
00193 <font class="comment">// ======================================================================================================</font>
<a name="l00194"></a><a class="code" href="classNLMISC_1_1CStringStream.html#z328_6">00194</a> <font class="keywordtype">void</font>            CStringStream::serial(uint64 &amp;b) 
00195 {
00196         <font class="keywordflow">if</font> ( <a class="code" href="classNLMISC_1_1IStream.html#a4">isReading</a>() )
00197         {
00198                 <a class="code" href="mem__stream_8h.html#a0">readnumber</a>( b, uint64, 20, atoiInt64 ); <font class="comment">// 18446744073709551615</font>
00199         }
00200         <font class="keywordflow">else</font>
00201         {
00202                 <a class="code" href="mem__stream_8h.html#a1">writenumber</a>( b, <font class="stringliteral">"%"</font>NL_I64<font class="stringliteral">"u"</font>, 20 );
00203         }
00204 }
00205 
00206 <font class="comment">// ======================================================================================================</font>
<a name="l00207"></a><a class="code" href="classNLMISC_1_1CStringStream.html#z328_7">00207</a> <font class="keywordtype">void</font>            CStringStream::serial(sint64 &amp;b) 
00208 {
00209         <font class="keywordflow">if</font> ( <a class="code" href="classNLMISC_1_1IStream.html#a4">isReading</a>() )
00210         {
00211                 <a class="code" href="mem__stream_8h.html#a0">readnumber</a>( b, sint64, 20, atoiInt64 ); <font class="comment">// -9223372036854775808</font>
00212         }
00213         <font class="keywordflow">else</font>
00214         {
00215                 <a class="code" href="mem__stream_8h.html#a1">writenumber</a>( b, <font class="stringliteral">"%"</font>NL_I64<font class="stringliteral">"d"</font>, 20 );
00216         }
00217 }
00218 
00219 <font class="comment">// ======================================================================================================</font>
<a name="l00220"></a><a class="code" href="classNLMISC_1_1CStringStream.html#z328_8">00220</a> <font class="keywordtype">void</font>            CStringStream::serial(<font class="keywordtype">float</font> &amp;b) 
00221 {
00222         <font class="keywordflow">if</font> ( <a class="code" href="classNLMISC_1_1IStream.html#a4">isReading</a>() )
00223         {
00224                 <a class="code" href="mem__stream_8h.html#a0">readnumber</a>( b, <font class="keywordtype">float</font>, 128, atof ); <font class="comment">// ?</font>
00225         }
00226         <font class="keywordflow">else</font>
00227         {
00228                 <a class="code" href="mem__stream_8h.html#a1">writenumber</a>( (<font class="keywordtype">double</font>)b, <font class="stringliteral">"%f"</font>, 128 );
00229         }
00230 }
00231 
00232 <font class="comment">// ======================================================================================================</font>
<a name="l00233"></a><a class="code" href="classNLMISC_1_1CStringStream.html#z328_9">00233</a>         <font class="keywordtype">void</font>            CStringStream::serial(<font class="keywordtype">double</font> &amp;b) 
00234 {
00235         <font class="keywordflow">if</font> ( <a class="code" href="classNLMISC_1_1IStream.html#a4">isReading</a>() )
00236         {
00237                 <a class="code" href="mem__stream_8h.html#a0">readnumber</a>( b, <font class="keywordtype">double</font>, 128, atof ); <font class="comment">//</font>
00238         }
00239         <font class="keywordflow">else</font>
00240         {
00241                 <a class="code" href="mem__stream_8h.html#a1">writenumber</a>( b, <font class="stringliteral">"%f"</font>, 128 );
00242         }
00243 }
00244 
00245 <font class="comment">// ======================================================================================================</font>
<a name="l00246"></a><a class="code" href="classNLMISC_1_1CStringStream.html#z328_10">00246</a> <font class="keywordtype">void</font>            CStringStream::serial(<font class="keywordtype">bool</font> &amp;b) 
00247 {
00248         <a class="code" href="classNLMISC_1_1CStringStream.html#a5">serialBit</a>(b);
00249 }
00250 
00251 
00252 <font class="comment">// ======================================================================================================</font>
<a name="l00253"></a><a class="code" href="classNLMISC_1_1CStringStream.html#a5">00253</a> <font class="keywordtype">void</font>                    CStringStream::serialBit(<font class="keywordtype">bool</font> &amp;bit)
00254 {
00255         uint8 u;
00256         <font class="keywordflow">if</font> ( <a class="code" href="classNLMISC_1_1IStream.html#a4">isReading</a>() )
00257         {
00258                 <a class="code" href="classNLMISC_1_1CStringStream.html#a6">serial</a>( u );
00259                 bit = (u!=0);
00260         }
00261         <font class="keywordflow">else</font>
00262         {
00263                 u = (uint8)bit;
00264                 <a class="code" href="classNLMISC_1_1CStringStream.html#a6">serial</a>( u );
00265         }
00266 }
00267 
00268 
00269 <font class="preprocessor">#ifndef NL_OS_CYGWIN</font>
00270 <font class="preprocessor"></font><font class="comment">// ======================================================================================================</font>
<a name="l00271"></a><a class="code" href="classNLMISC_1_1CStringStream.html#z328_11">00271</a> <font class="keywordtype">void</font>            CStringStream::serial(<font class="keywordtype">char</font> &amp;b) 
00272 {
00273         <font class="keywordtype">char</font> buff [2];
00274         <font class="keywordflow">if</font> ( <a class="code" href="classNLMISC_1_1IStream.html#a4">isReading</a>() )
00275         {
00276                 <a class="code" href="classNLMISC_1_1CMemStream.html#a5">serialBuffer</a>( (uint8*)buff, 2 );
00277                 b = buff[0];
00278         }
00279         <font class="keywordflow">else</font>
00280         {
00281                 buff[0] = b;
00282                 buff[1] = <a class="code" href="namespaceNLMISC.html#a169">SEPARATOR</a>;
00283                 <a class="code" href="classNLMISC_1_1CMemStream.html#a5">serialBuffer</a>( (uint8*)buff, 2 );
00284         }
00285 
00286 }
00287 <font class="preprocessor">#endif</font>
00288 <font class="preprocessor"></font>
00289 <font class="comment">// ======================================================================================================</font>
<a name="l00290"></a><a class="code" href="classNLMISC_1_1CStringStream.html#z328_12">00290</a> <font class="keywordtype">void</font>            CStringStream::serial(std::string &amp;b) 
00291 {
00292         sint32  len=0;
00293         <font class="comment">// Read/Write the length.</font>
00294         <font class="keywordflow">if</font>(<a class="code" href="classNLMISC_1_1IStream.html#a4">isReading</a>())
00295         {
00296                 <a class="code" href="classNLMISC_1_1CStringStream.html#a6">serial</a>(len);
00297                 <a class="code" href="debug_8h.html#a6">nlassert</a>( len&lt;1000000 ); <font class="comment">// limiting string size</font>
00298                 b.resize(len);
00299         }
00300         <font class="keywordflow">else</font>
00301         {
00302                 len= b.size();
00303                 <a class="code" href="classNLMISC_1_1CStringStream.html#a6">serial</a>(len);
00304         }
00305         
00306         <font class="comment">// Read/Write the string.</font>
00307         <font class="keywordflow">for</font>(sint i=0;i&lt;len;i++)
00308                 <a class="code" href="classNLMISC_1_1CMemStream.html#a5">serialBuffer</a>( (uint8*)&amp;(b[i]), <font class="keyword">sizeof</font>(b[i]) );
00309 
00310         <font class="keywordtype">char</font> sep = <a class="code" href="namespaceNLMISC.html#a169">SEPARATOR</a>;
00311         <a class="code" href="classNLMISC_1_1CMemStream.html#a5">serialBuffer</a>( (uint8*)&amp;sep, 1 );
00312 }
00313 
00314 
00315 <font class="comment">// ======================================================================================================</font>
<a name="l00316"></a><a class="code" href="classNLMISC_1_1CStringStream.html#z328_13">00316</a> <font class="keywordtype">void</font>            CStringStream::serial(<a class="code" href="classucstring.html">ucstring</a> &amp;b) 
00317 {
00318         sint32  len=0;
00319         <font class="comment">// Read/Write the length.</font>
00320         <font class="keywordflow">if</font>(<a class="code" href="classNLMISC_1_1IStream.html#a4">isReading</a>())
00321         {
00322                 <a class="code" href="classNLMISC_1_1CStringStream.html#a6">serial</a>(len);
00323                 b.resize(len);
00324         }
00325         <font class="keywordflow">else</font>
00326         {
00327                 len= b.size();
00328                 <a class="code" href="classNLMISC_1_1CStringStream.html#a6">serial</a>(len);
00329         }
00330         <font class="comment">// Read/Write the string.</font>
00331         <font class="keywordflow">for</font>(sint i=0;i&lt;len;i++)
00332                 <a class="code" href="classNLMISC_1_1CMemStream.html#a5">serialBuffer</a>( (uint8*)&amp;b[i], <font class="keyword">sizeof</font>( <font class="keyword">sizeof</font>(b[i]) ) );
00333 
00334         <font class="keywordtype">char</font> sep = <a class="code" href="namespaceNLMISC.html#a169">SEPARATOR</a>;
00335         <a class="code" href="classNLMISC_1_1CMemStream.html#a5">serialBuffer</a>( (uint8*)&amp;sep, 1 );
00336 }
00337 
00338 
00339 <font class="comment">// Specialisation of serialCont() for vector&lt;bool&gt;</font>
<a name="l00340"></a><a class="code" href="classNLMISC_1_1CStringStream.html#a21">00340</a> <font class="keywordtype">void</font>    CStringStream::serialCont(std::vector&lt;bool&gt; &amp;cont)
00341 {
00342         sint32  len=0;
00343         <font class="keywordflow">if</font>(<a class="code" href="classNLMISC_1_1IStream.html#a4">isReading</a>())
00344         {
00345                 <a class="code" href="classNLMISC_1_1CStringStream.html#a6">serial</a>(len);
00346                 <font class="comment">// special version for vector: adjut good size.</font>
00347                 <a class="code" href="namespaceNLMISC.html#a222">contReset</a>(cont);
00348                 cont.reserve(len);
00349 
00350                 <font class="keywordflow">for</font>(sint i=0;i&lt;len;i++)
00351                 {
00352                         <font class="keywordtype">bool</font>    <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>;
00353                         <a class="code" href="classNLMISC_1_1CStringStream.html#a6">serial</a>(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>);
00354                         cont.insert(cont.end(), <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>);
00355                 }
00356         }
00357         <font class="keywordflow">else</font>
00358         {
00359                 len= cont.size();
00360                 <a class="code" href="classNLMISC_1_1CStringStream.html#a6">serial</a>(len);
00361 
00362                 std::vector&lt;bool&gt;::iterator it= cont.begin();
00363                 <font class="keywordflow">for</font>(sint i=0;i&lt;len;i++, it++)
00364                 {
00365                         <font class="keywordtype">bool</font> b = *it;
00366                         <a class="code" href="classNLMISC_1_1CStringStream.html#a6">serial</a>( b );
00367                 }
00368         }
00369 }
00370 
00371 
00372 <font class="comment">/*</font>
00373 <font class="comment"> * Serialisation in hexadecimal</font>
00374 <font class="comment"> */</font>
<a name="l00375"></a><a class="code" href="classNLMISC_1_1CStringStream.html#a22">00375</a> <font class="keywordtype">void</font>    CStringStream::serialHex(uint32 &amp;b)
00376 {
00377         <font class="keywordflow">if</font> ( <a class="code" href="classNLMISC_1_1IStream.html#a4">isReading</a>() )
00378         {
00379                 <a class="code" href="mem__stream_8h.html#a0">readnumber</a>( b, uint32, 10, <a class="code" href="namespaceNLMISC.html#a271">atoihex</a> ); <font class="comment">// 4294967295</font>
00380         }
00381         <font class="keywordflow">else</font>
00382         {
00383                 <a class="code" href="mem__stream_8h.html#a1">writenumber</a>( b, <font class="stringliteral">"%x"</font>, 10 );
00384         }
00385 }
00386 
00387 
00388 } <font class="comment">// NLMISC</font>
</pre></div>

<!-- footer -->
<BR><FONT Size=+5>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </FONT>
</TD>
<TD WIDTH=15><IMG  SRC=/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>