]> Creatis software - gdcm.git/blob - src/gdcmDebug.cxx
ENH: Guess what ! Still some cosmetic cleanup
[gdcm.git] / src / gdcmDebug.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDebug.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/08/01 02:39:09 $
7   Version:   $Revision: 1.4 $
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 gdcmDebug gdcmDebug::debug;
24
25 //-----------------------------------------------------------------------------
26 /**
27  * \brief   constructor
28  * @param level debug level
29  */ 
30 gdcmDebug::gdcmDebug(int level) 
31 {
32    DebugLevel = level;
33 }
34
35 /**
36  * \brief   Accessor
37  * @param   level Set the debug level
38  */ 
39 void gdcmDebug::SetDebug(int level) 
40 {
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 {
52    if (level > DebugLevel)
53    {
54       return ;
55    }
56    std::cerr << msg1 << ' ' << msg2 << std::endl;
57 }
58
59 /**
60  * \brief   Error 
61  * @param Test test
62  * @param Msg1 first message part
63  * @param Msg2 second message part 
64  */
65 void gdcmDebug::Error(bool test, const char * msg1, const char * msg2) 
66 {
67    if (!test)
68    {
69       return;
70    }
71    std::cerr << msg1 << ' ' << msg2 << std::endl;
72    Exit(1);
73 }
74
75 /**
76  * \brief   Error 
77  * @param Msg1 first message part
78  * @param Msg2 second message part
79  * @param Msg3 Third message part  
80  */
81 void gdcmDebug::Error(const char* msg1, const char* msg2,
82                       const char* msg3) 
83 {
84    std::cerr << msg1 << ' ' << msg2 << ' ' << msg3 << std::endl;
85    Exit(1);
86 }
87
88 /**
89  * \brief   Assert 
90  * @param Level level 
91  * @param Test test
92  * @param Msg1 first message part
93  * @param Msg2 second message part
94  */
95 void gdcmDebug::Assert(int level, bool test, const char * msg1, 
96                        const char * msg2) 
97 {
98    if (level > DebugLevel)
99    {
100       return ;
101    }
102    if (!test)
103    {
104       std::cerr << msg1 << ' ' << msg2 << std::endl;
105    }
106 }
107
108 /**
109  * \brief   Exit 
110  * @param a return code 
111  */
112 void gdcmDebug::Exit(int a) 
113 {
114 #ifdef __GNUC__
115    std::exit(a);
116 #endif
117 #ifdef _MSC_VER
118    exit(a);    // Found in #include <stdlib.h>
119 #endif
120 }
121
122 /**
123  * \brief  Get the debug instance 
124  * \return Reference to the debug instance
125  */
126 gdcmDebug &gdcmDebug::GetReference()
127 {
128    return gdcmDebug::debug;
129 }
130