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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
|
<!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> <A CLASS=uplinks HREF='/'><b>Home</B></FONT></A> </TD>
<TD><IMG width=6 height=14 SRC="/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=><b>nevrax.com</B></FONT></A> </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>
<!-- 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> </td>
</tr></table>
<!-- Generated by Doxygen 1.2.14 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindexRef" doxygen="_cgi:/cgi-bin/nel-search.cgi" href="/cgi-bin/nel-search.cgi">Search</a> </center>
<hr><h1>log.cpp</h1><a href="log_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001
00007 <font class="comment">/* Copyright, 2000 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="stdmisc_8h.html">stdmisc.h</a>"</font>
00027
00028 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00029 <font class="preprocessor"></font><font class="preprocessor">#include <process.h></font>
00030 <font class="preprocessor">#include <windows.h></font>
00031 <font class="preprocessor">#else</font>
00032 <font class="preprocessor"></font><font class="preprocessor">#include <<a class="code" href="unistd_8h.html">unistd.h</a>></font>
00033 <font class="preprocessor">#endif</font>
00034 <font class="preprocessor"></font>
00035 <font class="preprocessor">#include <time.h></font>
00036 <font class="preprocessor">#include <stdarg.h></font>
00037
00038 <font class="preprocessor">#include "<a class="code" href="displayer_8h.html">nel/misc/displayer.h</a>"</font>
00039 <font class="preprocessor">#include "<a class="code" href="log_8h.html">nel/misc/log.h</a>"</font>
00040 <font class="preprocessor">#include "<a class="code" href="debug_8h.html">nel/misc/debug.h</a>"</font>
00041 <font class="preprocessor">#include "<a class="code" href="path_8h.html">nel/misc/path.h</a>"</font>
00042
00043 <font class="keyword">using</font> <font class="keyword">namespace </font>std;
00044
00045
00046 <font class="keyword">namespace </font>NLMISC
00047 {
00048
<a name="l00049"></a><a class="code" href="classNLMISC_1_1CLog.html#q0">00049</a> string *CLog::_ProcessName = NULL;
00050
<a name="l00051"></a><a class="code" href="classNLMISC_1_1CLog.html#a0">00051</a> CLog::CLog( TLogType logType) : _LogType (logType), _Line(-1), _FileName(NULL), _Mutex("LOG"+toString((uint)logType)), _PosSet(false)
00052 {
00053 }
00054
<a name="l00055"></a><a class="code" href="classNLMISC_1_1CLog.html#d1">00055</a> <font class="keywordtype">void</font> CLog::setDefaultProcessName ()
00056 {
00057 <font class="preprocessor">#ifdef NL_OS_WINDOWS</font>
00058 <font class="preprocessor"></font> <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CLog.html#q0">_ProcessName</a> == NULL)
00059 {
00060 <a class="code" href="classNLMISC_1_1CLog.html#q0">_ProcessName</a> = <font class="keyword">new</font> string;
00061 }
00062
00063 <font class="keywordflow">if</font> ((*_ProcessName).empty())
00064 {
00065 <font class="keywordtype">char</font> name[1024];
00066 GetModuleFileName (NULL, name, 1023);
00067 (*_ProcessName) = CFile::getFilename(name);
00068 }
00069 <font class="preprocessor">#endif</font>
00070 <font class="preprocessor"></font>}
00071
<a name="l00072"></a><a class="code" href="classNLMISC_1_1CLog.html#d0">00072</a> <font class="keywordtype">void</font> CLog::setProcessName (<font class="keyword">const</font> std::string &processName)
00073 {
00074 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CLog.html#q0">_ProcessName</a> == NULL)
00075 {
00076 <a class="code" href="classNLMISC_1_1CLog.html#q0">_ProcessName</a> = <font class="keyword">new</font> string;
00077 }
00078
00079 *<a class="code" href="classNLMISC_1_1CLog.html#q0">_ProcessName</a> = processName;
00080 }
00081
<a name="l00082"></a><a class="code" href="classNLMISC_1_1CLog.html#a7">00082</a> <font class="keywordtype">void</font> CLog::setPosition (sint line, <font class="keywordtype">char</font> *filename)
00083 {
00084 <font class="keywordflow">if</font> ( !<a class="code" href="classNLMISC_1_1CLog.html#a6">noDisplayer</a>() )
00085 {
00086 <a class="code" href="classNLMISC_1_1CLog.html#n5">_Mutex</a>.enter();
00087 <a class="code" href="classNLMISC_1_1CLog.html#n6">_PosSet</a>++;
00088 <a class="code" href="classNLMISC_1_1CLog.html#n1">_Line</a> = line;
00089 <a class="code" href="classNLMISC_1_1CLog.html#n2">_FileName</a> = filename;
00090 }
00091 }
00092
<a name="l00094"></a><a class="code" href="classNLMISC_1_1CLog.html#b0">00094</a> <font class="keywordtype">void</font> CLog::unsetPosition()
00095 {
00096 <a class="code" href="debug_8h.html#a6">nlassert</a>( !<a class="code" href="classNLMISC_1_1CLog.html#a6">noDisplayer</a>() );
00097
00098 <font class="keywordflow">if</font> ( <a class="code" href="classNLMISC_1_1CLog.html#n6">_PosSet</a> > 0 )
00099 {
00100 <a class="code" href="classNLMISC_1_1CLog.html#n2">_FileName</a> = NULL;
00101 <a class="code" href="classNLMISC_1_1CLog.html#n1">_Line</a> = -1;
00102 <a class="code" href="classNLMISC_1_1CLog.html#n6">_PosSet</a>--;
00103 <a class="code" href="classNLMISC_1_1CLog.html#n5">_Mutex</a>.leave(); <font class="comment">// needs setPosition() to have been called</font>
00104 }
00105 }
00106
00107
<a name="l00108"></a><a class="code" href="classNLMISC_1_1CLog.html#a1">00108</a> <font class="keywordtype">void</font> CLog::addDisplayer (IDisplayer *displayer, <font class="keywordtype">bool</font> bypassFilter)
00109 {
00110 <font class="keywordflow">if</font> (displayer == NULL)
00111 {
00112 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"Trying to add a NULL displayer"</font>);
00113 <font class="keywordflow">return</font>;
00114 }
00115
00116 <font class="keywordflow">if</font> (bypassFilter)
00117 {
00118 CDisplayers::iterator idi = std::find (<a class="code" href="classNLMISC_1_1CLog.html#n4">_BypassFilterDisplayers</a>.begin (), <a class="code" href="classNLMISC_1_1CLog.html#n4">_BypassFilterDisplayers</a>.end (), displayer);
00119 <font class="keywordflow">if</font> (idi == <a class="code" href="classNLMISC_1_1CLog.html#n4">_BypassFilterDisplayers</a>.end ())
00120 {
00121 <a class="code" href="classNLMISC_1_1CLog.html#n4">_BypassFilterDisplayers</a>.push_back (displayer);
00122 }
00123 <font class="keywordflow">else</font>
00124 {
00125 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"Couldn't add the displayer, it was already added"</font>);
00126 }
00127 }
00128 <font class="keywordflow">else</font>
00129 {
00130 CDisplayers::iterator idi = std::find (<a class="code" href="classNLMISC_1_1CLog.html#n3">_Displayers</a>.begin (), <a class="code" href="classNLMISC_1_1CLog.html#n3">_Displayers</a>.end (), displayer);
00131 <font class="keywordflow">if</font> (idi == <a class="code" href="classNLMISC_1_1CLog.html#n3">_Displayers</a>.end ())
00132 {
00133 <a class="code" href="classNLMISC_1_1CLog.html#n3">_Displayers</a>.push_back (displayer);
00134 }
00135 <font class="keywordflow">else</font>
00136 {
00137 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"Couldn't add the displayer, it was already added"</font>);
00138 }
00139 }
00140 }
00141
<a name="l00142"></a><a class="code" href="classNLMISC_1_1CLog.html#a3">00142</a> <font class="keywordtype">void</font> CLog::removeDisplayer (IDisplayer *displayer)
00143 {
00144 <font class="keywordflow">if</font> (displayer == NULL)
00145 {
00146 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"Trying to remove a NULL displayer"</font>);
00147 <font class="keywordflow">return</font>;
00148 }
00149
00150 CDisplayers::iterator idi = std::find (<a class="code" href="classNLMISC_1_1CLog.html#n3">_Displayers</a>.begin (), <a class="code" href="classNLMISC_1_1CLog.html#n3">_Displayers</a>.end (), displayer);
00151 <font class="keywordflow">if</font> (idi != <a class="code" href="classNLMISC_1_1CLog.html#n3">_Displayers</a>.end ())
00152 {
00153 <a class="code" href="classNLMISC_1_1CLog.html#n3">_Displayers</a>.erase (idi);
00154 }
00155
00156 idi = std::find (<a class="code" href="classNLMISC_1_1CLog.html#n4">_BypassFilterDisplayers</a>.begin (), <a class="code" href="classNLMISC_1_1CLog.html#n4">_BypassFilterDisplayers</a>.end (), displayer);
00157 <font class="keywordflow">if</font> (idi != <a class="code" href="classNLMISC_1_1CLog.html#n4">_BypassFilterDisplayers</a>.end ())
00158 {
00159 <a class="code" href="classNLMISC_1_1CLog.html#n4">_BypassFilterDisplayers</a>.erase (idi);
00160 }
00161
00162 }
00163
<a name="l00164"></a><a class="code" href="classNLMISC_1_1CLog.html#a4">00164</a> <font class="keywordtype">void</font> CLog::removeDisplayer (<font class="keyword">const</font> <font class="keywordtype">char</font> *displayerName)
00165 {
00166 <font class="keywordflow">if</font> (displayerName == NULL || displayerName[0] == <font class="charliteral">'\0'</font>)
00167 {
00168 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"Trying to remove an empty displayer name"</font>);
00169 <font class="keywordflow">return</font>;
00170 }
00171
00172 CDisplayers::iterator idi;
00173 <font class="keywordflow">for</font> (idi = <a class="code" href="classNLMISC_1_1CLog.html#n3">_Displayers</a>.begin (); idi != <a class="code" href="classNLMISC_1_1CLog.html#n3">_Displayers</a>.end ();)
00174 {
00175 <font class="keywordflow">if</font> ((*idi)->DisplayerName == displayerName)
00176 {
00177 idi = <a class="code" href="classNLMISC_1_1CLog.html#n3">_Displayers</a>.erase (idi);
00178 }
00179 <font class="keywordflow">else</font>
00180 {
00181 idi++;
00182 }
00183 }
00184
00185 <font class="keywordflow">for</font> (idi = <a class="code" href="classNLMISC_1_1CLog.html#n4">_BypassFilterDisplayers</a>.begin (); idi != <a class="code" href="classNLMISC_1_1CLog.html#n4">_BypassFilterDisplayers</a>.end ();)
00186 {
00187 <font class="keywordflow">if</font> ((*idi)->DisplayerName == displayerName)
00188 {
00189 idi = <a class="code" href="classNLMISC_1_1CLog.html#n4">_BypassFilterDisplayers</a>.erase (idi);
00190 }
00191 <font class="keywordflow">else</font>
00192 {
00193 idi++;
00194 }
00195 }
00196 }
00197
<a name="l00198"></a><a class="code" href="classNLMISC_1_1CLog.html#a2">00198</a> IDisplayer *CLog::getDisplayer (<font class="keyword">const</font> <font class="keywordtype">char</font> *displayerName)
00199 {
00200 <font class="keywordflow">if</font> (displayerName == NULL || displayerName[0] == <font class="charliteral">'\0'</font>)
00201 {
00202 <a class="code" href="debug_8h.html#a2">nlwarning</a> (<font class="stringliteral">"Trying to get an empty displayer name"</font>);
00203 <font class="keywordflow">return</font> NULL;
00204 }
00205
00206 CDisplayers::iterator idi;
00207 <font class="keywordflow">for</font> (idi = <a class="code" href="classNLMISC_1_1CLog.html#n3">_Displayers</a>.begin (); idi != <a class="code" href="classNLMISC_1_1CLog.html#n3">_Displayers</a>.end (); idi++)
00208 {
00209 <font class="keywordflow">if</font> ((*idi)->DisplayerName == displayerName)
00210 {
00211 <font class="keywordflow">return</font> *idi;
00212 }
00213 }
00214 <font class="keywordflow">for</font> (idi = <a class="code" href="classNLMISC_1_1CLog.html#n4">_BypassFilterDisplayers</a>.begin (); idi != <a class="code" href="classNLMISC_1_1CLog.html#n4">_BypassFilterDisplayers</a>.end (); idi++)
00215 {
00216 <font class="keywordflow">if</font> ((*idi)->DisplayerName == displayerName)
00217 {
00218 <font class="keywordflow">return</font> *idi;
00219 }
00220 }
00221 <font class="keywordflow">return</font> NULL;
00222 }
00223
00224 <font class="comment">/*</font>
00225 <font class="comment"> * Returns true if the specified displayer is attached to the log object</font>
00226 <font class="comment"> */</font>
<a name="l00227"></a><a class="code" href="classNLMISC_1_1CLog.html#a5">00227</a> <font class="keywordtype">bool</font> CLog::attached(IDisplayer *displayer)<font class="keyword"> const </font>
00228 <font class="keyword"></font>{
00229 <font class="keywordflow">return</font> (find( <a class="code" href="classNLMISC_1_1CLog.html#n3">_Displayers</a>.begin(), <a class="code" href="classNLMISC_1_1CLog.html#n3">_Displayers</a>.end(), displayer ) != <a class="code" href="classNLMISC_1_1CLog.html#n3">_Displayers</a>.end()) ||
00230 (find( <a class="code" href="classNLMISC_1_1CLog.html#n4">_BypassFilterDisplayers</a>.begin(), <a class="code" href="classNLMISC_1_1CLog.html#n4">_BypassFilterDisplayers</a>.end(), displayer ) != <a class="code" href="classNLMISC_1_1CLog.html#n4">_BypassFilterDisplayers</a>.end());
00231 }
00232
00233 <font class="keyword">static</font> string <a class="code" href="namespaceNLMISC.html#a195">TempString</a>;
00234 <font class="keyword">static</font> TDisplayInfo <a class="code" href="namespaceNLMISC.html#a196">TempArgs</a>;
00235
00236
<a name="l00237"></a><a class="code" href="classNLMISC_1_1CLog.html#b2">00237</a> <font class="keywordtype">void</font> CLog::displayString (<font class="keyword">const</font> <font class="keywordtype">char</font> *str)
00238 {
00239 <font class="keyword">const</font> <font class="keywordtype">char</font> *disp = NULL;
00240 TDisplayInfo localargs, *args = NULL;
00241
00242 <a class="code" href="classNLMISC_1_1CLog.html#d1">setDefaultProcessName</a> ();
00243
00244 <font class="keywordflow">if</font>(strchr(str,<font class="charliteral">'\n'</font>) == NULL)
00245 {
00246 <font class="keywordflow">if</font> (<a class="code" href="namespaceNLMISC.html#a195">TempString</a>.empty())
00247 {
00248 time (&<a class="code" href="namespaceNLMISC.html#a196">TempArgs</a>.Date);
00249 <a class="code" href="namespaceNLMISC.html#a196">TempArgs</a>.LogType = <a class="code" href="classNLMISC_1_1CLog.html#n0">_LogType</a>;
00250 <a class="code" href="namespaceNLMISC.html#a196">TempArgs</a>.ProcessName = *<a class="code" href="classNLMISC_1_1CLog.html#q0">_ProcessName</a>;
00251 <a class="code" href="namespaceNLMISC.html#a196">TempArgs</a>.ThreadId = <a class="code" href="namespaceNLMISC.html#a237">getThreadId</a>();
00252 <a class="code" href="namespaceNLMISC.html#a196">TempArgs</a>.Filename = <a class="code" href="classNLMISC_1_1CLog.html#n2">_FileName</a>;
00253 <a class="code" href="namespaceNLMISC.html#a196">TempArgs</a>.Line = <a class="code" href="classNLMISC_1_1CLog.html#n1">_Line</a>;
00254 <a class="code" href="namespaceNLMISC.html#a196">TempArgs</a>.CallstackAndLog = <font class="stringliteral">""</font>;
00255
00256 <a class="code" href="namespaceNLMISC.html#a195">TempString</a> = str;
00257 }
00258 <font class="keywordflow">else</font>
00259 {
00260 <a class="code" href="namespaceNLMISC.html#a195">TempString</a> += str;
00261 }
00262 <font class="keywordflow">return</font>;
00263 }
00264 <font class="keywordflow">else</font>
00265 {
00266 <font class="keywordflow">if</font> (<a class="code" href="namespaceNLMISC.html#a195">TempString</a>.empty())
00267 {
00268 time (&localargs.Date);
00269 localargs.LogType = <a class="code" href="classNLMISC_1_1CLog.html#n0">_LogType</a>;
00270 localargs.ProcessName = *<a class="code" href="classNLMISC_1_1CLog.html#q0">_ProcessName</a>;
00271 localargs.ThreadId = <a class="code" href="namespaceNLMISC.html#a237">getThreadId</a>();
00272 localargs.Filename = <a class="code" href="classNLMISC_1_1CLog.html#n2">_FileName</a>;
00273 localargs.Line = <a class="code" href="classNLMISC_1_1CLog.html#n1">_Line</a>;
00274 localargs.CallstackAndLog = <font class="stringliteral">""</font>;
00275
00276 disp = str;
00277 args = &localargs;
00278 }
00279 <font class="keywordflow">else</font>
00280 {
00281 <a class="code" href="namespaceNLMISC.html#a195">TempString</a> += str;
00282 disp = <a class="code" href="namespaceNLMISC.html#a195">TempString</a>.c_str();
00283 args = &<a class="code" href="namespaceNLMISC.html#a196">TempArgs</a>;
00284 }
00285 }
00286
00287 <font class="comment">// send to all bypass filter displayers</font>
00288 <font class="keywordflow">for</font> (CDisplayers::iterator idi=<a class="code" href="classNLMISC_1_1CLog.html#n4">_BypassFilterDisplayers</a>.begin(); idi!=<a class="code" href="classNLMISC_1_1CLog.html#n4">_BypassFilterDisplayers</a>.end(); idi++ )
00289 {
00290 (*idi)->display( *args, disp );
00291 }
00292
00293 <font class="comment">// get the log at the last minute to be sure to have everything</font>
00294 <font class="keywordflow">if</font>(args->LogType == <a class="code" href="classNLMISC_1_1CLog.html#s8s1">LOG_ERROR</a> || args->LogType == <a class="code" href="classNLMISC_1_1CLog.html#s8s6">LOG_ASSERT</a>)
00295 {
00296 <a class="code" href="namespaceNLMISC.html#a249">getCallStackAndLog</a> (args->CallstackAndLog, 4);
00297 }
00298
00299 <font class="keywordflow">if</font> (<a class="code" href="classNLMISC_1_1CLog.html#b1">passFilter</a> (disp))
00300 {
00301 <font class="comment">// Send to the attached displayers</font>
00302 <font class="keywordflow">for</font> (CDisplayers::iterator idi=<a class="code" href="classNLMISC_1_1CLog.html#n3">_Displayers</a>.begin(); idi!=<a class="code" href="classNLMISC_1_1CLog.html#n3">_Displayers</a>.end(); idi++ )
00303 {
00304 (*idi)->display( *args, disp );
00305 }
00306 }
00307 <a class="code" href="namespaceNLMISC.html#a195">TempString</a> = <font class="stringliteral">""</font>;
00308 <a class="code" href="classNLMISC_1_1CLog.html#b0">unsetPosition</a>();
00309 }
00310
00311
00312 <font class="comment">/*</font>
00313 <font class="comment"> * Display the string with decoration and final new line to all attached displayers</font>
00314 <font class="comment"> */</font>
<a name="l00315"></a><a class="code" href="classNLMISC_1_1CLog.html#a8">00315</a> <font class="keywordtype">void</font> CLog::displayNL (<font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>, ...)
00316 {
00317 <font class="keywordflow">if</font> ( <a class="code" href="classNLMISC_1_1CLog.html#a6">noDisplayer</a>() )
00318 {
00319 <font class="keywordflow">return</font>;
00320 }
00321
00322 <font class="keywordtype">char</font> *str;
00323 <a class="code" href="common_8h.html#a0">NLMISC_CONVERT_VARGS</a> (str, <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>, 256<font class="comment">/*NLMISC::MaxCStringSize*/</font>);
00324
00325 <font class="keywordflow">if</font> (strlen(str)<256<font class="comment">/*NLMISC::MaxCStringSize*/</font>-1)
00326 strcat (str, <font class="stringliteral">"\n"</font>);
00327 <font class="keywordflow">else</font>
00328 str[256<font class="comment">/*NLMISC::MaxCStringSize*/</font>-2] = <font class="charliteral">'\n'</font>;
00329
00330 <a class="code" href="classNLMISC_1_1CLog.html#b2">displayString</a> (str);
00331 }
00332
00333 <font class="comment">/*</font>
00334 <font class="comment"> * Display the string with decoration to all attached displayers</font>
00335 <font class="comment"> */</font>
<a name="l00336"></a><a class="code" href="classNLMISC_1_1CLog.html#a9">00336</a> <font class="keywordtype">void</font> CLog::display (<font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>, ...)
00337 {
00338 <font class="keywordflow">if</font> ( <a class="code" href="classNLMISC_1_1CLog.html#a6">noDisplayer</a>() )
00339 {
00340 <font class="keywordflow">return</font>;
00341 }
00342
00343 <font class="keywordtype">char</font> *str;
00344 <a class="code" href="common_8h.html#a0">NLMISC_CONVERT_VARGS</a> (str, <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>, 256<font class="comment">/*NLMISC::MaxCStringSize*/</font>);
00345
00346 <a class="code" href="classNLMISC_1_1CLog.html#b2">displayString</a> (str);
00347 }
00348
00349
<a name="l00350"></a><a class="code" href="classNLMISC_1_1CLog.html#b3">00350</a> <font class="keywordtype">void</font> CLog::displayRawString (<font class="keyword">const</font> <font class="keywordtype">char</font> *str)
00351 {
00352 <font class="keyword">const</font> <font class="keywordtype">char</font> *disp = NULL;
00353 TDisplayInfo localargs, *args = NULL;
00354
00355 <a class="code" href="classNLMISC_1_1CLog.html#d1">setDefaultProcessName</a> ();
00356
00357 <font class="keywordflow">if</font>(strchr(str,<font class="charliteral">'\n'</font>) == NULL)
00358 {
00359 <font class="keywordflow">if</font> (<a class="code" href="namespaceNLMISC.html#a195">TempString</a>.empty())
00360 {
00361 localargs.Date = 0;
00362 localargs.LogType = CLog::LOG_NO;
00363 localargs.ProcessName = <font class="stringliteral">""</font>;
00364 localargs.ThreadId = 0;
00365 localargs.Filename = NULL;
00366 localargs.Line = -1;
00367 localargs.CallstackAndLog = <font class="stringliteral">""</font>;
00368
00369 <a class="code" href="namespaceNLMISC.html#a195">TempString</a> = str;
00370 }
00371 <font class="keywordflow">else</font>
00372 {
00373 <a class="code" href="namespaceNLMISC.html#a195">TempString</a> += str;
00374 }
00375 <font class="keywordflow">return</font>;
00376 }
00377 <font class="keywordflow">else</font>
00378 {
00379 <font class="keywordflow">if</font> (<a class="code" href="namespaceNLMISC.html#a195">TempString</a>.empty())
00380 {
00381 localargs.Date = 0;
00382 localargs.LogType = CLog::LOG_NO;
00383 localargs.ProcessName = <font class="stringliteral">""</font>;
00384 localargs.ThreadId = 0;
00385 localargs.Filename = NULL;
00386 localargs.Line = -1;
00387 localargs.CallstackAndLog = <font class="stringliteral">""</font>;
00388
00389 disp = str;
00390 args = &localargs;
00391 }
00392 <font class="keywordflow">else</font>
00393 {
00394 <a class="code" href="namespaceNLMISC.html#a195">TempString</a> += str;
00395 disp = <a class="code" href="namespaceNLMISC.html#a195">TempString</a>.c_str();
00396 args = &<a class="code" href="namespaceNLMISC.html#a196">TempArgs</a>;
00397 }
00398 }
00399
00400 <font class="comment">// send to all bypass filter displayers</font>
00401 <font class="keywordflow">for</font> (CDisplayers::iterator idi=<a class="code" href="classNLMISC_1_1CLog.html#n4">_BypassFilterDisplayers</a>.begin(); idi!=<a class="code" href="classNLMISC_1_1CLog.html#n4">_BypassFilterDisplayers</a>.end(); idi++ )
00402 {
00403 (*idi)->display( *args, disp );
00404 }
00405
00406 <font class="comment">// get the log at the last minute to be sure to have everything</font>
00407 <font class="keywordflow">if</font>(args->LogType == <a class="code" href="classNLMISC_1_1CLog.html#s8s1">LOG_ERROR</a> || args->LogType == <a class="code" href="classNLMISC_1_1CLog.html#s8s6">LOG_ASSERT</a>)
00408 {
00409 <a class="code" href="namespaceNLMISC.html#a249">getCallStackAndLog</a> (args->CallstackAndLog, 4);
00410 }
00411
00412 <font class="keywordflow">if</font> ( <a class="code" href="classNLMISC_1_1CLog.html#b1">passFilter</a>( disp ) )
00413 {
00414 <font class="comment">// Send to the attached displayers</font>
00415 <font class="keywordflow">for</font> ( CDisplayers::iterator idi=<a class="code" href="classNLMISC_1_1CLog.html#n3">_Displayers</a>.begin(); idi!=<a class="code" href="classNLMISC_1_1CLog.html#n3">_Displayers</a>.end(); idi++ )
00416 {
00417 (*idi)->display( *args, disp );
00418 }
00419 }
00420 <a class="code" href="namespaceNLMISC.html#a195">TempString</a> = <font class="stringliteral">""</font>;
00421 <a class="code" href="classNLMISC_1_1CLog.html#b0">unsetPosition</a>();
00422 }
00423
00424 <font class="comment">/*</font>
00425 <font class="comment"> * Display a string (and nothing more) to all attached displayers</font>
00426 <font class="comment"> */</font>
<a name="l00427"></a><a class="code" href="classNLMISC_1_1CLog.html#a10">00427</a> <font class="keywordtype">void</font> CLog::displayRawNL( <font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>, ... )
00428 {
00429 <font class="keywordflow">if</font> ( <a class="code" href="classNLMISC_1_1CLog.html#a6">noDisplayer</a>() )
00430 {
00431 <font class="keywordflow">return</font>;
00432 }
00433
00434 <font class="keywordtype">char</font> *str;
00435 <a class="code" href="common_8h.html#a0">NLMISC_CONVERT_VARGS</a> (str, <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>, 256<font class="comment">/*NLMISC::MaxCStringSize*/</font>);
00436
00437 <font class="keywordflow">if</font> (strlen(str)<256<font class="comment">/*NLMISC::MaxCStringSize*/</font>-1)
00438 strcat (str, <font class="stringliteral">"\n"</font>);
00439 <font class="keywordflow">else</font>
00440 str[256<font class="comment">/*NLMISC::MaxCStringSize*/</font>-2] = <font class="charliteral">'\n'</font>;
00441
00442 <a class="code" href="classNLMISC_1_1CLog.html#b3">displayRawString</a>(str);
00443 }
00444
00445 <font class="comment">/*</font>
00446 <font class="comment"> * Display a string (and nothing more) to all attached displayers</font>
00447 <font class="comment"> */</font>
<a name="l00448"></a><a class="code" href="classNLMISC_1_1CLog.html#a11">00448</a> <font class="keywordtype">void</font> CLog::displayRaw( <font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>, ... )
00449 {
00450 <font class="keywordflow">if</font> ( <a class="code" href="classNLMISC_1_1CLog.html#a6">noDisplayer</a>() )
00451 {
00452 <font class="keywordflow">return</font>;
00453 }
00454
00455 <font class="keywordtype">char</font> *str;
00456 <a class="code" href="common_8h.html#a0">NLMISC_CONVERT_VARGS</a> (str, <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>, 256<font class="comment">/*NLMISC::MaxCStringSize*/</font>);
00457
00458 <a class="code" href="classNLMISC_1_1CLog.html#b3">displayRawString</a>(str);
00459 }
00460
00461
<a name="l00462"></a><a class="code" href="classNLMISC_1_1CLog.html#a12">00462</a> <font class="keywordtype">void</font> CLog::forceDisplayRaw (<font class="keyword">const</font> <font class="keywordtype">char</font> *<a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>, ...)
00463 {
00464 <font class="keywordflow">if</font> ( <a class="code" href="classNLMISC_1_1CLog.html#a6">noDisplayer</a>() )
00465 {
00466 <font class="keywordflow">return</font>;
00467 }
00468
00469 <font class="keywordtype">char</font> *str;
00470 <a class="code" href="common_8h.html#a0">NLMISC_CONVERT_VARGS</a> (str, <a class="code" href="driver__opengl__extension__def_8h.html#a398">format</a>, 256<font class="comment">/*NLMISC::MaxCStringSize*/</font>);
00471
00472 TDisplayInfo args;
00473
00474 <font class="comment">// Send to the attached displayers</font>
00475 <font class="keywordflow">for</font> ( CDisplayers::iterator idi=<a class="code" href="classNLMISC_1_1CLog.html#n3">_Displayers</a>.begin(); idi!=<a class="code" href="classNLMISC_1_1CLog.html#n3">_Displayers</a>.end(); idi++ )
00476 {
00477 (*idi)->display( args, str );
00478 }
00479 }
00480
00481
00482
00483 <font class="comment">/*</font>
00484 <font class="comment"> * Returns true if the string must be logged, according to the current filter</font>
00485 <font class="comment"> */</font>
<a name="l00486"></a><a class="code" href="classNLMISC_1_1CLog.html#b1">00486</a> <font class="keywordtype">bool</font> CLog::passFilter( <font class="keyword">const</font> <font class="keywordtype">char</font> *filter )
00487 {
00488 <font class="keywordtype">bool</font> yes = <a class="code" href="classNLMISC_1_1CLog.html#n8">_PositiveFilter</a>.empty();
00489
00490 <font class="keywordtype">bool</font> found;
00491 list<string>::iterator ilf;
00492
00493 <font class="comment">// 1. Positive filter</font>
00494 <font class="keywordflow">for</font> ( ilf=<a class="code" href="classNLMISC_1_1CLog.html#n8">_PositiveFilter</a>.begin(); ilf!=<a class="code" href="classNLMISC_1_1CLog.html#n8">_PositiveFilter</a>.end(); ++ilf )
00495 {
00496 found = ( strstr( filter, (*ilf).c_str() ) != NULL );
00497 <font class="keywordflow">if</font> ( found )
00498 {
00499 yes = <font class="keyword">true</font>; <font class="comment">// positive filter passed (no need to check another one)</font>
00500 <font class="keywordflow">break</font>;
00501 }
00502 <font class="comment">// else try the next one</font>
00503 }
00504 <font class="keywordflow">if</font> ( ! yes )
00505 {
00506 <font class="keywordflow">return</font> <font class="keyword">false</font>; <font class="comment">// positive filter not passed</font>
00507 }
00508
00509 <font class="comment">// 2. Negative filter</font>
00510 <font class="keywordflow">for</font> ( ilf=<a class="code" href="classNLMISC_1_1CLog.html#n7">_NegativeFilter</a>.begin(); ilf!=<a class="code" href="classNLMISC_1_1CLog.html#n7">_NegativeFilter</a>.end(); ++ilf )
00511 {
00512 found = ( strstr( filter, (*ilf).c_str() ) != NULL );
00513 <font class="keywordflow">if</font> ( found )
00514 {
00515 <font class="keywordflow">return</font> <font class="keyword">false</font>; <font class="comment">// negative filter not passed (no need to check another one)</font>
00516 }
00517 }
00518 <font class="keywordflow">return</font> <font class="keyword">true</font>; <font class="comment">// negative filter passed</font>
00519 }
00520
00521
00522 <font class="comment">/*</font>
00523 <font class="comment"> * Removes a filter by name. Returns true if it was found.</font>
00524 <font class="comment"> */</font>
<a name="l00525"></a><a class="code" href="classNLMISC_1_1CLog.html#a16">00525</a> <font class="keywordtype">void</font> CLog::removeFilter( <font class="keyword">const</font> <font class="keywordtype">char</font> *filterstr )
00526 {
00527 <font class="keywordflow">if</font> (filterstr == NULL)
00528 {
00529 <a class="code" href="classNLMISC_1_1CLog.html#n8">_PositiveFilter</a>.clear();
00530 <a class="code" href="classNLMISC_1_1CLog.html#n7">_NegativeFilter</a>.clear();
00531 <font class="comment">//displayNL ("CLog::addNegativeFilter('%s')", filterstr);</font>
00532 }
00533 <font class="keywordflow">else</font>
00534 {
00535 <a class="code" href="classNLMISC_1_1CLog.html#n8">_PositiveFilter</a>.remove( filterstr );
00536 <a class="code" href="classNLMISC_1_1CLog.html#n7">_NegativeFilter</a>.remove( filterstr );
00537 <font class="comment">//displayNL ("CLog::removeFilter('%s')", filterstr);</font>
00538 }
00539 }
00540
<a name="l00541"></a><a class="code" href="classNLMISC_1_1CLog.html#a17">00541</a> <font class="keywordtype">void</font> CLog::displayFilter( CLog &log )
00542 {
00543 <a class="code" href="classstd_1_1list.html">std::list<std::string></a>::iterator it;
00544 log.displayNL (<font class="stringliteral">"Positive Filter(s):"</font>);
00545 <font class="keywordflow">for</font> (it = <a class="code" href="classNLMISC_1_1CLog.html#n8">_PositiveFilter</a>.begin (); it != <a class="code" href="classNLMISC_1_1CLog.html#n8">_PositiveFilter</a>.end (); it++)
00546 {
00547 log.displayNL (<font class="stringliteral">"'%s'"</font>, (*it).c_str());
00548 }
00549 log.displayNL (<font class="stringliteral">"Negative Filter(s):"</font>);
00550 <font class="keywordflow">for</font> (it = <a class="code" href="classNLMISC_1_1CLog.html#n7">_NegativeFilter</a>.begin (); it != <a class="code" href="classNLMISC_1_1CLog.html#n7">_NegativeFilter</a>.end (); it++)
00551 {
00552 log.displayNL (<font class="stringliteral">"'%s'"</font>, (*it).c_str());
00553 }
00554 }
00555
<a name="l00556"></a><a class="code" href="classNLMISC_1_1CLog.html#a13">00556</a> <font class="keywordtype">void</font> CLog::addPositiveFilter( <font class="keyword">const</font> <font class="keywordtype">char</font> *filterstr )
00557 {
00558 <font class="comment">//displayNL ("CLog::addPositiveFilter('%s')", filterstr);</font>
00559 <a class="code" href="classNLMISC_1_1CLog.html#n8">_PositiveFilter</a>.push_back( filterstr );
00560 }
00561
<a name="l00562"></a><a class="code" href="classNLMISC_1_1CLog.html#a14">00562</a> <font class="keywordtype">void</font> CLog::addNegativeFilter( <font class="keyword">const</font> <font class="keywordtype">char</font> *filterstr )
00563 {
00564 <font class="comment">//displayNL ("CLog::addNegativeFilter('%s')", filterstr);</font>
00565 <a class="code" href="classNLMISC_1_1CLog.html#n7">_NegativeFilter</a>.push_back( filterstr );
00566 }
00567
<a name="l00568"></a><a class="code" href="classNLMISC_1_1CLog.html#a15">00568</a> <font class="keywordtype">void</font> CLog::resetFilters()
00569 {
00570 <font class="comment">//displayNL ("CLog::resetFilter()");</font>
00571 <a class="code" href="classNLMISC_1_1CLog.html#n8">_PositiveFilter</a>.clear();
00572 <a class="code" href="classNLMISC_1_1CLog.html#n7">_NegativeFilter</a>.clear();
00573 }
00574
00575 } <font class="comment">// NLMISC</font>
00576
</pre></div>
<!-- footer -->
<BR><FONT Size=+5> </FONT>
</TD>
<TD WIDTH=15><IMG SRC=/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD>
</TR>
</TABLE>
</BODY>
</HTML>
|