]> Creatis software - gdcm.git/blob - src/gdcmDebug.cxx
* Erroneous leading white fix:
[gdcm.git] / src / gdcmDebug.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDebug.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/06/20 18:08:47 $
7   Version:   $Revision: 1.2 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.htm for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18
19 #include <iostream>
20 #include "gdcmDebug.h"
21
22 /**
23  * \ingroup Globals
24  * \brief   Instance of debugging utility.
25  */
26 gdcmDebug dbg;
27
28 /**
29  * \brief   constructor
30  * @param level debug level
31  */ 
32 gdcmDebug::gdcmDebug(int level) {
33    DebugLevel = level;
34 }
35
36 /**
37  * \brief   Accessor
38  * @param   level Set the debug level
39  */ 
40 void gdcmDebug::SetDebug(int level) {
41    DebugLevel = level;
42 }
43
44 /**
45  * \brief   Verbose 
46  * @param Level level
47  * @param Msg1 first message part
48  * @param Msg2 second message part 
49  */
50 void gdcmDebug::Verbose(int Level, const char * Msg1, const char * Msg2) {
51    if (Level > DebugLevel)
52       return ;
53    std::cerr << Msg1 << ' ' << Msg2 << std::endl;
54 }
55
56 /**
57  * \brief   Error 
58  * @param Test test
59  * @param Msg1 first message part
60  * @param Msg2 second message part 
61  */
62 void gdcmDebug::Error( bool Test, const char * Msg1, const char * Msg2) {
63    if (!Test)
64       return;
65    std::cerr << Msg1 << ' ' << Msg2 << std::endl;
66    Exit(1);
67 }
68
69 /**
70  * \brief   Error 
71  * @param Msg1 first message part
72  * @param Msg2 second message part
73  * @param Msg3 Third message part  
74  */
75 void gdcmDebug::Error(const char* Msg1, const char* Msg2,
76                       const char* Msg3) {
77    std::cerr << Msg1 << ' ' << Msg2 << ' ' << Msg3 << std::endl;
78    Exit(1);
79 }
80
81 /**
82  * \brief   Assert 
83  * @param Level level 
84  * @param Test test
85  * @param Msg1 first message part
86  * @param Msg2 second message part
87  */
88  void gdcmDebug::Assert(int Level, bool Test,
89                  const char * Msg1, const char * Msg2) {
90    if (Level > DebugLevel)
91       return ;
92    if (!Test)
93       std::cerr << Msg1 << ' ' << Msg2 << std::endl;
94 }
95
96 /**
97  * \brief   Exit 
98  * @param a return code 
99  */
100 void gdcmDebug::Exit(int a) {
101 #ifdef __GNUC__
102    std::exit(a);
103 #endif
104 #ifdef _MSC_VER
105    exit(a);    // Found in #include <stdlib.h>
106 #endif
107 }