OFFIS DCMTK
Version 3.6.0
Main Page
Related Pages
Classes
Files
File List
File Members
ofstd
include
dcmtk
ofstd
ofconsol.h
1
/*
2
*
3
* Copyright (C) 1999-2010, OFFIS e.V.
4
* All rights reserved. See COPYRIGHT file for details.
5
*
6
* This software and supporting documentation were developed by
7
*
8
* OFFIS e.V.
9
* R&D Division Health
10
* Escherweg 2
11
* D-26121 Oldenburg, Germany
12
*
13
*
14
* Module: ofstd
15
*
16
* Author: Marco Eichelberg
17
*
18
* Purpose: Define general purpose facility for console output
19
*
20
* class OFConsole and its global instance, ofConsole,
21
* provide access to the standard console output and error streams
22
* in a way that allows multiple threads to concurrently create output
23
* even if that output is redirected, e. g. to file or memory.
24
* Protection is implemented if the module is compiled with -DWITH_THREADS
25
* and is based on Mutexes.
26
*
27
* In cases where DCMTK is used for GUI development, the fact that the
28
* libraries send many error messages to the standard or error streams
29
* are annoying since these streams are not present in a GUI environment.
30
* Either the messages just go lost or they even cause the GUI
31
* application to fail. This file introduces aliases for the standard
32
* stream handles called COUT and CERR, which are normally only
33
* preprocessor macros for cout and cerr, respectively. If the
34
* toolkit is compiled with the flag DCMTK_GUI defined, however, these
35
* streams are created as OFOStringStream. This will allow a GUI based
36
* application to extract the messages and either present them to the
37
* user or store them in a log file.
38
*
39
* GUI based applications making use of this feature should periodically
40
* check and clear these streams in order to avoid increasing consumption
41
* of heap memory.
42
*
43
* Caveat 1: The DCMTK command line tools do not yet support the DCMTK_GUI
44
* flag, and will most likely exhibit all kinds of undesired behaviour
45
* if this flag is used.
46
*
47
* Caveat 2: The direct use of the COUT and CERR macros is unsafe
48
* in multithread applications. Use ofConsole instead.
49
*
50
* Last Update: $Author: joergr $
51
* Update Date: $Date: 2010-10-14 13:15:50 $
52
* CVS/RCS Revision: $Revision: 1.21 $
53
* Status: $State: Exp $
54
*
55
* CVS/RCS Log at end of file
56
*
57
*/
58
59
60
#ifndef OFCONSOL_H
61
#define OFCONSOL_H
62
63
#include "dcmtk/config/osconfig.h"
64
#include "dcmtk/ofstd/ofstream.h"
65
#include "dcmtk/ofstd/ofthread.h"
66
67
#define INCLUDE_CSTDLIB
68
#include "dcmtk/ofstd/ofstdinc.h"
69
70
79
class
OFConsole
80
{
81
public
:
82
85
virtual
~OFConsole
(){ }
86
91
STD_NAMESPACE ostream&
lockCout
()
92
{
93
#ifdef WITH_THREADS
94
coutMutex.lock();
95
#endif
96
return
*
currentCout
;
97
}
98
101
void
unlockCout
()
102
{
103
#ifdef WITH_THREADS
104
coutMutex.unlock();
105
#endif
106
}
107
113
STD_NAMESPACE ostream&
getCout
()
114
{
115
return
*
currentCout
;
116
}
117
129
STD_NAMESPACE ostream *
setCout
(STD_NAMESPACE ostream *newCout=NULL);
130
135
STD_NAMESPACE ostream&
lockCerr
()
136
{
137
#ifdef WITH_THREADS
138
cerrMutex.lock();
139
#endif
140
if
(
joined
)
141
{
142
#ifdef WITH_THREADS
143
coutMutex.lock();
144
#endif
145
return
*
currentCout
;
146
}
147
else
return
*
currentCerr
;
148
}
149
155
STD_NAMESPACE ostream&
getCerr
()
156
{
157
if
(
joined
)
return
*
currentCout
;
158
else
return
*
currentCerr
;
159
}
160
163
void
unlockCerr
()
164
{
165
#ifdef WITH_THREADS
166
if
(
joined
) coutMutex.unlock();
167
cerrMutex.unlock();
168
#endif
169
}
170
182
STD_NAMESPACE ostream *
setCerr
(STD_NAMESPACE ostream *newCerr=NULL);
183
190
void
join
();
191
198
void
split
();
199
205
OFBool
isJoined
();
206
210
static
OFConsole
&
instance
();
211
212
private
:
213
219
OFConsole
();
220
222
OFConsole
(
const
OFConsole
&arg);
223
225
OFConsole
&
operator=
(
const
OFConsole
&arg);
226
228
STD_NAMESPACE ostream *
currentCout
;
229
231
STD_NAMESPACE ostream *
currentCerr
;
232
234
int
joined
;
235
236
#ifdef WITH_THREADS
237
238
OFMutex
coutMutex;
239
241
OFMutex
cerrMutex;
242
#endif
243
244
// dummy declaration to keep gcc quiet
245
friend
class
OFConsoleDummyFriend;
246
};
247
248
252
#define ofConsole (OFConsole::instance())
253
254
/*
255
* definitions for COUT, CERR, CLOG.
256
*
257
* NOTE: DIRECT USE OF THESE MACROS IS UNSAFE IN MULTITHREAD APPLICATIONS.
258
*/
259
260
#ifdef DCMTK_GUI
261
262
extern
OFOStringStream COUT;
263
extern
OFOStringStream CERR;
264
265
#else
/* DCMTK_GUI */
266
267
#define COUT (ofConsole.getCout())
268
#define CERR (ofConsole.getCerr())
269
270
#endif
/* DCMTK_GUI */
271
272
#endif
/* OFCONSOL_H */
273
274
275
/*
276
*
277
* CVS/RCS Log:
278
* $Log: ofconsol.h,v $
279
* Revision 1.21 2010-10-14 13:15:50 joergr
280
* Updated copyright header. Added reference to COPYRIGHT file.
281
*
282
* Revision 1.20 2010-10-04 14:44:47 joergr
283
* Replaced "#ifdef _REENTRANT" by "#ifdef WITH_THREADS" where appropriate (i.e.
284
* in all cases where OFMutex, OFReadWriteLock, etc. are used).
285
*
286
* Revision 1.19 2006/08/14 16:42:26 meichel
287
* Updated all code in module ofstd to correctly compile if the standard
288
* namespace has not included into the global one with a "using" directive.
289
*
290
* Revision 1.18 2005/12/08 16:05:52 meichel
291
* Changed include path schema for all DCMTK header files
292
*
293
* Revision 1.17 2004/01/21 11:50:10 meichel
294
* Fixed DOS CR/LF in preprocessor directives
295
*
296
* Revision 1.16 2004/01/16 10:30:12 joergr
297
* Removed acknowledgements with e-mail addresses from CVS log.
298
*
299
* Revision 1.15 2003/12/17 17:38:39 meichel
300
* Changed definition of COUT and CERR macros to allow redirection to file.
301
*
302
* Revision 1.14 2003/12/05 10:37:41 joergr
303
* Removed leading underscore characters from preprocessor symbols (reserved
304
* symbols). Updated copyright date where appropriate.
305
*
306
* Revision 1.13 2002/11/27 11:23:05 meichel
307
* Adapted module ofstd to use of new header file ofstdinc.h
308
*
309
* Revision 1.12 2002/05/16 15:56:33 meichel
310
* Changed ofConsole into singleton implementation that can safely
311
* be used prior to start of main, i.e. from global constructors
312
*
313
* Revision 1.11 2002/05/16 08:16:44 meichel
314
* changed return type of OFConsole::setCout() and OFConsole::setCerr()
315
* to pointer instead of reference.
316
*
317
* Revision 1.10 2002/05/02 14:05:50 joergr
318
* Added support for standard and non-standard string streams (which one is
319
* supported is detected automatically via the configure mechanism).
320
*
321
* Revision 1.9 2002/04/16 13:36:02 joergr
322
* Added configurable support for C++ ANSI standard includes (e.g. streams).
323
*
324
* Revision 1.8 2001/06/01 15:51:33 meichel
325
* Updated copyright header
326
*
327
* Revision 1.7 2000/12/13 15:14:25 joergr
328
* Introduced dummy parameter for "default" constructor of class OFConsole
329
* to "convince" linker of gcc 2.5.8 (NeXTSTEP) to allocate memory for global
330
* variable 'ofConsole'.
331
*
332
* Revision 1.6 2000/10/10 12:01:21 meichel
333
* Created/updated doc++ comments
334
*
335
* Revision 1.5 2000/09/26 13:46:12 meichel
336
* Simplified inline code in ofconsol.h, required by Sun CC 2.x
337
*
338
* Revision 1.4 2000/06/21 15:47:54 meichel
339
* Including stdlib.h, required for Sun CC 4.2
340
*
341
* Revision 1.3 2000/04/14 15:41:40 meichel
342
* Added unprotected get methods, required for the cmdata debug facility.
343
*
344
* Revision 1.2 2000/04/14 15:16:08 meichel
345
* Added new class OFConsole and global instance ofConsole which provide
346
* access to standard output and error streams in a way that allows multiple
347
* threads to safely create output concurrently.
348
*
349
* Revision 1.1 2000/03/03 14:02:47 meichel
350
* Implemented library support for redirecting error messages into memory
351
* instead of printing them to stdout/stderr for GUI applications.
352
*
353
*
354
*/
Generated on Thu Dec 20 2012 for
OFFIS DCMTK
Version 3.6.0 by
Doxygen
1.8.2