]> Creatis software - gdcm.git/blob - src/gdcmDebug.cxx
ENH: Change the gdcmDebug approach. Remov the global static debug 'dbg'. And now...
[gdcm.git] / src / gdcmDebug.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDebug.cxx,v $
5   Language:  C++
6   Date:      $Date: 2005/01/07 16:26:12 $
7   Version:   $Revision: 1.14 $
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.html 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 namespace gdcm 
23 {
24
25 /// warning message level to be displayed
26 static int DebugLevel = -1;
27 //-----------------------------------------------------------------------------
28 /**
29  * \brief   Accessor
30  * @param   level Set the debug level
31  */ 
32 void Debug::SetDebugLevel (int level) 
33 {
34    DebugLevel = level;
35 }
36
37 /**
38  * \brief   Verbose 
39  * @param level level
40  * @param msg1 first message part
41  * @param msg2 second message part 
42  */
43 void Debug::Verbose(int level, const char *msg1, const char *msg2) 
44 {
45    if (level > DebugLevel)
46    {
47       return ;
48    }
49    std::cerr << "gdcm::" << msg1 << ' ' << msg2 << std::endl;
50 }
51
52 /**
53  * \brief   Error 
54  * @param test test
55  * @param msg1 first message part
56  * @param msg2 second message part 
57  */
58 void Debug::Error(bool test, const char *msg1, const char *msg2) 
59 {
60    if (!test)
61    {
62       return;
63    }
64    std::cerr << "gdcm::" << msg1 << ' ' << msg2 << std::endl;
65    Exit(1);
66 }
67
68 /**
69  * \brief   Error 
70  * @param msg1 first message part
71  * @param msg2 second message part
72  * @param msg3 Third message part  
73  */
74 void Debug::Error(const char *msg1, const char *msg2,
75                   const char *msg3) 
76 {
77    std::cerr << "gdcm::" << msg1 << ' ' << msg2 << ' ' << msg3
78              << std::endl;
79    Exit(1);
80 }
81
82 /**
83  * \brief   Assert 
84  * @param level level 
85  * @param test test
86  * @param msg1 first message part
87  * @param msg2 second message part
88  */
89 void Debug::Assert(int level, bool test, const char *msg1, 
90                    const char *msg2) 
91 {
92    if (level > DebugLevel)
93    {
94       return ;
95    }
96    if (!test)
97    {
98       std::cerr << "gdcm::" <<  msg1 << ' ' << msg2
99                 << std::endl;
100    }
101 }
102
103 /**
104  * \brief   Exit 
105  * @param a return code 
106  */
107 void Debug::Exit(int a) 
108 {
109    exit(a);    // Found in #include <stdlib.h>
110 }
111
112 } // end namespace gdcm